1 / 12

Introduction to NetCDF

Introduction to NetCDF. Ernesto Munoz. Outline. Overview of NetCDF NetCDF file information CDL utilities: ncdump, ncgen Reading NetCDF file with Fortran with GrADS with Matlab Writing NetCDF file. What is NetCDF?. Network Common Data Form (NetCDF)

nansen
Download Presentation

Introduction to NetCDF

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to NetCDF Ernesto Munoz

  2. Outline • Overview of NetCDF • NetCDF file information • CDL utilities: ncdump, ncgen • Reading NetCDF file • with Fortran • with GrADS • with Matlab • Writing NetCDF file

  3. What is NetCDF? • Network Common Data Form (NetCDF) • An interface for (array-oriented) data access • A collection of libraries of data-access routines (for Fortran, C++, etc.) • A machine-independent format for scientific data • Developed at Unidata UCAR • More information at: • www.unidata.ucar.edu/software/netcdf/

  4. Positive Attributes of NetCDF • Self-describing – includes information about the data it contains • Portable - A machine-independent binary data format • Direct-access – can access efficiently a subset of the dataset

  5. NetCDF file contents • Dimensions Information about its name and length At most one unlimited dimension (i.e., a dimension with no maximum size) • Variables Information about its name, type, shape, attributes & values • Coordinate variable: 1-D array with the same name as its dimension (e.g., latitude) • Primary variable: the data • Fixed-length variable: primary variable with fixed dimensions • Record variable: primary variable with an unlimited dimension • Attributes –“metadata” Information about its name, type, values & length • Variable attributes • Global attributes

  6. Example of NetCDF file contents • Data values on a 2-D latitude/longitude grid • E.g., zonal and meridional wind data • Information about the dimensions • Latitudes, longitudes, vertical levels and times • The units of the data values • Scaling factor and offset to be applied to data

  7. CDL - Common Data Language • NetCDF ↔ ASCII translator • Its two main utilities: 1. ncdump (from netcdf to ascii) • to get overview of NetCDF file contents 2. ncgen (from ascii to netcdf) • to create NetCDF files • to create Fortran (or C) programs to write NetCDF files

  8. ncdump For quick glimpse at file’s “metadata” • To view header info: ncdump -h myfile.nc • To view header info plus values of coordinate variables: ncdump -c myfile.nc • To output data values in ascii form: ncdump –v varname myfile.nc

  9. Exercise Look at description of file with ncdump • Compare -c and -h options ncdump -h myfile.nc > filehdr.txt ncdump -c myfile.nc > filehdrdim.txt

  10. Reading NetCDF with Fortran Typical order of calls to read a NetCDF file NF_OPEN ! open NetCDF dataset . . . . . NF_INQ_DIMID ! get dimensions IDs . . . . . NF_INQ_DIMLEN ! get dimensions lengths . . . . . NF_INQ_VARID ! get variables IDs . . . . . NF_GET_ATT ! get attribute values . . . . . NF_GET_VAR ! get values of variables . . . . . NF_CLOSE ! close NetCDF dataset

  11. Reading NetCDF • With Matlab • Read Takemasa’s memo at: • http://www.atmos.umd.edu/~miyoshi/memorandum/memo_netcdf.html • With GrADS • Open GrADS with gradsnc command (instead of grads) • Open NetCDF file with sdfopen command (instead of open) • For more information refer to: http://grads.iges.org/grads/gadoc/SDFdescriptorfile.html

  12. Writing a NetCDF file with ncgen • ncgen can be used to: • Generate code that will produce a NetCDF file Fortran: ncgen -f mydata.cdl > mydata.f C: ncgen -c mydata.cdl > mydata.c • Generate a NetCDF file ncgen -o mydata.nc mydata.cdl • Best practices to writing NetCDF files: • www.unidata.ucar.edu/software/netcdf/docs/BestPractices.html

More Related