home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / xplatfrm / tierra / extract.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-26  |  2.6 KB  |  97 lines

  1. /* extract.c  28-10-91  genome extraction for the Tierra simulator */
  2. /** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
  3.  
  4. #include "license.h"
  5.  
  6. #ifndef lint
  7. static char sccsid[] = "@(#)extract.c    2.7    10/8/91";
  8. #endif
  9.  
  10. #include "tierra.h"
  11. #include "extern.h"
  12.  
  13. void extract(ci)
  14.     I32s  ci;
  15. {
  16.     Pcells  ce = cells + ci;
  17.     I8s   file[80];
  18.     I16u  i, j;
  19.     I32s  size;
  20.     Ind  ip;
  21.     Pgl  g;
  22.     Psl  ts;
  23.  
  24.     isolate = 0;
  25.     if (GeneBnker)
  26. #ifdef IBM3090
  27.         sprintf(file,"%04ld.gen.d", ce->d.gen.size);
  28. #else
  29.         sprintf(file,"%s%04ld.gen", GenebankPath, ce->d.gen.size);
  30. #endif
  31.     else
  32. #ifdef IBM3090
  33.         sprintf(file,"mut%ld.gen.d", ++ExtractCount);
  34. #else
  35.         sprintf(file,"mut%ld", ++ExtractCount);
  36. #endif
  37.     size = ce->d.gen.size;
  38.     if (GeneBnker)
  39.     {   ts = sl + ce->d.gli.si;
  40.         g = ts->g + ce->d.gli.gi;
  41.     }
  42.     else
  43.     {   g = (Pgl) thcalloc(1, sizeof(struct g_list));
  44.         g->bits = 0;
  45.         g->gen = ce->d.gen;
  46.         g->parent = ce->d.parent;
  47.         g->d1 = ce->d.d1;
  48.         g->d2.inst = ce->d.inst + 1 - ce->d.d1.inst;
  49.         g->d2.flags = ce->d.flags - ce->d.d1.flags;
  50.         g->d2.mov_daught = ce->d.mov_daught;
  51.         g->d2.BreedTrue = 2;
  52.         g->originI = InstExe;
  53.         g->originC = time(NULL);
  54.         g->MaxPropPop = g->MaxPropInst = -1;
  55. #ifdef COMMENTS
  56.         g->comments = (I8s  *) thcalloc(2,sizeof(I8s));
  57.         strcpy(g->comments,"\n");
  58. #else
  59.         g->comments = 0;
  60. #endif
  61.         g->ploidy = ce->d.ploidy;
  62.         g->track = ce->c.tr;
  63.         g->genome = (HpInst) thcalloc(g->gen.size,sizeof(Instruction));
  64.         g->gbits  = (HpGenB) thcalloc(g->gen.size,sizeof(GenBits));
  65.         for (i = 0, ip = ce->mm.p; ip < ce->mm.p + size; i++, ip++)
  66.         {   for(j = 0; j < g->ploidy; j++)
  67.              /* g->genome[i] = fetch(ip); */
  68.                 g->genome[i][j] = soup[ip][j];
  69.         }
  70.     }
  71.     if (!GeneBnker)
  72.         sprintf(mes[0],"extract: about to save genome %04ld%s",
  73.             g->gen.size, g->gen.label);
  74.     else
  75.         sprintf(mes[0],"extract: about to save genome %04ld%s = %ld",
  76.             g->gen.size, g->gen.label, g->pop);
  77.     FEMessage(1);
  78.     if (GeneBnker)
  79.     {   FILE *fp;
  80.         head_t head;
  81.         indx_t *indx;
  82.     
  83.         fp = open_ar(file, ce->d.gen.size, INST, 0);
  84.         head = read_head(fp);
  85.         indx = read_indx(fp, &head);
  86.         add_gen(fp, &head, &indx, g);
  87.         free(indx);
  88.         fclose(fp);
  89.     }
  90.     else
  91.     {   WritGenFile(g,file);
  92.         if (g->genome) thfree(g->genome);
  93.         if (g->comments) thfree(g->comments);
  94.         thfree(g);
  95.     }
  96. }
  97.