Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

fpp preprocessor portability

Izaak_Beekman
New Contributor II
650 Views
I have just started using (and am somewhat enamored with) Intel's fpp preprocessor. I worry, however, that when I migrate my code (I am mostly using it for data post-processing codes which we run exclusively in-house) to another machine where the intel compiler is unavailable I will not be able to build my applications. Does anybody know a good resource to learn more about how to write portable Fortran code with pre-processing? I am trying to figure out how to create a robust object-oriented exception handling framework, and features like __FILE__ and __LINE__ are a convenient way to produce a pseudo stack trace. I am also planning on looking at PyF95++ and the standard Fortran library being developed there, but have not had a chance to do so yet.
0 Kudos
3 Replies
Ron_Green
Moderator
650 Views
FPP and Fortran preprocessing has been a topic of debate within the Fortran community for quite some time. On at least one occasion there was a concentrated effort to get a preprocess language definition into the Fortran Standard. To this date, though, there is no "standard" for FPP and it will vary by vendor.

We do see customers using cpp as their preprocessor. This does require an 'outside' processing step to run everything through CPP prior to invocation of the Fortran build. It's not very clean, and prone to errors. And CPP does vary somewhat, although the variations are much less severe than those in FPP variants.

I hadn't heard about PyF95++ before today. I pulled up their PDF paper describing the project. Very interesting, thanks for the tip.

ron
0 Kudos
mecej4
Honored Contributor III
650 Views
The source to a rather old version of fpp, from Sun, is available on Netlib ( http://netlib.sandia.gov/fortran/ ). See if that will serve your needs.

There will always be a handicap on pre-processors based on CPP, since C and Fortran have different line continuation rules; in fact, Fortran has now got two sets, with "free" format added. The interaction between these continuation rules and the allowing of multiple line macro expansions will probably cause bugs.

If you can keep your macros short and simple, you should be able to use fpp satisfactorily.
0 Kudos
TimP
Honored Contributor III
650 Views
If you haven't filled in mentally the gcc version of Ron's suggestion about external pre-processors, the following are equivalent, and frequently appear in Makefile rules:
gcc -E -traditional -x c yourfile.F > yourfile.f
gfortran -E yourfile.F > yourfile.f

These invoke tradcpp, which avoids treating // as a comment. If you don't use // as a Fortran operator, gcc -E may work without -traditional. Note that the option -x c treats any file name as C source code, so it's not limited to file names which gfortran would recognize.
0 Kudos
Reply