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.")
|
|
|
Re: Question about user input in IDL [message #67317 is a reply to message #67178] |
Fri, 10 July 2009 12:28  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Joanna writes:
> Hi, thanks for the response...I actually figured out a way to make it
> work using an if loop. I just said if x eq 'alpha' then a=alpha, and
> then stuck that a into the function I was actually using on the data
> and it worked. Thanks again!
Well, then, here is one of your first programming lessons: There
are typically *many* ways to do the job in software. The
only trick is to learn how to be either as elegant or
as efficient (depends on your personality) as possible.
It takes a while. Try to pick good mentors. :-)
Cheers,
David
P.S. To determine if you tend toward "elegance"
or "efficiency", try watching a replay of the 2008
Wimbledon tennis final and see if you find yourself
rooting for Federer or Nadal. That should give you
a pretty good clue.
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: Question about user input in IDL [message #67318 is a reply to message #67178] |
Fri, 10 July 2009 11:54  |
Joanna
Messages: 2 Registered: July 2009
|
Junior Member |
|
|
On Jul 9, 4:46 pm, David Fanning <n...@dfanning.com> wrote:
> 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.")
Hi, thanks for the response...I actually figured out a way to make it
work using an if loop. I just said if x eq 'alpha' then a=alpha, and
then stuck that a into the function I was actually using on the data
and it worked. Thanks again!
|
|
|