#include "head.h"
#include "getp.h"
#include "fgetword.h"

/* Read the parameter values from the file specified as \texttt{inputfile} */

int getparameters(             /* Returns 1 if inputfile successfully */
		               /* read and 0 otherwise */
		  char *dataloc,    /* Path name of the data file */
		  double *sigma,    /* Value of $\sigma$ */
		  double *tau,      /* Value of $\tau$ */
		  double *lambda,   /* Value of $\lambda$ */
		  double *gamma,    /* Value of $\gamma$ */
		  double *time,     /* Size of initial backwards step */
				    /* for the CFTP routine ($-M$)*/
		  double *exponent, /* Value of $J_{jk}$'s exponent */
		  long *seed,       /* Values of the two seeds */
		  long *seedtwo,    /* for the marks and the times */
		  char *inputfile   /* File to read all these from */
		  )
{
  int n;
  char word[MAXWORD];
  FILE *fopen(), *datafile;
  int stop;
  
  datafile = fopen(inputfile,"r");
  
  stop = 0;

  if ((n=fgetword(datafile,MAXWORD,word))!=0 && n <MAXWORD)
    sscanf(word,"%s",dataloc);
  else if (n==0){
    printf("The input file was empty!");
    stop = 1;
  }

  else{
    printf("Data file name too long.  ");
    printf("Must be < %d characters.",MAXWORD);
    stop = 1;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%lf",sigma);

  else if (!stop){
    printf("There was insufficient data in the input file");
    stop = 1;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%lf",tau);

  else if (!stop){
    printf("There was insufficient data in the input file");
    stop = 1;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%lf",lambda);

  else if (!stop){
    printf("There was insufficient data in the input file");
    stop = 1;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%lf",gamma);

  else if (!stop){
    printf("There was insufficient data in the input file");
    stop = 1;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%lf",time);

  else if (!stop){
    printf("There was insufficient data in the input file");
    stop = 1;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%lf",exponent);

  else if (!stop){
    printf("There was insufficient data in the input file");
    stop = 1;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%ld",seed);

  else if (!stop){
    printf("There was insufficient data in the input file");
    stop = 1;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%ld",seedtwo);

  else if (!stop){
    printf("There was insufficient data in the input file");
    stop = 1;
  }

  fclose(datafile);

  return (!stop);
}
