create a new time in a netcdf file and copy the values of the variable from another time to the new time created

From: Montane Caminal, Francesc <fmontane_at_nyahnyahspammersnyahnyah>
Date: Fri Mar 08 2013 - 16:34:09 MST

Hi,

Attached is a netcdf file that contains 3-h temperature data for 3 times. The file dimensions are (time, lat, lon): (3, 360, 720). What I need to do in this file is to create a new time (either at the beginning or at the end) and then copy the temperature values of one of the 3 available times (let’s say time 2 for instance) in the new created time. So, the new file should have dimensions (time, lat, lon): (4, 360, 720) with temperature values for all the times. The new time created should be either 3-h after the last time in the attached file (if the new time is created at the end of the file), or 3-h before the first time of the initial file (if the new time is created at the begining of the file).

Is it possible to do this in NCL? How can I do it for the attached netcdf file?

Dennis: some days ago you send a function called “make_big”, and I was trying to use this function to do this, but I got error messages (see script below). The error messages are related with coordinate variables for the time dimension. Do you know where the mistakes lie in the script? Is “make_big” the recommended way to proceed to do this or there are better options to create a new time and copy the variable values from another time to the new time created? Perhaps, there are problems related with the time units after creating a new time?

I really appreciate any help with this.
Thanks in adavance.

Sincerely,

Francesc

SCRIPT:

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"

begin

print("reading the variables")

a = addfile("cruncep_tairnew_2010_1x1_3h_2time.nc","w")

y1=a->y

TIME1=a->TIME

print("variables read")

 

 

function make1_big(x,d1big)

begin

dimx = dimsizes(x)

rankx= dimsizes(dimx)

if (rankx.ne.1) then

print("make_big: rankx="+rankx+": expecting rank=1")

exit

end if

xnew = new ( (/d1big/) \

,typeof(x), getFillValue(x))

xnew(0:dimx(0)-1) = (/ x /)

xnew(3) = (/2717424/)

return(xnew)

end

TIME2=make1_big(TIME1,4)

TIME2!0 = "TIME"

function make_big(x, d1big)

begin

dimx = dimsizes(x)

rankx= dimsizes(dimx)

if (rankx.ne.3) then

print("make_big: rankx="+rankx+": expecting rank=3")

exit

end if

xnew = new ( (/d1big, dimx(1) \

,dimx(2)/) \

,typeof(x), getFillValue(x))

xnew(0:dimx(0)-1,:,:) = (/ x /)

xnew(3,:,:) = xnew(1,:,:)

return(xnew)

end

 

y2=make_big(y1,4)

y2!0 = "TIME"

y2!1 = "lat"

y2!2 = "lon"

;y2&TIME = y1&TIME

y2&lat = y1&lat

y2&lon = y1&lon

 

fout=addfile("tair_2010_3h_4times_new.nc", "c")

fout->TIME=TIME2

fout->lon=a->lon

fout->lat=a->lat

fout->y=y2

 

end

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

Received on Fri Mar 8 14:34:24 2013

This archive was generated by hypermail 2.1.8 : Wed Mar 13 2013 - 14:19:38 MDT