Re: Question about user input in IDL [message #67178] |
Thu, 09 July 2009 14:46  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Joanna writes:
> Hi! I'm a very, very amateur programmer, much less IDL user... so if
> this question doesn't even make sense, I wouldn't be surprised!
>
> Okay, so I'm writing a code that requires the user to input a string.
> I have this:
>
> x=''
> read,'Enter first type (Example: alpha, beta, gamma): ',x
> print,x
>
> So, when I execute this, and someone chooses alpha, then alpha gets
> printed on the screen. However, within the program, I've read in some
> data using rdfloat,'filename.txt',alpha,beta,gamma. So, really I want
> to define x as alpha which then refers to this column of data, so that
> when it gets to the print,x it actually prints this column of data. I
> don't even know if this is possible, but if there's a way to do it, I
> would be ecstatic!
How about something like this:
rdfloat, 'filename.txt', alpha, beta, gamma
x = ''
read,'Enter first type (Example: alpha, beta, gamma): ',x
CASE StrLowCase(x) OF
'alpha': Print, alpha
'beta': Print, beta
'gamma': Print, gamma
ELSE: Print, 'I have no idea what you want!!'
ENDCASE
Cheers,
David
--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|