Hello.
(1) The easiest approach is to use the "netCDF Operators"
if they are available on your system. If so, "cd"
to the directory where the model files are located.
if the model files have a consistent prefix, say, "hist"
then
ncrcat -v TS hist*nc TS.nc
(2) NCL approach: What version of NCL do you have?
Just enter
ncl <return>
This will tell you the version number. The current
version is "4.2.0.a022" [Type "quit" to exit]
I'm assuming you have a version higher than 4.2.0.a012.
If so something like the following will work:
begin
diri = "......./" ; directory where files reside
fils = systemfunc ("ls "+diri+"hist*.nc")
f = addfiles (fils, "r") ; note the "s" of addfile
ListSetType (f, "cat") ; concatenate or "merge"
T = f[:]->TS
print (dimsizes(T)) ; T will have 60 time steps
T!0 = "time"
T!1 = "lev"
T!2 = "lat"
T!3 = "lon"
T&time = f[:]->time ; time coord variable
T&lev = f[0]->lev ; get lev from the 1st file
T&lat = f[0]->lat ; get lat from the 1st file
T&lon = f[0]->lon ; get lon from the 1st file
filo = "TS.nc"
system ("/usr/bin/rm "+filo) ; remove any pre-existing file
fo = addfile(filo , "c") ; open output file
fo@title = "TS from model files"
fo->TS = T ; write TS to a file
end
If you have a recent version of the user "contributed" library.
it is easier:
load "load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
begin
diri = "....../" ; directory where files reside
fils = systemfunc ("ls "+diri+"hist*.nc") ; file paths
f = addfiles (fils, "r") ; reference "list"
ListSetType (f, "cat") ; specify type of merge
TS = addfiles_GetVar (f, fils, "TS") ; contributed function
filo = "TS.nc"
system ("/usr/bin/rm "+filo) ; remove any pre-existing file
fo = addfile(filo , "c") ; open output file
fo@title = "TS from model files"
fo->TS = TS ; write TS to a file
end
I strongly urge all user to download the most recent version of NCL:
http://ngwww.ucar.edu/ncl/download.html
Regards,
Dennis Shea
>Date: Mon, 3 Dec 2001 08:24:57 -0600 (CST)
>From: Qiaozhen Mu <qiaozhen@utig.ig.utexas.edu>
>Subject: read from many files and write to only one netCDF file
>To: ncl-talk@UCAR.EDU
>MIME-Version: 1.0
>Content-MD5: CEYebB6oy3YlJnNiAJEQSQ==
>
>Dear all hands,
>
>I am running a climate model. There are many history files in netCDF format.
Now
>I want to read from many different history files, and get the same variable
>(such as TS) in different history files out to be in a same file (such as
>TS.nc). What can I do? Thanks in advance.
>
>Best regards,
>Qiaozhen
>
>***************************************
>*The University of Texas at Austin *
>*Institute for Geophysics *
>*4412 Spicewood Springs Rd., Bldg. 600*
>*Austin, Texas 78759-8500 *
>*phone:(512) 471-0462 *
>***************************************
>
This archive was generated by hypermail 2b29 : Sun Dec 09 2001 - 16:13:14 MST