Re: help loop [Loop end must be scalar]

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Apr 29 2013 - 08:46:45 MDT

On Apr 25, 2013, at 11:10 AM, Vanúcia Schumacher wrote:

> Hi Mary,
>
> This loop is to add all cases and calculating the average,
> The loop is necessary when you have more cases ( + 3)

We have functions that do averaging across dimensions. There's no need to loop.

For example, let's say you have a variable "t" dimensioned case x level x lat x lon,
and you want to average across all level, lat, and lon dimensions for every "case".

You want to use the "dim_avg_n" function, which allows you to specify which dimensions to average across:

tavg = dim_avg_n(t,(/1,2,3/))

The (/1,2,3/) represents the rightmost three dimensions of "t" (dimension "0" is the case dimension).

"tavg" will be a 1D array the same length as the leftmost (case dimension) of "t".

If you want to retain metadata (attributes and coordinate arrays), then use "dim_avg_n_Wrap":

tavg = dim_avg_n_Wrap(t,(/1,2,3/))

For more information, see the "dim_avg" documentation:

http://www.ncl.ucar.edu/Document/Functions/Built-in/dim_avg_n.shtml
http://www.ncl.ucar.edu/Document/Functions/Contributed/dim_avg_n_Wrap.shtml

For more information on NCL's averaging functions in general, go to:

http://www.ncl.ucar.edu/Document/Functions/math.shtml

and search for the words "average" or "averaging"

--Mary

>
>
>
>
>
>
> > Subject: Re: help loop [Loop end must be scalar]
> > From: haley@ucar.edu
> > Date: Thu, 25 Apr 2013 10:25:53 -0600
> > CC: ncarg-talk@ucar.edu
> > To: vanucia-schumacher@hotmail.com
> >
> > Hi,
> >
> > This is an NCL question and should be posted to ncl-talk, not ncarg-talk (which is for NCAR Graphics questions).
> >
> > "cas1" and "cas1" are multi-dimensional variables that you read off the file. Using them as looping values really doesn't make sense.
> > That's why you are getting an error that the loop start and end must be scalars.
> >
> > What do you need to accomplish with this loop?
> >
> > --Mary
> >
> >
> > On Apr 24, 2013, at 4:23 PM, Vanúcia Schumacher wrote:
> >
> > > Hi, someone could help me with this error in my script:
> > >
> > > data=addfile("pgbhnl.gdas.2000010912.grb2", "r")
> > > data1=addfile("pgbhnl.gdas.2000011512.grb2", "r")
> > > cas1=data->TMP_P0_L100_GLL0({500},:,:)
> > > cas2=data1->TMP_P0_L100_GLL0({500},:,:)
> > >
> > > x=0
> > > do i=cas1, cas2,1
> > > s=x+i
> > > end do
> > >
> > > fatal:Loop end must be scalar, can't execute loop
> > > fatal:Loop variable must be scalar, can't execute loop
> > > fatal:["Execute.c":8126]:Execute: Error occurred at or near line 7
> > >
> > >
> > > Thanks
> > > _______________________________________________
> > > ncarg-talk mailing list
> > > ncarg-talk@ucar.edu
> > > http://mailman.ucar.edu/mailman/listinfo/ncarg-talk
> >

_______________________________________________
ncarg-talk mailing list
ncarg-talk@ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncarg-talk
Received on Mon Apr 29 08:46:53 2013

This archive was generated by hypermail 2.1.8 : Wed May 15 2013 - 10:21:23 MDT