/* 
   * Copyright (C) 1997, Alexander Pukhov 
   * Copyright (C) 2001-2003, CompHEP Collaboration
   *------------------------------------------------------
   * $Id: view_tab.c,v 1.5 2003/06/25 18:46:41 kryukov Exp $
   *
   * $Log: view_tab.c,v $
   * Revision 1.5  2003/06/25 18:46:41  kryukov
   * *** empty log message ***
   *
   * Revision 1.4  2003/05/01 12:16:26  sherstnv
   * Sdelana standartnaya peredacha puti k CompHEP v programme
   * tab_view.exe
   * Sdelan script vizova tab_view iz user area.
   *
   * Revision 1.3  2003/04/22 09:01:19  kryukov
   * Apply indent to improve readability of files
   *
   * Revision 1.2  2003/04/20 17:55:02  kryukov
   * Clean up warnings during make
   *
 */
#include "chep_crt/include/chep_crt.h"
#include "service2/include/os.h"
#include "service2/include/files.h"
#include "plot.h"

int 
main (int argc, char **argv)
{				/*  MAIN - COMPHEP  */

  char procName[100], xName[60], yName[60];
  double xMin, xMax;
  double *f = NULL, *df = NULL;
  int dim;
  int i;
  int n;
  char icon_name[STRSIZ];
  FILE *file;

  char *p = getenv ("COMPHEP");
  if (!p)
    {
      fprintf (stderr, " Environment variable COMPHEP is not defined.\n");
      exit (0);
    }
  strcpy (_pathtocomphep, p);
  n = strlen (_pathtocomphep) - 1;
  while (n >= 0 && _pathtocomphep[n] != f_slash)
    n--;
  _pathtocomphep[n] = '\0';
  sprintf (pathtocomphep, "%s%c", _pathtocomphep, d_slash);
  sprintf (pathtohelp, "%shelp%c", pathtocomphep, f_slash);

  file = fopen (argv[1], "r");
  if (!file)
    {
      fprintf (stderr, "***Error! File not found: %s\n", argv[1]);
      return 2;
    }

  fscanf (file, "%[^\n]", procName);
  trim (procName);


  fscanf (file, "%*[^\"]%*c%[^\"]%*c%*s%lf%*s%lf%*s%d%*c", xName, &xMin, &xMax, &dim);
  f = (double *) malloc (dim * sizeof (double));
  df = (double *) malloc (dim * sizeof (double));

  fscanf (file, "%[^\n]", yName);
  trim (yName);

  n = fscanf (file, "%lf +/- %lf", f, df);
  if (n == 2)
    for (i = 1; i < dim; i++)
      fscanf (file, "%lf +/- %lf", f + i, df + i);
  else
    {
      for (i = 1; i < dim; i++)
	fscanf (file, "%lf", f + i);
      free (df);
      df = NULL;
    }

  sprintf (icon_name, "%sicon", pathtocomphep);
  start1 (version, icon_name, "comphep.ini;../comphep.ini;[-]comphep.ini");
  clearTypeAhead ();
  plot_0 (xMin, xMax, dim, f, df, procName, xName, yName);
  finish ("");
  return 0;
}
