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

📄 ttools.c

📁 地球模拟器
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ======================================================================*//* ttools.c  9-9-92  support for data analysis of the    Tierra Simulator V4.0: Copyright (c) 1992 Dan Pirone & Virtual Life   written by Daniel pirone   v 2.0*//* ======================================================================*/#ifndef lintstatic char ttools_sccsid[] = "@(#)ttools.c	1.7 7/21/92";#endif#include "tierra.h"#include "extern.h"#include <signal.h>#ifdef ALCOMM#include "tmonitor.h"#include "trequest.h"#include <mlayer.h>#endif#ifdef MEM_CHK#include <memcheck.h>#endif/*-----------------------------------------------------------------------*//*-----------------------------------------------------------------------*//* routines for query_species *//*-----------------------------------------------------------------------*/I16s hg_compare(i,j)         HistType   *i,*j;   {   if(i->size == j->size)     return(i->lbl - j->lbl);   return(i->size - j->size);   }/*-----------------------------------------------------------------------*/I16s hs_compare(i,j)         HistType   *i,*j;   {   return(i->size - j->size);   }/*-----------------------------------------------------------------------*/I16s hc_compare(i,j)         HistType   *i,*j;   {   return(j->count - i->count);   }/*-----------------------------------------------------------------------*//* routines for query_size *//*-----------------------------------------------------------------------*/I16s bc_compare(i,j)         struct size_buf {   I32s count;   I32s lbl;   I32s moves;   I32s flags;   I32s bits;   } *i,*j;   {   return(j->count - i->count);   }/*-----------------------------------------------------------------------*/I16s bg_compare(i,j)         struct size_buf {   I32s count;   I32s lbl;   I32s moves;   I32s flags;   I32s bits;   } *i,*j;   {     return(i->lbl - j->lbl);   }/*-----------------------------------------------------------------------*/void query_size(size_class)I32s size_class;{I32s nnn,num_spec,top_buf,tc,tl,ci,t,thit;typedef struct size_buf {   I32s count;   I32s lbl;   I32s moves;   I32s flags;   I32s bits;   } bf;   bf * buf;   Pcells  ce;if((size_class < 1) || (size_class > siz_sl)|| (!GeneBnker)   || (sl[size_class]<(SList *)4)) return;num_spec = sl[size_class]->num_g;if ((buf = (bf *) thcalloc((num_spec+1) , sizeof(bf) )) == (bf *) NULL)   {   FEError(-1500,NOEXIT,NOWRITE,      "Tierra query_size() Not enough memory to create size table");    return;   }for(tc = 0,t= 0; tc < sl[size_class]->num_g,t < sl[size_class]->a_num; t++)   {   if (!((I32s) sl[size_class]->g[t] > 4)) continue;       buf[tc].lbl = tc;    buf[tc].count =  sl[size_class]->g[t]->pop;   buf[tc].moves =  sl[size_class]->g[t]->d1.mov_daught;   buf[tc].flags =  sl[size_class]->g[t]->d1.flags;   buf[tc].bits =  sl[size_class]->g[t]->bits;   tc++;    }tc = (tc > fe_lines-MSG_Y)? fe_lines - MSG_Y -1 : tc;qsort(buf,num_spec-1,sizeof(bf),bc_compare); /*sort all, by count*/qsort(buf,tc, sizeof(bf),bg_compare); /* sort top num, by size */ FEPrintf(MSG_X,MSG_Y,0,"Gene:    #  Mem Errs   Move  Bits\n"); if (Log && HistPrint) fprintf(tfp_log,"Gene:    #  Mem Errs   Move  Bits\n");    for(t= 0; t < tc; t++)      {      if (buf[t].count < 1) break;      WritEcoB(buf[t].bits ,mes[9]);      FEPrintf(MSG_X,MSG_Y+t+1,0,"%3.3s %6ld %3ld %3ld %6ld    %s\n",        Int2Lbl(buf[t].lbl),        buf[t].count,        (I32s) (100.0 * buf[t].count * size_class / SoupSize),        buf[t].flags ,        buf[t].moves,         mes[9]        );      if (Log && HistPrint)         fprintf(tfp_log,"%3.3s %6ld %3ld %3ld %6ld    %s\n",        Int2Lbl(buf[t].lbl),        buf[t].count,        (I32s) (100.0 * buf[t].count * size_class / SoupSize),        buf[t].flags ,        buf[t].moves,         mes[9]        );      }   if (Log && HistPrint) {fprintf(tfp_log,"\n"); fflush(tfp_log);}   if (buf)   {  thfree(buf);      buf = NULL;   }} /* end query_size *//*-----------------------------------------------------------------------*/void query_species(num)I32s num;{I32s num_ent = 0,     nnn = 0,     ci,t,n_star = 0;     Pcells ce;if ((!GeneBnker)|| (NumSizes < 1) || (num < 2)) return; if (Hist != NULL)   {     thfree(Hist);   Hist = (HistType *)NULL;   }Max_hits = -1;if (IMode == GEN_HIST)    num_ent = NumGenotypes;else                                 /* IMode == SIZ_HIST  || SIZM_HIST*/   num_ent = NumSizes;if ((Hist  = (HistType *) thcalloc((num_ent+1) , sizeof(HistType)))     == (HistType *) NULL)   {   FEError(-1501,NOEXIT,NOWRITE,      "Tierra query_species() Not enough memory to create %s table",          (IMode == GEN_HIST)? "genotype":       (IMode == SIZM_HIST)? "memory" : "size");    return;   }for(nnn= 0,ci = 1; (ci < siz_sl && nnn < num_ent); ci++)   {   if(((I32u) sl[ci] > 4L) && (sl[ci]->num_c > 0))      {         if (IMode == GEN_HIST)            {            for(n_star = 0,t= 0;                (n_star < sl[ci]->num_g && t < sl[ci]->a_num); t++)               {               if(((I32u) sl[ci]->g[t] < 5L) || (sl[ci]->g[t]->pop < 1))                  continue;               Hist[nnn].size = ci;               Hist[nnn].lbl =  t; /* int form of label */               Hist[nnn].count =  sl[ci]->g[t]->pop;               if (Hist[nnn].count >= Max_hits)                   {Max_hits = Hist[nnn].count;}               nnn++; n_star++;               }            }         else /* IMode == SIZ_HIST  || SIZM_HIST */           {           Hist[nnn].size = ci;           Hist[nnn].count =  sl[ci]->num_c;           if (Hist[nnn].count >= Max_hits)               {Max_hits = Hist[nnn].count;}           nnn++;           }    } /* end of valid size class */}if (( Max_hits ) < 1) return;nnn = ((nnn > num_ent)? num_ent : nnn);nnn = ((nnn > num)? num : nnn);nnn = ((nnn > fe_lines - MSG_Y)? fe_lines - MSG_Y :nnn);if (IMode == SIZM_HIST)    for (t = 0; t < nnn; t++)     {     Hist[t].count *= Hist[t].size;     if (Hist[t].count >= Max_hits)         {Max_hits = Hist[t].count;}    }qsort(Hist,num_ent-1,sizeof(HistType),hc_compare); /*sort all, by count*/if (IMode == GEN_HIST)   qsort(Hist,nnn, sizeof(HistType),hg_compare); /* sort top num, by size */else /* IMode == SIZ_HIST  || SIZM_HIST*/   qsort(Hist,nnn, sizeof(HistType),hs_compare); /* sort top num, by size */if ((Hist  = (HistType *) threcalloc(Hist,((nnn+1)*sizeof(HistType)),                                          ((num_ent+1) * sizeof(HistType))))     == (HistType *) NULL)   {   FEError(-1502,NOEXIT,NOWRITE,      "Tierra query_species() problem reallocing %s table",          (IMode == GEN_HIST)? "genotype":       (IMode == SIZM_HIST)? "memory" : "size");    return;   }HistSize = nnn;HistNStars =  ((float)(fe_width -20) /(float) Max_hits);for(t= 0; t < nnn; t++)    {         if (Hist[t].count < 1) continue;         Buff[0]=  '*'; Buff[1]=  '\0';         Hist[t].nstar = n_star =  HistNStars * Hist[t].count;         if (IMode == GEN_HIST)            {            if ((t > 0) && (Hist[t].size == Hist[t-1].size))               {               FEPrintf(MSG_X,MSG_Y+t,0,"      %3s %6ld | ",                  Int2Lbl(Hist[t].lbl) ,Hist[t].count);               if (Log && HistPrint) fprintf(tfp_log,"    %3s %6ld |",                  Int2Lbl(Hist[t].lbl) ,Hist[t].count);               }            else               {               FEPrintf(MSG_X,MSG_Y+t,0," %5hd%3s %6ld | ",                  Hist[t].size,Int2Lbl(Hist[t].lbl) ,Hist[t].count);               if (Log && HistPrint) fprintf(tfp_log,"%5hd%3s %6ld |",                  Hist[t].size,Int2Lbl(Hist[t].lbl) ,Hist[t].count);               }            }         else /* IMode == SIZ_HIST || SIZM_HIST */            {            FEPrintf(MSG_X,MSG_Y+t,0,"%5hd %3hd %6ld | ",               Hist[t].size,sl[Hist[t].size]->num_g,Hist[t].count);            if (Log && HistPrint) fprintf(tfp_log,"%5hd %3hd %6ld |",               Hist[t].size,sl[Hist[t].size]->num_g,Hist[t].count);            }        for(ci= 0;ci < n_star;ci++,strcat(Buff, "*"));         FEPrintf((MSG_X+19),MSG_Y+t,0,"%s\n",Buff);         if (Log && HistPrint) fprintf(tfp_log,"%s\n",Buff);     }FEClrmsg(MSG_Y+t);if (Log && HistPrint) {fprintf(tfp_log,"\n"); fflush(tfp_log);}}        /* end of query_species *//*-----------------------------------------------------------------------*/#if FRONTEND == BASICvoid query_spec_d(size,lbl)I32s size,lbl;{I32s l,n,nnn, tcount, SigSaveSet;I16s empty = 0, a = 0, b = 1;I8s old_n_star, ns_dlta;if((size > siz_sl) || (size < 0)) return;if((Hist == NULL)) {query_species(fe_lines);return;}

⌨️ 快捷键说明

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