Re: Use of STOP inside an IF statement [message #60861] |
Wed, 18 June 2008 11:19 |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On Jun 17, 1:46 pm, Benjamin.R.Ev...@gmail.com wrote:
> I currently have:
>
> spawn, 'mkdir '+output_dir, message
> IF ( string(message) ) then begin
> print, message
> stop
> ENDIF
>
> But the stop command will not work inside the IF statment but it will
> work
> outside the IF statment. I need it to be inside the IF statement so
> that the program
> stops if a message is printed out.
>
> Any help would be appreciated.
>
> Ben
Why don't you just use the MESSAGE procedure, since it is virtually
the same thing as a PRINT followed by a STOP?
-Jeremy.
|
|
|
Re: Use of STOP inside an IF statement [message #60877 is a reply to message #60861] |
Tue, 17 June 2008 14:56  |
Brian Larsen
Messages: 270 Registered: June 2006
|
Senior Member |
|
|
> spawn, 'mkdir '+output_dir, message
Ben,
the other thing that occurs to me is that you ought to use the IDL
routine FILE_MKDIR not spawn for this application. It will be
faster, more portable, and behave in the way that you want.
do a help on directory to see all the commands you can use.
Cheers,
Brian
------------------------------------------------------------ --------------
Brian Larsen
Boston University
Center for Space Physics
http://people.bu.edu/balarsen/Home/IDL
|
|
|
Re: Use of STOP inside an IF statement [message #60880 is a reply to message #60877] |
Tue, 17 June 2008 11:16  |
Chris[5]
Messages: 16 Registered: May 2008
|
Junior Member |
|
|
On Jun 17, 7:46 am, Benjamin.R.Ev...@gmail.com wrote:
> I currently have:
>
> spawn, 'mkdir '+output_dir, message
> IF ( string(message) ) then begin
> print, message
> stop
> ENDIF
>
> But the stop command will not work inside the IF statment but it will
> work
> outside the IF statment. I need it to be inside the IF statement so
> that the program
> stops if a message is printed out.
>
> Any help would be appreciated.
>
> Ben
The code looks fine. Have you considered the fact that the if
statement isn't true? For example, on my linux machine at least, if I
call mkdir through spawn and attempt to create an illegal directory
(one that already exists, for example), I get an error message printed
directly to the terminal, but not returned to the message variable. In
this case, your if loop fails to fire. The error message WOULD be
displayed to the screen but, if this if statement is embedded in some
sort of computationally intensive region of code, there tends to be a
lag between when messages are sent to the the terminal and when they
show up, leading you to think that it's not printing at all.
chris
|
|
|
Re: Use of STOP inside an IF statement [message #60881 is a reply to message #60880] |
Tue, 17 June 2008 11:01  |
Brian Larsen
Messages: 270 Registered: June 2006
|
Senior Member |
|
|
> But I think there is something else going on here that
> is confusing you.
As is the norm, I think that David is right here. Your command:
spawn, 'mkdir '+output_dir, message
will not have any output unless there is an error in the creation. So
the statement:
IF ( string(message) ) then begin
is a little odd as you are testing '' (nothing), with IF. You
probably want something more like:
IF strlen(String(message)) ne 0 then begin ;; print an error message
and go about you business
The reason that you are never hitting the STOP is that the IF
statement is never true.
Cheers,
Brian
------------------------------------------------------------ --------------
Brian Larsen
Boston University
Center for Space Physics
http://people.bu.edu/balarsen/Home/IDL
|
|
|
Re: Use of STOP inside an IF statement [message #60882 is a reply to message #60881] |
Tue, 17 June 2008 10:54  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Benjamin.R.Evans@gmail.com writes:
> But the stop command will not work inside the IF statment but it will
> work
> outside the IF statment. I need it to be inside the IF statement so
> that the program
> stops if a message is printed out.
Are you sure you mean "STOP"? I would think you would
want a RETURN here. But, in any case, there is no reason
you can't have a STOP inside of an IF statement. It is
identical to a breakpoint.
But I think there is something else going on here that
is confusing you.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|