NCL Home >
Documentation >
Functions >
Array query
isscalar
Returns True if the given argument is a scalar (rank one and size one).
Available in version 6.4.0 and later.
Prototype
function isscalar ( x )
Arguments
xA variable of any type.
Return value
Returns True if x is a scalar; False otherwise.
Description
In mathematics, a 'scalar' refers to a variable (x) of type numeric that has an array rank and size of one. This implementation adopts a broader definition. Here a scalar is defined as "an atomic quantity that can hold only one value at a time".
If a user wishes to restrict the test to type numeric, the following approach could be used:
if (isnumeric(x) .and. isscalar(x)) then
...
end if
or a user defined function could be created:
undef("isscalar_num")
function isscalar_num (x)
begin
if (isnumeric(x) .and. isscalar(x)) then
return(True)
else
return(False)
end if
end
Examples
Example 1
i = 1
x = (/ 3.3, 7.3111 /)
s = "s"
S = (/ "a", "q", "z"/)
print("isscalar(i)="+isscalar(i))
print("isscalar(x)="+isscalar(x))
print("isscalar(s)="+isscalar(s))
print("isscalar(S)="+isscalar(S))
yields
(0) isscalar(i)=True (0) isscalar(x)=False (0) isscalar(s)=True (0) isscalar(S)=False