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

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Mon Mar 11 2013 - 11:03:22 MDT

Hi Francesc,
Yes, you can use Dennis' make_big functions here. I have updated your
script and attached it here. (I moved the functions to the top of the
script due to personal preference.) I think the error messages that you
were getting was due to the fact that TIME did not have an associated
coordinate variable, and you were writing it to the file when y2 had the
same dimension name TIME. This caused a mismatch of some sort.

Anyway, test my script to make sure it is doing what you think it is
doing. Note that I changed this:
xnew(3) = (/2717424/)
to this:
xnew(3) = (/x(dimx(0)-1)+3/) ; will add 3 to the last time value in the
original file

I don't know if you will always want to do that so you might need to
change the coding.

Hope that helps. If you have any further issues please let ncl-talk know.
Adam

On 03/08/2013 04:34 PM, Montane Caminal, Francesc wrote:
>
> 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

-- 
______________________________________________________________
Adam Phillips                                asphilli@ucar.edu
NCAR/Climate and Global Dynamics Division       (303) 497-1726
P.O. Box 3000				
Boulder, CO 80307-3000    http://www.cgd.ucar.edu/cas/asphilli


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

Received on Mon Mar 11 09:03:37 2013

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