Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to NetCDF Ernesto Munoz. Outline Overview of NetCDF Overview of NetCDF NetCDF file information NetCDF file information CDL utilities: ncdump,

Similar presentations


Presentation on theme: "Introduction to NetCDF Ernesto Munoz. Outline Overview of NetCDF Overview of NetCDF NetCDF file information NetCDF file information CDL utilities: ncdump,"— Presentation transcript:

1 Introduction to NetCDF Ernesto Munoz

2 Outline Overview of NetCDF Overview of NetCDF NetCDF file information NetCDF file information CDL utilities: ncdump, ncgen CDL utilities: ncdump, ncgen Reading NetCDF file Reading NetCDF file with Fortranwith Fortran with GrADSwith GrADS with Matlabwith Matlab Writing NetCDF file Writing NetCDF file

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

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

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

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

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

8 ncdump For quick glimpse at file’s “metadata” To view header info: To view header info: ncdump -h myfile.nc To view header info plus values of coordinate variables: To view header info plus values of coordinate variables: ncdump -c myfile.nc To output data values in ascii form: 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 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_DIMID ! get dimensions IDs.......... NF_INQ_DIMLEN ! get dimensions lengths NF_INQ_DIMLEN ! get dimensions lengths.......... NF_INQ_VARID ! get variables IDs NF_INQ_VARID ! get variables IDs.......... NF_GET_ATT ! get attribute values NF_GET_ATT ! get attribute values.......... NF_GET_VAR ! get values of variables NF_GET_VAR ! get values of variables.......... NF_CLOSE ! close NetCDF dataset

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

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


Download ppt "Introduction to NetCDF Ernesto Munoz. Outline Overview of NetCDF Overview of NetCDF NetCDF file information NetCDF file information CDL utilities: ncdump,"

Similar presentations


Ads by Google