This can be done in conjunction with conditional compilation and using the "D" option on the command line. Here is a sample code:
program test_Dopt character (len=1) :: pathsep pathsep = "?" #ifdef WOS pathsep = "\" #endif #ifdef UOS pathsep = "/" #endif write (*, '( "pathsep is >", A1, "<")' ) pathsep end program test_Dopt
Name the program with the F90 file to force gfortran to run the preprocessor or use -cpp on the compilation line. Then pass the parameters to the preprocessor, including them after D in the compilation line, for example gfortran -DWOS. (This is more general than gfortran — most Fortran compilers handle C-style preprocessor directives.) Then you can define the OS outside Fortran and pass the information to Fortran.
You can compile your code using a file like F90 or -cpp.
Msb
source share