f2py with fortran netcdf

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


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.

  • 链接地址: http://www.djcxy.com/p/96138.html

    上一篇: Python导入错误使用F2py

    下一篇: f2py与fortran netcdf