Re: Reading multiple files

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Mon, 30 Mar 2009 14:36:21 -0600

Hi Michel

   Just as Jamie Scott suggested ... . addfiles is the "NCL way"
   Something like:

   fils_u = systemfunc ("ls u*.nc")
   fils_v = systemfunc ("ls v*.nc")
   fu = addfiles (fils_u, "r")
   fv = addfiles (fils_v, "r")

   ListSetType (f, "cat") ; concatenate (=default) no need to do
this
   u = fu[:]->U ; read U from all files
   v = fv[:]->V ; read V from all files

   printVarSummary(u) ; assuming (time,lat,lon) or (time,lev,lat,lon)
   printVarSummary(v)
;************************************************
; error checks: make sure sizes and times 'match'
;************************************************
   dims_u = dimsizes(u)
   dims_v = dimsizes(v)

   rank_u = dimsizes(dims_u)
   rank_v = dimsizes(dims_v)
  
   if (rank_u.ne.rank_v) then
       print("rank mismatch: rank_u="+rank_u+" rank_v="+rank_v)
       exit
   end if

   if (.not.all(dims_u.eq.dims_v)) then
       print("dimsizes mismatch: ")
       print(dims_u+" "+dims_v)
       exit
   end if

   if (.not.all(u&time .eq. v&time)) then
        print("times do not match: ")
        print(u&time+" "+v&time)
        exit
   end if

   ntim = dim_u(0) ; total number of times
;***************************************************
; Compute speed
;***************************************************
   spd = sqrt(u^2 + v^2) ; speed
   copy_VarCoords(u, spd) ; contributed.ncl
   spd_at_long_name = "speed"
   spd_at_units = u_at_units

    printVarSummary( spd )
;***************************************************
; Compute thresh hold countr at each grid point
;***************************************************

    spd_lo =
    spd_hi =

    if (rank_u.eq.3) then
         work = spd(lat|:,lon|:,time|:) ; dim_num works on the
right dimension
    else
         work = spd(lev|:,lat|:,lon|:,time|:)
    end if

     kspd = dim_num( work.ge.spd_lo .and. work.le.spd_hi ) ; type imteger
or
     kspd = 1.0*dim_num( work.ge.spd_lo .and. work.le.spd_hi ) ; type
float
     copy_VarCoords(work, kspd)

     kspd_at_long_name = "range count: lo="+spd_lo+" ; hi="+spd_hi
     kspd_at_units = "count: max would ne "+ntim

or, if type float and you want %

     kspd = (kspd/ntim)*100.
     kspd_at_units = "%"
   

   

Michel.Mesquita_at_bjerknes.uib.no 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
>

-- 
======================================================
Dennis J. Shea                  tel: 303-497-1361    |
P.O. Box 3000                   fax: 303-497-1333    |
Climate Analysis Section                             |
Climate & Global Dynamics Div.                       |
National Center for Atmospheric Research             |
Boulder, CO  80307                                   |
USA                        email: shea 'at' ucar.edu |
======================================================
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Mar 30 2009 - 14:36:21 MDT

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