//-----------------------------------------------------------------------------
//
//  Peter Richter (prichter@princeton.edu)
//  Princeton Plasma Physics Laboratory
//  August 2000
//
//  f77sv.cpp - Implementation of F77 ionization reaction routines.
//    impurity stopping cross sections, cold table only
//
//-----------------------------------------------------------------------------
 
#include "preact/f77sv.h"
#include <iostream>
#include "preact/svreaction.h"
 
using namespace std ;

#define M 100
 
static SVReaction *sv[M];
static int pr_next = 0;
 
//-----------------------------------------------------------------------------
 
integer_function F77NAME(sv_init)(integer& icode, integer& ierrlo,
			      	  integer& ierrhi)
{
  if (pr_next == M) {
    cerr << "Error: Too many (over " << M << ") calls to sv_init.\n";
    F77NAME(bad_exit)();
  }
  switch (icode) {
  case 1:  sv[pr_next] = new SVReaction((char *)"C+6->H", ierrlo, ierrhi); break;
  case 2:  sv[pr_next] = new SVReaction((char *)"C+6->He", ierrlo, ierrhi); break;
  case 3:  sv[pr_next] = new SVReaction((char *)"C+6->Li", ierrlo, ierrhi); break;
  case 4:  sv[pr_next] = new SVReaction((char *)"O+8->H", ierrlo, ierrhi); break;
  case 5:  sv[pr_next] = new SVReaction((char *)"O+8->He", ierrlo, ierrhi); break;
  case 6:  sv[pr_next] = new SVReaction((char *)"O+8->Li", ierrlo, ierrhi); break;
  default: cerr << "Error: Invalid icode value passed to sv_init.\n"; F77NAME(bad_exit)();
  }
  return pr_next++;
}
 
//-----------------------------------------------------------------------------
 
real_function F77NAME(sv_sigmav)(integer& ihandle, real_8& Erel)
{
  if (ihandle < 0 || ihandle >= pr_next) {
    cerr << "Error: Invalid ihandle value passed to sv_sigma.\n";
    F77NAME(bad_exit)();
  }
  return sv[ihandle]->sigmav(Erel);
}
 
//-----------------------------------------------------------------------------
 
subroutine F77NAME(sv_coldtarget_sigmatimesv)(integer& ihandle, real_8 *E,
					      real_8 *f, integer& n)
{
  if (ihandle < 0 || ihandle >= pr_next) {
    cerr << "Error: Invalid ihandle value passed to "
         << "sv_coldtarget_sigmatimesv.\n";
    F77NAME(bad_exit)();
  }
  sv[ihandle]->coldTarget_sigmaTimesV(E, f, n);
}
 
//-----------------------------------------------------------------------------
 
subroutine F77NAME(sv_coldtarget_erange)(integer& ihandle, real_8& Emin,
					 real_8& Emax,
					 integer& min_policy,
					 integer& max_policy)
{
  if (ihandle < 0 || ihandle >= pr_next) {
    cerr << "Error: Invalid ihandle value passed to sv_coldtarget_erange.\n";
    F77NAME(bad_exit)();
  }
  range r = sv[ihandle]->coldTarget_ERange();
  Emin = r.minimum;
  Emax = r.maximum;
  min_policy = r.min_policy;
  max_policy = r.max_policy;
}
 
//-----------------------------------------------------------------------------
subroutine F77NAME(sv_coldtarget_epolicy)(integer& ihandle,
					  integer& min_policy,
					  integer& max_policy)
{
  sv[ihandle]->coldTarget_EPolicy(min_policy,max_policy);
}
 
//-----------------------------------------------------------------------------
 
