NCL Home >
Documentation >
Language
There are several ways you can restore this information
Each of these functions has a slightly different effect, so please see the documentation to determine which function is best for you. To access in a script, be sure to load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
Lost Coordinate Variables and Attributes
The use of NCL built-in functions strips away the original data's meta data such as coordinate variables and attributes.There are several ways you can restore this information
Use a copy function
Some useful functions for copying attributes include: copyatt , copy_VarCoords , copy_VarAtts.Each of these functions has a slightly different effect, so please see the documentation to determine which function is best for you. To access in a script, be sure to load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
begin
f = addfile ("dummy.nc", "r") ; pointer to file
x = f->X ; read in data
xZon = dim_avg (x) ; zonal average
copyatt(xZon, x) ; copy meta data
xZon@long_name = x@long_name + ": Zonal Average" ; change attribute
end
Use a Wrapper function
Dennis Shea has created numerous wrappers to many popular NCL functions. Retrieval and reassignment of the meta data is done within the wrapper.
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
begin
f = addfile ("dummy.nc", "r")
x = f->X
xZon = dim_avg_Wrap(x)
end
Use DIMENSION REDUCTION/collapsing
This can be very useful but does require some understanding of NCL dimensioning and variable-to-variable transfer.
begin
f = addfile ("dummyI.nc", "r")
x = f->X
xZon = x(:,:,:,0) ; xZon is 3D: "x" is collapsed
xZon = dim_avg (x) ; compute zonal average
end
The statement "xZon = x(:,:,:,0)" copies the "time", "lev", "lat"
coordinate variables and all attributes from x to xZon. At this point,
xZon is merely a subset of x. IMPORTANTLY, the values at the lon
subscript corresponding to 0 will also be copied. Since NCL knows it
is collapsing the longitude array, it automatically creates an
additional variable attribute to let the user know this. e.g.
"xZon@lon = lon(0)". This is very useful if you are doing this on
purpose, but since this attribute is an artifact of the "trick" we
are employing, we just delete it, so it doesn't confuse future or
present users of the data.