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

Home » Public Forums » archive » Re: Question about user input in IDL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Question about user input in IDL [message #67178] Thu, 09 July 2009 14:46 Go to next message
David Fanning is currently offline  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 Go to previous message
David Fanning is currently offline  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 Go to previous message
Joanna is currently offline  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!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Are user-defined private methods possible?
Next Topic: findgen anomaly?

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

Current Time: Wed Oct 08 13:52:51 PDT 2025

Total time taken to generate the page: 0.00474 seconds