# rgrid2rcm_Wrap

Interpolates data on a rectilinear lat/lon grid to a curvilinear grid like those used by the RCM, WRF and NARR models/datasets and retains metadata.

## Prototype

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" function rgrid2rcm_Wrap ( lat [*] : numeric, lon [*] : numeric, fi : numeric, lat2d [*][*] : numeric, lon2d [*][*] : numeric, Option : numeric ) return_val : numeric

## Arguments

*lat*

A one-dimensional array that specifies the latitude coordinates of
the regular grid. Must be monotonically increasing. Of course, these
must be consistent with the latitude ordering of *fi*.

*lon*

A one-dimensional array that specifies the longitude coordinates of the regular grid. Must be monotonically increasing.

*fi*

A multi-dimensional array to be interpolated. The rightmost two dimensions
(latitude, longitude) are the dimensions to be interpolated. The data
**must** be ordered South-to-North.

*lat2d*

A two-dimensional array that specifies the latitude locations of
the output grid. Because this array is two-dimensional, it is not an
associated coordinate variable
of *fi*.

*lon2d*

A two-dimensional array that specifies the longitude locations of
the output grid. Because this array is two-dimensional, it is not an
associated coordinate variable
of *fi*.

*Option*

Reserved for future use. Currently not used. Set to 1.

## Return value

A multi-dimensional array of the same rank as *fi* except that the
rightmost dimension sizes have been replaced by the sizes of *lat2d*
and *lon2d* respectively. Double if *fi* is double, otherwise float.

## Description

Interpolates data on a rectilinear lat/lon grid to a curvilinear grid, such as those used by the RCM (Regional Climate Model), WRF (Weather Research and Forecasting) and NARR (North American Regional Reanalysis) models/datasets. No extrapolation is performed beyond the range of the input coordinates. The method used is simple inverse distance weighting. Missing values are allowed but ignored.

The algorithm is 'brute-force.' For large grids this can be slow.
For more robust and efficient regridding, see the
ESMF regridding examples, which
show how to regrid data from and
to rectilinear,
curvilinear, or
unstructured
grids. *Available in version 6.1.0 and later.*

## See Also

**rgrid2rcm**,
**rcm2rgrid**, **rcm2points**,
**linint2**, **linint2_points**,
**ESMF_regrid**

## Examples

**Example 1:** Interpolate from gaussian T42 (64,128) grid to 'some' curvilinear grid. .

f_rcm =addfile("some_RCM_file.nc", "r") lat2d_rcm = f_rcm->lat lon2d_rcm = f_rcm->lon fccm =addfile("some_CCM_file.nc", "r") x = fccm->X xgrd =rgrid2rcm_Wrap(x&lat, x&lon, x, lat2d, lon2d, 0)

If the output lat2d and lon2d arrays were of size (nlat,nlon), and if the input x was of size:

x(64,128) ==> xgrd(nlat,nlon) x(ntim,64,128) ==> xgrd(ntim,nlat,nlon) x(ntim,klev,64,128) ==> xgrd(ntim,klev,nlat,nlon)

**Example 2:** Interpolate from rectilinear grid (eg: 180,360) grid to a WRF curvilinear grid. .

f_wrf =addfile("some_WRF_file.nc", "r") lat2d = f_wrf->XLAT(0,:,:) lon2d = f_wrf->XLONG(0,:,:) f_rec =addfile("some_rectlinear_file.nc", "r") x = f_rec->X xgrd =rgrid2rcm_Wrap(x&lat, x&lon, x, lat2d, lon2d, 0)

Example 3: Example 2 interpolate from a 1x1 grid to a (generally) much smaller region
used for (say) WRF or NARR. To make **rgrid2rcm_Wrap**
more efficient, it is suggested that the user make the input *fi* as small as possible.

f_wrf =addfile("some_WRF_file.nc", "r") lat2d = f_wrf->XLAT(0,:,:) lon2d = f_wrf->XLONG(0,:,:) ; --- WRF boundaries extra = 1.0 ; arbitrary 'extra' grid points minLatWrf = min(lat2d) - extra maxLatWrf = max(lat2d) + extra minLonWrf = min(lon2d) - extra maxLonWrf = max(lon2d) + extra ; --- Subset global rectilinear grid to slightly large rectilinear grid area f_rec =addfile("some_rectlinear_file.nc", "r") x = f_rec->X(:,{minLatWrf:maxLatWrf},{minLonWrf:maxLonWrf}) xgrd =rgrid2rcm_Wrap(x&lat, x&lon, x, lat2d, lon2d, 0)