/*
* Copyright (C) 2001-2007, CompHEP COllaboration
*------------------------------------------------------
* $Id: event_reader.c,v 1.5 2003/06/25 18:46:41 kryukov Exp $
*
* $Log: event_reader.c,v $
* Revision 1.5  2003/06/25 18:46:41  kryukov
* *** empty log message ***
*
* Revision 1.4  2003/06/17 11:15:26  sherstnv
* An error in memory usage has been fixed.
*
* Revision 1.3  2003/04/22 09:01:18  kryukov
* Apply indent to improve readability of files
*
* Revision 1.2  2003/04/20 17:55:02  kryukov
* Clean up warnings during make
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "LesHouches.h"
#include "tag_reader.h"
#include "tag_parser.h"
#include "event_reader.h"

int 
number_proc (tags * t)
{
  int res;
  string_comnd com;

  strcpy (com.name, "Nproc");
  get_tag_with1com (0, t, "total", &com);
  res = atoi (com.value);
  return res;
}

elementary_tag **
preparer (FILE * f)
{
  int n, i;
  int Nproc;
  tags *head;
  elementary_tag **format;
  string_comnd *com;

  head = init_cap (1);
  cup_reader (f, head);

  Nproc = number_proc (head);

  strcpy (com->name, "IDprocess");
  n = -1;
  for (i = 1; i <= Nproc; i++)
    {
      sprintf (com->value, "%i", i);
      n = get_tag_with_exactcom (n + 1, head, "format", com);
      if (n != -1)
        {
          format[i] = head->tag[n];
        }
      else
        {
          fprintf (stderr, "***Error! The format tag for the %i-th subprocess has been lost.\n", i);
          exit (1);
        }
    }
  return format;
}
