1
votes

I have a set of .f codes written to be compiled in gfortran and a Makefile which makes a program.

I would like to use as additional code, NewCode.f90, in this program but this is a .f90 and are written to be compiled using Ifort. I have written a make file so that it compiles all the codes in ifort as this is needed for NewCode.f90:

FC=ifort

ARCH = linux

include SYS.$(ARCH)

MYFLGS = -O0 -pg -g -fbounds-check -Wall -fbacktrace -finit-real=nan
LINKFLAGS = -L$(MKLROOT)
FFLAGS = $(MYFLGS) -I$(INCDIR) -static

.SUFFIXES: .o .f .c .f90

.f.o:
    $(FC) $(FFLAGS) -c $*.f
NewCode.o NewCode.f90:
    $(FC) $(FFLAGS) -ffree-form NewCode.f90 -c
.c.o:
    $(CC) $(CFLAGS) -c $*.c

OBJ =   code1.o code2.o code3.o NewCode.o

default:    nonlinear

nonlinear:  setnl Program

setnl:
/bin/rm -f *.o *.bak core par.h
/bin/ln -sf INCLUDE/nonlinear.par par.h

clean:
/bin/rm -f *.o *.bak core par.h
/bin/rm -rf ../bin/*

cleanarch:
/bin/rm -f *.o *.bak core par.h
/bin/rm -f $(INSTDIR)/program


program:    program.f program.o $(OBJ) par.h
            $(FC) $(FFLAGS) $(LINKFLAGS) -o $@ program.o $(OBJ) $(LIBS)  -Wl,--start-group -L$(MKLROOT)/lib/intel64 -lmkl_gf_ilp64 -lmkl_core -lmkl_sequential -Wl,--end-group -lpthread

When I make this file it runs into problems compiling the files written in (I think) fortran 70 using the ifort compiler. For example the program calls the IPARITY function:

FUNCTION IPARITY(l)
IMPLICIT REAL*4 (A-H, O-Z)

k = l/2
kk = 2*k - l
IF ( kk.EQ.0 ) THEN
  IPARITY = 1
ELSE
  IPARITY = -1
END IF
RETURN
END

Calling it as, for example:

PRINT *,IPARITY(1)

When I compile this program using gfortran this function is compiled and called without any problems however when I compile it with ifort there are problems. It appears the compiler expects IPARITY to be an array:

An array-valued argument is required in this context. 

I have tried compiling the files written in fortran 70 using gfortran and the files in fortran 90 using ifort but I have not managed to get this quite right:

COMP=ifort
ARCH=linux 
...
...
.f.o:
    $(FC) $(FFLAGS) -c $*.f
NewCode.o NewCode.f90:
    $(COMP) $(FFLAGS) -ffree-form NewCode.f90 -c
.c.o:
    $(CC) $(CFLAGS) -c $*.c
...
...
...
program: program.f program.o $(OBJ) par.h
            $(FC) $(FFLAGS) $(LINKFLAGS) -o $@ program.o $(OBJ) $(LIBS)  -Wl,--start-group -L$(MKLROOT)/lib/intel64 -lmkl_gf_ilp64 -lmkl_core -lmkl_sequential -Wl,--end-group -lpthread

However weather I put the combiner as:

program:    program.f program.o $(OBJ) par.h
            $(FC) ...

Or

program:    program.f program.o $(OBJ) par.h
            $(COMP) ...

I get errors in the .f90 and .f codes respectively.

I think that what is needed is either a tag in the makefile:

  .f.o:
  $(FC) $(FFLAGS) -c $*.f

Which will tell the compiler that it is reading fortran 70 code but still be compiled correctly. Or a flag in the combiner line which will allow the different codes compiled using different compilers to make the program together.

Any advice would be very welcome.

Thank you very much

James

1
What should "are written in .f90 and are written to be compiled using Ifort." exactly mean? - Vladimir F
The makefiles are probably irrelevant, post the source code. - Vladimir F
When I say "are written....." I mean that when the .f90 file is compiled using ifort if runs without any problems however when it is compiled using gfortran it has errors with some basic lines in the code. There is the example I gave in my question. Similarly the .f files run without an problems when I compile them with gfortran but break on simple lines reading arrays etc.. when they are compiled with IFORT. I originally thought that the "-ffree-form" command mean that the .f90 file could be compiled using gfortran but this does not seem to have done the trick. - James
POST SOME MORE COMPLETE CODE!!! Probably you are just missing EXTERNAL somewhere. - Vladimir F
I would bet the code is FORTRAN77, hence no implicit none available in standard. - Vladimir F

1 Answers

3
votes

Your code is still very incomplete, but I will at least try to guess from your snippet what is in the top secret rest.

Probably, you fail to declare IPARITY as EXTERNAL although you always should do that for external functions. There is different function called IPARITY in Fortran 2008 so the compiler thinks you want this one. To tell it you want your own external procedure declare it as EXTERNAL.

     EXTERNAL IPARITY
     integer iparity
     ...
     print *,IPARITY(4)

or use an interface block if you use Fortran 90 or newer

     interface
       integer function iparity(i)
         integer i
       end function
     end interface
     ...
     print *,IPARITY(4)

For all your future programs i strongly recommend to use at least Fortran 90 and use implicit none in all scopes. Also, by using modules you avoid these problems and get many other advantages.