[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Creating Variables in Programs
- Subject: Re: Creating Variables in Programs
- From: Martin Schultz <mgs(at)io.harvard.edu>
- Date: Fri, 10 Jul 1998 21:02:40 -0400
- Newsgroups: comp.lang.idl-pvwave
- Organization: Dept. Earth&Planet. Sci., Harvard University
- References: <p.phillips-1007980758540001@es2.frc.utexas.edu> <35A61707.41C6@io.harvard.edu> <onemvtzrlu.fsf@cow.physics.wisc.edu>
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:11492
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
r=execute(name+'=findgen(10)')
print,r
print,b
return
end
--------------------------------------
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...
Martin.
--
-------------------------------------------------------------------
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/
-------------------------------------------------------------------