[ncl-talk] bug with isdefined and isvar?
Jared Lee
jaredlee at ucar.edu
Fri Aug 26 10:02:23 MDT 2016
Hi, I think I've found a bug with the functions isdefined and isvar.
Whether I pass in a variable from the command line or define it in the
script, isdefined() and isvar() both return False, instead of returning
True as the documentation says they should. And if I have them test a
variable name that has not been defined, then NCL exits with an undefined
variable error, instead of returning False as the documentation says they
should. See below for a test script and output from the test script that
demonstrates the problem.
What I need is the ability to test if a variable has been declared
(especially via the command line) to avoid crashing the code.
Here's the test script, which I called isdefined.ncl:
begin
print(var)
test1 = isdefined(var)
test2 = isvar(var)
print(var)
print(test1)
print(test2)
var = 20
test3 = isdefined(var)
test4 = isvar(var)
print(var)
print(test3)
print(test4)
var2 = 20
test5 = isdefined(var2)
test6 = isvar(var2)
print(var2)
print(test5)
print(test6)
test7 = isdefined(var3)
test8 = isvar(var3)
print(test7)
print(test8)
end
And then here is the output:
jaredlee$ ncl isdefined.ncl 'var=10'
Copyright (C) 1995-2015 - All Rights Reserved
University Corporation for Atmospheric Research
NCAR Command Language Version 6.3.0
The use of this software is governed by a License Agreement.
See http://www.ncl.ucar.edu/ for more details.
Variable: var
Type: integer
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) 10
warning:Argument 0 of the current function or procedure was coerced to the
appropriate type and thus will not change if the function or procedure
modifies its value
warning:Argument 0 of the current function or procedure was coerced to the
appropriate type and thus will not change if the function or procedure
modifies its value
Variable: var
Type: integer
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) 10
Variable: test1
Type: logical
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) False
Variable: test2
Type: logical
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) False
warning:Argument 0 of the current function or procedure was coerced to the
appropriate type and thus will not change if the function or procedure
modifies its value
warning:Argument 0 of the current function or procedure was coerced to the
appropriate type and thus will not change if the function or procedure
modifies its value
Variable: var
Type: integer
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) 20
Variable: test3
Type: logical
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) False
Variable: test4
Type: logical
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) False
warning:Argument 0 of the current function or procedure was coerced to the
appropriate type and thus will not change if the function or procedure
modifies its value
warning:Argument 0 of the current function or procedure was coerced to the
appropriate type and thus will not change if the function or procedure
modifies its value
Variable: var2
Type: integer
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) 20
Variable: test5
Type: logical
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) False
Variable: test6
Type: logical
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) False
fatal:Variable (var3) is undefined
fatal:["Execute.c":8575]:Execute: Error occurred at or near line 24 in file
isdefined.ncl
--
===============================
Jared A. Lee, Ph.D.
Project Scientist I
Research Applications Laboratory
National Center for Atmospheric Research
Boulder, Colorado, USA
Email: jaredlee at ucar.edu (w)
Phone: 303.497.8485 (w)
Web: https://staff.ucar.edu/users/jaredlee
===============================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160826/947f1953/attachment.html
More information about the ncl-talk
mailing list