[Thread Prev][Thread Next][Index]
Re: defining variables using IF-THEN-ELSE syntax
Hi Lia,
The grave-accent syntax is only valid for scalar variables, but without
the grave accents the IF test applies to all the values in the
variable. The syntax you want is this.
LET nav_lon_pos = IF nav_lon LT 0 THEN nav_lon+360 ELSE nav_lon
Here's a quick example, using a short list of values for the starting
variable
yes? let a = {118,158,180,-178,-100,-62}
yes? let b = IF a LT 0 THEN (a+360) ELSE a
yes? list a, b
X: 0.5 to 6.5
Column 1: A is {118,158,180,-178,-100,-62}
Column 2: B is IF A LT 0 THEN A + 360 ELSE A
A B
1 / 1: 118.0 118.0
2 / 2: 158.0 158.0
3 / 3: 180.0 180.0
4 / 4: -178.0 182.0
5 / 5: -100.0 260.0
6 / 6: -62.0 298.0
Ansley
Lia wrote:
Hello Ferreters,
I'm hoping there is an elegant solution to this- I'm trying to redefine
my variable nav_lon so it will be monotonic (so I can use nav_lon to
define a new x axis), by adding 360 to nav_lon when nav_lon is negative.
However, I'm having problems with my IF statement because nav_lon is
both positive AND negative (118:180, -178:-62), so I don't get a scalar
output. I've tried two primary tacks, with minor variations (i.e.
including and not including the LET command):
yes? IF `nav_lon LT 0` THEN LET nav_lon2= nav_lon + 360 ELSE LET
nav_lon2 = nav_lon
** ERROR: invalid command: grave accent doesnt evaluate to scalar
nav_lon LT 0
yes? IF `nav_lon LT 0 THEN nav_lon2 = nav_lon + 360 ELSE nav_lon2 =
nav_lon`
** ERROR: command syntax: options: "P=prec", "B=bad","W=width",
"ZW=zero-width" or "R=return-item"
I read a little in the users guide about P,B,W, and R syntax, but didn't
find it to really apply to my problem. Any ideas?
Thanks,
Lia
[Thread Prev][Thread Next][Index]
Dept of Commerce /
NOAA /
OAR /
PMEL /
TMAP
Contact Us | Privacy Policy | Disclaimer | Accessibility Statement