<div dir="ltr">As well as what Dennis said, if your question boils down to why would these sets of lines produce different outputs<div><br></div><div><br></div><div><span style="font-family:arial,sans-serif;font-size:16px">lon=new((/dims(2)/),float,"No_</span><span style="font-family:arial,sans-serif;font-size:16px">FillValue") </span></div><div>lon!0 = "lon"<br style="font-family:arial,sans-serif;font-size:16px"><span style="font-family:arial,sans-serif;font-size:16px">lon=tofloat(slon) </span><br style="font-family:arial,sans-serif;font-size:16px"><span style="font-family:arial,sans-serif;font-size:16px">print(lon(0)+" "+lon(539)) </span></div><div>delete(lon)</div><div><span style="font-family:arial,sans-serif;font-size:16px">lon=new((/dims(2)/),float,"No_</span><span style="font-family:arial,sans-serif;font-size:16px">FillValue") </span></div><div>lon!0 = "lon"<br style="font-family:arial,sans-serif;font-size:16px"><span style="font-family:arial,sans-serif;font-size:16px">lon&lon=tofloat(slon) </span><br style="font-family:arial,sans-serif;font-size:16px"><span style="font-family:arial,sans-serif;font-size:16px">print(lon(0)+" "+lon(539)) </span></div><div><br></div><div><br></div><div>In the 2nd set you still haven't defined what lon is when you print, just what it's coordinates are. By telling new() to have no FillValue NCL seems to fill the array with seemingly random numbers that may be close to zero. I don't think many people would recommend initialising an array without a _FillValue. In the 2nd example if you were to go that way, you need to also set lon=tofloat(slon) or follow Dennis' cleaner method. <br style="font-family:arial,sans-serif;font-size:16px"><br></div><div>Also rearranging an array through nested do loops will be archaically slow. You'll be much better using the named convention like you have commented out. </div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 22, 2014 at 10:20 AM, Dennis Shea <span dir="ltr"><<a href="mailto:shea@ucar.edu" target="_blank">shea@ucar.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>I have not looked carefully at your code.<br></div><div><br>[1] The 'tofloat' function does *NOT* preserve meta data. The contributed function 'dble2flt' does preserve meta data.<br></div> <br><br>[2]<span class=""><br><br><span style="font-size:16px;background-color:transparent">7 files = systemfunc("sh sortname.sh")
<br> 8 setfileoption("nc","Format","LargeFile")
<br> 9 fallvars = addfiles(files,"r")
<br> 10 ListSetType(fallvars,"cat")
<br> 11 runoff = fallvars[:]->runoff
</span><br><br></span></div><div>After line 11:<br><br></div> printVarSummary(runoff) ; <=== please look at this<br></div><div> ; it should have all meta data<br></div><div><br></div><div>FYI: NCL does not care if latitude/longitude/time are double<br><br></div><div> printVarSummary(runoff&latitude) ; double with meta data (eg: units)<br></div><div> printVarSummary(runoff&longitude) ; double<br> printVarSummary(runoff&time) ; double<br><br></div><div> LAT = runoff&latitude ; save double<br></div><div> delete( runoff&latitude ) ; delete double values in coordinate array but not dimension name<br></div><div> runoff&latitude = dble2flt(LAT)<br><br></div><div> print(runoff&latitude) ; <== should be type float<br><br></div><div>Do similar things with longitude and time<br></div><div> <br></div><div> <br></div><div> <br><br></div><div><br></div>To change the double to float, you do not need to do all the steps you <br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Wed, Oct 22, 2014 at 4:09 AM, <a href="mailto:dyjbean@gmail.com" target="_blank">dyjbean@gmail.com</a> <span dir="ltr"><<a href="mailto:dyjbean@gmail.com" target="_blank">dyjbean@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div>
<table style="padding:10px;background-color:transparent" background="cid:_Foxmail.1@36b61ecc-955c-3d1e-646c-7dbafd62b1ce" border="0" cellpadding="0" cellspacing="0" height="100%" width="99.99%">
<tbody><tr>
<td style="width:100%;height:100%" valign="top">
<div>
<div><span></span><br></div>
<div><span style="font-size:16px;background-color:rgba(0,0,0,0)">i'm processing merra-land daily production, the variable latitude and longitude are both double.
<br>the below is my code :
<br>
<br>+++++++++++++++++++++++++++++++++++++++++++++++++++
<br> 1 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
<br> 2 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
<br> 3 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
<br> 4 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
<br> 5
<br> 6 begin
<br> 7 files = systemfunc("sh sortname.sh")
<br> 8 setfileoption("nc","Format","LargeFile")
<br> 9 fallvars = addfiles(files,"r")
<br> 10 ListSetType(fallvars,"cat")
<br> 11 runoff = fallvars[:]->runoff
<br> 12 slat = fallvars[:]->latitude(0:360)
<br> 13 slon = fallvars[:]->longitude(0:539)
<br> 14
<br> 15 dims=dimsizes(runoff)
<br> 16
<br> 17 lat=new((/dims(1)/),float,"No_FillValue")
<br> 18 lon=new((/dims(2)/),float,"No_FillValue")
<br> 19 time=new((/dims(0)/),integer,"No_FillValue")
<br> 20 srunoff=new((/dims(2),dims(1),dims(0)/),float,runoff@_FillValue)
<br> 21
<br> 22 lon!0="lon"
<br> 23 lon@long_name="longitude"
<br> 24 lon@units="degrees-east"
<br> 25 lon=tofloat(slon)
<br> 26 print(slon(0)+" "+slon(539))
<br> 27 print(lon(0)+" "+lon(539))
<br> 28
<br> 29 lat!0="lat"
<br> 30 lat@long_name="latitude"
<br> 31 lat@units="degrees-north"
<br> 32 lat=tofloat(slat)
<br> 33
<br> 34 time!0="time"
<br> 35 time@long_name="time"
<br> 36 time@units="days since 1980-1-1 0"
<br> 37 time=yyyymm_time(1980,2013,"integer")
<br> 38
<br> 39 srunoff!0="lon"
<br> 40 srunoff!1="lat"
<br> 41 srunoff!2="time"
<br> 42 srunoff&lon=lon
<br> 43 srunoff&lat=lat
<br> 44 srunoff&time=(/time/)
<br> 45 srunoff@units = "kg.m-2.s-1"
<br> 46 srunoff@long_name = "Overland runoff"
<br> 47 ;srunoff=(/runoff(longitude|:,latitude|:,time|:)/)
<br> 48 do i=0,dims(0)-1
<br> 49 do j=0,dims(1)-1
<br> 50 do k=0,dims(2)-1
<br> 51 srunoff(k,j,i)=(/runoff(i,j,k)/)
<br> 52 end do
<br> 53 end do
<br> 54 end do
<br> 55
<br> 56 printVarSummary(runoff)
<br> 57 printVarSummary(srunoff)
<br> 58 end
<br>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
<br>in the line 25,32,37, if i change them with the following fashion:
<br>
<br>lon&lon=tofloat(slon)
<br>lat&lat=tofloat(slat)
<br>time&time=yyyymm_time(1980,2013,"integer")
<br>
<br>then, the wrong result will generate from line 26 and 27,
<br>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<br>
<br>(0) -180 179.3333282470703
<br>(0) -254807 0
<br>
<br>......
<br>
<br>Variable: srunoff
<br>Type: float
<br>Total Size: 318142080 bytes
<br> 79535520 values
<br>Number of Dimensions: 3
<br>Dimensions and sizes: [lon | 540] x [lat | 361] x [time | 408]
<br>Coordinates:
<br> lon: [-180..179.3333]
<br> lat: [-90..90]
<br> time: [-931605192..0]
<br>Number Of Attributes: 3
<br> long_name : Overland runoff
<br> units : kg.m-2.s-1
<br> _FillValue : 1e+15
<br>
<br>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<br><br>if i change them with direct assignment, like the line 25,32,37,the right result will appear
<br>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<br>(0) -180 179.3333282470703
<br>(0) -180 179.333
<br>
<br>
<br>Variable: srunoff
<br>Type: float
<br>Total Size: 318142080 bytes
<br> 79535520 values
<br>Number of Dimensions: 3
<br>Dimensions and sizes: [lon | 540] x [lat | 361] x [time | 408]
<br>Coordinates:
<br> lon: [-180..179.3333]
<br> lat: [-90..90]
<br> time: [198001..201312]
<br>Number Of Attributes: 3
<br> long_name : Overland runoff
<br> units : kg.m-2.s-1
<br> _FillValue : 1e+15
<br>
<br>++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<br>
<br>i want to know why the "lon&lon, lat&lat, time&time" style gave wrong results?
<br>
<br>thanks</span></div><hr style="width:210px;min-height:1px" align="left" color="#b5c4df" size="1"><span><font color="#888888">
<div><span><div style="FONT-FAMILY:verdana;FONT-SIZE:10pt">
<div><a href="mailto:dyjbean@gmail.com" target="_blank">dyjbean@gmail.com</a></div></div></span></div>
<div></div></font></span></div>
</td>
</tr>
</tbody></table>
</div><br></div></div>_______________________________________________<br>
ncl-talk mailing list<br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
ncl-talk mailing list<br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>