Thank you so much, Adam!
It works now.
Francesc
________________________________
From: ncl-talk-bounces@ucar.edu [ncl-talk-bounces@ucar.edu] on behalf of Adam Phillips [asphilli@ucar.edu]
Sent: Tuesday, March 12, 2013 10:23 AM
To: ncl-talk@ucar.edu
Subject: Re: create a new time in a netcdf file and copy the values of the variable from another time to the new time created
Hi Francesc,
Yes, my script was able to write out the new .nc file. I just noticed that I had an exit statement in there that I forgot to remove that you should comment out. I also noticed that you were opening the original file specifying the read/write option (=w). That is not really necessary, so I changed the w -> r. I have also added a couple of copy_VarAtts calls to copy information from the old file/variable to the new file/variable, and attached the script and resulting .nc file here. (Note though, commenting out the exit statement from the script I sent yesterday should allow the .nc file to be written out as well..)
Adam
On 03/11/2013 03:47 PM, Montane Caminal, Francesc wrote:
Hi Adam,
Thanks for your help, but I still have some pending issues.
I do not get any error message this time and the code apparently works, but the problem is that it does not create the new netcdf file. Do you know why this happens? Is there any missing info in the code (perhaps something related with the time dimension)? Did you get the new netcdf after running the script?
I am using version 6.0.0.
Attached are the updated code that you sent me and the original data file in case you want to check again if you get the new netcdf file or not.
I would really appreciate your help.
Thanks,
Francesc
________________________________
From: ncl-talk-bounces@ucar.edu<mailto:ncl-talk-bounces@ucar.edu> [ncl-talk-bounces@ucar.edu<mailto:ncl-talk-bounces@ucar.edu>] on behalf of Adam Phillips [asphilli@ucar.edu<mailto:asphilli@ucar.edu>]
Sent: Monday, March 11, 2013 12:03 PM
To: ncl-talk@ucar.edu<mailto:ncl-talk@ucar.edu>
Subject: Re: create a new time in a netcdf file and copy the values of the variable from another time to the new time created
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<mailto: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 -- ______________________________________________________________ Adam Phillips asphilli@ucar.edu<mailto: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 Tue Mar 12 07:40:57 2013
This archive was generated by hypermail 2.1.8 : Wed Mar 13 2013 - 14:19:38 MDT