How to include header files in .F files

Hi,
This is a simple code I wrote to test how to include header files in .F code.
------------------- VORT_2D.F--------------------
program vort
#undef BL_LANG_CC
#ifndef BL_LANG_FORT
#define BL_LANG_FORT
#endif
#include “REAL.H”
implicit none
real v_ycen, v_xcen
real v_strength, v_width, v_cl_x
real xlo, xhi, ylo, yhi, delta1, delta2
v_strength = 25.
v_width = .001
v_cl_x = 0.0
v_xcen = 0.001
v_ycen = 0.007
write (,) v_strength
end program vort

----------------REAL.H---------------------------
#ifndef BL_REAL_H
#define BL_REAL_H
/*

  • $Id: REAL.H,v 1.14 2007/03/29 19:40:57 lijewski Exp $
    */
    #ifdef BL_USE_FLOAT

undef BL_USE_DOUBLE

undef BL_USE_FLOAT

/@ManDoc:
The macro BL_USE_FLOAT indicates that C++ floating-point
calculations should
use “float” variables and Fortran floating-point calculations should
use
"real
4" variables. One of BL_USE_FLOAT or BL_USE_DOUBLE must
always be
defined when compiling and using BoxLib.
*/

define BL_USE_FLOAT 1

#else

undef BL_USE_FLOAT

undef BL_USE_DOUBLE

/@ManDoc:
The macro BL_USE_DOUBLE indicates that C++ floating-point
calculations
should use “double” variables and Fortran floating-point
calculations
should use "real
8" variables. One of BL_USE_FLOAT or BL_USE
_DOUBLE must
always be defined when compiling and using BoxLib.
*/

define BL_USE_DOUBLE 1

#endif
#if !defined(BL_LANG_FORT)
/@ManDoc:
Real is a typedef specifying the precision of the floating-point
calculations in C++ code. It will be either float' or double’
depending upon which of the macros BL_USE_FLOAT or
BL_USE_DOUBLE, respectively, is defined during compilations. For
portability, you should write floating-point code in terms of this
typedef, instead of using float' or double’ directly.
Note that exactly one of these macros must be defined
when compiling any module that uses floating-point.
/
#ifdef BL_USE_FLOAT
typedef float Real;
#else
typedef double Real;
#endif
#else
/
@ManDoc:
The REAL_T macro specifies the precision of the floating-point
calculations in Fortran code. It will be either real*4' or real
8’ depending upon which of the symbols BL_USE_FLOAT or
BL_USE_DOUBLE, respectively, is defined during compilations. For
portability, you should write floating-point code in terms of this
macro, instead of using real*4' or real*8’ directly.
Note that exactly one of these macros must be defined
when compiling any module that uses floating-point.
*/
#ifdef BL_USE_FLOAT
#ifdef BL_USE_FORT_STAR_PRECISION

define REAL_T real*4

#else

define REAL_T REAL

#endif
#if STDC==1

define BL_REAL(a) a##E0

define BL_REAL_E(a,b) a##E##b

#else

define BL_REAL(a) a/**/E0

define BL_REAL_E(a,b) a//E//b

#endif
#else
#ifdef BL_USE_FORT_STAR_PRECISION

define REAL_T real*8

#else

define REAL_T DOUBLE PRECISION

#endif
#if STDC==1

define BL_REAL(a) a##D0

define BL_REAL_E(a,b) a##D##b

#else

define BL_REAL(a) a/**/D0

define BL_REAL_E(a,b) a//D//b

#endif
#endif
#endif /* !BL_LANG_FORT */
#endif /BL_REAL_H/

I submit the code as … pgf90 -fastsse -o exec VORT_2D.F
and the errors I get is …

PGF90-W-0025-Illegal character (#) - ignored (VORT_2D.F: 3)
PGF90-S-0034-Syntax error at or near end of line (VORT_2D.F: 3)
PGF90-W-0025-Illegal character (#) - ignored (VORT_2D.F: 4)
PGF90-S-0034-Syntax error at or near identifier ndefbl_lang_fort
(VORT_2D.F: 4)
PGF90-S-0034-Syntax error at or near integer constant 3567 (VORT_2D.F:
5)
PGF90-S-0034-Syntax error at or near integer constant 14 (VORT_2D.F:
6)
PGF90-W-0025-Illegal character (#) - ignored (VORT_2D.F: 8)
PGF90-S-0021-Label field of continuation line is not blank (./REAL.H:
1)
PGF90-S-0021-Label field of continuation line is not blank (./REAL.H:
2)
PGF90-S-0018-Illegal label field (./REAL.H: 4)
PGF90-S-0021-Label field of continuation line is not blank (./REAL.H:
5)
PGF90-S-0018-Illegal label field (./REAL.H: 6)
PGF90-S-0021-Label field of continuation line is not blank (./REAL.H:
8)
PGF90-S-0021-Label field of continuation line is not blank (./REAL.H:
9)
PGF90-S-0021-Label field of continuation line is not blank (./REAL.H:
10)
PGF90-S-0021-Label field of continuation line is not blank (./REAL.H:
11)
PGF90-S-0018-Illegal label field (./REAL.H: 12)
PGF90-W-0025-Illegal character () - ignored (./REAL.H: 12)
PGF90-S-0034-Syntax error at or near identifier _use (./REAL.H: 12)
PGF90-S-0018-Illegal label field (./REAL.H: 13)
PGF90-S-0021-Label field of continuation line is not blank (./REAL.H:
14)
PGF90-S-0021-Label field of continuation line is not blank (./REAL.H:
15)
PGF90-S-0021-Label field of continuation line is not blank (./REAL.H:
17)
PGF90-S-0021-Label field of continuation line is not blank (./REAL.H:
18)
PGF90-S-0021-Label field of continuation line is not blank (./REAL.H:
19)
PGF90-S-0021-Label field of continuation line is not blank (./REAL.H:
20)
PGF90-S-0021-Label field of continuation line is not blank (./REAL.H:
21)
PGF90-S-0034-Syntax error at or near (./REAL.H: 13)
PGF90-S-0018-Illegal label field (./REAL.H: 22)
PGF90-F-0008-Error limit exceeded (./REAL.H: 22)

Can someone please help me with this

The default for .F files is fixed format (labels in cols 1-5, cont. char in col 6, statement in cols 7-72, etc.).

You may either use the -Mfree compiler option, or rename your file to …F90, for which the default is free format.

Hi nbvasude,

What OS and compiler version are you using? Your code compiles fine for me on Linux and Windows (after adding “-Mfree”). You might also try adding “-Mpreprecess” since it appears that the preprocessor is not being invoked.

  • Mat

Hi

Thank you guys, the code is working now. I had to invoke the C pre-processor as
pgf90 -MFree fimename.F
and the code compiled.

Thanks a bunch!