Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compiling .f vs .for files with g77

Status
Not open for further replies.

cluelesscompiler

Programmer
Aug 3, 2009
2
US
Hi.

I'm trying to compile some legacy code with g77 on a PC under the MinGW environment. When I compile the source file with a .f extension, it does not compile. I get a massive number of errors saying "zero-size array". It does not matter whther or not the array is singly or multiply indexed. The program makes heavy use of COMMON blocks, in which variables are dimensioned using integer variables, e.g.,

COMMON / ABC / A(N1), B(N2), C(N3)

where N1, N2, N3 are specified in an INCLUDE file. It seems as though the N1, N2, N3 values are not being applied to the variables in the common blocks.

The IINCLUDE file might look like this:

parameter (nxt = 150, nyt = 30, nzt = 80)
parameter (nsh = 50)
parameter (nhs = 1, nvs = 1, nbd = 1)
parameter (nxtm = nxt-1, nytm=nyt-1, nztm = nzt-1)
parameter (nmds = 12)
parameter (nmds2 = 2*nmds)
parameter (nhcs = 3)
parameter (nlt = 2*nyt + 2*nzt)
parameter (nmpt = 5, napt = 5)

A COMMON block might look like this:

common / bodybc / fbtnp(nxt,nyt,nbd), fbbnp(nxt,nyt,nbd)

and the error might look like:

captsdv25.f:9898:
common / bodybc / fbtnp(nxt,nyt,nbd), fbbnp(nxt,nyt,nbd)
^
Zero-size array at (^)
captsdv25.f:9898:
common / bodybc / fbtnp(nxt,nyt,nbd), fbbnp(nxt,nyt,nbd)
^
Zero-size array at (^)


Now here's what blows my mind. If I rename the source file to end with a .for extension, it compiles and executes just fine. Obviously I am missing something fundamental.

Can anyone help stop my spinning head?
 
In g77, .f is source, .F or .fpp or .FPP are preprocessed. At a guess, it is picking .f as .F and preprocessing the file.

1) Check that the extension is .f and not .F
2) If it is still .f then you can easily rename the whole lot with a dos command ren *.f *.for

I get the same problem in C++ when porting from Unix where .c is a C program and .C is a C++ program. In Windows, everything is .c.
 
OK, I begin to understand. Sadly, though, I'm not even sure what preprocessed means. Is there a two-line answer to what it is?

Thanks xwb.
 
g77 takes macro definitions like in C. These are non-standard so it is best to avoid them. These macros can be expanded by the g77 preprocessor and saved as .F.

You can use preprocessed files as include files in the program.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top