1

I'm always using free form .f90 to write Fortran code, but now I have to use some fixed form .f code. As far as I know, a line continuation in the fixed format can be achieved by putting an arbitrary nonblank, nonzero symbol in column 6. So this first block should work

      x =
     &    1

and this second block would fail

      x = &
     &    1

I have the above conclusion proved by a simple demo code, both compiling with a Makefile and comping with Cmake. If using the first way, everything is good; if the second, compiler will report an error saying it can't understand the "&" after the equal sign.

Now what makes me puzzled is that I have a huge Fortran code in fixed form(.f) by someone else. What's used in this huge code for line continuation is like the second way(which seems not working to me). But the Makefile of that code managed to overcome this issue somehow. That code and Makefile is so large and complicated that I can't manage.

So my question is: How can I let the compiler go through the second way? What magic did the huge Fortran code do? Thanks for any hints.

Update:

I tried to use -ffree-form as suggested, but still get the same error. Here is the demo .f file and Makefile.

main.f

      PROGRAM main


      IMPLICIT NONE
        REAL        ::  x
        REAL        ::  y

        x =  &
     &      1
        WRITE(*,*) x

      END PROGRAM main

Makefile:

FC = gfortran
FCFLAGS = -ffree-form

SRCS = main.f
SOBJ = $(SRCS:.f=.o)
EXEC = $(SRCS:.f=)

all: $(EXEC)

%.o: %.f
    $(FC) $(FCFLAGS) -c $<
Ruizhi
  • 87
  • 10
  • 2
    the second for would work if the first ampersand is past column 72 (This is indeed a way to make dual fixed/free compatible continuation) – agentp Apr 29 '17 at 01:45
  • If you were using gfortran adding the option `-ffree-form` would compile the second code without errors. – builder-7000 Apr 29 '17 at 05:08
  • Rhe Makefile may be large, but the list of options used to compile one file will be limited. You should post that. And tell us which compiler do you use. – Vladimir F Героям слава Apr 29 '17 at 05:54
  • @agentp That's a good point! Thanks – Ruizhi Apr 29 '17 at 23:03
  • you do know if you generically tell the compiler all `.f` files are free form that will break other things. What are you actually trying to accomplish? – agentp Apr 30 '17 at 00:43
  • @agentp There's a project which has all the .f files. Besides, the ampersand use follow the second way and they are not past column 72. Using the original Makefile, the project is successfully compiled. I'm trying to use Cmake to rewrite the compiling procedure, but has the above error. – Ruizhi Apr 30 '17 at 02:38
  • When I use fixed form I use -fixed with ifort. I have never gotten -DD or -d-lines to work with free form. Gfortran should have a similar switch to do -fixed form. – Holmz Apr 30 '17 at 06:26

0 Answers0