how to use loop to read in multiple nc files

From: Ke Deng <kdeng1_at_nyahnyahspammersnyahnyah>
Date: Fri Oct 19 2012 - 11:25:12 MDT

Dear all,
I am computing the vertical integrated moisture transport (this is not the
point) and get the right code for that. But now I meet with one problem.
The data I use now are rhum.****.nc uwnd.****.nc vwnd.****.nc yearly
data.(60 nc files for each one so 180 nc files totally) The below code is
useful for one year data so the code is absolutely right. But now I want to
compute the moisture transport over 60 years (1948-2007). At first I used
the ncrcat command in linux to integrate the 60 nc files into one file but
when I run the code it displayed the segmentation fault. And then I used
the command systemfunc and addfiles in ncl to process that and also show
some errors. So the only reason is there are too many files and the
software can not see them as one big file to process. Now I am stuck here
and don't know how to write one loop to solve that. Please your response
will be appreciated! Thank u!

;***********************************************
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
;***********************************************
;read in netCDF file
;***********************************************
f1 = addfiles("rhum.1977.nc","r")
f2 = addfiles("uwnd.1977.nc","r")
f3 = addfiles("vwnd.1977.nc","r")
rhum = f1->rhum(:,:,:,:)
q = rhum/100+302.66
copy_VarCoords(rhum,q)
uwnd = f2->uwnd(:,0:7,:,:)
u = uwnd/100+202.66
copy_VarCoords(uwnd,u)
vwnd = f3->vwnd(:,0:7,:,:)
v = vwnd/100+202.66
copy_VarCoords(vwnd,v)

qu=q*u
qv=q*v
copy_VarCoords(q,qu)
copy_VarCoords(q,qv)

g = 9.81
q = qu+qv
copy_VarCoords(qu,q)

qint = dim_sum_Wrap(q(time|:,lat|:,lon|:,level|:)) ;*integration*******
Qint = dim_sum_Wrap(qint(lat|:,lon|:,time|:))
Qint = (Qint/g) ;***********weight by gravity****************
Qint@units = "kg/ms"
;************************************
; create the plot1
;************************************
wks=gsn_open_wks("ps","q")

res = True ; plot mods desired
res@tiMainString = "vertical integrated moisture transport" ;
main title
res@cnFillOn = True ; turn on color fill
plot = gsn_csm_contour_map(wks,Qint(:,:),res)

end

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Oct 19 11:25:36 2012

This archive was generated by hypermail 2.1.8 : Tue Oct 23 2012 - 11:10:04 MDT