schint(): Psiout==NULL case

Often times, when schint() is called, the values placed in Psiout[] are ignored. A common device in C for communicating to the subroutine that a set of values need not be computed is to pass the value ``NULL'' to the subroutine. The subroutine may then check whether it needs to return the value and may then skip the associated calculations if they are not needed. Another significant advantage is that the calling function no longer needed to provide space for the result!

For instance, at the moment, your func_Schrodinger() routine in ``physics.c'' should look something like the function below:

double func_Schrodinger(double E,
			int match, double V[], double r[], double dr[], int N)
{
  double Psi=0.,Psip=1.;
  int k1,k2;

  /* Allocation of space that is NOT actually NEEDED */
  double *Psiout;
  Psiout=dvector(0,N);

  /* Outward integration */
  schint(&Psi,&Psip,Psiout,k1=0,k2=N,V,E,r,dr,N);

  /* Free the space that was NOT actually NEEDED */
  free_dvector(Psiout,0,N);

  return Psi;
}
If, on the other hand, we rewrite schint() to not compute Psiout if it is passed as ``NULL'', then we can write simply
double func_Schrodinger(double E,
			int match, double V[], double r[], double dr[], int N)
{
  double Psi=0.,Psip=1.;
  int k1,k2;

  /* Outward integration */
  schint(&Psi,&Psip,NULL,k1=0,k2=N,V,E,r,dr,N);

  return Psi;
}
and never need to allocate (or have schint() compute) Psiout[]!

You should thus modify schint() so that, before each operation involving Psiout, you check whether the operation actually needs to be performed by using a statement like ``if (Psiout!=NULL) ...''.

Hints:
(1) Note that when you have to rescale an entire range of values in Psiout[] (Problem 2.2) it is much more efficient to place the ``if (Psiout!=NULL) ...'' statement before the ``for (...)'' loop, rather than after it.

(2) You may have to rearrange your program a little to use new variables if (when counting nodes, for instance) you were using values stored in Psiout[].

Tomas Arias 2006-02-22