NCL Home>
Application examples>
File IO ||
Data files for some examples
Example pages containing:
tips |
resources |
functions/procedures
NCL: Reading Supported Formats
There are several supported formats in NCL. Support for GRIB2 files was added in version 4.3.0.
- NetCDF
- GRIB1/GRIB2
- HDF4
- HDF-EOS
- CCM History tape (COS blocked only)
Pointers to supported format files
The NCL function
addfile is used to access supported format files. It takes
two arguments, the filename, and an action flag (e.g. "r" for read).
The filename must have a suffix that identifies the file format:
'.nc' for netCDF, '.grb' and '.grib' for GRIB, '.grb2' and '.grib2'
for GRIB2, '.hdf' for HDF Scientific Data Set,
'.hdfeos', '.he2', and '.he5' for HDF-EOS and '.ccm' for CCM History Tape.
addfile is a function, so it must be set equal to some variable. This
variable is the pointer to the file, and it will be used extensively.
Actual Script
begin
;************************************
; create pointer to several types of
; files. Note the syntax is the same
;************************************
in = addfile("./uv300.nc","r") ; netcdf
h = addfile("./S2000759.hdf","r") ; hdf
g1 = addfile("./monthly_1979_1151.tar.grb","r") ; grib1
g2 = addfile("./monthly_1979_1151.tar.grb2","r") ; grib2
;************************************
; read variable from the file
; no space between in and the variable name
;************************************
u = in->U ; on RHS, case sensitive
end
Many netCDF and HDF files store data originally of type
"float" or "double" as numeric type "short" or "byte".
The purpose of the file creator is to reduce the size
of the file. To accomplish this the original data are scaled
and offset. The function
pack_values located in contributed.ncl describes one approach. To unpack these
data use the short2flt
or the byte2flt function.
Actual Script
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
begin
in = addfile("./h500.nc","r") ; netcdf [,hdf]
h = short2flt( in->HGT ) ; HGT [short] , h [float]
printVarSummary( h )
end