Unfortunately, the Fortran preprocessor doesn’t support the “##” syntax. However, the C/C++ preprocessor does, so if you don’t mind adding a preprocessing step to your build, you can do the following:
I think we’re stuck, at least for now. I’ve put a request in with engineering to add an option to pgprepro (our preprocessor which is envoked with -Mcpp) to disable whitespace collapsing. This is necessary for C but obviously not good if you want to preprocess Fortran with a fixed format. I’ve also requested that they update the pgf90 internal preprocessor so it can handle “##”. But, I’m not sure if this can done.
I’ve too many f77 style fortran subroutines (several hundred of thousand lines !!) and I need to find a solution with preprocessing files without rewriting them (like writing a simple perl preprocessor)
As a remark, I will say that I’m very disapointed with this compiler :
I think you will have trouble finding a standard preprocessor that takes the syntax you have. The latest C spec specifically talks about the C preprocessor, and says:
Merging of tokens to form new tokens in Standard C is controlled by the presence of a merging operator, ##, in macro definitions. … ## must not appear at the beginning or end of a replacement list…
Of course, Fortran has nothing to say about a preprocessor standard…
I did some research and found a solution. Instead of using “##” to concatentate do the following:
#define FS(X) fs_/**/X
The C style comments are removed after the “X” variable is replaced, thus causing the concatentation.
As for your other concerns. I believe Brent has found a soultion to your multiple python module issue and has posted a reponse to your previous post. (See here).
Fortran 90 compatability between major releases is a concern of us as well. Unfortunately in order continue advances in optimizations, we sometimes do need break compatability. However, since most Fortran libraries are written in F77, if you compile your libraries with pgf77 instead, you should not need to recompile.
We do appreciate your comments. Understanding our customers needs and helping them meet their goals is greatly important to us.
The /**/ can be used successfully instead of ## with pgf90 -Mpreprocess
Dealing with compilers, preprocessors, linker is a whole story (the one of my working life !!) when doing porting : we actually use fortran with c/c++ with python on solaris,irix64,hp-ux11,linux,aix1, …)
Thank’s a lot to both of you (I’m also replying to brentl in the other post)
The preprocessor in pgf90 (version 11.1.0) will leave the following:
#define NF_TYPE int
interface nfu_get_var
module procedure GET_VAR_D0
end interface
as:
interface nfu_get_var
module procedure get_var_##int## D0
end interface
However, if I use ‘pgf90 -Mcpp’ the output is correct.
interface nfu_get_var
module procedure get_var_intD0
end interface
Why is there a disconnect between the using ‘pgf90 -Mcpp’, and the standard pgf90 preprocessor (or ‘pgf90 -F’ and even ‘pgf90 -E’)? Also, is there a way to not do the ‘pgf90 -Mcpp’ first followed by the actual pgf90 compile?
Why is there a disconnect between the using ‘pgf90 -Mcpp’, and the standard pgf90 preprocessor
Legacy reasons. -Mcpp uses the C preprocessor, while the default is to use a Fortran preprocessor that takes into account Fortran issues (such as Fixed format).