//-----------------------------------------------------------------------------
//
//  Peter Richter (prichter@princeton.edu)
//  Princeton Plasma Physics Laboratory
//  August 2000
//
//  f77ei.cpp - Implementation of F77 sigma*v(Te) reactions
//  electron-Hydrogen recombination; electron impact ionization
//
//-----------------------------------------------------------------------------
 
#include "preact/f77ei.h"
#include <iostream>
#include "preact/eireaction.h"
 
using namespace std ;

#define M 100
 
static EIReaction *ei[M];
static int pr_next = 0;
 
//-----------------------------------------------------------------------------
 
integer_function F77NAME(ei_init)(integer& icode, integer& ierrlo,
			      	  integer& ierrhi)
{
  if (pr_next == M) {
    cerr << "Error: Too many (over " << M << ") calls to ei_init.\n";
    F77NAME(bad_exit)();
  }
  switch (icode) {
  case 0:  ei[pr_next] = new EIReaction((char *)"recombine", ierrlo, ierrhi); break;
  case 1:  ei[pr_next] = new EIReaction((char *)"i:e->H0", ierrlo, ierrhi); break;
  case 2:  ei[pr_next] = new EIReaction((char *)"i:e->He0", ierrlo, ierrhi); break;
  case 3:  ei[pr_next] = new EIReaction((char *)"i:e->Li0", ierrlo, ierrhi); break;
  default: cerr << "Error: Invalid icode value passed to ei_init.\n"; F77NAME(bad_exit)();
  }
  return pr_next++;
}
 
//-----------------------------------------------------------------------------
 
real_function F77NAME(ei_sigmav)(integer& ihandle, real_8& Erel)
{
  if (ihandle < 0 || ihandle >= pr_next) {
    cerr << "Error: Invalid ihandle value passed to ei_sigma.\n";
    F77NAME(bad_exit)();
  }
  return ei[ihandle]->sigmav(Erel);
}
 
//-----------------------------------------------------------------------------
 
subroutine F77NAME(ei_sigvte_sigmatimesv)(integer& ihandle, real_8 *E,
					      real_8 *f, integer& n)
{
  if (ihandle < 0 || ihandle >= pr_next) {
    cerr << "Error: Invalid ihandle value passed to "
         << "ei_sigvte_sigmatimesv.\n";
    F77NAME(bad_exit)();
  }
  ei[ihandle]->sigvTe_sigmaTimesV(E, f, n);
}
 
//-----------------------------------------------------------------------------
 
subroutine F77NAME(ei_sigvte_trange)(integer& ihandle, real_8& Tmin,
					 real_8& Tmax,
					 integer& min_policy,
					 integer& max_policy)
{
  if (ihandle < 0 || ihandle >= pr_next) {
    cerr << "Error: Invalid ihandle value passed to ei_sigvte_trange.\n";
    F77NAME(bad_exit)();
  }
  range r = ei[ihandle]->sigvTe_TRange();
  Tmin = r.minimum;
  Tmax = r.maximum;
  min_policy = r.min_policy;
  max_policy = r.max_policy;
}
 
//-----------------------------------------------------------------------------
subroutine F77NAME(ei_sigvte_tpolicy)(integer& ihandle,
					  integer& min_policy,
					  integer& max_policy)
{
  ei[ihandle]->sigvTe_TPolicy(min_policy,max_policy);
}
 
//-----------------------------------------------------------------------------
