Re: reading multiple files

From: Jamie Scott <James.D.Scott_at_nyahnyahspammersnyahnyah>
Date: Mon, 30 Mar 2009 14:02:03 -0600

Michel, here's how to read in a long time series from multiple files:

;;;;;;;;begin ncl code
diri ="/data/$USER/"

lat1=5.
lat2=16.5
lon1=250.
lon2=285.
;;
fils = systemfunc ("ls -x1 "+diri+"uwnd.*.nc") ; file paths
print("opening input "+fils)
f = addfiles (fils, "r")

ListSetType (f, "cat") ; concatenate (=default)

;200mb uwnd
invar = f[:]->uwnd(:,{200.},{lat1:lat2},{lon1:lon2})

lat=f[0]->lat({lat1:lat2})
lon=f[0]->lon({lon1:lon2})

invar!0="time"
invar!1="lat"
invar!2="lon"
;;
invar&lon=lon
invar&lat=lat

;;200mb vwnd

fils2 = systemfunc ("ls -x1 "+diri+"vwnd.*.nc") ; file paths
print("opening input "+fils2)
f2 = addfiles (fils2, "r")

ListSetType (f2, "cat") ; concatenate (=default)

invar2 = f2[:]->vwnd(:,{200.},{lat1:lat2},{lon1:lon2})

invar2!0="time"
invar2!1="lat"
invar2!2="lon"
;;
invar2&lon=lon
invar2&lat=lat

wspd=invar ;;;create new variable for speed with metadata from uwnd
wspd=sqrt(invar^2+invar^2)

;;;;;;;;;;;;;;;;end ncl code

On Mar 30, 2009, at 1:42 PM, ncl-talk-request_at_ucar.edu wrote:

> Hi,
>
> I have a question about reading multiple files. From a list of 100
> netcdf files (50 U
> wind and 50 V wind) I need to calculate the wind speed. Each of my
> files refers to a year
> of data (4x daily), for example, uwind.1950.nc, vwind.1950.nc and so
> on...
>
> After I compute the windspeed (sqrt(u2+v2)) for all years and for each
> timestep, I need
> to compute, per grid point, the number of 'events' in which the wind
> speed was between
> certain thresholds.
>
> This means that I need to calculate the wind speed and then
> concatenate/append each time
> step for all years. What is the 'NCL' way of doing that?
>
> Let's suppose I try the sequence:
>
> fili = systemfunc("ls *.nc")
> print(fili)
> nfili = dimsizes(fili)
> (A) emptymatrix = ??????
> do i=0,nfili-1
> (B) emptymatrix = ???? CONCATENATE/APPEND VALUES ????
> end do
>
> One way of doing that would be to create an empty matrix (as shown in
> A) and then to
> concatenate the new values (as shown in B). This way, I would have a
> new matrix which
> would contain wind speed data for all years (4x daily).
>
> Which would be the optimal procedure to do that in NCL?
>
> I thank you so much in advance!
>
> Regards,
>
> Michel
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Mar 30 2009 - 14:02:03 MDT

This archive was generated by hypermail 2.2.0 : Mon Apr 06 2009 - 14:56:31 MDT