next up previous contents
Next: Bifurcation Diagram Files Up: Running AUTO using Python Previous: Second Example   Contents


Extending the AUTO CLUI

The code in Figure 4.7 performed a very useful and common procedure, it started an AUTO  calculation and performed additional continuations at every point which AUTO detected as a bifurcation. Unfortunately, the script as written can only be used for the bvp demo. In this section we will generalize the script in Figure 4.7 for use with any demo, and demonstrate how it can be imported back into the interactive mode to create a new command for the AUTO CLUI. Several examples of such ``expert'' scripts can be found in auto/07p/demos/python/n-body.

Just as loops and conditionals can be used in Python , one can also define functions. For example, Figure 4.12 is a functional version of script from Figure 4.7. The changes are actually quite minor. The first line, from AUTOclui import *, includes the definitions of the AUTO CLUI commands, and must be included in all AUTO CLUI scripts which define functions. The next line, def myRun(demo):, begins the function definition, and creates a function named myRun which takes one argument demo. The rest of the script is the same except that it has been indented to indicate that it is part of the function definition, and all occurrences of string 'bvp' have been replaced with the variable demo. Finally we have added a line myRun('bvp') which actually calls the function we have created and runs the same computation as the original script.

\begin{figure}
% latex2html id marker 826
{\small\begin{center}\begin{boxedverb...
...an be found in {\sf \$AUTO\_DIR/demos/python/userScript.xauto}.
}
\end{figure}

While the script in Figure 4.12 is only slightly different then the one showed in Figure 4.7 it is much more powerful. Not only can it be used as a script for running any demo by modifying the last line, it can be read back into the interactive mode of the AUTO CLUI and used to create a new command, as in Figure 4.13. First, we create a file called userScript.py which contains the script from Figure 4.12, with one minor modification. We want the function only to run when we use it interactively, not when the file userScript.py is read in, so we remove the last line where the function is called. We start the AUTO CLUI with the Unix command auto, and once the AUTO CLUI is running we use the command from userScript import *, to import the file userScript.py into the AUTO CLUI. The import command makes all functions in that file available for our use (in this case myRun is the only one). It is important to note that from userScript import * does not use the .py extension on the file name. After importing our new function, we may use it just like any other function in the AUTO  CLUI, for example by typing myRun('bvp').

\begin{figure}
% latex2html id marker 849
{\small\begin{center}\begin{boxedverb...
...pt can be found in
{\sf \$AUTO\_DIR/python/demo/userScript.py }}
\end{figure}


next up previous contents
Next: Bifurcation Diagram Files Up: Running AUTO using Python Previous: Second Example   Contents
Gabriel Lord 2007-11-19