View Full Version : Programmatic use of INFO

02-24-2009, 06:45 AM
I need to find out in the middle of a program if a particular structure has been defined. Is there a way to extract the information returned via INFO,/userstruct into a string array where I could search for the existence of the structure?

02-24-2009, 10:02 AM
Hmmmm.... Would something like

mystr = 'Hello World!'
mystrct = {,a:'unnamed structure', b:10}
info, variables=vars
if sum(strmatch(vars, 'MYSTRCT')) eq 1 then print, 'Exists' else print, 'DNE'

help? Note that 'MYSTRCT is uppercase because INFO returns variable names in uppercase, and we sum the results of the STRMATCH returned array and if the sum is one then there was one unique match...

02-24-2009, 10:31 AM
A good way to do this is to use the SIZE function.

t = size(a)
; If t(N_ELEMENTS(t) -2) eq 0 then a is undefined.


02-24-2009, 10:56 AM
Event shorter

print, n_elements(ffsdddadacbvdfhfh)

Is there an issue that you won't know the names of the structures until runtime?

02-25-2009, 11:23 AM
I have ten very large data files. They all have the same structure.
I use a function to read in all the data and output one data structure. Here's how:
I read the first file in, and define a named structure 'BOZO.' For each of the next 9 files I read each into the BOZO structure and append this data to the previous. At the end I output the one big structure. No problems.

I have no visibility within the function if the BOZO structure already exists before I try to initialize it. If it does, I get the "& Conflicting data structure: ..." message. Sometimes we lose the first data set. I don't know why. If I take out the initialize structure, the first time I run this I get the "% Structure type not defined...' error message.

I can put a STOP in the code, perform a INFO,/USERSTRUCT on the command line, and look through the output and see if BOZO exists. This doesn't help in a programmatic sense. If execute the INFO,variables=vars it does return the data, but not the existence of BOZO.

What I really need is a way to do INFO,USERSTRUCT=vars, but that is not a viable PV-Wave construct.

Due to flexibility I can't really use the INFO,Vars method if the user does not conform to a particular naming convention. If they did, then I could assume by the vars list, whether the underlying structure exists.

Thanks for the help,