//-----------------------------------------------------------------------------
//
//  Peter Richter (prichter@princeton.edu)
//  Princeton Plasma Physics Laboratory
//  August 2000
//
//  listtables.cpp - List table parameters for a particular reaction.
//
//-----------------------------------------------------------------------------

#include <iostream>
#include <stdlib.h>
#include <string>
#include "preact/table.h"

#define M 180

using namespace std ;

//-----------------------------------------------------------------------------

void showparam(char reaction[], char table[], char desc[])
{
  char buf[M];
  fp_64 p[8];

  strcpy(buf, reaction);
  strcat(buf, table);
  getparam(buf, p);
  cout << desc << endl;

  if (!strcmp(table, "thermonuclear"))
    cout << "T axis (keV):  ";
  else
    cout << "E axis (keV):  ";
  if (!strcmp(table, "gyroAvg"))
    cout << "min = " << 1e-3 * p[0] << ", max = " << 1e-3 * p[1];
  else
    cout << "min = " << p[0] << ", max = " << p[1];
  cout << ", #points = " << p[2] << ", spacing = ";
  if (p[3] == LOG)
    cout << "logarithmic" << endl;
  else /* p[3] == LIN */
    cout << "linear" << endl;

  if (p[4] != -1) {
    if (!strcmp(table, "gyroAvg"))
      cout << "Var axis (dimensionless):  ";
    else
      cout << "T axis (keV):  ";
    cout << "min = " << p[4] << ", max = " << p[5]
	 << ", #points = " << p[6] << ", spacing = ";
    if (p[7] == LOG)
      cout << "logarithmic" << endl;
    else /* p[7] == LIN */
      cout << "linear" << endl;
  }
  cout << endl;
}

//-----------------------------------------------------------------------------

void showtables(char reaction[], char tag[])
{
  cout << "----------------------------------------"
       << "----------------------------------------\n" << endl;
  cout << tag << " tables:\n" << endl;

  showparam(reaction, "coldTarget", "sigma*v beam to cold target");
  showparam(reaction, "warmTarget", "<sigma*v> beam to warm target");

  if (!strncmp(reaction, "cx", 2)) {
    showparam(reaction, "energyAvg_perAMU", "<E/A> of target reagent");
    showparam(reaction, "average_vDotNorm", "<Vb dot Vtarg / |Vb|*|Vth|>");
  }
  else if (!strncmp(reaction, "fs", 2)) {
    showparam(reaction, "thermonuclear", "<<sigma*v>> thermonuclear");
    showparam(reaction, "gyroAvg", "<sigma*v> gyro average");
  }
}

//-----------------------------------------------------------------------------

int main()
{
  char reaction[M], tag[M];
  char response[M];
  int n;

  // get reaction type
  do {
    cout << "Select a reaction type, or enter 'q' to quit:\n"
         << "  1 = charge exchange\n"
         << "  2 = ionization\n"
	 << "  3 = fusion\n"
	 << "> ";
    cin >> response;
    if (!strcmp(response, "q"))
      exit(0);
    else
      n = atoi(response);
  } while (n < 1 || n > 3);

  // charge exchange reaction
  if (n == 1) {
    do {
      cout << "Select a particular reaction, or enter 'q' to quit:\n"
	   << "  1 = H->H(cx)\n"
	   << "  2 = H+->He0x\n"
	   << "  3 = He++>Hex\n"
	   << "  4 = H+->Li0x\n"
	   << "  5 = He++>Lix\n"
	   << "  6 = Li+++>Lx\n"
	   << "> ";
      cin >> response;
      if (!strcmp(response, "q"))
	exit(0);
      else
	n = atoi(response);
    } while (n < 1 || n > 6);
    switch (n) {
    case 1: strcpy(reaction, "cx/cxtabl/"); strcpy(tag, "H->H(cx)"); break;
    case 2: strcpy(reaction, "cx/phecxt/"); strcpy(tag, "H+->He0x"); break;
    case 3: strcpy(reaction, "cx/hextbl/"); strcpy(tag, "He++>Hex"); break;
    case 4: strcpy(reaction, "cx/plicxt/"); strcpy(tag, "H+->Li0x"); break;
    case 5: strcpy(reaction, "cx/helixt/"); strcpy(tag, "He++>Lix"); break;
    case 6: strcpy(reaction, "cx/lilixt/"); strcpy(tag, "Li+++>Lx"); break;
    }
  }

  // ionization reaction
  else if (n == 2) {
    do {
      cout << "Select a particular reaction, or enter 'q' to quit:\n"
	   << "  1 = H->H(ii)\n"
	   << "  2 = H+->He0i\n"
	   << "  3 = He++>H0i\n"
	   << "  4 = He++>Hei\n"
	   << "  5 = H+->Li0i\n"
	   << "  6 = He++>Lii\n"
	   << "  7 = Li+++->H\n"
	   << "  8 = Li+++>He\n"
	   << "  9 = Li+++>Li\n"
	   << "> ";
      cin >> response;
      if (!strcmp(response, "q"))
	exit(0);
      else
	n = atoi(response);
    } while (n < 1 || n > 9);
    switch (n) {
    case 1: strcpy(reaction, "ii/iitabl/"); strcpy(tag, "H->H(ii)"); break;
    case 2: strcpy(reaction, "ii/pheiit/"); strcpy(tag, "H+->He0i"); break;
    case 3: strcpy(reaction, "ii/hehixt/"); strcpy(tag, "He++>H0i"); break;
    case 4: strcpy(reaction, "ii/heitbl/"); strcpy(tag, "He++>Hei"); break;
    case 5: strcpy(reaction, "ii/pliiit/"); strcpy(tag, "H+->Li0i"); break;
    case 6: strcpy(reaction, "ii/heliit/"); strcpy(tag, "He++>Lii"); break;
    case 7: strcpy(reaction, "ii/lihiit/"); strcpy(tag, "Li+++->H"); break;
    case 8: strcpy(reaction, "ii/liheit/"); strcpy(tag, "Li+++>He"); break;
    case 9: strcpy(reaction, "ii/liliit/"); strcpy(tag, "Li+++>Li"); break;
    }
  }

  // fusion reaction
  else {
    do {
      cout << "Select a particular reaction, or enter 'q' to quit:\n"
	   << "  1 = D->D(n)\n"
	   << "  2 = D->D(p)\n"
	   << "  3 = D->T\n"
	   << "  4 = T->D\n"
	   << "  5 = D->He3\n"
	   << "  6 = He3->D\n"
	   << "  7 = T->T\n"
	   << "  8 = T->He3\n"
	   << "  9 = He3->T\n"
	   << "> ";
      cin >> response;
      if (!strcmp(response, "q"))
	exit(0);
      else
	n = atoi(response);
    } while (n < 1 || n > 9);
    switch (n) {
    case 1: strcpy(reaction, "fs/ddntab/"); strcpy(tag, "D->D(n)"); break;
    case 2: strcpy(reaction, "fs/ddptab/"); strcpy(tag, "D->D(p)"); break;
    case 3: strcpy(reaction, "fs/dttabl/"); strcpy(tag, "D->T");    break;
    case 4: strcpy(reaction, "fs/tdtabl/"); strcpy(tag, "T->D");    break;
    case 5: strcpy(reaction, "fs/dh3tab/"); strcpy(tag, "D->He3");  break;
    case 6: strcpy(reaction, "fs/h3dtab/"); strcpy(tag, "He3->D");  break;
    case 7: strcpy(reaction, "fs/tttabl/"); strcpy(tag, "T->T");    break;
    case 8: strcpy(reaction, "fs/th3tab/"); strcpy(tag, "T->He3");  break;
    case 9: strcpy(reaction, "fs/h3ttab/"); strcpy(tag, "He3->T");  break;
    }
  }

  // show reaction table info
  showtables(reaction, tag);
}

//-----------------------------------------------------------------------------
