Re: interp WRF to WRF using NCL 6.0.0

From: Erik N <nobleeu_at_nyahnyahspammersnyahnyah>
Date: Mon Aug 20 2012 - 12:46:48 MDT

Looking over your code briefly, I think your error is because you are
trying to force the linint2_Wrap function to accept 2-dimensional lats
and lons, when it expects 1-dimensional lats and lons.

XLAT and Xlon are 2D.
    XLAT (time, lat, lon)
    XLONG(time,lat,lon)

So make a 1D lat and lon variable and go from there.

lat = XLAT(0,:,0)
lon = XLONG(0,0,:)

or in your case,...
;*** get course mesh ***
filec = addfile(pathc+"geo_em.d01.nc","r")
coarselat = filec->XLAT_M(0,:,0)
coarselon = filec->XLONG_M(0,:,0)

;*** get fine mesh ***
filef = addfile(pathc+"geo_em.d01.nc","r")
finelat = filef->XLAT_M(0,:,0)
finelon = filef->XLONG_M(0,:,0)

check data using printVarSummary BEFORE trying to forse it into linint2_Wrap.

-Erik
Erik Noble | Research Assistant | NASA Goddard Institute for Space Studies
Direct: 1 (212) 678-5512 | www.giss.nasa.gov | 2880 Broadway, New York, NY-10025

> Thanks,
> Nicole
>
> ----------------
> NCL CODE:
>
> ; load community-contributed NCL functions
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>
> ; set constants
> varname = (/"terrain"/)
> resolutionc = "25km"
> resolutionf = "10km"
>
> pathc = "./2004/25km/WPS/NAM25/"
> pathf = "./2004/10km/WPS/NAM/"
>
> ;**************
> ; Main Program
> ;**************
>
> begin
>
> ; assign output file name
> outfilename = "./"+resolutionc+"-"+resolutionf+"terrain"
>
> ; assign input file names
> filec = addfile(pathc+"geo_em.d01.nc","r")
> filef = addfile(pathf+"geo_em.d01.nc","rw")
> ;print(systemfunc("ncdump -h "+pathc+"geo_em.d01.nc"))
> ;print(pathc+"geo_em.d01.nc")
> ;print(isfilepresent(pathc+"geo_em.d01.nc"))
>
> ; initialize regridded array variables
> nclat = dimsizes(filec->XLAT_M(0,:,:))
> nclon = dimsizes(filec->XLONG_M(0,:,:))
> nctopo = dimsizes(filec->HGT_M(0,:,:))
> coarselat = new(nclat,float) ;coarse grid latitude
> coarselon = new(nclon,float) ;coarse grid longitude
> coarsetopo = new(nctopo,float) ;coarse grid topo
>
> nflat = dimsizes(filef->XLAT_M(0,:,:))
> nflon = dimsizes(filef->XLONG_M(0,:,:))
> nftopo = dimsizes(filef->HGT_M(0,:,:))
> finelat = new(nflat,float) ;fine grid latitude
> finelon = new(nflon,float) ;fine grid longitude
> finetopo = new(nftopo,float) ;fine grid topo
>
> ; read in coarse and fine lat-lon data
> coarselat = filec->XLAT_M(0,:,:)
> coarselon = filec->XLONG_M(0,:,:)
> finelat = filef->XLAT_M(0,:,:)
> finelon = filef->XLONG_M(0,:,:)
>
> print("Reading terrain data from input file...")
> ; read in coarse terrain
> ; | don't need to read in fine terrain b/c would overwrite it anyhow
> ; | finetopo = filef->HGT_M(0,:,:)
> coarsetopo = filec->HGT_M(0,:,:)
> ; make sure merdata has attributes (inc. missing value)
> copy_VarAtts(getfilevaratts(filec,"HGT_M"),coarsetopo)
> copy_VarAtts(getfilevaratts(filef,"HGT_M"),finetopo)
> printVarSummary(coarsetopo)
>
> ; regrid data and lat-lon using linint2_Wrap (_Wrap preserves metadata)
> ; | *linint2_Wrap(oldx,oldy,olddata,cyclic,newx,newy)
> ; | **rightmost dimensions of arg[2] must be lat, lon**
> ; | *bilinear interpolation in x-dim, then y-dim
> ; | *if new dims are outside old dims, extra values set to missing
> ; | *processed annually
> print("Interpolating data...")
> finetopo = \
> linint2_Wrap(coarselon,coarselat,coarsetopo,False,finelon,finelat,0)
>
> printVarSummary(finetopo)
>
> ; write regridded data to file
> print("Writing data...")
> filef->HGT_M(0,:,:) = finetopo
> print("Writing latitude...")
> filef->XLAT_M(0,:,:) = finelat
> print("Writing longitude...")
> filef->XLONG_M(0,:,:) = finelon
>
> end
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
- Erik -
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Aug 20 12:46:59 2012

This archive was generated by hypermail 2.1.8 : Thu Aug 23 2012 - 16:16:15 MDT