.. highlight:: rst Gluing Stand-Alone Applications =============================== This section follows closely the approach of Langtangen: Python Scripting for Computational Science and Engineering, chapter 2.3. Scripting --------- Suppose you have a stand-alone code for solving the ODE: :math:`m\frac{d^2 u}{dt^2} + b \frac{du}{dt} + cf(u) = A \cos \omega t` and you wish to have simulation results for varoius choices of the parameters. For instance, the provided oscillator.f inp run (gfortran -O3 -o oscillator oscillator.f) reads the following parameters from the standard input, in the listed order: :math:`m,b,c`, name of f(y) function, A, :math:`\omega, y_0, t_{{stop}}, \Delta t` The values of the parameters may be placed in a file inp: and the program can be run as oscillator < inp The output consists of data points :math:`t_i u(t_i)`, a suitable format to plot, e.g. with gnuplot. Under the `link `_ you'll find fortran, C and python versions of this stand-alon code. .. highlight:: python :linenothreshold: 5 Our first goal is to simplify the user's interaction with the program; with the script simviz1.py it is possible to adjust the parameters through command-line options:: python simviz1.py -m 3.3 -b 0.9 -dt 0.05 The result should be png-files and an otional plot on the screen. The files for each such experiment should go in a subdirectory. .. literalinclude:: SAMtut01/oscillator/F77/simviz1.py :language: python One can easily generate an automatic LaTeX-report or HTML-report containing the values of the parameters and the corresponding pictures. Conducting Numerical Experiments -------------------------------- Suppose we want to keep most of the parameters fixed and vary one parameter between a minimum and a maximum value; the results should be collected in a HTML-report:: python loop4simviz1.py m_min m_max m_increment [ simviz1.py options ] .. literalinclude:: SAMtut01/oscillator/F77/loop4simviz1.py :language: python or let vary any parameter:: loop4simviz2.py parameter min max increment [ simviz2.py options ] .. literalinclude:: SAMtut01/oscillator/F77/loop4simviz2.py :language: python