vinth2p

This function interpolates CCM2/3 hybrid coordinate data to pressure coordinates using pressure surfaces as the coordinate surface where the interpolation is done.


Synopsis

	function vinth2p(
		datai[*][*][*] : float,
		hbcofa[*] : float,
		hbcofb[*] : float,
		plevo[*] : float,
		psfc[*][*] : float,
		intyp[1] : integer,
		p0[1] : float,
		ilev[1] : integer,
		kxtrp[1] : logical
	)

Arguments

datai
3 dimensional data with the vertical level as the 0-th (leftmost) dimension
hbcofa
Hybrid coefficients A, a single vector dimensioned the same as the 0'th dimension of datai
hbcofb
Hybrid coefficients B, a single vector dimensioned the same as the 0'th dimension of datai
plevo
An array of desired output pressure levels (mb)
psfc
2 dimensional surface pressure data (Pa). These two dimensions should agree with the two rightmost dimensions of datai
intyp
Single scalar value to determine interpolation type 1 - LINEAR, 2 - LOG, 3 - LOG LOG
p0
Single scalar float value that is the surface reference pressure (mb)
ilev
Single scalar integer value that specifies whether the data exist on level midpoints or level interfaces, 1 - interface levels, 2 - midpoint levels
kxtrp
If False no extrapolation is done when the pressure level is ouside of the range of psfc.

Description

This function interpolates CCM2/3 hybrid coordinate data to pressure coordinates using pressure surfaces as the coordinate surface where the interpolation is done. The type of interpolation is currently a variant of transformed pressure coordinates with the interpolation type specified by intyp. All hybrid coordinate values are transformed to pressure values.

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.


Examples

Example 1:

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 do
Example 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 do
or:

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

Reference Manual Control Panel

NG4.1 Home, Index, Examples, Glossary, Feedback, Ref Contents, Ref WhereAmI?


$Revision: 1.9 $ $Date: 1999/02/26 16:34:57 $