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

Home » Public Forums » archive » Help needed for a CASE statement, something subtle going on ...
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: Help needed for a CASE statement, something subtle going on ... [message #87777 is a reply to message #87773] Wed, 26 February 2014 14:57 Go to previous messageGo to previous message
David Fanning is currently offline  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.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Wrapping image on polar projection
Next Topic: Re: Guide: how to call Fortran from IDL in a portable and stardard F 2003 way

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

Current Time: Thu Oct 09 07:50:07 PDT 2025

Total time taken to generate the page: 0.88043 seconds