Re: time-slice

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Sun Mar 17 2013 - 22:20:32 MDT

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.

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/","r")
> b = a->GPP(0,:,:)
> c = ndtooned(b)
> system("/bin/rm -f") ; remove any pre-exist file
> cout = addfile("", "c") ; new netCDF file
> cout@title = "day1"
> cout->c = c
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:

ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
Received on Sun Mar 17 22:20:46 2013

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