This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
>To: address@hidden >From: "degui" <address@hidden> >Subject: netCDF Fortran (77 + 90) - F77 to read netcdf >Organization: UCAR/Unidata >Keywords: 200503081918.j28JIEM7012392 Hi Degui, > Do you have a sample code of Fortran to read netcdf file? I'm not sure whether you're interested in Fortran-77 or Fortran-90 code. Although the netCDF Fortran Users Guides: http://my.unidata.ucar.edu/content/software/netcdf/docs/netcdf-f77.html http://my.unidata.ucar.edu/content/software/netcdf/docs/netcdf-f90.html include example code fragments for every netCDF function call, complete self-contained example programs are sometimes more useful. A program general enough to read an arbitrary netCDF file (any dimensions, variables, and attributes) is relatively complex, so doesn't make a good example to learn from. There are some relatively good primers available such as "A first time primer for reading netCDF files": http://www.nodc.noaa.gov/woce_V2/disk10/html/ncprimer.htm and "Modeler's Introduction to NetCDF": http://hemulen.uchicago.edu/~tobis/ideas/ncdfx.html Consider a simple netCDF file that looks like this (using "CDL" to show the names, types, and shapes of variables, their attributes, and values): http://www.unidata.ucar.edu/packages/netcdf/examples/read1.cdl I've just whipped up a small Fortran-90 example for reading data from the above file: http://www.unidata.ucar.edu/packages/netcdf/examples/read1.f90 The corresponding netCDF file to read is: http://www.unidata.ucar.edu/packages/netcdf/examples/read1.nc You can generate netCDF example programs that write files using the "ncgen" utility and CDL files. For example, invoking ncgen -f read1.cdl will generate, on stdout, a Fortran-77 program that creates the read1.nc file above. Similarly, "ncgen -c" generates a C program and "ncgen -b" generates a binary netCDF file corresponding to a specified CDL file. Someday we hope to have more complete example programs for all the various netCDF interfaces ... --Russ _____________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu/staff/russ