[ncl-talk] a question about assigning value mode?

Dennis Shea shea at ucar.edu
Wed Oct 22 08:20:22 MDT 2014


I have not looked carefully at your code.

[1] The 'tofloat' function does *NOT* preserve meta data. The contributed
function 'dble2flt' does preserve meta data.


[2]

7   files = systemfunc("sh sortname.sh")
8   setfileoption("nc","Format","LargeFile")
9   fallvars = addfiles(files,"r")
10 ListSetType(fallvars,"cat")
11 runoff = fallvars[:]->runoff

After line 11:

  printVarSummary(runoff)                   ; <=== please look at this
                                                            ; it should
have all meta data

FYI: NCL does not care if latitude/longitude/time are double

  printVarSummary(runoff&latitude)    ; double with meta data (eg: units)
  printVarSummary(runoff&longitude) ; double
  printVarSummary(runoff&time)         ; double

  LAT = runoff&latitude      ; save double
  delete( runoff&latitude )   ; delete double values in coordinate array
but not dimension name
  runoff&latitude = dble2flt(LAT)

  print(runoff&latitude)  ; <== should be type float

Do similar things with longitude and time





To change the double to float, you do not need to do all the steps you

On Wed, Oct 22, 2014 at 4:09 AM, dyjbean at gmail.com <dyjbean at gmail.com>
wrote:

>
> i'm processing merra-land daily production, the variable latitude and
> longitude are both double.
> the below is my code :
>
> +++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> 2 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> 3 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> 4 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
> 5
> 6 begin
> 7 files = systemfunc("sh sortname.sh")
> 8 setfileoption("nc","Format","LargeFile")
> 9 fallvars = addfiles(files,"r")
> 10 ListSetType(fallvars,"cat")
> 11 runoff = fallvars[:]->runoff
> 12 slat = fallvars[:]->latitude(0:360)
> 13 slon = fallvars[:]->longitude(0:539)
> 14
> 15 dims=dimsizes(runoff)
> 16
> 17 lat=new((/dims(1)/),float,"No_FillValue")
> 18 lon=new((/dims(2)/),float,"No_FillValue")
> 19 time=new((/dims(0)/),integer,"No_FillValue")
> 20 srunoff=new((/dims(2),dims(1),dims(0)/),float,runoff at _FillValue)
> 21
> 22 lon!0="lon"
> 23 lon at long_name="longitude"
> 24 lon at units="degrees-east"
> 25 lon=tofloat(slon)
> 26 print(slon(0)+" "+slon(539))
> 27 print(lon(0)+" "+lon(539))
> 28
> 29 lat!0="lat"
> 30 lat at long_name="latitude"
> 31 lat at units="degrees-north"
> 32 lat=tofloat(slat)
> 33
> 34 time!0="time"
> 35 time at long_name="time"
> 36 time at units="days since 1980-1-1 0"
> 37 time=yyyymm_time(1980,2013,"integer")
> 38
> 39 srunoff!0="lon"
> 40 srunoff!1="lat"
> 41 srunoff!2="time"
> 42 srunoff&lon=lon
> 43 srunoff&lat=lat
> 44 srunoff&time=(/time/)
> 45 srunoff at units = "kg.m-2.s-1"
> 46 srunoff at long_name = "Overland runoff"
> 47 ;srunoff=(/runoff(longitude|:,latitude|:,time|:)/)
> 48 do i=0,dims(0)-1
> 49 do j=0,dims(1)-1
> 50 do k=0,dims(2)-1
> 51 srunoff(k,j,i)=(/runoff(i,j,k)/)
> 52 end do
> 53 end do
> 54 end do
> 55
> 56 printVarSummary(runoff)
> 57 printVarSummary(srunoff)
> 58 end
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
> in the line 25,32,37, if i change them with the following fashion:
>
> lon&lon=tofloat(slon)
> lat&lat=tofloat(slat)
> time&time=yyyymm_time(1980,2013,"integer")
>
> then, the wrong result will generate from line 26 and 27,
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> (0) -180 179.3333282470703
> (0) -254807 0
>
> ......
>
> Variable: srunoff
> Type: float
> Total Size: 318142080 bytes
> 79535520 values
> Number of Dimensions: 3
> Dimensions and sizes: [lon | 540] x [lat | 361] x [time | 408]
> Coordinates:
> lon: [-180..179.3333]
> lat: [-90..90]
> time: [-931605192..0]
> Number Of Attributes: 3
> long_name : Overland runoff
> units : kg.m-2.s-1
> _FillValue : 1e+15
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> if i change them with direct assignment, like the line 25,32,37,the right
> result will appear
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> (0) -180 179.3333282470703
> (0) -180 179.333
>
>
> Variable: srunoff
> Type: float
> Total Size: 318142080 bytes
> 79535520 values
> Number of Dimensions: 3
> Dimensions and sizes: [lon | 540] x [lat | 361] x [time | 408]
> Coordinates:
> lon: [-180..179.3333]
> lat: [-90..90]
> time: [198001..201312]
> Number Of Attributes: 3
> long_name : Overland runoff
> units : kg.m-2.s-1
> _FillValue : 1e+15
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> i want to know why the "lon&lon, lat&lat, time&time" style gave wrong
> results?
>
> thanks
> ------------------------------
>  dyjbean at gmail.com
>
> _______________________________________________
> ncl-talk mailing list
> 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/20141022/6c870ccf/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bg.jpg
Type: image/jpeg
Size: 46225 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20141022/6c870ccf/attachment.jpg 


More information about the ncl-talk mailing list