AMB@SLACVM.SLAC.STANFORD.EDU (02/14/91)
Does anyone know of any tools that ease the problem of porting fortran code across many platforms, for code that uses extensions to Fortran77? For example, hex data statements, some keywords in open statements, etc. differ from platform to platform. e.g. a hex data statement is DATA J/Z12345678/ on VSFORTRAN (IBM) DATA J/'12345678'X/ on VAX DATA J/Z'12345678'/ on NeXT One would like only a single master file, which has statements for all platforms, and preprocessors for conditionally compiling statements on each target platform. In C, there are compiler directives (#if, #else, etc) for this. Anyone have a method, or commercial product, for doing this to fortran? Adam Boyarski, Stanford Linear Accelerator Center.
rchrd@well.sf.ca.us (Richard Friedman) (02/16/91)
AMB@SLACVM.SLAC.STANFORD.EDU writes: >In C, there are compiler directives (#if, #else, etc) for this. >Anyone have a method, or commercial product, for doing this to fortran? On most systems the C preprocessor can be called directly (cpp ...), to give the same functionality for fortran. For example, on Cray UNICOS: cpp -P small_mdl.fig source.f > source.x.f cf77 -o myprog source.x.f Unfortunatly on UNICOS cf77 wont accept a pipe so you have to create an intermediate file from the output of cpp. Note the usage here, allowing the user to create "configuration files" (xyz.fig, say) which contain a set of definitions (in the example, perhaps small_mdl.fig is the set of defines to specify compilation of a small size model for source.f.. say). We are currently implementing this sort of "configuration control" scheme in our FORGE/MIMDizer product, thus allowing the user to maintain a variety of "flavors" of a source code within a single file. -- /\=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=/\ \/Richard Friedman (415)540-5216 | rchrd@well.sf.ca.us \/ /\Pacific-Sierra Rsrch (Berkeley) | or well!rchrd@apple.com /\ \/=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\/
dik@cwi.nl (Dik T. Winter) (02/16/91)
In article <23175@well.sf.ca.us> rchrd@well.sf.ca.us (Richard Friedman) writes: > AMB@SLACVM.SLAC.STANFORD.EDU writes: > >In C, there are compiler directives (#if, #else, etc) for this. > >Anyone have a method, or commercial product, for doing this to fortran? > > On most systems the C preprocessor can be called directly (cpp ...), > to give the same functionality for fortran. For example, on Cray UNICOS: > cpp -P small_mdl.fig source.f > source.x.f > cf77 -o myprog source.x.f > Beware, do not do this on *your* system, unless you are willing to thrash your source files. (Some of the cpp's I know can take two file parameters; it will process the first file and leave the output in the second, so in the example above source.f will be replaced by the result of cpp processing of small_mdl.fig. One of those systems is, surprise, Cray UNICOS.) The behaviour of cpp is extremely ill-defined. If you really want the C preprocessor for your Fortran sources you are entering a machine dependant domain. One of the following may work (or it may not), do some experiments. 1. /lib/cpp src.f | sed -e '/^#/d' > src.x.f 2. cc -E src.f | sed -e '/^#/d' > src.x.f 3. cp src.f src.c; cc -P src.c; mv src.i src.x.f; rm src.c Or perhaps some variation of this. However you will not be satisfied with the result on some systems (most notable: Cray UNICOS with the standard C compiler; it will destroy your program layout). If you want configuration control you should use include files using the C preprocessor syntax. -- dik t. winter, cwi, amsterdam, nederland dik@cwi.nl
ghe@physics.orst.edu (Guangliang He) (02/19/91)
In article <23175@well.sf.ca.us>, rchrd@well.sf.ca.us (Richard Friedman) writes: |> AMB@SLACVM.SLAC.STANFORD.EDU writes: |> |> >In C, there are compiler directives (#if, #else, etc) for this. |> >Anyone have a method, or commercial product, for doing this to fortran? |> |> On most systems the C preprocessor can be called directly (cpp ...), |> to give the same functionality for fortran. For example, on Cray UNICOS: |> |> cpp -P small_mdl.fig source.f > source.x.f |> cf77 -o myprog source.x.f [some text deleted here] On most unix workstation I've used (Sys V and BSD), f77 compiler support the cpp directives. You have to name your FORTRAN file file.F, notice the capital F. f77 will compile the .F file direct to .o then a.out. There is also a option in f77 to let you create .f file (After precessed by cpp). I find that it is very nice feature. Guangliang He ghe@physics.orst.edu