Re: writing netcdf

From: Mary Haley (haley AT ucar.edu)
Date: Mon Oct 03 2005 - 10:45:43 MDT

  • Next message: Micah Sklut: "oversized images"

    Hi Ben,

    The problem with your script is with these two separate lines:

          fnew(:,nnewlev:newnlev-1,:,:) = f(:,0:nlev-1,:,:)
          fnew(:,k,:,:) = f(:,0,:,:)

    These two lines effectively copy over the data as well as the metadata.
    So, the line:

          fnew(:,k,:,:) = f(:,0,:,:)

    is effectively copying the first "lev" value (f&lev(0)) to each of the
    "lev" values at position "k" (fnew&lev(k)). In this case, it's the
    first six values of the new "lev" coordinate array on the file.

    Copying the metadata is redundant because you've already gone through
    the trouble of defining the coordinates on the file, and you don't
    need to write them out again. So, replace the above two lines with:

          fnew(:,nnewlev:newnlev-1,:,:) = (/f(:,0:nlev-1,:,:)/)
          fnew(:,k,:,:) = (/f(:,0,:,:)/)

    and your "lev" values should remain intact. Putting "(/" and "/)" around
    your variable tells NCL to only copy the data values, and not the
    metadata.

    As for generalizing your script, I'll try to think more about this,
    and write you a separate email if I get a chance. Dennis Shea might
    also have some input on this.

    One other minor thing: you can actually assign double precision values
    directly without having to call the "new" statement first. So, the
    lines:

       newilev = new(newnlev,"double")
       newilev = (/ -10.,-9.5,-9.,-8.5,-8.,-7.5,-7.,-6.5,-6.,-5.5,-5.,-4.5,\
       -4.,-3.5,-3.,-2.5,-2.,-1.5,-1.,-0.5,0.,0.5,1.,1.5,2.,2.5,3.,3.5\
       ,4.,4.5,5.,5.5,6.,6.5,7. /)

    can be changed to:

       newilev = (/ -10.d,-9.5,-9.,-8.5,-8.,-7.5,-7.,-6.5,-6.,-5.5,\
         -5.,-4.5,-4.,-3.5,-3.,-2.5,-2.,-1.5,-1.,-0.5,0.,0.5,1.,\
         1.5,2.,2.5,3.,3.5,4.,4.5,5.,5.5,6.,6.5,7. /)

    (Note the 'd' after the "-10." is what flags this as a double.) You
    only need one of the numbers to have a "d" in it, and the whole thing
    will get promoted to double.

    Even better:

       newilev = 0.5d * ispan(-20,14,1)

    --Mary

    On Sun, 2 Oct 2005, Ben Foster wrote:

    >
    > Hi ncl:
    >
    > I am reading a netcdf file containing 4-d model data (time,lev,lat,lon),
    > and writing a new one, equivalent to the input file except with the bottom
    > boundary extended downward several levels (6 new levels in this case).
    >
    > My script (see attached) seems to be working ok so far, except that the
    > values on the output file of one of the two vertical coordinate variables
    > is incorrect. When I print the values of this coordinate var (lev(lev)) to
    > stdout from the script immediately after writing them to the output file,
    > they look fine, but an ncdump of the output file after script execution shows
    > wrong values. The other vertical coord var (ilev(ilev)) is correct on the
    > output file.
    >
    > To find where the problem is occurring in the script, please search on
    > "Ask ncl" in the attached script.
    >
    > My main problem is stated above, but as you can see, this is kind of a
    > brute force script, so I appreciate any suggestions about how to generalize
    > this, or make it more efficient.
    >
    > BTW, in case you want to try running the script, I have put the netcdf
    > input file on http://download.hao.ucar.edu/pub/foster/for_ncl
    > (a copy of the script is there too).
    >
    > Thanks for looking at this,
    >
    > --Ben
    >
    > -----------------------------------------------------------------------
    > Ben Foster High Altitude Observatory (HAO)
    > foster@ucar.edu phone: 303-497-1595 fax: 303-497-1589
    > Nat. Center for Atmos. Res. P.O. Box 3000 Boulder CO 80307 USA
    > -----------------------------------------------------------------------
    >
    _______________________________________________
    ncl-talk mailing list
    ncl-talk@ucar.edu
    http://mailman.ucar.edu/mailman/listinfo/ncl-talk



    This archive was generated by hypermail 2b29 : Mon Oct 03 2005 - 11:00:30 MDT