MEGAN 3.2 Error While Running and Compiling

Hello Everyone,
I want to run MEGANv3.2 and when I try to run pre-compiled executable files I get the following error:

error while loading shared libraries: libiomp5.so: cannot open shared object file: No such file or directory

I realized that this error is because the executable files were created using “ifort” compilers and my system supports “gfortran”. (I do not whether I am write or wrong about this)
Then I installed Intel OneAPI and tried to run the programs while setting LD_LIBRARY_PATH pointing to libiomp5.so library, and I got this error:

Please verify that both the operating system and the processor support Intel(R) MOVBE, F16C, FMA, BMI, LZCNT and AVX2 instructions.

Afterwards I tried to compile the programs by changing the compilers from ifort to gfortran. Here is what my makefile looks like after changing the FC:


SHELL=/bin/sh
PROGRAM= megcan
FC = gfortran
#FFLAGS= -O -Mvect=sse -Mextend -Msecond_underscore -Bstatic_pgi -Mlfs
#FFLAGS = -O3 –fixed -132 -traceback -qopenmp -xHost –Bstatic
FFLAGS = -O3 -fixed -132 -traceback -qopenmp -xHost -Bstatic
LIBS =   -L/home/fernando/Build_CMAQ/LIBRARIES/ioapi/lib -lioapi \
         -L/home/fernando/Build_CMAQ/LIBRARIES/netcdf/lib -lnetcdf -lnetcdff
INCLUDE = -I/home/fernando/Build_CMAQ/src/ioapi/ioapi/fixed_src \
          -I/home/fernando/Build_CMAQ/LIBRARIES/netcdf/include \
          -I$(CURDIR)/INCLDIR


OBJS = \
     checkmem.o \
     findlai.o  \
     $(PROGRAM).o

MODULES= *mod.f

#-----------------------------------------------------------------------
# line to allow file.mod files to be recognised by GNU make
%.o : %.mod
#-----------------------------------------------------------------------

.SUFFIXES : .f .f .o 

.f.o:
	$(FC) -c $(FFLAGS) $(INCLUDE) $<
.F.o:
	$(FC) -c $(FFLAGS) $(INCLUDE) $<

#-----------------------------------------------------------------------

$(PROGRAM):	$(OBJS)
	$(FC) $(FFLAGS) $(INCLUDE) -o $(@) $(OBJS) $(LIBS)

#-----------------------------------------------------------------------

clean:
	rm -f $(PROGRAM) *.o *.mod *.core
#-----------------------------------------------------------------------

And I got the following errors while performing “make” on this:

gfortran -c -O3 -fixed -132 -traceback -qopenmp -xHost -Bstatic -I/home/fernando/Build_CMAQ/src/ioapi/ioapi/fixed_src -I/home/fernando/Build_CMAQ/LIBRARIES/netcdf/include -I/home/fernando/megan32/MEGANv3.2_Dec_2021/src/MEGCAN/INCLDIR checkmem.f
gfortran: error: unrecognized command line option ‘-fixed’; did you mean ‘-ffixed-’?
gfortran: error: unrecognized command line option ‘-132’; did you mean ‘-m32’?
gfortran: error: unrecognized command line option ‘-traceback’
gfortran: error: unrecognized command line option ‘-qopenmp’; did you mean ‘-fopenmp’?
make: *** [makefile:29: checkmem.o] Error 1

After that I changed the FFLAGS to “FFLAGS = FFLAGS = -O3 -fopenmp -xHost -Bstatic” and got this error:

gfortran -c -O3 -fopenmp -xHost -Bstatic -I/home/fernando/Build_CMAQ/src/ioapi/ioapi/fixed_src -I/home/fernando/Build_CMAQ/LIBRARIES/netcdf/include -I/home/fernando/megan32/MEGANv3.2_Dec_2021/src/MEGCAN/INCLDIR checkmem.f
gfortran: error: language Host not recognized
gfortran: error: language Host not recognized
make: *** [makefile:29: checkmem.o] Error 1

I would really appreciate it if someone could help me with this problem. I am a beginner and I do not know much about this matter.
Thanks
Fer

Look at the I/O API Makeinclude.Linux2_x86_64gfort (see https://github.com/cjcoats/ioapi-3.2/blob/master/ioapi/Makeinclude.Linux2_x86_64gfort for compile-flags for gfortran (or if your gfortran is version 10 or later, look at Makeinclude.Linux2_x86_64gfort10).

2 Likes

Dear @cjcoats,
Thank you for your help. All the programs are compiled now without problem. There’s only an error which I do not think is related to compile-flags and this is the error:

gfortran -c -O3 -ffixed-line-length-132 -fopenmp -ffast-math -funroll-loops -m64 -I/home/fernando/Build_CMAQ/src/ioapi/ioapi/fixed_src -I/home/fernando/Build_CMAQ/LIBRARIES/netcdf/include -I/home/fernando/megan32/MEGANv3.2_Dec_2021/src/MET2MGN/INCLDIR met2mgn.f
gfortran -c -O3 -ffixed-line-length-132 -fopenmp -ffast-math -funroll-loops -m64 -I/home/fernando/Build_CMAQ/src/ioapi/ioapi/fixed_src -I/home/fernando/Build_CMAQ/LIBRARIES/netcdf/include -I/home/fernando/megan32/MEGANv3.2_Dec_2021/src/MET2MGN/INCLDIR readpar.f
readpar.f:15:15:

   15 |       parameter   nlat=61,nlon=121
      |               1
Warning: Legacy Extension: PARAMETER without '()' at (1)
readpar.f:184:132:

  184 |           do 200 i = 1,nx
      |                                                                                                                                    1
Warning: Fortran 2018 deleted feature: Shared DO termination label 200 at (1)
gfortran -c -O3 -ffixed-line-length-132 -fopenmp -ffast-math -funroll-loops -m64 -I/home/fernando/Build_CMAQ/src/ioapi/ioapi/fixed_src -I/home/fernando/Build_CMAQ/LIBRARIES/netcdf/include -I/home/fernando/megan32/MEGANv3.2_Dec_2021/src/MET2MGN/INCLDIR readmcip.f
readmcip.f:331:19:

  331 |           lfirst = .TRUE.
      |                   1
Warning: Extension: Conversion from LOGICAL(4) to INTEGER(4) at (1)
readmcip.f:333:19:

  333 |           lfirst = .FALSE.
      |                   1
Warning: Extension: Conversion from LOGICAL(4) to INTEGER(4) at (1)
readmcip.f:335:12:

  335 |         if (lfirst) then
      |            1
Error: IF clause at (1) requires a scalar LOGICAL expression
make: *** [makefile:43: readmcip.o] Error 1

This is the readmcip.f file that is causing the error: readmcip.f - Google Drive

There are a lot of things wrong with this code.

It doesn’t have IMPLICIT NONE (which I consider unacceptable for a production code).

lfirst should be declared as type LOGICAL:


     LOGICAL :: LFIRST

You didn’t include readpar.f, but… it should have something like

       INTEGER, parameter :: nlat=61
       INTEGER, parameter :: nlon=121

(or else should get these values from a DESC3 call)

Match beginning and ending of DO loops with END DO statements, e.g.,

          do j=1,ny
          do i=1,nx
                ...
          end do
          end do

M3ERR was declared obsolete in I/O API version prototype-0.5, roughly September 1992. It should be replaced by the correct M3WARN or M3EXIT calls.

The code should USE M3UTILIO instead of INCLUDEing the (obsolete as of I/O API 3.0, May 2004) I/O API INCLUDE-files.

ALLOCATE should be used with a STATUS argument, which should be checked to ensure that the code doesn’t blindly proceed in case of a failure.

The MESG arguments in the ENVYN calls are bogus.

The author clearly does not understand the I/O API DESC3 call.

[Code in this day and age ought to be written in Fortran (.f90) free source format, instead of in a non-Standard “fixed-132” format. Willem Vermin’s findent utility (https://sourceforge.net/projects/findent/) can be used to automate the conversion:


     findent i4 -k6 -ofree  -RR < foo.f > foo.f90
1 Like

Thank you so much @cjcoats for your elaborate instructions.

This existed in the readpar.f file as you have mentioned.
About the “LFIRST”, I tried implicit none which produced even more errors:

 -I/home/fernando/Build_CMAQ/src/ioapi/ioapi/fixed_src -I/home/fernando/Build_CMAQ/LIBRARIES/netcdf/include -I/home/fernando/megan32/MEGANv3.2_Dec_2021/src/MET2MGN/INCLDIR readmcip.f
readmcip.f:16:132:

   16 |       implicit none
      |                                                                                                                                    1
Error: IMPLICIT NONE statement at (1) cannot follow COMMON statement at (2)
readmcip.f:243:12:

  243 |         do i=1,nx
      |            1
Error: Symbol ‘i’ at (1) has no IMPLICIT type
readmcip.f:78:12:

   78 |       ietime = etime/100
      |            1
Error: Symbol ‘ietime’ at (1) has no IMPLICIT type; did you mean ‘etime’?
readmcip.f:77:12:

   77 |       istime = stime/100
      |            1
Error: Symbol ‘istime’ at (1) has no IMPLICIT type; did you mean ‘stime’?
readmcip.f:242:12:

  242 |         do j=1,ny
      |            1
Error: Symbol ‘j’ at (1) has no IMPLICIT type
readmcip.f:131:17:

  131 |         isoilm = INDEX1('SOIM1',NVARS3D,VNAME3D)
      |                 1
Error: Function ‘index1’ at (1) has no IMPLICIT type
readmcip.f:132:17:

  132 |         isoilt = INDEX1('SOIT1',NVARS3D,VNAME3D)
      |                 1
Error: Function ‘index1’ at (1) has no IMPLICIT type
readmcip.f:133:19:

  133 |         isoiltyp = INDEX1('SLTYP',NVARS3D,VNAME3D)
      |                   1
Error: Function ‘index1’ at (1) has no IMPLICIT type
make: *** [makefile:43: readmcip.o] Error 1

I tried this too, and it produced the same error.

Then I did something which don’t think is the right approach to these problems, but it worked. I changed “LFIRST” from logical to integer and changed the code to this:

        if((sdate+2000000).eq.jdate.and.(stime*100).eq.jtime) then
          lfirst = 100
        else
          lfirst = 50
        endif 
        if (lfirst==100) then

LFIRST is only used in this part of the code so I don’t think that there will be a problem with this change (I really have no idea whether I am write or wrong here).

I believe that if someone like you tells the MEGAN developers to change their codes to something which isn’t obsolete, they’ll probably listen to your words. I am just a simple user who wants to get his job done, but your experience in this field is something that they should try to listen to.

Again, thank you for your helps