isstructype#
Purpose#
Returns 1 if structure matches the input type.
Format#
- structure_matches = isStructType(struct_instance, struct_type)#
- Parameters:
struct_instance (Struct) – Structure to check.
struct_type (String) – Structure type to check for.
- Returns:
match (Scalar) – 1 if struct_instance is a structure of the type type specified by struct_type.
Examples#
Basic usage#
// Create structure
struct plotControl plt;
plt = plotGetDefaults("Bar");
// Check if structure is olsmtControl
isStructType(plt, "olsmtControl");
Because plt is a plotControl
structure this returns 0.
// Now check for plotControl structure
isStructType(plt, "plotControl");
This returns 1 because plt is a plotControl
structure.
Create a function to handle different data types#
isstructtype()
can be used to verify data in your program and handle it appopriately.
In this example, we will create a function that will print our data differently whether it comes in as a numeric matrix, a PV structure or a DS structure. Our first step is to create the procedures to print the different data:
proc (0) = printMatrix(p);
print p;
endp;
proc (0) = printDSData(struct DS d);
for i(1, rows(d), 1);
print d[i].dataMatrix;
endfor;
endp;
proc (0) = printPVData(struct PV p);
print pvGetParNames(p);
print pvGetParVector(p);
endp;
Next we will create our main printData
function that will check the input and call the correct print procedure:
proc (0) = printData(p);
if isStructType(p, "DS");
print "DS structure passed in:";
printDSData(p);
elseif isStructType(p, "PV");
print "PV structure passed in:";
printPVData(p);
else;
print "Numeric vector passed in:";
printMatrix(p);
endif;
endp;
Now let’s try it out with different data:
x = { -1.2, 0.83, 0.03 };
printData(x);
Numeric vector passed in:
-1.2000000
0.83000000
0.030000000
struct DS data;
data = reshape(data, 2, 1);
data[1].dataMatrix = x;
data[2].dataMatrix = 2 * x;
printData(data);
DS structure passed in:
-1.2000000
0.83000000
0.030000000
-2.4000000
1.6600000
0.060000000
struct PV p1;
p1 = pvPack(pvCreate(), x[1], "alpha");
p1 = pvPack(p1, x[2], "beta");
printData(p1);
PV structure passed in:
alpha[1,1]
beta[1,1]
-1.2000000
0.83000000
See also
Functions isstring()
, type()