1 /* DLIFE Copyright (C) 2000 Richard W.M. Jones <rich@annexia.org>
2 * and other authors listed in the ``AUTHORS'' file.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * $Id: image.c,v 1.2 2002/04/05 16:47:12 rich Exp $
31 #define FILE_SAVE_VERSION 1
33 static void global_state_save (struct state *state, FILE *fp);
34 static void global_state_load (struct state *state, FILE *fp);
37 image_load (const char *filename, int _soup_size, int thread_num)
42 fp = fopen (filename, "r");
43 if (fp == 0) { perror (filename); return 0; }
45 state = state_malloc (_soup_size, thread_num);
47 global_state_load (state, fp);
48 cell_state_load (state, fp);
49 soup_state_load (state, fp);
57 image_save (struct state *state, const char *filename)
61 fp = fopen (filename, "w");
62 if (fp == 0) { perror (filename); return -1; }
64 global_state_save (state, fp);
65 cell_state_save (state, fp);
66 soup_state_save (state, fp);
74 global_state_save (struct state *state, FILE *fp)
76 int version = FILE_SAVE_VERSION;
78 fwrite (&version, sizeof version, 1, fp);
79 fwrite (&state->cell_cycle, sizeof state->cell_cycle, 1, fp);
83 global_state_load (struct state *state, FILE *fp)
87 if (fread (&version, sizeof version, 1, fp) != 1)
89 fprintf (stderr, "error in global state\n");
92 if (version != FILE_SAVE_VERSION)
94 fprintf (stderr, "soup image version numbers do not match\n");
98 if (fread (&state->cell_cycle, sizeof state->cell_cycle, 1, fp) != 1)
100 fprintf (stderr, "error in global state\n");
104 if (verbose) printf ("Total number of cycles executed so far: %LuB\n",
105 state->cell_cycle / 1000000000);