[ncl-talk] write variable attribute
Alan Brammer
abrammer at albany.edu
Fri Aug 28 12:06:55 MDT 2015
You've commented out the line that explicitly writes the attributes to the
file. Likely because you haven't explicitly defined the variable in the
file.
But by also surrounding temp2 with (/ /) you're telling ncl to not copy any
metadata.
That notation is only useful when you have already defined the variable in
the file.
So
ncdf->temp2 = temp2
Will write out the contents and the metadata/attributes with the variable.
; filevarattdef(ncdf,"temp2",temp2)
ncdf->TFLAG =TFLAG
ncdf->temp2 = (/temp2/)
On Fri, Aug 28, 2015 at 1:33 PM, Luo, Chao <chao.luo at eas.gatech.edu> wrote:
> Dear All,
>
> I am working on temperature interpolation from 36km to 4km by ESMF_regrid,
> and want to write out the TEMP2 at new resolution,
> unfortunately the temp2 attribute didn't write out in netcdf file, I have
> tried to define TEMP2 attribute by:
>
> temp2!0 = "time"
> temp2!1 = "lay"
> temp2!2 = "lat"
> temp2!3 = "lon"
> temp2 at long_name = "TEMP2"
> temp2 at units = "k"
> temp2 at var_desc = "temperature at 2 m"
>
> and by function of filevarattdef. Both didn't work.
>
> Thanks very much for and help or suggestions!
>
> Here is the script I used:
>
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl"
>
> begin
>
> diri_36 = "/data11/cluo/CMAQv5.0.1/scripts/mcip4.1/36km/201107/data/"
> diri_4 = "/data12/cluo/smoke3.6.5/data/ge_dat/"
> namei_36 = "GRIDCRO2D_148x112_20110701"
> namei_4 = "geo_em.d01_1332x1008.nc"
>
> f1 = addfile(diri_36+namei_36,"r")
>
> ;output lat/lon
> lat2d_36km = f1->LAT(0,0,:,:) ; (TSTEP, LAY, ROW, COL) , 36km
> lon2d_36km = f1->LON(0,0,:,:) ; (TSTEP, LAY, ROW, COL) , 36km
>
> printVarSummary (lon2d_36km)
> printMinMax(lon2d_36km,True)
>
>
> f2 = addfile(diri_4+namei_4,"r")
> ;input lat/lon
>
> lat2d_4km = f2->XLAT_M(0,:,:) ; 4km
> lon2d_4km = f2->XLONG_M(0,:,:) ; 4km
>
> printVarSummary (lon2d_4km)
> printMinMax(lon2d_4km,True)
>
> name_in = "METCRO2D_148x112_20110701"
>
> nlay = 1
> ntime = 25
>
> time = new((/ntime/),integer)
> time = ispan(0,ntime-1,1)
>
> f3 = addfile(diri_36+name_in,"r") temp2_36 = f3->TEMP2(:,:,:,:)
> ;(TSTEP, LAY, ROW, COL)
> TFLAG = f3->TFLAG(:,0,:)
> temp2_36 at _FillValue = 9.999e+36
>
> printVarSummary (temp2_36)
> printMinMax(temp2_36,True)
>
> diro = "/data11/cluo/cmaq4.6/data/post/smk31_post/"
> filo = "out.nc" ; input file name
> fl_nm_out = diro+filo
> system ("/bin/rm -f "+fl_nm_out) ; Remove any pre-existing file
> ncdf = addfile(fl_nm_out,"c")
>
> ;---Set up options for regridding
> Opt = True
>
> Opt at SrcGridLat = lat2d_36km ; source grid
> Opt at SrcGridLon = lon2d_36km
> Opt at DstGridLat = lat2d_4km ; destination grid
> Opt at DstGridLon = lon2d_4km
>
> Opt at SrcRegional = True ; Necessary if grids
> Opt at DstRegional = True ; are regional
>
> Opt at InterpMethod = "bilinear" ; "patch", "conserve"
>
> Opt at ForceOverwrite = True ; Optional, but recommended.
> Opt at PrintTimings = True ; Optional.
> Opt at Debug = True ; Optional
>
> temp2 = ESMF_regrid(temp2_36,Opt) ; Do the regridding
>
> temp2!0 = "time"
> temp2!1 = "lay"
> temp2!2 = "lat"
> temp2!3 = "lon"
> temp2 at long_name = "TEMP2"
> temp2 at units = "k"
> temp2 at var_desc = "temperature at 2 m"
>
> printVarSummary (temp2)
> printMinMax(temp2,True)
>
> ; filevarattdef(ncdf,"temp2",temp2)
>
> ncdf->TFLAG =TFLAG
> ncdf->temp2 = (/temp2/)
>
> end
>
>
>
>
>
>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150828/d95a1f23/attachment.html
More information about the ncl-talk
mailing list