Re: Help needed for a CASE statement, something subtle going on ... [message #87777 is a reply to message #87773] |
Wed, 26 February 2014 14:57   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
john.hrv583@gmail.com writes:
> I'm learning to use CASE statements in IDL, and have tried to put the following code lines
>
> -----------------------------------------------------
> x = 2
>
> CASE x OF
> 1: print, 'one'
> 2: print, 'two'
> 3: print, 'three'
> 4: print, 'four'
> ELSE: print, 'not one through four'
> ENDCASE
> ----------------------------------------------------
>
> into a file called "case_st.pro". I then tried to run it under IDL using
> "@case_st", but got the following messages
Yes, the "@programname" syntax means execute these commands as if I was
typing these at the IDL command line. But, you can't execute multiple
line statements such as CASE statements, FOR loops, etc at the command
line. (People will tell you differently and then offer you 1970's syntax
to do so. Don't listen to them.)
You need to compile, then run, multiple line statements such as this.
The simplest way to do that is to put your commands in an IDL procedure,
like this.
PRO Case_St
x = 2
CASE x OF
1: print, 'one'
2: print, 'two'
3: print, 'three'
4: print, 'four'
ELSE: print, 'not one through four'
ENDCASE
ËND
Then, you compile and run the code like this.
IDL> case_st
Or, you can put your commands in a "main-level" program like this:
x = 2
CASE x OF
1: print, 'one'
2: print, 'two'
3: print, 'three'
4: print, 'four'
ELSE: print, 'not one through four'
ENDCASE
ËND
Note the END at the end of the program. It is required. To compile and
run a main-level program, you do this:
IDL> .run case_st
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|