<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif"> The below example is how it should work. A ncl_filedump of your output netcdf might be useful for people to see what is missing compared to the data in the script. </div><div class="gmail_default" style="font-family:verdana,sans-serif">Not sure I follow what the problem is. If the metadata is written I don't see how the attributes weren't also. </div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif"><div class="gmail_default">$ ncl </div><div class="gmail_default"><br></div><div class="gmail_default"><br></div><div class="gmail_default"> ncout = addfile("<a href="http://test.nc">test.nc</a>","c")</div><div class="gmail_default"> x = 0</div><div class="gmail_default"> x!0 = "test"</div><div class="gmail_default"> x&test = 23</div><div class="gmail_default"> x@Some_att = "First Att"</div><div class="gmail_default"> x@Some_other_att = "Second Att"</div><div class="gmail_default"> x@date = systemfunc("date")</div><div class="gmail_default"> ncout->x = x</div><div class="gmail_default"> exit</div><div class="gmail_default"><br></div><div class="gmail_default">$ ncl_filedump <a href="http://test.nc">test.nc</a> </div><div class="gmail_default"> Copyright (C) 1995-2015 - All Rights Reserved</div><div class="gmail_default"> University Corporation for Atmospheric Research</div><div class="gmail_default"> NCAR Command Language Version 6.3.0</div><div class="gmail_default"> The use of this software is governed by a License Agreement.</div><div class="gmail_default"> See <a href="http://www.ncl.ucar.edu/">http://www.ncl.ucar.edu/</a> for more details.</div><div class="gmail_default"><br></div><div class="gmail_default">Variable: f</div><div class="gmail_default">Type: file</div><div class="gmail_default">filename:<span class="" style="white-space:pre">        </span>test</div><div class="gmail_default">path:<span class="" style="white-space:pre">        </span><a href="http://test.nc">test.nc</a></div><div class="gmail_default"> file global attributes:</div><div class="gmail_default"> dimensions:</div><div class="gmail_default"> test = 1</div><div class="gmail_default"> variables:</div><div class="gmail_default"> integer x ( test )</div><div class="gmail_default"> date :<span class="" style="white-space:pre">        </span>Fri Aug 28 19:32:35 UTC 2015</div><div class="gmail_default"> Some_other_att :<span class="" style="white-space:pre">        </span>Second Att</div><div class="gmail_default"> Some_att :<span class="" style="white-space:pre">        </span>First Att</div><div class="gmail_default"><br></div><div class="gmail_default"> integer test ( test )</div><div class="gmail_default"><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 28, 2015 at 3:13 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">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><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" <<a href="mailto:abrammer@albany.edu" target="_blank">abrammer@albany.edu</a>><br><b>To: </b>"Chao Luo" <<a href="mailto:chao.luo@eas.gatech.edu" target="_blank">chao.luo@eas.gatech.edu</a>><br><b>Cc: </b>"ncl-talk Talk" <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>><br><b>Sent: </b>Friday, August 28, 2015 11:06:55 AM<br><b>Subject: </b>Re: [ncl-talk] write variable attribute<div><div class="h5"><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></div></div><br></div></div></div></blockquote></div><br></div>