Re: subscripts

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Wed Jan 20 2010 - 08:54:48 MST

On Jan 20, 2010, at 3:07 AM, sima sima wrote:

> Hi Dear,
>
> Can use non integer number in subscripts?

No, not for index subscripts, but you can for coordinate subscripts.
Coordinate subscripts only work if your data has coordinate arrays
attached to it. Also, if your coordinate subscripts are integers
themselves, then you can only use integers in the subscripting.

For example, let's define a dummy 1D array called "x" and attach a
coordinate array called "lat" to it:

   npts = 20
   x = fspan(-10,10,npts)
   dummy_lat = fspan(10,48,npts) ; make sure this is npts in length

   x!0 = "lat" ; Name the dimension
   x&lat = dummy_lat ; Assign a coordinate array
   printVarSummary(x)

This produces:

Variable: x
Type: float
Total Size: 80 bytes
             20 values
Number of Dimensions: 1
Dimensions and sizes: [lat | 20]
Coordinates:
             lat: [10..48]

Note the "lat" coordinate array that goes from 10 to 48.

Now, you can index "x" with integer indexes or coordinate values

Here's an example of integer indexes:

   print(x(1:3))

This produces:

Variable: x (subsection)
Type: float
Total Size: 12 bytes
             3 values
Number of Dimensions: 1
Dimensions and sizes: [lat | 3]
Coordinates:
             lat: [12..16]
(0) -8.947369
(1) -7.894737
(2) -6.842105

Use "{" and "}" for coordinate subscripts. The following code will
print all values of "x" whose corresponding "lat" values are between
20.5 and 30.5 inclusive:

   print(x({20.5:30.5}))

Variable: x (subsection)
Type: float
Total Size: 20 bytes
             5 values
Number of Dimensions: 1
Dimensions and sizes: [lat | 5]
Coordinates:
             lat: [22..30]
(0) -3.68421
(1) -2.631578
(2) -1.578947
(3) -0.5263157
(4) 0.5263157

--Mary

>
> Thanks,
>
> Hamzeloo.
>
>
> _______________________________________________
> 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 Jan 20 08:54:57 2010

This archive was generated by hypermail 2.1.8 : Thu Jan 21 2010 - 13:54:45 MST