Search code examples
fortranpreprocessorcray

The correct way to introduce preprocessing directives into a Fortran code for the Cray compiler


Am trying to compile a Fortran code with the Cray compiler. I have a standard preprocessing ifdef block in the code:

#ifdef DEBUG
!  print extra info
#endif

Cray doesn't like this at all. It tells me

#ifdef DEBUG
^            
ftn-100 crayftn: ERROR BALANCE_DATA, File = balance_data.f90, Line = 9, Column = 1 
  This statement must begin with a label, a keyword, or an identifier.
#endif
^      
ftn-100 crayftn: ERROR BALANCE_DATA, File = balance_data.f90, Line = 11, Column = 1 
  This statement must begin with a label, a keyword, or an identifier.

Does anyone know how I can make the Cray compiler happy? (This code, BTW, compiles fine with intel and gcc.)


Solution

  • These macros are not part of standard Fortran. The compiler must be somehow told to execute a preprocessor (cpp or fpp or something custom, they do differ).

    For Cray you should use -e Z or use a capital F in the file extension. Always consult the manual for any new compiler. However, the manpage for crayftn is very incomplete, it does mention the option, but only indirectly. One must go into full documentation, for example in the link supplied by RussF.