Re: Writing an irregular native grid to netCDF output

From: Dennis Shea (shea AT
Date: Mon Oct 17 2005 - 14:18:08 MDT

  • Next message: Fred Clare: "Re: info on converting NCL/NCARG images to other formats"

    >I'd like to write a native grid to netCDF output. I've
    >tried various combinations of attaching attributes
    >etc, to little avail. The file has been read in correctly;
    >ultimately the question is can I attach an array to
    >a coordinate variable?
    >Below is the fragment for attaching proper coords to
    >what was read in. lat2d and lon2d are both separate
    >arrays of 11000 unique lat and lon values
    >(native grid over the pole).
    >(This is from Dennis Shea's response to my
    >earlier question about getting the lat/lon
    >attached properly to the grid - it worked fine;
    >thank you Dennis).

    Preface comments:

    The NCL variable model is *based* upon the basic netCDF
    variable model. However, NCL's variable model has some
    extensions to the strict netCDF variable model.

      (a) NCL allows variables of type string.
          netCDF does not [character only].
      (b) NCL allows attributes to be multidimensional arrays
          netCDF requires attributes to be 1D arrays only.

      (c) Strict netCDF states that a "coordinate variable"
          is a one-dimensional array of monotonically
          {in/de}creasing values.
    The previous response for graphics took advantage of
    the (b). The gsn_csm* high level utilities recognize the
    "lat2d"and "lon2d" attributes names and does what is
    necessary to plot the data.

    >Generic appraoch
    >Say: x(lat,lon)
    > nlat = 100
    > mlon = 110
    > npts = nlat*mlon
    > ; assuming 2 col lat lon
    > ltln = asciiread("foo.LatLon", (/npts,2/), "float")
    > lat2d = onedtond(ltln(:,0), (/nlat,mlon/))
    > lat2d@units = "degrees_north"
    > lon2d = onedtond(ltln(:,1), (/nlat,mlon/))
    > lon2d@units = "degrees_east"
    > x@lat2d = lat2d
    > x@lon2d = lon2d
    >Any ideas? Perhaps it can't be done and I'll have
    >to have a separate lat/lon file, as the original data
    >were provided.

    Because the underlying netCDF software does not allow 2D
    attributes, the above could not be written to a netCDF file.
    The above lat2d/lon2d variables must be written as separate
    variables. Though they contain coordinates, they are not
    strict netCDF coordinate variables.

    There are more efficient ways to write netCDF in NCL
    but the following 'simple' approach works
    just fine if the number of variables and size of the
    file is smallish.

            diro = "./" ; output dir
            filo = "" ; output file name
            system ("/bin/rm -f "+diro+filo)
            fnc = addfile (diro+filo , "c")
            fnc@title = "...."
            fnc@creation_date = systemfunc("date")
            if (isatt(x,"lat2d")) then
            end if
            if (isatt(x,"lon2d")) then
            end if
            fnc->LAT = lat2d ; LAT(LAT,LON)
            fnc->LON = lon2D
            fnc->X = x
    good luck

    ncl-talk mailing list

    This archive was generated by hypermail 2b29 : Mon Oct 17 2005 - 22:14:21 MDT