2
votes

I'm trying to use f2py to compile some fortran code that makes use of netcdf libraries. The compilation appears to work but when I try to import the module in python I get the error message:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: ./cdfio_simple.so: undefined symbol: netcdf_mp_nf90_get_var_2d_fourbytereal_

There is also the following output during compilation:

In: :cdfio_simple:cdfio_simple.f90:cdfio_simple
get_useparameters: no module netcdf info used by cdfio_simple

The code I am trying to use is (note this is simplified code to demonstrate the problem):

MODULE cdfio_simple
 USE netcdf 

  PRIVATE
  PUBLIC  getvar

CONTAINS
  FUNCTION  getvar (cdfile,cdvar)

    CHARACTER(LEN=*), INTENT(in) :: cdfile,     &   ! file name
         &                          cdvar           ! variable 
    REAL(KIND=4), DIMENSION(1442,1021) :: getvar      ! 2D REAL

    !! * Local variables
    INTEGER :: ncid, id_var
    INTEGER :: istatus 
    CHARACTER(LEN=300) :: clvar

!f2py INTENT(in):: cdfile, cdvar

    clvar=cdvar

    istatus=NF90_OPEN(cdfile,NF90_NOWRITE,ncid) 

    istatus=NF90_INQUIRE(ncid,unlimitedDimId=id_dimunlim)
    istatus=NF90_INQ_VARID ( ncid,clvar,id_var)
    istatus=NF90_GET_VAR(ncid,id_var,getvar)

    istatus=NF90_CLOSE(ncid)
    getvar(:,:)=1

  END FUNCTION getvar

END MODULE cdfio_simple

To compile it I use the command:

f2py --fcompiler=intelem -c -I/usr/local/netcdf/include/ -L/usr/local/netcdf/lib -lnetcdff --f90flags=-fPIC -m cdfio_simple cdfio_simple.f90

Does anyone have an idea how I can get this to work correctly? Thanks in advance for any suggestions.

Tim

1
Do you need -lnetcdf too?Timothy Brown
Thanks for the suggestion. I've tried with -lnetcdf, -lnetcdff and both together. I still get the same error.TGraham
The both together is meant to be the new way, according to a unidata message. What does nc-config --fflags --flibs say?Timothy Brown
For the netcdf version I'm pointing to (compiled with ifort) it gives: -g -I/path/to/netcdf4/ifort/include -L/path/to/netcdf4/ifort_composerxe/lib -lnetcdff -lnetcdfTGraham

1 Answers

3
votes

The "no module netcdf" error message from the compiler may be an indication of either of the following problems:

  • There is no netcdf.mod module file installed in /usr/local/netcdf/include/, where it should have been installed as part of the installation of the netcdf-fortran software

  • You're using a different Fortran compiler than was used to create the netcdf.mod module file installed in that directory. Different Fortran compilers have different formats for the binary .mod files.