[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Fwd: Example]
- Subject: Re: [Fwd: Example]
- Date: Thu, 03 Jun 2004 18:59:57 -0600
>To: Joanne Graham <address@hidden>
>From: "Sunwook Park" <address@hidden>
>Subject: Re: Example
>Organization: Meteorology, Iowa State University
>Keywords: Fortran example
Hi Sunwook,
The NetCDF Fortran Users Guide has many excerpts of example programs
showing how each function is called, but the only complete Fortran
examples we currently distribute in our source distribution are the
Fortran-90 example in src/f90/netcdf_test.f90 and the more complete
Fortran-77 test program in src/nf_test/nf_test.F. These test
creating new netCDF files and writing more than reading.
I've appended an excerpt from a Fortran-77 program I found on the Web
that looks like a pretty good example of reading a netCDF file when
you know the names of the variables (which you could determine with
the "ncdump" utility. If you are trying to read data from a netCDF
file but you don't know the names of the dimensions or variables, a
little more programming is required, but this is illustrated in the
Fortran User's Guide.
--Russ
_____________________________________________________________________
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu/staff/russ
PROGRAM CPEX16
C
C This program reads user data defining a global field of temperatures
C on what is called a POP grid.
include 'netcdf.inc'
C Dimension arrays to receive the data we want to look at. TLAT and
C TLON specify the positions of the centers of the POP grid boxes; the
C values in these arrays, as read from the source file, are in error
C near the North Pole, so this program recomputes some of the values.
C ULAT and ULON specify the positions of the corners of the POP grid
C boxes. TEMP specifies temperatures at the centers of the POP grid
C boxes.
C
DIMENSION TLAT(100,116),TLON(100,116)
DIMENSION ULAT(100,116),ULON(100,116)
DIMENSION TEMP(100,116)
C Open the "NetCDF" file.
ISTA=NF_OPEN('cpex16.dat.nc',0,NCID)
IF (ISTA.NE.NF_NOERR) THEN
PRINT * , 'ERROR RETURN FROM NF_OPEN: ',ISTA
PRINT * , NF_STRERROR(ISTA)
STOP
END IF
C Read the array of latitudes of cell centers.
ISTA=NF_INQ_VARID(NCID,'TLAT',IVID)
IF (ISTA.NE.NF_NOERR) THEN
PRINT * , 'ERROR RETURN FROM NF_INQ_VARID: ',ISTA
PRINT * , NF_STRERROR(ISTA)
STOP
END IF
ISTA=NF_GET_VAR_REAL(NCID,IVID,TLAT)
IF (ISTA.NE.NF_NOERR) THEN
PRINT * , 'ERROR RETURN FROM NF_GET_VAR_REAL: ',ISTA
PRINT * , NF_STRERROR(ISTA)
STOP
END IF
C Read the array of longitudes of cell centers.
ISTA=NF_INQ_VARID(NCID,'TLONG',IVID)
IF (ISTA.NE.NF_NOERR) THEN
PRINT * , 'ERROR RETURN FROM NF_INQ_VARID: ',ISTA
PRINT * , NF_STRERROR(ISTA)
STOP
END IF
ISTA=NF_GET_VAR_REAL(NCID,IVID,TLON)
IF (ISTA.NE.NF_NOERR) THEN
PRINT * , 'ERROR RETURN FROM NF_GET_VAR_REAL: ',ISTA
PRINT * , NF_STRERROR(ISTA)
STOP
END IF
C Read the array of latitudes of cell corner points.
ISTA=NF_INQ_VARID(NCID,'ULAT',IVID)
IF (ISTA.NE.NF_NOERR) THEN
PRINT * , 'ERROR RETURN FROM NF_INQ_VARID: ',ISTA
PRINT * , NF_STRERROR(ISTA)
STOP
END IF
ISTA=NF_GET_VAR_REAL(NCID,IVID,ULAT)
IF (ISTA.NE.NF_NOERR) THEN
PRINT * , 'ERROR RETURN FROM NF_GET_VAR_REAL: ',ISTA
PRINT * , NF_STRERROR(ISTA)
STOP
END IF
C Read the array of longitudes of cell corner points.
ISTA=NF_INQ_VARID(NCID,'ULONG',IVID)
IF (ISTA.NE.NF_NOERR) THEN
PRINT * , 'ERROR RETURN FROM NF_INQ_VARID: ',ISTA
PRINT * , NF_STRERROR(ISTA)
STOP
END IF
ISTA=NF_GET_VAR_REAL(NCID,IVID,ULON)
IF (ISTA.NE.NF_NOERR) THEN
PRINT * , 'ERROR RETURN FROM NF_GET_VAR_REAL: ',ISTA
PRINT * , NF_STRERROR(ISTA)
STOP
END IF
C Read the array of temperature values.
ISTA=NF_INQ_VARID(NCID,'TEMP',IVID)
IF (ISTA.NE.NF_NOERR) THEN
PRINT * , 'ERROR RETURN FROM NF_INQ_VARID: ',ISTA
PRINT * , NF_STRERROR(ISTA)
STOP
END IF
ISTA=NF_GET_VAR_REAL(NCID,IVID,TEMP)
IF (ISTA.NE.NF_NOERR) THEN
PRINT * , 'ERROR RETURN FROM NF_GET_VAR_REAL: ',ISTA
PRINT * , NF_STRERROR(ISTA)
STOP
END IF
C Close the "NetCDF" file.
ISTA=NF_CLOSE(NCID)
IF (ISTA.NE.NF_NOERR) THEN
PRINT * , 'ERROR RETURN FROM NF_CLOSE: ',ISTA
PRINT * , NF_STRERROR(ISTA)
STOP
END IF
END