preprocessor macros

I’m trying to make a program platform idependent by using a preprocessor macro.
I’m compiling with the -D option.
The compile line includes -D pgf=1.
Then the code for the subroutine used is :

subroutine file_closer
#ifdef pgf
use netcdf


end subroutine file_closer

I get the following errors when compiling:

pgf90 -c -g -D pgf=1 -Mnoframe -tp athlonxp -Ktrap=fp -Minfo=loop,inline -Minform,inform -I/usr/local/netcdf/include output_control.f90 -o output_control.o
PGF90-W-0025-Illegal character (#) - ignored (output_control.f90: 97)
PGF90-S-0034-Syntax error at or near identifier def (output_control.f90: 97)
PGF90-W-0025-Illegal character (#) - ignored (output_control.f90: 99)
PGF90-S-0070-Incorrect sequence of statements (output_control.f90: 101)
0 inform, 2 warnings, 2 severes, 0 fatal for file_closer

Anyone have any idea what is going on here?


There should not be any space between the “-D” and the “pgf=1”, i.e. “-Dpgf=1” instead of “-D pgf=1”.

Note that using “#ifdef pgf” only indicates if the macro is present, not what it’s value is. In otherwords, you don’t need the to set it to 1 and “-Dpgf” will work file. However, if you change “#ifdef pgf” to “#if pgf”, then the 1 is important since it must now evaluate to 1 in order for the if statement to be true.

Hope ths helps,

I tried that and it still doesn’t work. This is my exact compile command:

pgf90 -c -g -Dpgf=1 -Mnoframe -tp athlonxp -Ktrap=fp -Minfo=loop,inline -Minform,inform -I/usr/local/netcdf/include output_control.f90 output_control.o

If I leave the code like this:

subroutine file_closer

#ifdef pgf
use netcdf
use kinds
use sib_io_module

! local variables
integer(kind=int_kind) :: status

! close all output files
status = nf90_close( qp2id )
status = nf90_close( qp3id )
status = nf90_close( pbpid )
status = nf90_close( pbp2id )

end subroutine file_closer

I get this error:
PGF90-S-0021-Label field of continuation line is not blank (output_control.f90: 102)
PGF90-S-0021-Label field of continuation line is not blank (output_control.f90: 104)

Then if I tab the #ifdef and #endif statements, I get the error I posted in the original message( illegal character # and incorrect sequence of statements).
Any tips you could give me on this problem or some other sources would be fabulous! Thanks a bunch,
Erin C

Hi Erin,

I should have noticed the file extension before answering the first time. pgf90 automatically preprocesses files with the “.F” or “.F90” extention. For files with “.f” or “.f90”, you need to add the “-Mpreprocess” flag to enable preprocessing.

Hope this helps!

You were right! Thanks a bunch!!!

I am trying to compile and run Fortran in my Windows Vista with no success up to now. I have Cygwin and I use it as a kind of terminal. I tried typing in this:

login4% vim try1.f
login4% pgf95 -o try1 try1.f
PGF90-S-0021-Label field of continuation line is not blank (try1.f: 1)
PGF90-S-0021-Label field of continuation line is not blank (try1.f: 2)
PGF90-S-0018-Illegal label field (try1.f: 3)
PGF90-S-0022-Unexpected end of file - missing END statement (try1.f: 3)
0 inform, 0 warnings, 3 severes, 0 fatal for MAIN

BTW, when I make the try1.f file I write this:

program hello world
write(,)‘Hello world!’

Is there any advise you could give me on how to solve this problem? I am 99% sure the code is rigth, but then, what goes wrong? Is it the extension? Should I use a different command to compile? Or maybe I have not installed the right packages…

Hi Moe,

“.f” defaults to Fixed form. Looks like you’re using Free form. Either use the flag “-Mfree” or change your suffix to “.f90”.

Hope this helps,