MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Aborting a computation ...

  • To: mathgroup at smc.vnet.net
  • Subject: [mg93305] Re: Aborting a computation ...
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Mon, 3 Nov 2008 05:27:43 -0500 (EST)
  • References: <gejj0o$2j3$1@smc.vnet.net>

Ignacio Plazeta wrote:
> Dear friends
> 
> There is a conceptual lack in my
> understanding of the way to stop
> a computation; nor Abort[] neither
> Interrupt[] works as I supposed
> they do.
> 
> The following code prints
> "something" when myFolder
> exists and when it doesn't.
> 
> ------------------------------------
> myFolder="c\\someFolder";
> 
> errorLevel=Catch[
> 
>    Off[SetDirectory::"cdir"];
>    SetDirectory[myFolder];
>    On[SetDirectory::"cdir"];
> 
>    If[
>      Directory[]!=myFolder,
> 
>      Print["Warning: folder non found ..."];
>      Throw[0];,
> 
>      Throw[1];
>    ];
> ];
> 
> If[errorLevel==0,Abort[]];
> 
> Print["something"];
> 
> ------------------------------------
> 
> Of course it may be fixed using:
> 
> If[errorLevel == 0,
> 
>    Abort[];
>    Print["something"];
> 
>    ];
> 
> but, in the long run, the code
> became too nested and the questions
> about Abort[]/Interrupt[] still hangs.
> 
> Warmest regards.
> Ignacio
> 
> ------------------------------------
> P.S. You see, I'm not a native
> speaking English; I apologize for
> my poor lamguage.
> 
Abort stops a Mathematica execution, it does not stop the frontend 
issuing a series of executions - e.g. when you execute a whole notebook. 
The answer is to change the structure to something like this:

myProg[]:=Module[{},
    myFolder="c\\someFolder";

    errorLevel=Catch[

    Off[SetDirectory::"cdir"];
    SetDirectory[myFolder];
    On[SetDirectory::"cdir"];

    If[
      Directory[]!=myFolder,

      Print["Warning: folder non found ..."];
      Throw[0];,

      Throw[1];
    ];
];

If[errorLevel==0,Abort[]];

Print["something"];
];

myProg[];

In this form, all your actual code is embedded in the function myProg, 
and using Abort[] will do what you want.

Note that you may want to make many of the variables local by adding 
them to the list which forms the first argument of Module.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: Mathematica 6.0: How to collect data with Manipulate?
  • Next by Date: Data fitting from coupled differential equations
  • Previous by thread: Re: Aborting a computation ...
  • Next by thread: Re: Aborting a computation ...