Re: Computing monthly-mean using daily data

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu, 07 Feb 2008 08:09:10 -0700

C/fortran ... any compiled language is generally faster than
interpreted languages. f90 is an array language so the following
is more like f90 than C.

Completely untested .... You could make a function out of this
if you want.

   nyrs = max(year)-min(year)+1
   ntim = nyrs*12

   MONAVG = ((/nyrs,12, nlat,mlon/), typeof(x), getFillValue(x))
or
   monavg = ( (/ntim,nlat,mlon/) typeof(x), getFillValue(x))

   nt = -1
   do nyr=0,nyrs-1
      do nmo=0,11
           i = ind(year(nyr).eq.year .and. month(nmo).eq.(nmo)+1)

           MONAVG(nyr,nmo,:,:) = dim_avg(lat|:,lon|:, time|i)
or
           nt = nt+1
           monavg(nt,:,:) = dim_avg(lat|:,lon|:, time|i)

           delete(i)
      end do
    end to

Christian Pagé wrote:
> Hello all,
>
> I am still a newbie regarding NCL advanced array functions and
> subscripting (I always think more in a C-like programming fashion).
> It is probably why I cannot find a proper way to do the following
> efficiently using NCL :
>
> Goal : compute monthly-mean using daily data...
>
> I have a CF-1.0 compliant NetCDF file with some daily-data 2D fields
> (time,x,y).
> I also have the time in a 1D vector in hours.
> I want to compute the monthly mean and variance and generate two
> monthly data fields.
>
> I already dealt with time :
> time = filein->time ; time:units = "hours
> since"
> TIME = ut_calendar(time, 0) ; type float
> year = floattointeger( TIME(:,0) )
> month = floattointeger( TIME(:,1) )
> day = floattointeger( TIME(:,2) )
>
> and I have my field, accessing it with : filein->dailyfield
>
> Now, the question is :
> Is there an efficient way to loop over time, and :
> - Find indices which belong to a specific month/year couple
> - Mean my field on all these indices
> - Mark this month/year couple as "done"
>
> as I don't know in advance :
> - the number of years in the input data
> - the number of months for each year in the input data (whole years
> are not in the same files)
>
> This can be done easily in C using standard loops and extra vectors to
> keep track of what has been done.
>
> Many thanks for any hints or solutions...! :)
>
> --
> Christian Pagé
> ------------------------------------------------------------------------
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> 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
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Feb 07 2008 - 08:09:10 MST

This archive was generated by hypermail 2.2.0 : Thu Feb 07 2008 - 08:58:57 MST