Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28446 Discussions

Using NetCDF library with Intel Fortran

Matthew_Nicoll
Beginner
766 Views

This is just a description of how to port a CVF NetCDF-using Fortran program to IVF, so that someone can do it in less time than it took me!

I did this in Windows 7 with Intel Visual Fortran 16, working at the command line.

From web page: https://www.gfd-dennou.org/arch/ucar/netcdf/contrib/win32/
download files:
    netcdf-4.1.1-win32-bin.zip
    netcdf-4.1.1-win32-src.zip

From the bin zip file, you need files:
  hdf5dll.dll
  hdf5_hldll.dll
  netcdf.dll
  szip.dll
  zlib1.dll
  netcdf.lib

From the src zip file you may need file netcdf.inc

Your Fortran must either be compiled with the  /iface:cvf option OR
you must add a "!DIR$ATTRIBUTES CVF"  statement  in each of your netCDF-calling Fortran subroutines or functions, naming every netcdf function you call in that routine.   I did the latter, because I use other libraries which are NOT compiled with /iface:cvf.

Example:
 
       SUBROUTINE Open_NetCDF

!-------------------------------------------------------------------------------
!  Opens the NetCDF File for readind, initializes some dimension variables and
!  checks to see if input file is a multiple profile file.
!-------------------------------------------------------------------------------
      !DIR$ATTRIBUTES CVF :: NF_INQ, NF_OPEN

      INCLUDE 'argo2ios.inc'     ! which includes 'netcdf.inc'

      INTEGER       ndims,nvars,nGlobalAtts,unlimdimid,len
      INTEGER       trmlen      ! IOSLIB
      CHARACTER*100 upperc      ! IOSLIB

      status = NF_OPEN(inpfname,0, ncid)  ! open NetCDF file

      len = trmlen(inpfname)
      IF(status .ne. nf_noerr) THEN
        WRITE(outfnum,1000) inpfname(1:len)
 1000   FORMAT('0***ERROR: Error opening file: ',a)
      ENDIF

      status = NF_INQ(ncid, nDims, nVars, nGlobalAtts, unlimdimid)
<--- more code -->
      RETURN
      END

 

Linking:
ifort  my_main.obj my_subs.obj netcdf.lib otherlibs.lib

To run the executable, the DLL files listed above must be in the same folder.

 

0 Kudos
1 Reply
mecej4
Honored Contributor III
765 Views

There were a couple of threads that pertain to a more recent version (4.4.0) of NetCDF than the one that you used (4.1.1) :

     https://software.intel.com/en-us/comment/1816799

     https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/676006

     

0 Kudos
Reply