/* This file contains routine for loading and saving states. 
   06/21/94 AW  Created.
*/

#include <stdio.h>
#include <stdlib.h>
#include "types.h"

/* ----- prototype files ------------------------------------------------ */
#include "load.h"       /* prototypes file */

/* ----- constants ------------------------------------------------------ */

/* ----- ifdef constants ------------------------------------------------ */

/* ----- subroutines ---------------------------------------------------- */

/***** load_population *****/
/* parameters:	the_context
		the_population
   called by:
   actions:	Loads a state into the program a file specified by
		the user.
		Expects the_context to have space allocated already,
		but not the_population.
		Returns ERROR or OK.
*/
int load_state(Context the_context, Population the_population)
   {
   int error;
   char filename[100];
   FILE *fp;

#define DEBUG
   printf("  ---in load_state---\");
#endif
   printf(" Read state from which file? ");
   scanf("%s", filename);
   fp = fopen(filename, "r");
   if (fp == NULL)
      {
      printf(" Error(load_state): cannot open file: %s\n", filename);
      return (ERROR);
      }  /* if */

   error = load_context(the_context);
   if (error == ERROR)  return ERROR;
   error = load_population(the_population);
   if (error == ERROR)  return ERROR;
   error = load_envr();
   if (error == ERROR)  return ERROR;
#define DEBUG
   printf("  ---end load_state---\n");
#endif
   return(OK);
   }  /* load_state */
