Re: time-slice

From: Nate Mikle <natemikle_at_nyahnyahspammersnyahnyah>
Date: Mon Mar 18 2013 - 09:01:26 MDT

Thanks Mary, that works very well.

Nate

On Sun, Mar 17, 2013 at 11:20 PM, Mary Haley <haley@ucar.edu> wrote:

> Hi Nate,
>
> You read a 2D subset of a variable off a file, converted it to a 1D array,
> and then wrote the 1D array to the file.
>
> By converting it to 1D this caused all the metadata to be stripped off.
> I'm not sure why you were converting it to 1D, but I don't think you want
> to do that.
>
> If you are just trying to write each timestep to a different file, then
> try something like this:
>
> gpp = a->GPP
> dims_gpp = dimsizes(gpp)
> ntime = dims_gpp(0) ; leftmost dimension
>
> do n=0,ntime-1
> filename = "day" + i + ".nc"
> system("rm -f " + filename)
> cout = addfile(filename,"c")
> cout->GPP = gpp(nt,:,:) ; This will write a 2D array to
> the file
> end do
>
> The metadata, including coordinate arrays (if any), should be preserved.
>
> If "GPP" on the file had a time coordinate array, then when you subscript
> gpp, the subscripted array will now have an additional attribute called
> "time", with the appropriate value.
>
> --Mary
> On Mar 14, 2013, at 8:29 AM, Nate Mikle wrote:
>
> > Hello,
> >
> > I'm trying to write a simple script to output a new .nc file at each
> timestep. The data is 3 dimensional (time-365, lat-354, lon-720). I am
> able to take a timeslice one at a time with the following script. The
> output has no metadata. How can I change this? Also, what would a "do
> loop" look like that would output a new file(365 files) with different
> names for every time (0:364)?
> >
> > Thanks,
> > Nate
> >
> > load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> > load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl
> > load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> > load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
> > a =
> addfile("/home/mikl6340/MsTMIP_Model/DLEM/BG1_DLEM_v2_daily_GPP_2000.nc","r")
> > b = a->GPP(0,:,:)
> >
> > c = ndtooned(b)
> > system("/bin/rm -f day1.nc") ; remove any pre-exist file
> > cout = addfile("day1.nc", "c") ; new netCDF file
> > cout@title = "day1"
> > cout->c = c
> > _______________________________________________
> > 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 Mar 18 09:01:41 2013

This archive was generated by hypermail 2.1.8 : Tue Mar 19 2013 - 16:31:18 MDT