home *** CD-ROM | disk | FTP | other *** search
- /* extract.c 28-10-91 genome extraction for the Tierra simulator */
- /** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
-
- #include "license.h"
-
- #ifndef lint
- static char sccsid[] = "@(#)extract.c 2.7 10/8/91";
- #endif
-
- #include "tierra.h"
- #include "extern.h"
-
- void extract(ci)
- I32s ci;
- {
- Pcells ce = cells + ci;
- I8s file[80];
- I16u i, j;
- I32s size;
- Ind ip;
- Pgl g;
- Psl ts;
-
- isolate = 0;
- if (GeneBnker)
- #ifdef IBM3090
- sprintf(file,"%04ld.gen.d", ce->d.gen.size);
- #else
- sprintf(file,"%s%04ld.gen", GenebankPath, ce->d.gen.size);
- #endif
- else
- #ifdef IBM3090
- sprintf(file,"mut%ld.gen.d", ++ExtractCount);
- #else
- sprintf(file,"mut%ld", ++ExtractCount);
- #endif
- size = ce->d.gen.size;
- if (GeneBnker)
- { ts = sl + ce->d.gli.si;
- g = ts->g + ce->d.gli.gi;
- }
- else
- { g = (Pgl) thcalloc(1, sizeof(struct g_list));
- 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;
- #ifdef COMMENTS
- g->comments = (I8s *) thcalloc(2,sizeof(I8s));
- strcpy(g->comments,"\n");
- #else
- g->comments = 0;
- #endif
- g->ploidy = ce->d.ploidy;
- g->track = ce->c.tr;
- g->genome = (HpInst) thcalloc(g->gen.size,sizeof(Instruction));
- g->gbits = (HpGenB) thcalloc(g->gen.size,sizeof(GenBits));
- for (i = 0, ip = ce->mm.p; ip < ce->mm.p + size; i++, ip++)
- { for(j = 0; j < g->ploidy; j++)
- /* g->genome[i] = fetch(ip); */
- g->genome[i][j] = soup[ip][j];
- }
- }
- if (!GeneBnker)
- sprintf(mes[0],"extract: about to save genome %04ld%s",
- g->gen.size, g->gen.label);
- else
- sprintf(mes[0],"extract: about to save genome %04ld%s = %ld",
- g->gen.size, g->gen.label, g->pop);
- FEMessage(1);
- if (GeneBnker)
- { FILE *fp;
- head_t head;
- indx_t *indx;
-
- fp = open_ar(file, ce->d.gen.size, INST, 0);
- head = read_head(fp);
- indx = read_indx(fp, &head);
- add_gen(fp, &head, &indx, g);
- free(indx);
- fclose(fp);
- }
- else
- { WritGenFile(g,file);
- if (g->genome) thfree(g->genome);
- if (g->comments) thfree(g->comments);
- thfree(g);
- }
- }
-