Howdy all!
I am in the midst of writing some functions to handle reading and
writing the dimensionless vertical coordinates listed in appendix D of
the CF document.
Many of these use scalar variables to hold reference values. For
example:
standard_name = "atmosphere_sigma_coordinate"
Definition:
p(n,k,j,i) = ptop + sigma(k)*(ps(n,j,i)-ptop)
where p(n,k,j,i) is the pressure at gridpoint (n,k,j,i), ptop is
the pressure at the top of the model, sigma(k) is the dimensionless
coordinate at vertical gridpoint (k), and ps(n,j,i) is the surface
pressure at horizontal gridpoint (j,i) and time (n).
The format for the formula_terms attribute is
formula_terms = "sigma: var1 ps: var2 ptop: var3"
In this case, PTOP is a scalar value.
If this were an attribute and not a variable, libcf could do more for
the user.
When setting up a sigma coordinate file with libcf, I do this:
/* Create a file and define four coordinate varibles, lat, lon,
* sigma level, and time. */
if (nc_create(FILE_NAME, 0, &ncid)) ERR;
if (nccf_def_latitude(ncid, NLAT, NC_FLOAT, &lat_did, &lat_vid)) ERR;
if (nccf_def_longitude(ncid, NLON, NC_FLOAT, &lat_did, &lat_vid)) ERR;
/* Before we can define a sigma level coordinate var/dim, we
* need to define two variables, the surface pressure and PTOP
* (a scalar).*/
dimids[0] = lat_did;
dimids[1] = lon_did;
if (nc_def_var(ncid, "ps", NC_FLOAT, 2, dimids, &ps_vid)) ERR;
if (nc_def_var(ncid, "PTOP", NC_FLOAT, 0, NULL, &ptop_vid)) ERR;
/* Now define sigma level coordinage var and dim. */
if (nccf_def_lvl_sigma(ncid, "sigma", NC_FLOAT, NLVL, ps_vid, ptop_vid,
&lvl_did, &lvl_vid)) ERR;
/* Now define the time coordinate. */
if (nccf_def_time(ncid, "time", NC_UNLIMITED, NC_FLOAT, TIME_UNITS,
"time", &lat_did, &lat_vid)) ERR;
As you can see, the function nccf_def_lvl_sigma takes the variable IDs
of the surface pressure variable (ps_vid), and the PTOP variable
(ptop_vid).
This works fine, but it is still up to the user to first create the
PTOP scalar variable, and then to remember to write a value to it
later, after leaving define mode.
If the PTOP were stored in an attribute, which I think would be more
natural in netCDF, then my function nccf_def_lvl_sigma could accept
the value itself, and write it into an attribute. Then the whole thing
could be better hidden from the user.
Can CF be adjusted to accept attribute names in addition to variable
names for the variables listed in formula_terms?
The ocean double sigma coordinate, for example, uses 4 scalar
variables.
Using attributes would simplify the implementation. Also, I think that
these values would fall under the category of attribute data rather
than variable data, in the netCDF model.
Thanks,
Ed
--
Ed Hartnett -- ed at unidata.ucar.edu
Received on Thu Oct 05 2006 - 08:30:38 BST