[Thread Prev][Thread Next][Index]

caution about negative index values (eg i=-5:5)



Hi Namba Takaya,
	There is a saying in English - "You learn something new
every day", and it was true for me with your example using the
negative values of "i".  I had never thought to use that, but a
quick test shows that it does work if the x-axis is defined to
be MODULO.  However the demo below shows that one needs to be wary.

! ------------- demo of the use of negative indices -------------
! with the modulo ...
def axis/modulo/x=0:360:60/units=longitude xax1
def grid/x=xax1 g1 ; let/title="with modulo" v1=x[g=g1]
list/i=-2:2 v1
! VARIABLE : with modulo
! 180E    / -2: -180.0
! 120W    / -1: -120.0
! 60W     /  0:  -60.0
! 0E      /  1:    0.0
! 60E     /  2:   60.0  ! all is well

! ... but if the /modulo is missing ...
def axis/x=0:360:60/units=longitude xax2
def grid/x=xax2 g2 ; let/title="no modulo" v2=x[g=g2]
list/i=-2:2 v2
! VARIABLE : no modulo
! 0E    / 1:   0.00
! 60E   / 2:  60.00   ! again as expected but with no warning

! However if you mix the two ...
list/i=-2:2 v1,v2
! ... an error appears
! **ERROR: inconsistent sizes of data regions: X axis
!          Variable 2 is I=1:2
!          expression is I-2:2

! Now suppose we make a new variable by regridding v2 onto the
! "modulo" grid g1 ...
let/title="v2 regridded onto g1" v3=v2[g=g1]
list/i=-2:2 v3
! VARIABLE : v2 regridded onto g1
! 180E    / -2:   ....
! 120W    / -1:   ....   !!! notice the missing values !!!
! 60W     /  0:   ....
! 0E      /  1:   0.00
! 60E     /  2:  60.00

! Missing values are introduced and there is no warning! I suspect
! that in some cases the result of a calculation could be affected
! if one were not aware of what was going on behind the scenes.
!----------------------------------------------------------------
	I guess the message from all this is to be a bit cautious
when using negative index variables. Perhaps this is all well
known to those who have been long aware of negative indices but, for
the "old dogs" slow to "learn new tricks" (like me), I thought it
was worth mention.
Good luck,
Mick

|!!! Mick.Spillane@noaa.gov !!!|
|__Room 2070 Bldg#3 NOAA/PMEL__|
|____Phone_:_(206)526-6780_____|




[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement