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 >
C/C++ Source or Header  |  1992-04-18  |  3KB  |  99 lines

  1. /* extract.c   92-3-19  genome extraction for the Tierra Simulator */
  2. /* Tierra Simulator V3.1: Copyright (c) 1991, 1992 Tom Ray & Virtual Life */
  3.  
  4. #ifndef lint
  5. static char sccsid[] = "%W%    %G%";
  6. #endif
  7.  
  8. #include "license.h"
  9. #include "tierra.h"
  10. #include "extern.h"
  11.  
  12.  
  13. #ifdef MEM_CHK
  14. #include <memcheck.h>
  15. #endif
  16.  
  17. void extract(ce)
  18.     Pcells ce;
  19. {
  20.     I16u i, j;
  21.     I32s size;
  22.     Ind ip;
  23.     Pgl g;
  24.  
  25.     isolate = 0;
  26.     if (GeneBnker)
  27. #ifdef IBM3090
  28.     sprintf(Buff, "%04ld.gen.d", ce->d.gen.size);
  29. #else
  30.     sprintf(Buff, "%s%04ld.gen", GenebankPath, ce->d.gen.size);
  31. #endif
  32.     else
  33. #ifdef IBM3090
  34.     sprintf(Buff, "mut%ld.gen.d", ++ExtractCount);
  35. #else
  36.     sprintf(Buff, "mut%ld", ++ExtractCount);
  37. #endif
  38.     size = ce->d.gen.size;
  39.     if (GeneBnker) g = sl[size]->g[ce->d.gi];
  40.     else
  41.     {   g = (Pgl) tcalloc(1, sizeof(GList));
  42.         g->bits = 0;
  43.         g->gen = ce->d.gen;
  44.         g->parent = ce->d.parent;
  45.         g->d1 = ce->d.d1;
  46.         g->d2.inst = ce->d.inst + 1 - ce->d.d1.inst;
  47.         g->d2.flags = ce->d.flags - ce->d.d1.flags;
  48.         g->d2.mov_daught = ce->d.mov_daught;
  49.         g->d2.BreedTrue = 2;
  50.         g->originI = InstExe;
  51.         g->originC = time(NULL);
  52.         g->MaxPropPop = g->MaxPropInst = -1;
  53.     g->mpp_time.m = g->mpp_time.i = 0;
  54.         g->ploidy = ce->d.ploidy;
  55.         g->track = ce->c.tr;
  56.         g->genome = (FpInst) tcalloc(g->gen.size, sizeof(Instruction));
  57.         g->gbits = (FpGenB) tcalloc(g->gen.size, sizeof(GenBits));
  58.         for (i = 0, ip = ce->mm.p; ip < ce->mm.p + size; i++, ip++)
  59. #if PLOIDY == 1
  60.             g->genome[i] = soup[ip];
  61. #else
  62.             for (j = 0; j < g->ploidy; j++) g->genome[i][j] = soup[ip][j];
  63. #endif
  64.     }
  65.     sprintf(ExtrG, "%04ld%s @ %ld", g->gen.size, g->gen.label,
  66.        (GeneBnker)? g->pop : 0L);
  67. #if FRONTEND == STDIO
  68. sprintf(mes[0], "extract: about to save genome %s", ExtrG);
  69. FEMessage(1,mes);
  70. #else
  71.     if (Log) fprintf(tfp_log, "ex = %s\n", ExtrG);
  72. #endif
  73.  
  74.     if (GeneBnker)
  75.     {   FILE *fp;
  76.         head_t head;
  77.         indx_t *indx;
  78.  
  79. /* DAN open an archive, if it does not exist, create it */
  80.            if (!(fp = open_ar(Buff, ce->d.gen.size, GFormat, -1)))
  81.               {   FEError(-90,EXIT,NOWRITE,
  82.                    "Unable to open extract file %s",Buff);
  83.               }
  84.         head = read_head(fp);
  85.         indx = read_indx(fp, &head);
  86.         add_gen(fp, &head, &indx, g);
  87.         thfree(indx);
  88.         fclose(fp);
  89.     }
  90.     else
  91.     {   WritGenFile(g, Buff);
  92.         if (g)
  93.         {   if (g->genome) tfree(g->genome);
  94.             if (g->gbits) tfree(g->gbits);
  95.         tfree(g);
  96.         }
  97.     }
  98. }
  99.