Global variables

Each of the operators, O(), L(), Linv(), cI(), cJ() require certain basic data, such as R, S or G2, to carry out its operation. In normal C programming style, we would pass this information as addition arguments to the functions. However, our solution to Poisson's equation would then cease to resemble the formal expression $\vec
\phi={\cal I}{\bf L}^{-1}(-4\pi{\cal O}{\cal J}\vec n)$ and become the quite ugly expression

  phi=cI(Linv(-4*pi*O(cJ(n,S),R),R,G2),S);

C++ provides an elegant solution to this problem. With full control over object types, one could ensure that each vector includes a pointer to the information in R, S and G2, thus giving operator access to the relevant information through its input vector. Octave does provide a primitive capacity to build and pass structures, but there is not enough control over these structures to provide the capabilities we would require.

Our solution to this dilemma is less elegant than the C++ solution but workable within the limits of octave. The alternative to passing information to a function through an argument is to pass it through a ``global'' variable. Generally, we strongly discourage the use of such variables because one easily looses track of which functions may, or may not, unexpectedly change the values of such variables. Under such circumstances, debugging becomes extremely difficult.

Fortunately, in our case, the information we wish to pass via global variables (R, S, G2) remains constant throughout our calculations, thus averting most of the dangers associated with use of global variables. Also, we will take the extra precaution of prefixing all global variables with ``gbl_'' so as to to mitigate the chances of inadvertent modification of global variables with common variable names.

To make the setup information available as global variables, declare the corresponding variables as global by adding the following lines to the very top of ``setup.m''

%# Make setup info globally accessible (ugh!)
global gbl_S; global gbl_R; global gbl_G2;
and set these variables to the appropriate values by adding the following lines to the very bottom of ``setup.m''
%# Assign computed values to the global variables
gbl_S=S; gbl_R=R; gbl_G2=G2;

Tomas Arias 2005-04-03