Re: nc_add_recs.m

Oops, here is the attachment.

--Dave

Dave Allured wrote:
This is easy to do in NCL. See attached NCL script. This demo makes a new Netcdf file with a 3D variable as you specified. By changing to "append mode" in the addfile statement, you could add the same kind of array to a pre-existing Netcdf file. Will an NCL solution work for you?

--Dave A.
CU/CIRES Climate Diagnostics Center (CDC)
NOAA/ESRL/PSD, Climate Analysis Branch (CAB)
http://www.cdc.noaa.gov/
Boulder, Colorado
303-497-6825

David Wang wrote:
Hello,

i've been scratching my head how to add a three-dimensional (time, lat, lon) variable into a netcdf file where time is the unlimited dimension and both lat and lon are dimensions of size 1. i work with matlab (nc_add_recs.m in snctools) but matlab doesn't allow trailing singleton dimensions. so while nc_add_recs.m (and nc_varput.m as well presumably) requires an input of rank 3, i'm not able to provide it an array of size (ntime, 1, 1). it's a pain in the neck. if there is any workaround out there, please give me a hint.

thanks,
david

===============================================================================
To unsubscribe netcdfgroup, visit:
http://www.unidata.ucar.edu/mailing-list-delete-form.html
===============================================================================


;-----------------------------------------------------------------------------
;
; singleton.ncl - Demo script to create a netcdf variable dimensioned (n,1,1).
; 2007-aug-03   Original version.  By Dave Allured.
;
; This version names the three dimensions, but does not define the
; coordinate arrays.  Creation of coordinate arrays is documented on
; the NCL website.
;
;-----------------------------------------------------------------------------

begin
   n = 3
   dims = (/ n, 1, 1 /)                         ; create a simple 3D array
   data = new (dims, "float")
   data(:,0,0) = (/ 11, 22, 33 /)
   
   data!0 = "time"                              ; name the three dimensions
   data!1 = "lat"
   data!2 = "lon"
   print (data)
   
   outfile = addfile ("out.nc", "c")            ; create a new Netcdf file
   
   time_name = "time"                   ; special to make unlimited dimension
   time_dummy_size = 0
   time_unlimited = True
   filedimdef (outfile, time_name, time_dummy_size, time_unlimited)
   
   outfile->var = data                          ; write data array and companion
                                                ; dimensions to the output file
end
  • 2007 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: