Re: while loop

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon May 03 2010 - 13:56:32 MDT

I'm guessing the code is failing here:

> p1 = p(i,99,71)
> p1 = floor(p1)

because "p" is a float and you are trying to put the value into "p1"
which is an integer.

Why not just do:

  p1 = floor(p(i,99,71))

You can also use floattointeger (or "tointeger" if you have V5.2.0 or later) to just
truncate the value to an integer.

However, you might be able to accomplish all this with the "ind" function,
which returns the indices where a certain condition is True.

In your case, it might be something like this:

ii = ind(p(:,99,71).gt.850) ; get the list of indexes where the subset of "p" is greater than 850
msum = floattointeger(sum(m(ii))) ; or floor(sum(m(ii))) ; Calculate the sum of "m" at these locations

--Mary

> Dear NCL users
> I try to sum up the moisture flux when the pressure is higher than 850 mb.
> But I got the error that I could not compare each other because of
> Assignment type mismatch, right hand side can't be coerced to type of left hand side.
> I try to put floor over p to make it as integer but it still did not work.
> and for the while loop it is required scalar number to compare with 850.
> How can I change the type of data around??
> Thanks
> Jam
>
> p = wrf_user_getvar(f,"pressure",4)
> Q = f ->QVAPOR(0,:,99,71)
> v = f ->V(0,:,99,71)
> m = Q * v * 1000
> print(m)
> i = 1
> msum = new((/1,1/),integer)
> print(msum)
> p1 = new((/1,1/),integer)
> p1 = floor(p(0,99,71))
> print(p1)
> do while (p1.gt.850)
> print(m(i))
> print(msum)
> msum = msum + m(i)
> print(msum)
> i = i+1
> p1 = p(i,99,71)
> p1 = floor(p1)
> print(p1)
> end do
> > Date: Mon, 3 May 2010 08:49:17 -0600
> > From: shea@ucar.edu
> > To: prabshr@gmail.com
> > CC: ncl-talk@ucar.edu
> > Subject: Re: analogous of CASE statement in IDL for NCL usage
> >
> > Sorry there is no CASE statement in NCL at this time.
> >
> > Extracting flags:
> >
> > http://www.ncl.ucar.edu/Applications/HDF.shtml
> >
> > See Example 5
> >
> > Good luck
> >
> > On 5/2/10 10:25 PM, p s wrote:
> > > Hi,> > I am trying to convert this IDL
> > > code(http://eosweb.larc.nasa.gov/PRODOCS/calipso/Tools/vfm_feature_flags.pro)
> > > provided for reading the VFM data in CALIPSO.
> > > Is their any statements in NCL i.e. similar to CASE statement of IDL?
> > >
> > > Regards,
> > > Prabhakar
> > >
> > >
> > >
> > > _______________________________________________
> > > 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
>
> Hotmail: Free, trusted and rich email service. Get it now. _______________________________________________
> 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 Mon May 3 13:56:41 2010

This archive was generated by hypermail 2.1.8 : Mon May 03 2010 - 14:51:25 MDT