Re: looping through variables

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Wed Oct 03 2012 - 15:06:02 MDT

Hi Nicole,
You're right that string referencing is not available for regular variables. However, I think you can use a list to accomplish your goal. Rather than a list of names, just make a list of the actual variables. Here's a little interactive session to illustrate:

ncl 0> x = 5
ncl 1> y = 10.0
ncl 2> z = 1d14
ncl 3> vars = [/ x, y, z /]
ncl 4> do i = 0, ListCount(vars) - 1
ncl 5> print(vars[i])
ncl 6> end do

Variable: x
Type: integer
Total Size: 4 bytes
            1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) 5

Variable: y
Type: float
Total Size: 4 bytes
            1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) 10

Variable: z
Type: double
Total Size: 8 bytes
            1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) 100000000000000
ncl 7>

Hope this helps...
 -dave

On Oct 3, 2012, at 2:45 PM, Schiffer, Nicole June wrote:

> I think this has been addressed before, but I can't find it in the
> archives.
>
> I'm trying to loop through program variables using a list of the variable
> names. One can read in file variables by using $filevar$, but this doesn't
> work for program variables. How do I do the same thing with file
> variables? The variables are all of type float. Code snippet below.
>
> Thanks,
> Nicole
>
> Code snippet:
> varname = [/"pr","pw","mfc","evap"/]
> do i=0,nvars-1 ;variables
> print(varname[i])
> calcdata = calc_stats(varname[i],region,nruns,nstat)
> end do ;variables
>
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> * Nicole Schiffer
> * Science Writing Intern (NCSA)
> * Graduate Research Fellow (Dept. of Energy)
> * Department of Atmospheric Sciences
> * University of Illinois, Urbana-Champaign
> * Email: nschiff2 [at] illinois [dot] edu
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
>
> _______________________________________________
> 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 Wed Oct 3 15:06:08 2012

This archive was generated by hypermail 2.1.8 : Mon Oct 08 2012 - 15:54:16 MDT