2

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

4
  • Do you need -lnetcdf too? Oct 31, 2013 at 16:16
  • Thanks for the suggestion. I've tried with -lnetcdf, -lnetcdff and both together. I still get the same error.
    – TGraham
    Oct 31, 2013 at 16:29
  • The both together is meant to be the new way, according to a unidata message. What does nc-config --fflags --flibs say? Oct 31, 2013 at 16:37
  • 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 -lnetcdf
    – TGraham
    Oct 31, 2013 at 17:10

1 Answer 1

3

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.

1
  • Thanks for the suggestion again. I've already checked both of these. I accidentally set the path to the netcdf include file incorrectly at one point and the compilation failed at the USE netcdf line. I have also tried using a different compiler which then returns an error message stating that the netcdf library was built with a different compiler. I should add that I am able to compile and call this module in native fortran so it is a problem with using f2py rather than the fortran compilation itself.
    – TGraham
    Nov 1, 2013 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.