add first time with make_big function

From: Montane Caminal, Francesc <fmontane_at_nyahnyahspammersnyahnyah>
Date: Fri Mar 22 2013 - 10:10:46 MDT

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).

I used 'make_big' function to add a new time at the end of the file (see script below and attached netcdf file). The new time added was 3-h after the last time in the original file and then the temperature value from time 2 was copied to the new time (new file dimensions (time, lat, lon): (4, 360, 720) with temperature values for all the times; thank you, Adam!).

Now I am trying to create the first time in the file (new time created 3-hour before the first time in the initial file), and then copy the temperature values from time 2 to the new time created. But I have problems because the last time has no temperature values. What is necessary to modify in the script below to add the first time instead of the last time with 'make_big' function? I guess that when creating a new time with the 'make_big' function the new time by default is created last instead of first in the new file. But I wonder how to deal with this if I am interested in creating the first time instead of the last time.

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

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"

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) = (/x(dimx(0)-1)+3/) ; will add 3 to the last time value in the original file
return(xnew)
end

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

begin
print("reading the variables")
a = addfile("cruncep_tairnew_2010_1x1_3h_2time.nc","r")
y1=a->y
TIME1=a->TIME
print("variables read")

time=make1_big(TIME1,4)
time!0 = "time"
time&time = time
copy_VarAtts(TIME1,time)

y2=make_big(y1,4)
copy_VarAtts(y1,y2)
;printVarSummary(y2)
exit

y2!0 = "time"
y2!1 = "lat"
y2!2 = "lon"

y2&time = time
y2&lat = y1&lat
y2&lon = y1&lon

fout=addfile("tair_2010_3h_4times_new.nc", "c")
copy_VarAtts(a,fout)
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 22 10:10:58 2013

This archive was generated by hypermail 2.1.8 : Thu Apr 04 2013 - 21:06:41 MDT