Re: Assignment type mismatch

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Tue Aug 21 2012 - 16:45:57 MDT

Copying metadata can be an expensive operation. Also, it is frequently not desired.

The functions with _Wrap are ones that we felt users may want metadata copied over for.
If a function doesn't have a _Wrap equivalent, then that means we either didn't think it
was an appropriate function to do this for, or we haven't gotten around to it yet.

If you really need to copy metadata, then you can use copy_VarMeta:

http://www.ncl.ucar.edu/Document/Functions/Contributed/copy_VarMeta.shtml

--Mary

On Aug 21, 2012, at 3:25 PM, jagadish karmacharya wrote:

> Hi Dennis and Mary,
>
> Many thanks for details. Now it works.
>
> Why a mix of _Wrap ond not other functions => I got this script from a resource person; I have little knowledge about ncl so can't comment on content of the script.
>
> Thanks once again
>
> Jagadish
>
> From: Dennis Shea <shea@ucar.edu>
> To: jagadish karmacharya <j_karmacharya@yahoo.com>
> Cc: "ncl-talk@ucar.edu" <ncl-talk@ucar.edu>
> Sent: Tuesday, August 21, 2012 8:47 PM
> Subject: Re: Assignment type mismatch
>
> Assuming
> 'p' is type float
> 'lat' is type double
>
> Both of the following are type float
> pt = p(lat|:,lon|:,time|:) ; (lat,lon,time)
> ptw = pt
>
> If 'lat' is double then
> lat=p&lat
> wgt = sqrt(cos(lat*0.01745329))
> will result in wgt being double.
>
> Then
> ptw = pt*conform(pt,wgt,0)
> the right hand side will be double (float*double=>double)
> Since ptw is previously defined as float NCL will (currently)
> not allow this. For debug you could do
> xxx=sqrt(cos(lat*0.01745329))
> print(typeof(xxx))
>
> The simplest soltion is
> wgt = sqrt(cos(tofloat(lat)*0.01745329))
>
>
> The message below is a awrning ... not a fatal error.
>
> ===
> Why a mix of _Wrap ond not other functions
>
> > eof = eofunc_Wrap(ptw,neval,optEOF)
> > ts = eofunc_ts(ptw,eof,optEOF)
> > reof = eofunc_varimax_Wrap(eof, 1)
> > rts = eofunc_ts(ptw,reof,optEOF)
>
> eof = eofunc_Wrap(ptw,neval,optEOF)
> ts = eofunc_ts_Wrap(ptw,eof,optEOF)
> reof = eofunc_varimax_Wrap(eof, 1)
> rts = eofunc_ts_Wrap(ptw,reof,optEOF)
>
>
> On 8/21/12 1:14 PM, jagadish karmacharya wrote:
> > Thanks Dave,
> >
> > But, it still gives same error.
> > By the way, with ptw =tofloat(pt) on the previos line it gives follwing
> > warning.
> > warning:Dimension (0) has not been defined
> > warning:Dimension (1) has not been defined
> >
> > Jagadish
> >
> > =====================
> > Here is the script:
> >
> > 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
> >
> > ;-- INPUT-----------------
> >
> > ;input="noaa.slp.djf.abs.nc"
> > ;neval=10
> > ;type=1 ; 1=correlation matrix , 0=covariance matrix
> > ;output-> loading: out.load.nc
> > ; pc : out.pc.nc
> > ;------------------------
> >
> > f = addfile (input, "r")
> > p =f->$var$
> >
> > ; calculate the weights using the square root of the cosine of the
> > latitude and
> > ; also convert degrees to radians
> > lat=p&lat
> > wgt = sqrt(cos(lat*0.01745329))
> >
> > ; reorder data so time is fastest varying
> > pt = p(lat|:,lon|:,time|:) ; (lat,lon,time)
> > ptw = pt ; create an array with metadata
> >
> > ; weight each point prior to calculation.
> > ; conform is used to make wgt the same size as pt
> > ptw = pt*conform(pt,wgt,0)
> >
> > optEOF = True
> > optEOF@jopt = type ; correlation / covariance matrix
> > ; optEOF@pcrit = 85
> >
> > eof = eofunc_Wrap(ptw,neval,optEOF)
> > ts = eofunc_ts(ptw,eof,optEOF)
> > reof = eofunc_varimax_Wrap(eof, 1)
> > rts = eofunc_ts(ptw,reof,optEOF)
> >
> > ; output
> > system("rm out.load.nc")
> > eof!0="time" ; reformat dimension for grads
> > eof&time@units=p&time@units
> > reof!0="time"
> > reof&time@units=p&time@units
> > g = addfile("out.load.nc","c")
> > g->eof=eof
> > g->reof=reof
> >
> > pc=new((/1,1,neval,dimsizes(p&time)/),"double",-9999)
> > pc!0="lat"
> > pc&lat=0.0
> > pc&lat@units=p&lat@units
> > pc&lat@long_name=p&lat@long_name
> > pc!1="lon"
> > pc&lon=0.01
> > pc&lon@units=p&lon@units
> > pc&lon@long_name=p&lon@long_name
> > pc!2="lev"
> > pc&lev=ispan(1,neval,1)
> > pc&lev@units=""
> > pc&lev@long_name="pc"
> > pc!3="time"
> > pc&time=doubletoint(p&time)
> > pc&time@units=p&time@units
> >
> > pc(0,0,:,:)=(/ts/)
> > rpc=pc
> > rpc(0,0,:,:)=(/rts/)
> > pc@long_name="rotate pc"
> > pc@units=p@units
> > rpc@long_name="rotate pc"
> > rpc@units=p@units
> >
> >
> > system("rm out.pc.nc")
> > g = addfile("out.pc.nc","c")
> > g->pc=pc(time|:,lev|:,lat|:,lon|:)
> > g->rpc=rpc(time|:,lev|:,lat|:,lon|:)
> > system("cdo -s -r -f nc copy out.pc.nc foo.nc ; mv foo.nc out.pc.nc")
> >
> > end
> >
> >
> > ------------------------------------------------------------------------
> > *From:* Dave Allured <dave.allured@noaa.gov>
> > *To:* jagadish karmacharya <j_karmacharya@yahoo.com>
> > *Cc:* ncl-talk@ucar.edu
> > *Sent:* Tuesday, August 21, 2012 7:39 PM
> > *Subject:* Re: [ncl-talk] Assignment type mismatch
> >
> > Without seeing more of your script, I think this is what you want:
> >
> > ptw = pt ; make new array with all metadata
> > ptw = pt * conform (pt, tofloat (wgt), 0))
> >
> > The tofloat function could be inserted in three different places here,
> > to get the same effect. There are other ways to do this, but this way
> > is cleanest, I think. HTH.
> >
> > --Dave
> >
> > On Tue, Aug 21, 2012 at 10:46 AM, jagadish karmacharya
> > <j_karmacharya@yahoo.com <mailto:j_karmacharya@yahoo.com>> wrote:
> > > Hi,
> > >
> > > I have received a script to compute eof, which works fine on a
> > demonstation
> > > dataset. But when I attemped the same on my datasets it gave
> > following
> > > error:
> > >
> > > fatal:["NclVar.c":1376]:Assignment type mismatch, right hand side
> > can't be
> > > coerced to type of left hand side
> > > fatal:Execute: Error occurred at or near line 30 in file
> > denosing1.ncl
> > >
> > > The corresponding line of the script is as follows:
> > > ptw = pt*conform(pt,wgt,0)
> > >
> > > I found, in response to a query, that NCL is a "strongly typed
> > language", it
> > > will not allow a float variable
> > > on the left hand side to be over written with a variable of type
> > double and
> > > suggested solutoin was following:
> > > eof_ts = eof_ts/tofloat(sumWgt)
> > >
> > > When I tried the same for "ptw" on previous line ( i.e replaced
> > ptw = pt
> > > with ptw =tofloat(pt) ) the script runs OK but the trouble is
> > axes of the
> > > resulting file lacks latitude or longitude information.
> > >
> > > How can I solve the problem?
> > >
> > > Thanks in advance.
> > >
> > > Jagadish
> >
> >
> >
> >
> > _______________________________________________
> > ncl-talk mailing list
> > List instructions, subscriber options, unsubscribe:
> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> >
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Aug 21 16:46:04 2012

This archive was generated by hypermail 2.1.8 : Thu Aug 23 2012 - 16:16:15 MDT