home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
t
/
tierra31.zip
/
tierra
/
Part01
/
extract.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-18
|
3KB
|
99 lines
/* extract.c 92-3-19 genome extraction for the Tierra Simulator */
/* Tierra Simulator V3.1: Copyright (c) 1991, 1992 Tom Ray & Virtual Life */
#ifndef lint
static char sccsid[] = "%W% %G%";
#endif
#include "license.h"
#include "tierra.h"
#include "extern.h"
#ifdef MEM_CHK
#include <memcheck.h>
#endif
void extract(ce)
Pcells ce;
{
I16u i, j;
I32s size;
Ind ip;
Pgl g;
isolate = 0;
if (GeneBnker)
#ifdef IBM3090
sprintf(Buff, "%04ld.gen.d", ce->d.gen.size);
#else
sprintf(Buff, "%s%04ld.gen", GenebankPath, ce->d.gen.size);
#endif
else
#ifdef IBM3090
sprintf(Buff, "mut%ld.gen.d", ++ExtractCount);
#else
sprintf(Buff, "mut%ld", ++ExtractCount);
#endif
size = ce->d.gen.size;
if (GeneBnker) g = sl[size]->g[ce->d.gi];
else
{ g = (Pgl) tcalloc(1, sizeof(GList));
g->bits = 0;
g->gen = ce->d.gen;
g->parent = ce->d.parent;
g->d1 = ce->d.d1;
g->d2.inst = ce->d.inst + 1 - ce->d.d1.inst;
g->d2.flags = ce->d.flags - ce->d.d1.flags;
g->d2.mov_daught = ce->d.mov_daught;
g->d2.BreedTrue = 2;
g->originI = InstExe;
g->originC = time(NULL);
g->MaxPropPop = g->MaxPropInst = -1;
g->mpp_time.m = g->mpp_time.i = 0;
g->ploidy = ce->d.ploidy;
g->track = ce->c.tr;
g->genome = (FpInst) tcalloc(g->gen.size, sizeof(Instruction));
g->gbits = (FpGenB) tcalloc(g->gen.size, sizeof(GenBits));
for (i = 0, ip = ce->mm.p; ip < ce->mm.p + size; i++, ip++)
#if PLOIDY == 1
g->genome[i] = soup[ip];
#else
for (j = 0; j < g->ploidy; j++) g->genome[i][j] = soup[ip][j];
#endif
}
sprintf(ExtrG, "%04ld%s @ %ld", g->gen.size, g->gen.label,
(GeneBnker)? g->pop : 0L);
#if FRONTEND == STDIO
sprintf(mes[0], "extract: about to save genome %s", ExtrG);
FEMessage(1,mes);
#else
if (Log) fprintf(tfp_log, "ex = %s\n", ExtrG);
#endif
if (GeneBnker)
{ FILE *fp;
head_t head;
indx_t *indx;
/* DAN open an archive, if it does not exist, create it */
if (!(fp = open_ar(Buff, ce->d.gen.size, GFormat, -1)))
{ FEError(-90,EXIT,NOWRITE,
"Unable to open extract file %s",Buff);
}
head = read_head(fp);
indx = read_indx(fp, &head);
add_gen(fp, &head, &indx, g);
thfree(indx);
fclose(fp);
}
else
{ WritGenFile(g, Buff);
if (g)
{ if (g->genome) tfree(g->genome);
if (g->gbits) tfree(g->gbits);
tfree(g);
}
}
}