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 
Switch to threaded view of this topic Create a new topic Submit Reply
Help needed for a CASE statement, something subtle going on ... [message #87773] Wed, 26 February 2014 14:42 Go to next message
john.hrv583 is currently offline  john.hrv583
Messages: 4
Registered: February 2014
Junior Member
Hi,

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:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@case_st
% Case statement found no matches.
% Execution halted at: $MAIN$

1: print, 'one'
^
% Syntax error.
At: /C1/ryu/IDL_tools/examples/case_st.pro, Line 4

2: print, 'two'
^
% Syntax error.
At: /C1/ryu/IDL_tools/examples/case_st.pro, Line 5

3: print, 'three'
^
% Syntax error.
At: /C1/ryu/IDL_tools/examples/case_st.pro, Line 6

4: print, 'four'
^
% Syntax error.
At: /C1/ryu/IDL_tools/examples/case_st.pro, Line 7

ELSE: print, 'not one through four'
^
% Syntax error.
At: /C1/ryu/IDL_tools/examples/case_st.pro, Line 8

ENDCASE
^
% Syntax error.
At: /C1/ryu/IDL_tools/examples/case_st.pro, Line 9

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++

That's a bit surprising, because this is one of the examples that I found on the web about the usage of CASE statements, and I just copied the example code into a text file. I checked the IDL manual, and also compared the code with codes I saw on different websites, but could not find out what's wrong with the syntax of the case statements. So I guess something subtle is going on here, and it's quite frustrating, because I tried different things, and also some different examples, but they all gave this kind of syntax errors. So there must be something that I have done totally wrong.

Your help would be highly appreciated!

John
Re: Help needed for a CASE statement, something subtle going on ... [message #87775 is a reply to message #87773] Wed, 26 February 2014 14:47 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Wednesday, February 26, 2014 5:42:50 PM UTC-5, john....@gmail.com wrote:
> Hi,
>
>
>
> I'm learning to use CASE statements in IDL, and have tried to put the following code lines
...
> That's a bit surprising, because this is one of the examples that I found on the web about the usage of CASE statements, and I just copied the example code into a text file. I checked the IDL manual, and also compared the code with codes I saw on different websites, but could not find out what's wrong with the syntax of the case statements. So I guess something subtle is going on here, and it's quite frustrating, because I tried different things, and also some different examples, but they all gave this kind of syntax errors. So there must be something that I have done totally wrong.


When you run something with "@", it's just like typing them on the command line. There are some limitations on the command line, such as multi-line complex statements are not allowed. So, sorry, CASE statements as you tried will not work.

You can use .RUN to try it out, which is just about as easy. You just need an END statement as the last line in your file.

Craig
Re: Help needed for a CASE statement, something subtle going on ... [message #87776 is a reply to message #87775] Wed, 26 February 2014 14:52 Go to previous messageGo to next message
john.hrv583 is currently offline  john.hrv583
Messages: 4
Registered: February 2014
Junior Member
On Wednesday, February 26, 2014 5:47:24 PM UTC-5, Craig Markwardt wrote:
> On Wednesday, February 26, 2014 5:42:50 PM UTC-5, john....@gmail.com wrote:
>
>> Hi,
>
>>
>
>>
>
>>
>
>> I'm learning to use CASE statements in IDL, and have tried to put the following code lines
>
> ...
>
>> That's a bit surprising, because this is one of the examples that I found on the web about the usage of CASE statements, and I just copied the example code into a text file. I checked the IDL manual, and also compared the code with codes I saw on different websites, but could not find out what's wrong with the syntax of the case statements. So I guess something subtle is going on here, and it's quite frustrating, because I tried different things, and also some different examples, but they all gave this kind of syntax errors. So there must be something that I have done totally wrong.
>
>
>
>
>
> When you run something with "@", it's just like typing them on the command line. There are some limitations on the command line, such as multi-line complex statements are not allowed. So, sorry, CASE statements as you tried will not work.
>
>
>
> You can use .RUN to try it out, which is just about as easy. You just need an END statement as the last line in your file.
>
>
>
> Craig

Hi Craig,

I did what you suggested. It worked perfectly. Thank you so much!

John
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 next 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.")
Re: Help needed for a CASE statement, something subtle going on ... [message #87780 is a reply to message #87777] Wed, 26 February 2014 16:08 Go to previous messageGo to next message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
Summarizing what Craig and David have said: this all goes back to the difference in a

1) script (run with IDL>@case_st)
2) main level program (run with IDL>.run case_st
3) procedure (run with IDL>case_st

One of times I use scripts is for a "make" file for GUIs. Usually, I write procedures though. Far better programming practice.

I keep a "temp" main level program laying around to "play around" in. Usually, it's a precursor for a procedure I end up writing.

I also use main level programs as "wrappers" - usually for some sort of analysis that needs to be repeated over and over.

On Wednesday, February 26, 2014 4:57:47 PM UTC-6, David Fanning wrote:
> 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.)
>
>

Then don't listen to this :-)

If you absolutely *must* you can do this in a script. Here's the 1970's syntax (it's not pretty and *very* cumbersome)

CASE x OF & $
1: print, 'one' & $
2: print, 'two' & $
3: print, 'three' & $
4: print, 'four' & $
ELSE: print, 'not one through four' & $
ENDCASE

Again, this should be a last resort.
Re: Help needed for a CASE statement, something subtle going on ... [message #87782 is a reply to message #87780] Wed, 26 February 2014 16:23 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Phillip Bitzer writes:

> Then don't listen to this :-)
>
> If you absolutely *must* you can do this in a script. Here's the 1970's syntax (it's not pretty and *very* cumbersome)
>
> CASE x OF & $
> 1: print, 'one' & $
> 2: print, 'two' & $
> 3: print, 'three' & $
> 4: print, 'four' & $
> ELSE: print, 'not one through four' & $
> ENDCASE
>
> Again, this should be a last resort.

I used to be one of thorough people, too. But, over the years, I've
learned to give people just enough information to move one step forward.
That's about all they can handle and stay productive. ;-)

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.")
Re: Help needed for a CASE statement, something subtle going on ... [message #87817 is a reply to message #87782] Thu, 27 February 2014 09:33 Go to previous messageGo to next message
john.hrv583 is currently offline  john.hrv583
Messages: 4
Registered: February 2014
Junior Member
On Wednesday, February 26, 2014 7:23:38 PM UTC-5, David Fanning wrote:
> Phillip Bitzer writes:
>
>
>
>> Then don't listen to this :-)
>
>>
>
>> If you absolutely *must* you can do this in a script. Here's the 1970's syntax (it's not pretty and *very* cumbersome)
>
>>
>
>> CASE x OF & $
>
>> 1: print, 'one' & $
>
>> 2: print, 'two' & $
>
>> 3: print, 'three' & $
>
>> 4: print, 'four' & $
>
>> ELSE: print, 'not one through four' & $
>
>> ENDCASE
>
>>
>
>> Again, this should be a last resort.
>
>
>
> I used to be one of thorough people, too. But, over the years, I've
>
> learned to give people just enough information to move one step forward.
>
> That's about all they can handle and stay productive. ;-)
>
>
>
> 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.")


Hi, everyone,

Thank you all so much for your overwhelming responses and help.

Actually I am not just learning to use CASE statements in IDL, I'm learning
to use IDL per se. And as it so happened, yesterday I got stuck with the case
statement for quite a while, because I was trying out different things that
I learned recently. Basically, I had tried almost every option that you have
suggested regarding the CASE statement, but none of them worked. (In retrospect,
with your insightful explanations, I know that's because there was always something missing in my codes.) And I was really quite frustrated.

Then I thought what I really need is to find some step by step tutorials and get familiar with some of the "subtleties" of the IDL programming language. So I searched on the Internet. While doing so, I came across this discussion group. Because I did not find anything that would help solve my problem any time soon, I decided to try to ask for help in this discussion group. But I was quite unsure if I would get any response at all, because I thought although my problem is a big problem for me, people in this group might be tired of answering this kind of questions.

To my surprise, your responses proved that I am totally wrong again:-). And I think your responses are the best tutorials I can get, because in addition to solving my particular problem at hand, they also provided precise answers to some questions I have had since I started to learn IDL recently. This definitely saved me a lot of time that I would otherwise have to spend in looking for the answers in the documents etc. myself.

All in all, I really think that each and every response from you all is a treasure. And thank you so much again for your generosity in sharing your precious time and expertise!


John


P.S.: David, I intended to post my response so that everyone in the discussion group can see it. Since I am using such a discussion group for the first time,
I'm not sure if I'm doing it correctly. If not, please give me advice on how to
do it CORRECTLY. Thanks a lot in advance!

John
Re: Help needed for a CASE statement, something subtle going on ... [message #87820 is a reply to message #87817] Thu, 27 February 2014 09:40 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
john.hrv583@gmail.com writes:

> P.S.: David, I intended to post my response so that everyone in the discussion group can see it. Since I am using such a discussion group for the first time,
> I'm not sure if I'm doing it correctly. If not, please give me advice on how to
> do it CORRECTLY. Thanks a lot in advance!

John, you are doing it correctly. We have NEVER minded answering simple
questions here if we see evidence that someone is willing to do some
work to learn IDL. It's the people who want to use us to do their
homework for them that piss us off. You will find this a friendly and
AMAZINGLY helpful community if you continue to show this kind of effort.

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.")
Re: Help needed for a CASE statement, something subtle going on ... [message #87824 is a reply to message #87820] Thu, 27 February 2014 09:58 Go to previous message
john.hrv583 is currently offline  john.hrv583
Messages: 4
Registered: February 2014
Junior Member
On Thursday, February 27, 2014 12:40:36 PM UTC-5, David Fanning wrote:
> john.hrv583@gmail.com writes:
>
>
>
>> P.S.: David, I intended to post my response so that everyone in the discussion group can see it. Since I am using such a discussion group for the first time,
>
>> I'm not sure if I'm doing it correctly. If not, please give me advice on how to
>
>> do it CORRECTLY. Thanks a lot in advance!
>
>
>
> John, you are doing it correctly. We have NEVER minded answering simple
>
> questions here if we see evidence that someone is willing to do some
>
> work to learn IDL. It's the people who want to use us to do their
>
> homework for them that piss us off. You will find this a friendly and
>
> AMAZINGLY helpful community if you continue to show this kind of effort.
>
>
>
> 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.")

Hi, David,

this is indeed a FRIENDLY & AMAZINGLY HELPFUL community. I'm touched :-)

Cheers,
John
  Switch to threaded view of this topic Create a new topic Submit Reply
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: Wed Oct 08 13:37:00 PDT 2025

Total time taken to generate the page: 0.00971 seconds