comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Variable name to string
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Variable name to string [message #25868 is a reply to message #25780] Wed, 18 July 2001 07:04 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Chad Bender <cbender@mail.astro.sunysb.edu> writes:

> Hello-
>
> Can anyone please point me towards the solution of the following
> problem?
>
> Say I want to create a program that will write the contents of a named
> array to a
> file of the same name. This could be accomplished by having the program
> prompt
> the user for both the variable name (getting the array by reference) and
> the file name
> (getting the string naming the output file), and the user just puts the
> same
> thing twice. However, I would like to be able to do it so the user only
> has one prompt.

This appears to be basic string manipulation, which can be
accomplished using the "+" symbol.

;; Get variable name.
varname = ''
read, varname

;; Derive file name from variable name
filename = varname + '.dat'

Now, as the others have pointed out, the harder question is really,
how do you get at a variable for which you only have the name?
EXECUTE can work if the variable and your code are at the same level.
For example, this code

return_code = execute('DATA = '+varname)

will put the data into a variable named DATA. Also, sneaky use of
ROUTINE_NAMES can do it. But honestly, you should try to re-work your
concept so you don't have to do that if you can.

Craig


--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: help with findfile
Next Topic: Re: Plotting a 3D Array In IDL

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 19:55:19 PDT 2025

Total time taken to generate the page: 0.00274 seconds