Re: Error Statement

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Wed, 08 Aug 2007 09:34:55 -0600

Hi Sean,

The printVarSummary info you sent me of v shows that v is of type short,
and has an offset and a scale_factor:

Variable: v
Type: short
Total Size: 521815680 bytes
             260907840 values
Number of Dimensions: 4
Dimensions and sizes: [time | 1460] x [level | 17] x [lat | 73] x [lon |
144]
Coordinates:
             time: [17566752..17575506]
             level: [1000..10]
             lat: [90..-90]
             lon: [ 0..357.5]
Number Of Attributes: 17
   long_name : 4xDaily V wind
<snip>
   add_offset : 202.66
   scale_factor : 0.01
<snip>

When reading in vwnd, you should immediately use the short2flt function
to convert the array from short to float:
http://www.ncl.ucar.edu/Document/Functions/Contributed/short2flt.shtml

v = short2flt(in1->vwnd)

The function will unpack the data correctly by applying the scale_factor
and then adding the add_offset...

Regarding the error message, we aren't totally sure why you are getting
that specific message when trying to pass shorts to dim_avg, as testing
here didn't give us an error message. Behind the scenes dim_avg will
convert a float array to a double array for the calculations, and then
back to a float array when it is returned from the function. It is
possible that when NCL tried to convert the short array to a double
array internally that your system ran out of memory, which could produce
the error message you described... If that is the case you may get a
memory error when using dim_avg on the converted short->float array...
Good luck,
Adam

Sean Heuser wrote:
> NCL Users,
> So a friend of mine is working on NCL and is using a dim_Avg function. He
> gets this error when running the script.
>
> Could not coerce input data to double, can't continue.
>
> Any idea on what this error means? I've attached a part of his code below.
>
>
> 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"
> begin
> ;*************************************************
> ; read in data
> ;*************************************************
> in1 = addfile("/ncsu/volume1/bonol/DATA/NNRP1/2005/vwnd.2005.nc","r")
> lon = in1->lon
> lat = in1->lat
> time = in1->time
> lev = in1->level
>
> v = in1->vwnd
>
> ;**************************************************
> ; take input data and calculate derived quantities
> ;**************************************************
> ; dims = dimsizes(ps)
> ; ntim = dims(0)
> ; nlat = dims(1)
> ; nlon = dims(2)
> ; dims_lev = dimsizes(sigma)
> ; nlev = dims_lev
> ; pres = new((/ntim,nlev,nlat,nlon /),float)
> ; do k=0,nlev-1 ; calc press @ pt
> ; pres(:,k,:,:) = (ps-pt)*sigma(k)-pt
> ; end do
> ; pres!0 = "time"
> ; pres!1 = "lev"
> ; pres!2 = "lat"
> ; pres!3 = "lon"
> ; pres&time = time
> ; pres&lev = lev
> ; pres&lon = lon
> ; pres&lat = lat
> v!0 = "time"
> v!1 = "lev"
> v!2 = "lat"
> v!3 = "lon"
> v&time = time
> v&lev = lev
> v&lon = lon
> v&lat = lat
>
> ; ===============================================
> ; filter code
> ;================================================
> ; get the meridional average you intend to analyze by using the
> function dim_avg()
> ; the right most is lat/lon you intend to average
> ; add your stuff here
> ; for example, your data v(time|:,lat|:,lon|:)
> ; v_zonal = dim_avg_Wrap( pres(time|:, lev|:, lon|:, lat|:) )
> v_zonal = dim_avg(v(time|:, lev|:, lon|:, lat|:) )(ERROR IS HERE!!!!)
> ; you will get v_zonal(time|:,lat|:)
> ; create the weight by using filwgts_lancos
> ; you can adjust the nwt to fit your own research
> nwt = 43
> fca = 0.05 ; 3 day
> fcb = 0.085 ; 5 day
> ihp = 2 ; band pass filter
> nsigma = 1.
> wgt = filwgts_lancos (nwt, ihp, fca, fcb, nsigma)
>
> ; weight average wgt_runave
> opt = 0
> v_zonal1 = wgt_runave_Wrap(v_zonal(lev|:,lon|:, lat|:,time|:), wgt,
> opt)
>
>
>

-- 
--------------------------------------------------------------
Adam Phillips			             asphilli_at_ucar.edu
National Center for Atmospheric Research   tel: (303) 497-1726
ESSL/CGD/CAS                               fax: (303) 497-1333
P.O. Box 3000				
Boulder, CO 80307-3000	  http://www.cgd.ucar.edu/cas/asphilli
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Aug 08 2007 - 09:34:55 MDT

This archive was generated by hypermail 2.2.0 : Thu Aug 09 2007 - 10:59:25 MDT