问题
I inherited a fixed-format file FFTRUN.f The beginning of that files looks like this:
SUBROUTINE FFTRUN_2e
USE, intrinsic :: ISO_C_BINDING
USE FFTWmod, ONLY : FFTWplan_fwd, FFTWplan_inv, FFTWplanReady
INCLUDE 'INCL_PARAM.FOR'
INCLUDE 'INCL_PRATT.FOR'
INCLUDE 'INCL_XYZ.FOR'
INCLUDE 'FFTW3.f03'
PARAMETER (NDIM=2, NDAT=IMAX*JMAX)
DIMENSION NN(NDIM),DATA(NDAT)
COMPLEX*16 FACTR,SCATT(IMAX,JMAX),WAVINC,DATA
IF (.not.FFTWplanReady) THEN
FFTWplan_fwd = fftw_plan_dft_2d(nn2,nn1,data,data,
& FFTW_FORWARD,FFTW_MEASURE)
FFTWplan_inv = fftw_plan_dft_2d(nn2,nn1,data,data,
& FFTW_BACKWARD,FFTW_MEASURE)
ENDIF
I would compile it using
gfortran -c FFTRUN.f
however, it fails because fftw3.f03 is free form. Is there a way I can accomplish this include without having to reformat the fftw3.f03 to fixed-format?
This is a massive piece of software, so it's not possible for me to reformat the entire rest of the project which is fixed format.
回答1:
No. You'll probably make quicker progress by compiling the two sources separately and linking them together. Since you're already using Fortran 90 features such as use
this shouldn't cause you too much pain.
First, make sure that fftw3.f03
contains a module which itself contains the function(s) you want to use. Delete the include fftw3.f03
line and insert, with the other use
statements, the statement use fftw3_mod
(or whatever the module is called). Then modify your makefile to compile fftw3.f03
before it compiles fftrun.f
. That's about it.
回答2:
Source Code Useable for All Source Forms
To write source code that is useable for all source forms (free, fixed, or tab), follow these rules :
Blanks - Treat as significant (See Free Source Form ).
Statement labels - Place in column positions 1 through 5 (or before the first tab character).
Statements - Start in column position 7 (or after the first tab character).
Comment indicator - Use only! Place anywhere except in column position 6 (or immediately after the first tab character).
Continuation indicator - Use only &. Place in column position 73 of the initial line and each continuation line, and in column 6 of each continuation line (no tab character can precede the ampersand in column 6).
FROM : https://software.intel.com/en-us/node/510921
回答3:
gfortran has an option -ffree-form
. Look here
Two suggestions:
- Compile first only fftw3.f03 with
-ffree-form
option. Then compile the whole project as you usually do, but with with resulted object filefftw3.o
. - Compile the whole project with
-ffree-form
option.
来源:https://stackoverflow.com/questions/25021896/can-free-format-code-be-included-in-fixed-format-code