View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

Case structures in IRAF scripts

Elden Paul Iverson wrote on Apr 24, 2008

Mike-

Does SPP support case structures? If so, can you give me a simple example of the syntax?

Thanks.
-Paul

Mike Fitzpatrick wrote on Apr 24, 2008

Are you asking about SPP (the compiled language now shunned by all but the truly enlightened), or CL scripts?

In both cases the answer is yes. For SPP the syntax is


        switch (int_expr) {             SWITCH CASE construct
        case int_const_list:
            statements
        case int_const_list:
            statements
        default:
            statements
        }


Where 'int_expr' would include things like a single character if you wanted to switch over keystrokes.

For CL scripts the basic structure is the same but the switch value can be a script variable, a constant, a cursor/keystroke read. or even an expression. It is most often used (by me anyway) to put keystroke interactivity into a script. For example:


        switch (ch) {
        case "?":  
            {   
                print ("you need help")
            }
        case "t": 
            {   
                printf ("something clever here ")
            }
        default:
               print ("Invalid command")
        }


Note that don't need a BREAK statement, the code block executes and doesn't fallthru to the next case the way it does in C.

Cheers,
-Mike

Last post on Apr 24, 2008