Re: Average initial CLM dataset

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Fri, 19 Jun 2009 15:26:14 -0600

Get v5.1.1 ... recently released

Read Method 1
http://www.ncl.ucar.edu/Applications/o-netcdf.shtml

Use
http://www.ncl.ucar.edu/Document/Functions/Built-in/getfilevarnames.shtml
to get all the variable names

Thee following will be slow but easy

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

    system("/bin/rm -f foo.nc") ; remove any pre-existing file
    ncdf = addfile("foo.nc" ,"c") ; open output netCDF file

    f = addfiles (fils , "r") ; could also have ccm, grb or hdf suffux
    vNames = getfilevarnames (f(0)) ; get names of all variables on 1st
file
     
    nNames = dimsizes (vNames) ; number of variables on the file
     
    print (vNames) ; print all variable names on file

     ListSetType (f, "join") ; add ncl_join dimension
 
    do n=0,nNames-1 ; loop thru each variable
       v = f[:]->$vNames(n)$ ; read the variable to memory
      
       vAve = dim_avg_n_Wrap(vAve, 0) ; v5.1.1 average with meta data
      
       ncdf->$vNames(n)$ = vAve ; write to output nc file
              
       delete (v)
       delete (vAve)
   end do

Good Luck

Lei wrote:
> Hi Dennis,
> Thanks for your suggestions. One more question before I try to test
> it, if the initial datasets contain many variables, how can I make
> sure the new dataset file contains the same contents as the old
> dataset files. Thanks,
>
> Lei
>
> A sample of variables in the initial dataset is provided as follows,
> *****************
> variables:
> integer mcdate ( ncl_scalar )
> long_name : current date as 8 digit integer (YYYYMMDD)
>
> integer mcsec ( ncl_scalar )
> long_name : current seconds of current date
> units : s
>
> double grid1d_lon ( gridcell )
> long_name : gridcell longitude
> units : degrees_east
>
> double grid1d_lat ( gridcell )
> long_name : gridcell latitude
> units : degrees_north
>
> integer grid1d_ixy ( gridcell )
> long_name : 2d longitude index of corresponding gridcell
>
> integer grid1d_jxy ( gridcell )
> long_name : 2d latitude index of corresponding gridcell
>
> double land1d_lon ( landunit )
> long_name : landunit longitude
> units : degrees_east
>
> double land1d_lat ( landunit )
> long_name : landunit latitude
> units : degrees_north
>
> integer land1d_ixy ( landunit )
> long_name : 2d longitude index of corresponding landunit
>
> integer land1d_jxy ( landunit )
> long_name : 2d latitude index of corresponding landunit
>
> integer land1d_gi ( landunit )
> long_name : 1d grid index of corresponding landunit
>
> double land1d_wtxy ( landunit )
> long_name : landunit weight relative to corresponding gridcell
>
> integer land1d_ityplun ( landunit )
> long_name : landunit type (vegetated,urban,lake,wetland or
> glacier)
>
> double cols1d_lon ( column )
> long_name : column longitude
> units : degrees_east
>
> double cols1d_lat ( column )
> long_name : column latitude
> units : degrees_north
>
> integer cols1d_ixy ( column )
> long_name : 2d longitude index of corresponding column
>
> integer cols1d_jxy ( column )
> long_name : 2d latitude index of corresponding column
>
> integer cols1d_gi ( column )
> long_name : 1d grid index of corresponding column
>
> integer cols1d_li ( column )
> long_name : 1d landunit index of corresponding column
>
> double cols1d_wtxy ( column )
> long_name : column weight relative to corresponding gridcell
>
> double cols1d_wtlnd ( column )
> long_name : column weight relative to corresponding landunit
>
> integer cols1d_ityplun ( column )
> long_name : column landunit type
> (vegetated,urban,lake,wetland or glacier)
>
> double pfts1d_lon ( pft )
> long_name : pft longitude
> units : degrees_east
>
> double pfts1d_lat ( pft )
> long_name : pft latitude
> units : degrees_north
>
> integer pfts1d_ixy ( pft )
> long_name : 2d longitude index of corresponding pft
>
> integer pfts1d_jxy ( pft )
> long_name : 2d latitude index of corresponding pft
>
> integer pfts1d_gi ( pft )
> long_name : 1d grid index of corresponding pft
>
> integer pfts1d_li ( pft )
> long_name : 1d landunit index of corresponding pft
>
> integer pfts1d_ci ( pft )
> long_name : 1d column index of corresponding pft
>
> double pfts1d_wtxy ( pft )
> long_name : pft weight relative to corresponding gridcell
>
> double pfts1d_wtlnd ( pft )
> long_name : pft weight relative to corresponding landunit
>
> double pfts1d_wtcol ( pft )
> long_name : pft weight relative to corresponding column
>
> integer pfts1d_itypveg ( pft )
> long_name : pft vegetation type
>
> integer pfts1d_ityplun ( pft )
> long_name : pft landunit type
> (vegetated,urban,lake,wetland or glacier)
>
> double T_VEG ( pft )
> long_name : vegetation temperature
> units : K
>
> double T_GRND ( column )
> long_name : ground temperature
> units : K
>
> double EFLX_LWRAD_OUT ( pft )
> long_name : emitted infrared (longwave) radiation
> units : watt/m^2
>
> double H2OCAN ( pft )
> long_name : canopy water
> units : kg/m2
>
> double H2OSNO ( column )
> long_name : snow water
> units : kg/m2
>
>
>
>
> On Thu, Jun 18, 2009 at 6:14 PM, Dennis Shea <shea_at_ucar.edu
> <mailto:shea_at_ucar.edu>> wrote:
>
> [1]
> Use addfiles with "join"
> See Example 2
> http://www.ncl.ucar.edu/Document/Functions/Built-in/addfiles.shtml
>
> [2]
> If you have: x(column, levtot) on each file and you have (say) 4
> files
>
> you will have
> [ncl_join | 4] x [column | ?] x [levtot | ?]
>
> [3]
> avex = dim_avg_Wrap(x(column|:,levtot|:,ncl_join|:)) ; v5.1.0
>
> or, better, with 5.1.1
>
> avex = dim_avg_n_Wrap(x, 0)
>
> In eother case,
>
> avex(column,levtot)
>
> Possibly, you may also uecatse the netCDF operators [ncecat]
>
> Good luck
>
>
>
> Lei wrote:
>
> Hello,
> I am working on simulation of the impact of soil moisture on
> precipitation. I have used CAM-CLM3.0 to create a number of
> initial datasets ( such as camrun1.clm2.i.***.nc). I am trying
> to average variable values in the different initial datasets
> to a new initial dataset and have no idea on how to achieve
> this. The difficulties are: these initial datasets contain
> many variables and variable dimensions are like (column,
> levtot), not like (levtot, lat, lon). I would appreciate any
> suggestions or comments. Thank you!
>
> Lei
> Texas A&M University
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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 Fri Jun 19 2009 - 15:26:14 MDT

This archive was generated by hypermail 2.2.0 : Mon Jun 22 2009 - 15:36:10 MDT