#include <stdio.h>
#include "getp.h"
#include "fgetword.h"

int getparameters(           /* Returns 1 if inputfile successfully */
			     /*    read and 0 otherwise */
		  double *lambda,  /* Value of lambda */
		  double *gamma1,  /* Value of gamma1 */
		  double *gamma2,  /* Value of gamma2 */
		  double *a1,      /* Parameter a of G1 */
		  double *a2,      /* Parameter a of G2 */
		  double *b1,      /* Parameter b of G1 */
		  double *b2,      /* Parameter b of G2 */
		  double *time,    /* Size of the initial backwards */
				   /* step for the CFTP routine */
		  long *seed,      /* Values of the three seeds */
		  long *seedtwo,   /* for the marks, the times */
		  long *seedthree, /* and the positions of the points */
		  char *inputfile  /* File to read all these from */
		  )
{
  int n;
  char word[MAXWORD];
  FILE *fopen(), *datafile;

  datafile = fopen(inputfile,"r");

  if ((n=fgetword(datafile,MAXWORD,word))!=0 && n <MAXWORD)
    sscanf(word,"%lf",lambda);
  else if (n==0){
    printf("The input file was empty!");
    return 0;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%lf",gamma1);
  else {
    printf("There was insufficient data in the input file");
    return 0;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%lf",gamma2);
  else {
    printf("There was insufficient data in the input file");
    return 0;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%lf",a1);
  else {
    printf("There was insufficient data in the input file");
    return 0;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%lf",a2);
  else {
    printf("There was insufficient data in the input file");
    return 0;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%lf",b1);
  else {
    printf("There was insufficient data in the input file");
    return 0;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%lf",b2);
  else {
    printf("There was insufficient data in the input file");
    return 0;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%lf",time);
  else {
    printf("There was insufficient data in the input file");
    return 0;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%ld",seed);
  else {
    printf("There was insufficient data in the input file");
    return 0;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%ld",seedtwo);
  else {
    printf("There was insufficient data in the input file");
    return 0;
  }

  if ((n=fgetword(datafile,MAXWORD,word))!=0)
    sscanf(word,"%ld",seedthree);
  else {
    printf("There was insufficient data in the input file");
    return 0;
  }

  fclose(datafile);

  return 1;
}
