
NCL Home >
Documentation >
Functions >
Unclassified routines
isconform
Check two variables for array conformance (same shape and size).
Available in version 6.5.0 and later.
Prototype
function isconform ( x , y )
Arguments
xA scalar or array variable of any type.
yA scalar or array variable of any type.
Return value
Returns True if x and y are array conformant; False otherwise.
Description
Variable arrays are considered to conform if they have the same dimensionality (ie; same number of dimensions (rank) and identical dimension sizes). In NCL, a scalar variable is special in the sense that scalars conform to any array.
Note: Variables can 'conform' but they may have different variable types.
See Also
Examples
Example 1:
a = 1 ; scalar (integer) b = 2 ; " " ab = isconform(a, b) ; ab=True; both scalars of same types c = 3.0 ; scalar (float) ac = isconform(a, c) ; ac=True; both scalars of different types d = (/1,99/) ; integer array ad = isconform(a, d) ; ad=True; array conformant because 'a' is a scalar e = (/1,50, 99/) ; integer array de = isconform(d, e) ; de=False ; arrays non-conformant because of size difference ntim = 10 klev = 5 nlat = 3 mlon = 2 w = random_normal(0,1, (/ntim,nlat,mlon/)) ; (10, 3, 2) , rank=3 xf = random_normal(0,1, (/ntim,nlat,mlon/)) ; (10, 3, 2) xd = random_normal(0,1d,(/ntim,nlat,mlon/)) ; (10, 3, 2) y = random_normal(0,1, (/ntim,mlon,nlat/)) ; (10, 2, 3) z = random_normal(0,1, (/nlat,mlon,ntim/)) ; ( 2, 3,10) z4 = random_normal(0,1 ,(/ntim,klev,nlat,mlon/)) ; (10, 5, 3, 2) , rank=4 wxf = isconform(w, xf) ; wxf=True ; conformant ; same rank and dimension sizes wxd = isconform(w, xd) ; wxd=True ; conformant ; same rank and dimension sizes ; different types wy = isconform(w, y) ; wy =False ; not conformant ; same rank but size differences wz = isconform(w, z) ; wz =False ; not conformant ; same rank but size differences wz4 = isconform(w, z4) ; wz4=False ; not conformant ; different ranks
Example 2: Create functions that use isconform as the basis for testing multiple variables. For the 4-variable test, include a text string.
undef("isconform_3var") function isconform_3var(x, y, z) ; ; USAGE: tf_3var = isconform_3var(FLUX, T, Q ) ; local tf begin tf = (/False, False, False/) tf(0) = isconform(x, y) tf(1) = isconform(x, z) tf(2) = isconform(y, z) if (all(tf)) then return(True) else return(False) end if end ;--- undef("isconform_4var") function isconform_4var(text[1]:string, w, x, y, z) ; ; USAGE: tf_4var = isconform_4var("Moisture Transport: " , FLUX, T, Q, ZG ) ; local tf begin tf = (/False, False, False, False, False, False/) tf(0) = isconform(w, x) tf(1) = isconform(w, y) tf(2) = isconform(w, z) tf(3) = isconform(x, y) tf(4) = isconform(x, z) tf(5) = isconform(y, z) if (all(tf)) then print("isconform_4var: "+text+": all arrays are conformant") return(True) else print("isconform_4var: "+text+": all arrays are NOT conformant") return(False) end if end