[comp.lang.fortran] Preprocessing Fortran

silvert@cs.dal.ca (Bill Silvert) (07/10/90)

There has been a lot of traffic about Fortran preprocessors.  Here is a
more efficient way of handling at least some such matters than trying to
emulate C protocols.

Since Fortran is line oriented, you can deactivate a line with a
suitable comment sequence, which can be removed by sed(1).  For example,
the C-like code:

#ifdef EXTERNAL
	CALL XCODE
#endif

can be replaced by the single line:

CX	CALL XCODE

where CX can be removed by "sed 's/^CX/  /'".  I use this extensively
for Fortran code which has to be ported to a range of other platforms.

There are several advantages to this.

-  It is shorter.

-  It is clearer to users who do not use cc or m4.

-  You only need sed(1) as a preprocessor, and this is available from
   sources (such as the GNU distribution) which are free.

-  You can make the changes with any editor if desired.

-  The unpreprocessed code is valid Fortran and will compile.
-- 
William Silvert, Habitat Ecology Division, Bedford Inst. of Oceanography
P. O. Box 1006, Dartmouth, Nova Scotia, CANADA B2Y 4A2.  Tel. (902)426-1577
UUCP=..!{uunet|watmath}!dalcs!biomel!bill
BITNET=bill%biomel%dalcs@dalac	InterNet=bill%biomel@cs.dal.ca