[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating Variables in Programs

Craig Markwardt wrote:
> > IDL> r=execute('a=fltarr(200)')
> > IDL> help,a
> > A               FLOAT     = Array[200]
> >
> There is a "gotcha."  in the case of a compiled procedure, the
> variable "a" must have already been defined.  The following is usually
> sufficient:
> [...]

Huh? Here is a little program:

pro testexec,name



Of course, you have to call it as testexec,'b' in order to have it work
properly ;-), but it demonstrates that you don't have to have your
variable initialized!! 

But I don't really see the point of the original question: why the h...
do you want to do this? To my knowledge, creating variables only makes
sense if you know what to do with them afterwards - and in order to do
something with them, you must know their name beforehand. If you want to
export your newly created variables to the main program or some other
procedure, you would have to proceed completely different. I would
create a structure with 
    template = { name:'', pvalue:ptr_new() }
(or an array of these structures with replicate(...)  )

then manipulatge the string 'name=expression' to 'tmp=expression', store
the 'name' field in the name tag of the structure and
pvalue=ptr_new(tmp) will save the value.

This would act as a container (sounds awfully like OOP doesn't it ?),
and you would have to do a lot of type and error checking in any routine
that uses the information in this structure (array). Note, that IDL
itself would not "know" anything about your variables - but, as I said,
it doesn't make sense if it had to.

... and don't forget to clean up your heap once a while...


Dr. Martin Schultz                   
Department for Earth&Planetary Sciences, Harvard University
109 Pierce Hall, 29 Oxford St., Cambridge, MA-02138, USA

phone: (617)-496-8318
fax  : (617)-495-4551

e-mail: mgs@io.harvard.edu
Internet-homepage: http://www-as.harvard.edu/people/staff/mgs/