<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: arial,helvetica,sans-serif; font-size: 12pt; color: #000000'>Yes, it write out metadata of TEMP2, but still no TEMP2 attribute write out when I use ncdf->tem2 = temp2. What I want to write out is TEMP2 values and attribute. Thanks!<div><br></div><div>Chao<br><br><hr id="zwchr"><div style="color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Alan Brammer" <abrammer@albany.edu><br><b>To: </b>"Chao Luo" <chao.luo@eas.gatech.edu><br><b>Cc: </b>"ncl-talk Talk" <ncl-talk@ucar.edu><br><b>Sent: </b>Friday, August 28, 2015 11:06:55 AM<br><b>Subject: </b>Re: [ncl-talk] write variable attribute<br><br><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif"><div style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:16px">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. </div><div style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:16px">But by also surrounding temp2 with (/ /) you're telling ncl to not copy any metadata. </div><div style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:16px">That notation is only useful when you have already defined the variable in the file. </div><div style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:16px">So </div><div style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:16px"> ncdf->temp2 = temp2<br></div><div style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:16px">Will write out the contents and the metadata/attributes with the variable. </div><div style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:16px"><br></div><div style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:16px"><br></div><div style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:16px"><br></div><div style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:16px">; filevarattdef(ncdf,"temp2",temp2)</div><div style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:16px"><div> </div><div> ncdf->TFLAG =TFLAG</div><div> ncdf->temp2 = (/temp2/)</div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 28, 2015 at 1:33 PM, Luo, Chao <span dir="ltr"><<a href="mailto:chao.luo@eas.gatech.edu" target="_blank">chao.luo@eas.gatech.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:#000000"><font face="arial, helvetica, sans-serif"><span style="font-size:12pt">Dear All,</span></font><div style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:12pt"><br></div><div style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:12pt">I am working on temperature interpolation from 36km to 4km by ESMF_regrid, and want to write out the TEMP2 at new resolution,</div><div style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:12pt">unfortunately the temp2 attribute didn't write out in netcdf file, I have tried to define TEMP2 attribute by:</div><div style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:12pt"><br></div><div><div><font face="arial, helvetica, sans-serif"> temp2!0 = "time"</font></div><div><font face="arial, helvetica, sans-serif"> temp2!1 = "lay"</font></div><div><font face="arial, helvetica, sans-serif"> temp2!2 = "lat"</font></div><div><font face="arial, helvetica, sans-serif"> temp2!3 = "lon"</font></div><div><font face="arial, helvetica, sans-serif"> temp2@long_name = "TEMP2"</font></div><div><font face="arial, helvetica, sans-serif"> temp2@units = "k"</font></div><div><font face="arial, helvetica, sans-serif"> temp2@var_desc = "temperature at 2 m"</font></div></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">and by function of filevarattdef. Both didn't work. </font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Thanks very much for and help or suggestions!</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Here is the script I used:</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><div>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"</div><div>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"</div><div>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"</div><div>load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"</div><div>load "$NCARG_ROOT/lib/ncarg/nclscripts/esmf/ESMF_regridding.ncl"</div><div><br></div><div>begin</div><div><br></div><div> diri_36 = "/data11/cluo/CMAQv5.0.1/scripts/mcip4.1/36km/201107/data/"</div><div> diri_4 = "/data12/cluo/smoke3.6.5/data/ge_dat/"</div><div> namei_36 = "GRIDCRO2D_148x112_20110701"</div><div> namei_4 = "<a href="http://geo_em.d01_1332x1008.nc" target="_blank">geo_em.d01_1332x1008.nc</a>"</div><div><br></div><div> f1 = addfile(diri_36+namei_36,"r")</div><div><br></div><div>;output lat/lon</div><div> lat2d_36km = f1->LAT(0,0,:,:) ; (TSTEP, LAY, ROW, COL) , 36km</div><div> lon2d_36km = f1->LON(0,0,:,:) ; (TSTEP, LAY, ROW, COL) , 36km</div><div><br></div><div> printVarSummary (lon2d_36km)</div><div> printMinMax(lon2d_36km,True)</div><div><br></div><div><br></div><div> f2 = addfile(diri_4+namei_4,"r")</div><div>;input lat/lon</div><div><br></div><div> lat2d_4km = f2->XLAT_M(0,:,:) ; 4km</div><div> lon2d_4km = f2->XLONG_M(0,:,:) ; 4km</div><div><br></div><div> printVarSummary (lon2d_4km)</div><div> printMinMax(lon2d_4km,True)</div><div><br></div><div> name_in = "METCRO2D_148x112_20110701"</div><div><br></div><div> nlay = 1</div><div> ntime = 25</div><div><br></div><div> time = new((/ntime/),integer)</div><div> time = ispan(0,ntime-1,1)</div><div><br></div><div> f3 = addfile(diri_36+name_in,"r") temp2_36 = f3->TEMP2(:,:,:,:) ;(TSTEP, LAY, ROW, COL)</div><div> TFLAG = f3->TFLAG(:,0,:)</div><div> temp2_36@_FillValue = 9.999e+36</div><div><br></div><div> printVarSummary (temp2_36)</div><div> printMinMax(temp2_36,True)</div><div><br></div><div> diro = "/data11/cluo/cmaq4.6/data/post/smk31_post/"</div><div> filo = "<a href="http://out.nc" target="_blank">out.nc</a>" ; input file name</div><div> fl_nm_out = diro+filo</div><div> system ("/bin/rm -f "+fl_nm_out) ; Remove any pre-existing file</div><div> ncdf = addfile(fl_nm_out,"c")</div><div><br></div><div></div><div>;---Set up options for regridding</div><div> Opt = True</div><div> </div><div><div> Opt@SrcGridLat = lat2d_36km ; source grid</div><div> Opt@SrcGridLon = lon2d_36km</div><div> Opt@DstGridLat = lat2d_4km ; destination grid</div><div> Opt@DstGridLon = lon2d_4km</div><div><br></div><div> Opt@SrcRegional = True ; Necessary if grids</div><div> Opt@DstRegional = True ; are regional</div><div><br></div><div> Opt@InterpMethod = "bilinear" ; "patch", "conserve"</div><div><br></div><div> Opt@ForceOverwrite = True ; Optional, but recommended.</div><div> Opt@PrintTimings = True ; Optional.</div><div> Opt@Debug = True ; Optional</div></div><div><br></div><div><div> temp2 = ESMF_regrid(temp2_36,Opt) ; Do the regridding</div><div><br></div><div> temp2!0 = "time"</div><div> temp2!1 = "lay"</div><div> temp2!2 = "lat"</div><div> temp2!3 = "lon"</div><div> temp2@long_name = "TEMP2"</div><div> temp2@units = "k"</div><div> temp2@var_desc = "temperature at 2 m"</div><div><br></div><div> printVarSummary (temp2)</div><div> printMinMax(temp2,True)</div><div><br></div><div>; filevarattdef(ncdf,"temp2",temp2)</div></div><div><div> </div><div> ncdf->TFLAG =TFLAG</div><div> ncdf->temp2 = (/temp2/)</div><div><br></div><div> end</div></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><br></div></div></div><br>_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>
</div><br></div></div></body></html>