This function interpolates CCM2/3 hybrid coordinate data to pressure coordinates using pressure surfaces as the coordinate surface where the interpolation is done.
function vinth2p( datai[*][*][*] : float, hbcofa[*] : float, hbcofb[*] : float, plevo[*] : float, psfc[*][*] : float, intyp : integer, p0 : float, ilev : integer, kxtrp : logical )
The output variable from vinth2p will be a 3-dimensional field with the 0-th (leftmost dimension) being the same dimension as plevo [dimsizes(plevo)] and the next two dimensions being the same as in "datai." The function automatically creates the 3D space for the returned variable (the user need not pre-allocate space via the "new" statement). If there are more than 3 dimensions, then the user must explicitly allocate the required memory (see example 3 below).
Note: This is the *exact* routine used within the CCM Processor. The mixture of Pa for psfc and mb for plevo and p0 is specified by the source routine.
The models which produce files in CCM History Tape format write the variables in the following order ([time],lat,lev,lon). This example has no time dimension. The function "vinth2p" requires the "lev" dimension to be the slowest varying (leftmost) dimension. Thus, the following example uses NCL's dimension reordering to put the dimensions into the required order. The surface pressure (PS) has two dimensions (lat,lon).
fccm = addfile ("dummy.ccm" , "r") ; a CCM file pnew = (/ 850.0,200.0 /) ; desired output levels [hPa/mb] hyam = fccm->hyam ; read to memory [optional] hybm = fccm->hybm T = fccm->T ; say "T" is (lat,lev,lon) P0mb = 1000. ; reference pressure [mb] Tnew = vinth2p (T(lev|:, lat|:, lon|:) \ ; dimension reorder ,hyam, hybm, pnew ,fccm->PS, 1 ,P0mb, 2, True)Tnew is a 3D array returned by "vinth2p" with dimensions:
Tnew(dimsizes(pnew),lat,lon) ==> Tnew(2,lat,lon)Example 2:
Let's assume that the above file had been converted to netCDF format with the following dimension order (lev,lat,lon). This is typically the case when the "ccm2nc" tool is used. (See http://www.cgd.ucar.edu/pubsoft/.) In this case, the "lev" dimension is as required by "vint2p" and dimension reordering is not required. Also, "ccm2nc" explicitly adds the reference pressure [P0; Pa] to the file so it may be retrieved from the file (fncf->P0). Thus,
fncf = addfile ("dummy.nc" , "r") ; a CCM file converted to netCDF via "ccm2nc" P0mb = 0.01*fncf->P0 ; change Pa to mb (as required) . . Tnew = vinth2p (T ,hyam, hybm, pnew ,fncf->PS, 1 ,P0mb, 2, True)Example 3:
A variable with a time dimension is being read directly from a CCMHT file. Each variable's dimension order is (time,lat,lev,lon). We want to interpolate each variable with four dimensions to the specified pressure levels and we want the output to be in (time,lev_new,lat,lon) order. The program will then proceed to operate on each variable. Naming dimensions and creating coordinate variables is also demonstrated.
fccm = addfile ("dummy.ccm" , "r") ; a CCM file pnew = (/ 850., 500., 200. /) ; desired output levels hyam = fccm->hyam ; read to memory (optional) hybm = fccm->hybm time = fccm->time P0mb = 1000. ; reference pressure [mb] vname= getfilevarnames(fccm) ; get all variable names on input file ; preallocate memory Vnew = new ((/dimsizes(time),dimsizes(pnew),dimsizes(lat),dimsizes(lon) ) Vnew!0 = "time" ; name dimensions (not required) Vnew!1 = "lev_new" Vnew!2 = "lat" Vnew!3 = "lon" lev_new = pnew ; create a new coordinate variable lev_new!0 = "lev_new" ; variable and dimension name the same do i=0,dimsizes(vnames)-1 dims = getfilevardims(fccm,vname(i)) nrank = dimsizes(dims) ; determine the number of dimensions if (nrank.eq.4) then ; only interp 4D variables Vold = fccm->$vname(i)$ ; read each variable to memory ; (faster dimension reordering) do nt=0, dimsizes(time)-1 ; interpolate at each time step Vnew(nt,:,:,:) = vinth2p (Vold(nt,lev|:, lat|:, lon|:) \ ; dimension reorder ,hyam, hybm, pnew ,fccm->PS(nt,:,:), 1 \ ,P0, 2, True) end do end if ; do something with Vnew end doExample 4:
Again, let's assume that "ccm2nc" had been used to create a netCDF file with the following dimension ordering (time,lev,lat,lon). Thus dimension reordering is not required. Either of the following approaches could be used:
fncf = addfile ("dummy.nc" , "r") ; a CCM file created by "ccm2nc" [snip] Vold = fncf->$vname(i)$ ; read to memory [could be large] do nt=0, dimsizes(time)-1 ; interpolate at each time step Vnew(nt,:,:,:) = vinth2p (Vold(nt,:,:,:) \ ,hyam, hybm, pnew ,fncf->PS(nt,:,:), 1 \ ,P0mb, 2, True) end door:
Do NOT read all of Vold to memory (in other words, don't use Vold = fncf->$vname(i)$). Just read each time step from the file. This is a bit slower but uses minimum memory.
do nt=0, dimsizes(time)-1 ; interpolate at each time step Vnew(nt,:,:,:) = vinth2p (fncf->$vname(i)$(nt,:,:,:) \ ,hyam, hybm, pnew ,fncf->PS(nt,:,:), 1 \ ,P0mb, 2, True) end do
NG4.1 Home, Index, Examples, Glossary, Feedback, Ref Contents, Ref WhereAmI?