If I have a structure with the field name 'fieldname', is it possible to access the data in this field using only a variable?
t
x = 'fieldname'
can do
data = struct. (x) somehow? I want to use the string in x as the name of the field.
Yes, this is possible using the function TAG_NAMES:
TAG_NAMES
tnames=TAG_NAMES(struct) tindex=WHERE(STRCMP(tnames,'fieldname') EQ 1) data=struct.(tindex)
TAG_NAMES , , struct. WHERE tnames , 'fieldname'. , struct.(tindex), .
struct
WHERE
tnames
'fieldname'
struct.(tindex)
, , tindex -, IDL -1.
tindex