Re: How to create a dimension within a dimension

From: Wei Huang <huangwei_at_nyahnyahspammersnyahnyah>
Date: Mon Apr 28 2014 - 15:49:18 MDT

Try the script below.

Wei

---------------

 flnm = "my.nc"
 system("rm -f " + flnm)
 f = addfile(flnm, "c")

;Create some file attributes
 fAtt = True
 fAtt@title = "NCL generated file"
 fAtt@creation_date = systemfunc ("date")
 fileattdef(f, fAtt)

;We want to create a variable of one dimension:
;Define some parameters for dimension.
;===================================================================
;Define the file dimensions, NOTE that both dimensions are unlimited.
 DateStrLen = 19
 dimNames = (/"Time", "DateStrLen"/)
 dimSizes = (/ -1, DateStrLen/)
 dimUnlim = (/ True, False/)
 filedimdef(f, dimNames, dimSizes, dimUnlim)

;===================================================================
;Generate time coordinate variable.
 Times = new((/2, DateStrLen/), character)
 Times@name = "Times"
 Times@units = "start time 2014-04-28_15:39:15"
 filevardef(f, "Times", typeof(Times), dimNames)
 filevarattdef(f,"Times", Times)

;Create a character array is tedious, so we create strings first and convert strings to character array
 Timestr = new((/2/), string)
 Timestr(0) = "2014-04-28_15:39:15"
 Timestr(1) = "2014-04-28_16:39:15"

 Times = tochar(Timestr)

;Write out Times
 f->Times = (/Times/)

On Apr 28, 2014, at 11:48 AM, Tabish Ansari <tabishumaransari@gmail.com> wrote:

> Hi
>
> I have a netcdf file with variables in the following format:
>
> varname (Time, emissions_zdim, south_north, west_east)
>
> ​where ncdump -h on the file gives:
>
> dimensions:
> Time = UNLIMITED ; // (792 currently)
> emissions_zdim_stag = 1 ;
> south_north = 109 ;
> west_east = 99 ;
>
> Now I need to change this to :
>
> dimensions:
> Time = UNLIMITED ; // (792 currently)
> DateStrLen = 19 ;
> west_east = 99 ;
> south_north = 109 ;
> emissions_zdim = 1 ;
> variables:
> char Times(Time, DateStrLen) ;
> float E_ISO(Time, emissions_zdim, south_north, west_east) ;
> ​
>
> ​So, in short, I need to create a "Times" dimension which has further two dimensions:
>
> Times(0) = Time (unlimited/792)
> Times(1)​ = DateStrLen (19)
>
>
> ​How can I achieve this?​
>
> --
> Thanks & Regards
> Tabish Umar Ansari
> MS Research Scholar
> Environmental & Water Resources Engineering Division
> Department of Civil Engineering
> IIT Madras
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Apr 28 15:49:39 2014

This archive was generated by hypermail 2.1.8 : Tue Apr 29 2014 - 09:04:20 MDT