⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tsetup.c

📁 地球模拟器
💻 C
📖 第 1 页 / 共 3 页
字号:
    fprintf(ouf, "SizDepSlice = %ld\n", SizDepSlice);    fprintf(ouf, "SlicePow = %g\n", SlicePow);    fprintf(ouf, "SliceSize = %ld\n", SliceSize);    fprintf(ouf, "SliceStyle = %ld\n", SliceStyle);    fprintf(ouf, "SlicFixFrac = %g\n", SlicFixFrac);    fprintf(ouf, "SlicRanFrac = %g\n", SlicRanFrac);    fprintf(ouf, "SoupSize = %ld\n", SoupSize);    fprintf(ouf, "\n0 to stop GetAVar\n\n");    /* end soup_in variables */    fprintf(ouf, "AverageSize = %ld\n", AverageSize);    fprintf(ouf, "BrkupCou = %ld\n", BrkupCou);    fprintf(ouf, "BrkupCum = %ld\n", BrkupCum);    fprintf(ouf, "CelArSiz = %ld\n", CelArSiz);    fprintf(ouf, "CellsSize = %ld\n", CellsSize);    fprintf(ouf, "CountFlaw = %ld\n", CountFlaw);    fprintf(ouf, "CountMovMut = %ld\n", CountMovMut);    fprintf(ouf, "CountMutRate = %ld\n", CountMutRate);    fprintf(ouf, "debug_switch = %ld\n", debug_switch);    fprintf(ouf, "DistNext.m = %ld\n", DistNext.m);    fprintf(ouf, "DistNext.i = %ld\n", DistNext.i);    fprintf(ouf, "Disturb.m = %ld\n", Disturb.m);    fprintf(ouf, "Disturb.i = %ld\n", Disturb.i);    fprintf(ouf, "ExtractCount = %ld\n", ExtractCount);    fprintf(ouf, "FirstOutDisk = %ld\n", FirstOutDisk);    fprintf(ouf, "FreeBlocks = %ld\n", FreeBlocks);    fprintf(ouf, "FreeMemCurrent = %ld\n", FreeMemCurrent);    fprintf(ouf, "Generations = %lf\n", Generations);    fprintf(ouf, "InstExe.i = %ld\n", InstExe.i);    fprintf(ouf, "InstExe.m = %ld\n", InstExe.m);    fprintf(ouf, "isolate = %ld\n", isolate);    fprintf(ouf, "LastDiv.i = %ld\n", LastDiv.i);    fprintf(ouf, "LastDiv.m = %ld\n", LastDiv.m);    fprintf(ouf, "MalLimit = %ld\n", MalLimit);    fprintf(ouf, "NumCelAr = %ld\n", NumCelAr);    fprintf(ouf, "NumGenotypes = %ld\n", NumGenotypes);    fprintf(ouf, "NumSizes = %ld\n", NumSizes);    fprintf(ouf, "Put_limit = %ld\n", Put_limit);    fprintf(ouf, "RandIx1 = %ld\n", RandIx1);    fprintf(ouf, "RandIx2 = %ld\n", RandIx2);    fprintf(ouf, "RandIx3 = %ld\n", RandIx3);    fprintf(ouf, "RateFlaw = %ld\n", RateFlaw);    fprintf(ouf, "RateMovMut = %ld\n", RateMovMut);    fprintf(ouf, "RateMut = %ld\n", RateMut);    fprintf(ouf, "reaped = %ld\n", reaped);    fprintf(ouf, "Search_limit = %ld\n", Search_limit);    fprintf(ouf, "SoupBot = %ld\n", SoupBot);    fprintf(ouf, "SoupTop = %ld\n", SoupTop);    fprintf(ouf, "TimeBirth = %ld\n", TimeBirth);    fprintf(ouf, "TimeDeath = %ld\n", TimeDeath);    fprintf(ouf, "TimePop = %lf\n", TimePop);    fprintf(ouf, "TotFlaw = %ld\n", TotFlaw);    fprintf(ouf, "TotMovMut = %ld\n", TotMovMut);    fprintf(ouf, "TotMut = %ld\n", TotMut);    fprintf(ouf, "filepos = %ld\n", pos);    fclose(ouf);#ifdef IBM3090    strcpy(comd, "core_out.io.d");#else    strcpy(comd, "core_out");#endif    SavDynMem(comd);}void SavDynMem(filename)I8s  filename[];{   I32s    i, j;    I8s     path[80], tpath[80];    GList   *tgl;    FILE    *fp, *tf, *ouf;    head_t  head, thead;    indx_t  *indx, *tindx, indxt, gindx;    CellInd  cind[3];    ouf = fopen(filename, "wb");    if (ouf == NULL)    {   FEError(-1311,EXIT,NOWRITE,            "Tierra SavDynMem() file %s not opened, exiting", filename);    }    tfwrite((I8s Hp) soup, sizeof(Instruction), SoupSize, ouf);    if (DiskOut)        fwrite(&lo, sizeof(LastOut), 1, ouf);    fwrite(&is, sizeof(PInst), 1, ouf);    fwrite(TrandArray, sizeof(double), 98, ouf);    cind[0].a = BottomReap->q.this.a;    cind[0].i = BottomReap->q.this.i;    cind[1].a = TopReap->q.this.a;    cind[1].i = TopReap->q.this.i;    cind[2].a = ThisSlice->q.this.a;    cind[2].i = ThisSlice->q.this.i;    fwrite(cind, sizeof(CellInd), 3, ouf);    for (i = 0; i < NumCelAr; i++)        fwrite((I8s Fp) cells[i], sizeof(Cell), CelArSiz, ouf);    tfwrite((I8s Hp) FreeMem, sizeof(MemFr), MaxFreeBlocks, ouf);    fclose(ouf);}void ReadDynMem(filename)I8s  filename[];{   I32s     i;    CellInd  cind[3];    FILE     *inf;    inf = fopen(filename, "rb");    if (inf == NULL)    {   FEError(-1311,EXIT,NOWRITE,            "Tierra ReadDynMem() file %s not opened, exiting", filename);    }    soup = (HpInst) thcalloc((I32u) SoupSize, sizeof(Instruction));    tfread((I8s Hp) soup, sizeof(Instruction), SoupSize, inf);    if (DiskOut)        fread(&lo, sizeof(LastOut), 1, inf);    fread(&is, sizeof(PInst), 1, inf);    fread(TrandArray, sizeof(double), 98, inf);    fread(cind, sizeof(CellInd), 3, inf);    cells = (Pcells  *) tcalloc(NumCelAr, sizeof(Pcells));    for (i = 0; i < NumCelAr; i++)    {   cells[i] = (Pcells) tcalloc(CelArSiz, sizeof(Cell));        fread((I8s Fp) cells[i], sizeof(Cell), CelArSiz, inf);    }    FreeMem = (MemFr Fp) tcalloc(MaxFreeBlocks, sizeof(MemFr));    tfread((I8s Hp) FreeMem, sizeof(MemFr), MaxFreeBlocks, inf);    fclose(inf);    TopDummy    = &cells[0][0];    BottomDummy = &cells[0][1];    BottomReap  = &cells[cind[0].a][cind[0].i];    TopReap     = &cells[cind[1].a][cind[1].i];    ThisSlice   = &cells[cind[2].a][cind[2].i];}void ReadGeneBank(){   I32s    gi, tgi, si, ar, ci, tNumGenotypes = 0, tNumSizes = 0;    Pcells  ce;    GlIndex  GiHash;    for (ar = 0; ar < NumCelAr; ar++)        for (ci = 0; ci < CelArSiz; ci++)    {   ce = &cells[ar][ci];        if (!ce->ld || (ar == 0 && ci < 2))            continue;        ce->d.genome = soup + ce->mm.p;        GiHash = CheckGenotype(ce->d, 15); /* check .gen and .tmp files */#ifdef ERROR                               /* and preserve bit 1 */        if (ce->d.hash != GiHash.si)            FEError(-1308,EXIT,NOWRITE,                "ReadGeneBank(): (ce->d.hash = %ld) != (GiHash.si = %ld)\n",                ce->d.hash, GiHash.si);        if (GiHash.gi != (tgi = Lbl2Int(ce->d.gen.label)))            FEError(-1308,EXIT,NOWRITE,             "ReadGeneBank(): ce->d.gen.label = %s = %ld, GiHash.gi = %hd\n",                ce->d.gen.label, tgi, GiHash.gi);        if (GiHash.gi != ce->d.gi)            FEError(-1308,EXIT,NOWRITE,             "ReadGeneBank(): ce->d.gi = %hd, GiHash.gi = %hd\n",                ce->d.gi, GiHash.gi);#endif /* ERROR */        gi = ce->d.gi = GiHash.gi;        si = ce->d.gen.size;        strcpy(ce->d.gen.label, Int2Lbl(GiHash.gi));        if (!sl[si]->g[gi]->pop)        {   tNumGenotypes++;            sl[si]->num_g++;        }        sl[si]->g[gi]->pop++;        if (!sl[si]->num_c)            tNumSizes++;        sl[si]->num_c++;    }#ifdef ERROR    if(tNumGenotypes != NumGenotypes)        FEError(-1308,NOEXIT,NOWRITE,    "Tierra ReadGeneBank() error: tNumGenotoypes = %ld  NumGenotypes = %ld\n",            tNumGenotypes, NumGenotypes);    if(tNumSizes != NumSizes)       FEError(-1308,NOEXIT,NOWRITE,           "Tierra ReadGeneBank() error: tNumSizes = %ld  NumSizes = %ld\n",           tNumSizes, NumSizes);#endif /* ERROR */}void SavGeneBank(){   I32s    i, j;    I8s     path[80], tpath[80];    GList   *tgl;    FILE    *fp, *tf;    head_t  head, thead;    indx_t  *indx, *tindx, indxt, gindx;    for (i = 0; i < siz_sl; i++)    {   if (!sl[i] || !sl[i]->num_c)            continue;        sprintf(path, "%s%04ld.gen", GenebankPath, i);        sprintf(tpath, "%s%04ld.tmp", GenebankPath, i);        fp = open_ar(path, i, GFormat, -1);        tf = open_ar(tpath, i, GFormat, 1);        head = read_head(fp);        thead = read_head(tf);#ifdef __TURBOC__        indx = &gindx;        tindx = &indxt;#else  /* __TURBOC__ */        indx = read_indx(fp, &head);        tindx = read_indx(tf, &thead);#endif /* __TURBOC__ */        /* for each genotype of this size */        for (j = 0; j < sl[i]->a_num; j++)        {   if ((I32u) (tgl = sl[i]->g[j]) > 4)            {   if (IsBit(tgl->bits, 0)) /* if permanent genotype name */                    add_gen(fp, &head, &indx, tgl);                else if (tgl->pop)    /* or has a residual population */                    add_gen(tf, &thead, &tindx, tgl);            }        }        fclose(fp); fclose(tf);        if (!head.n)            unlink(path);        if (!thead.n)            unlink(tpath);#ifndef __TURBOC__        if (indx)        {   thfree(indx);            indx = NULL;        }        if (tindx)        {   thfree(tindx);            tindx = NULL;        }#endif /* __TURBOC__ */    }}void InitCell(ar, ci, ce)    I32s    ar, ci;    Pcells  ce;{   I16s  i;#ifdef unix    bzero(ce, sizeof(Cell));#endif               /* unix */#ifdef __TURBOC__    memset(ce, 0, sizeof(Cell));#endif               /* __TURBOC__ */    strcpy(ce->d.gen.label, "---");    strcpy(ce->d.parent.label, "---");    ce->d.gi = (I32s) -1;    /* index to genome in bank */    ce->d.ploidy = (I8s) 1;    /* how many tracks */    ce->q.this.a = ar; ce->q.this.i = ci;    ce->d.ne = ce->q.n_time = ce->q.p_time = ce->q.n_reap        = ce->q.p_reap = ce->q.this;    ce->c.sp = (I16s) STACK_SIZE - 1;#if INST == 2	for (i = 0; i < NUMREG; i++)		ce->c.re[NUMREG + i] = i;#endif /* INST == 2 */}#ifdef FUTUREvoid FreeDynMem(){   I32s  i, j;    if (GeneBnker)    {   for (i = 0; i < siz_sl; i++) /* for each size */        {   if (!sl[i])                continue;       /* for each genotype of this size */            for (j = 0; j < sl[i]->a_num; j++)            {   if ((I32u) (sl[i]->g[j]) > 4)                {   tfree(sl[i]->g[j]);                    sl[i]->g[j] = NULL;                }            }            tfree(sl[i]->g);            sl[i]->g = NULL;        }        tfree(sl);        sl = NULL;    }    if (soup)    {   thfree(soup);        soup = NULL;    }    for (i = 0; i < NumCelAr; i++)    {   if (cells[i])        {   tfree(cells[i]);            cells[i] = NULL;        }    }    if (cells)    {   tfree(cells);        cells = NULL;    }    if (FreeMem)    {   tfree(FreeMem);        FreeMem = NULL;    }}#endif /* FUTURE */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -