8. Real programming: if's and do's

In addition to the vectors and matrices that physica manipulates as a whole, it knows about scalars, and, in fact, it knows how to divide up its vectors and matrices into their elements. In physica, one addresses say, the fifth element of a vector v as v[5] or v(5), and an element of a matrix m as, say, m[5,6] or m(5,6). Thus we have another way of creating the matrices of the previous section, by writing a short macro like this, and then executing it:

do j=[1:10]
  do k=[1:10]
surface m

You can see the immediate similarity with Fortran that was mentioned in the beginning. This similarity is, in fact, more extensive: physica macros can contain labels, logical ifthen statements, and goto's. These allow you to perform fairly complicated routines without leaving physica. There are many examples of such macros shown in the User's Guide. A word of caution: physica macros are interpreted line-by-line, and so an equivalent but pre-compiled Fortran program will run much faster. Thus you should reserve your physica programming for relatively simple things; when the computations get complicated and long it is best to leave physica; write, compile, and run a Fortran program; and then return to physica to look at the produced output data. Always use the tools that are appropriate to the task at hand!

Congratulations! - you have reached the end of our brief tutorial. It should have given you a taste of the capabilities of physica. For a more comprehensive discussion you are, as always, referred to the manuals.

Up: Table of contents Next: Appendix: On the Unix end Previous: 7.1 Generating 3D data