home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / TIERRA40.ZIP / BEAGLE / TRACE.C < prev    next >
C/C++ Source or Header  |  1992-09-11  |  12KB  |  375 lines

  1. /* trace.c  27-3-92  trace display for the Beagle Explorer */
  2. /*** Beagle Explorer: Version 3.1  Copyright (c) 1990, 1991, 1992  Tom Ray ***/
  3.  
  4. #include "beagle.h"
  5. #include "externb.h"
  6.  
  7. extern struct barst    bs;
  8. extern struct sbar     sb;
  9. extern struct species  sp[];
  10. extern struct last_out  lo;
  11. extern char  directory[], info_file[], ifile[];
  12. extern int  pop, inst, num_sp, genotypes, gent, udisplay;
  13. extern float  xln, yln, xo, yo;
  14.  
  15. char  axes[5], lab_x[4], lab_y[4];
  16. int   siz_x, siz_y;
  17. char  gen_x[9], gen_y[9];
  18. float  shrink;
  19. FILE  *info;
  20. HWND         whbe, whint;
  21. TRANSACTION  *ptbe;
  22. struct tracest  tr;
  23.  
  24. int trace(void)
  25. {   int  i;
  26.     static int  first = 1;
  27.     char  sshrink[5];
  28.     HWND  whins;
  29.  
  30.     if(first)
  31.     {   first = pop = 0; genotypes = inst = 1;
  32.         xnvf = -.05; xxvf = 1.05; ynvf = -.05; yxvf = 1.1; shrink = 1.0;
  33.         siz_x = 80; siz_y = 45; sprintf(lab_x,"aaa"); sprintf(lab_y,"aaa");
  34.         sprintf(gen_x,"80aaa"); sprintf(gen_y,"45aaa");
  35. /*      sprintf(ifile,"tierra.run"); */
  36.         sprintf(ifile,"break.1");
  37.     }
  38.     sprintf(sshrink,"%g", shrink);
  39.     udisplay = 0;
  40.     sprintf(axes,"pop");
  41.     while(1) {
  42.     whbe = wigen(3,1,7,55,FRDOUBLE,"trace");
  43.     ptbe = vpreload(7,0,NULLF,NULLF,NULLF,NULLF);
  44.     for(i = 0; i <= 6; i++) (*(ptbe->def))[i].use_ext = TRUE;
  45.     (*(ptbe->def))[2].refresh = (*(ptbe->def))[3].refresh =
  46.     (*(ptbe->def))[6].refresh = ON;
  47.     vdeffld(ptbe,0,STRING,0,1, "directory  =",-1,40,NULL,directory,NO);
  48.     vdeffld(ptbe,1,STRING,1,1, "input file =",-1,12,NULL,ifile,NO);
  49.     vdeffld(ptbe,2,STRING,2,1, "x size     =",-1,8,NULL,gen_x,NO);
  50.     vdeffld(ptbe,3,STRING,3,1, "y size     =",-1,8,NULL,gen_y,NO);
  51.     vdeffld(ptbe,4,STRING,4,1, "axis (pop,inst)    =",-1,4,NULL,axes,NO);
  52.     vdeffld(ptbe,5,STRING,5,1, "shrink factor      =",-1,4,NULL,sshrink,NO);
  53.     vdeffld(ptbe,6,BOOLEAN,6,1,"separate genotypes =",-1,1,NULL,&genotypes,NO);
  54.     whins = wiinv(23,13,
  55.         "\x1e\x1f, or Enter to select; Esc to exit; Ctrl-Enter to run");
  56.     visible(whbe,YES,YES);
  57.     ptbe->fld_valfn = run_info_chk;
  58.     ptbe->fld_valid = run_info;
  59.     ptbe->fld_setfn = FieldSet;
  60.     if(DWSUCCESS == vread(ptbe,whbe,YES))
  61.     {   vdelete(whint,whbe); vdelete(whbe,NONE); vdelete(whins,NONE);
  62.         if(genotypes)
  63.         {   sscanf(gen_x,"%d%s", &siz_x, lab_x);
  64.             sscanf(gen_y,"%d%s", &siz_y, lab_y);
  65.         }
  66.         else
  67.         {   sscanf(gen_x,"%d", &siz_x);
  68.             sscanf(gen_y,"%d", &siz_y);
  69.         }
  70.         sscanf(sshrink,"%f", &shrink);
  71.         xln = yln = shrink;
  72.         xo = (1. - xln) / 2.;
  73.         yo = 1. - yln;
  74.         trac();
  75.     }
  76.     else
  77.     {   vdelete(whint,whbe); vdelete(whbe,NONE); vdelete(whins,NONE);
  78.         return 1;
  79.     }
  80.     }
  81.     vdelete(whins,NONE);
  82.     return 1;
  83. }
  84.  
  85. char    *sim_input = NULL;
  86. unsigned  key;
  87.  
  88. int FieldSet(TRANSACTION  *tp)
  89. {   MENUHDR  *disp;
  90.     MENUITEM  *sel;
  91.  
  92.   if(tp->cur_fld == 4)
  93.   {
  94.     key = tp->thiskey;
  95.     disp = MNUCreateHdr(POPUP);
  96.     disp->toprow = 7;
  97.     disp->topcol = 20;
  98.     disp->uattr  = 8;
  99.     disp->dattr  = 16;
  100.     disp->lattr  = 13;
  101.     MNUAddItem("pop", "display by population size   ",'P',0,NULL,disp,NULLF);
  102.     MNUAddItem("inst","display by instruction number",'I',0,NULL,disp,NULLF);
  103.       sel = MNUDoSelect(disp,NULLF);
  104.       if(sel)
  105.       {   tp->inp_get = KeySim;
  106.           sim_input = sel->item0;
  107.       }
  108.   }
  109.   else tp->inp_get = (unsigned (*)()) vgetkey;
  110.   return FALSE;
  111. }
  112.  
  113. unsigned KeySim(unsigned (*fp)(), TRANSACTION *tp)
  114. {   bool  ff = 0;
  115.  
  116.     if(ff) { ff = FALSE; return (unsigned) 11; } /* 11 == FIELD_ERASE */
  117.     if(*sim_input) return (unsigned) *sim_input++;
  118.     else
  119.     {   sim_input = NULL;
  120.         ff = TRUE;
  121.         tp->inp_get = (unsigned (*)()) vgetkey;
  122.         return key;
  123.     }
  124. }
  125.  
  126. int run_info_chk(TRANSACTION  *tp)
  127. {   char  path[80];
  128.     int   success;
  129.  
  130.     if(tp->cur_fld == 0)
  131.     {   getcwd(path,79);
  132.         success = chdir(directory);
  133.         chdir(path);
  134.         if(success)
  135.         {   wierror(2,45,"directory not found");
  136.             return FALSE;
  137.         }
  138.         return TRUE;
  139.     }
  140.     if(tp->cur_fld == 4)
  141.     {   if(!strcmp(axes,"pop") || !strcmp(axes,"inst")) return TRUE;
  142.         wierror(2,45,"pop or inst please");
  143.         return FALSE;
  144.     }
  145.     return TRUE;
  146. }
  147.  
  148. void run_info(TRANSACTION  *tp)
  149. {   char    data[100];
  150.     int     i, tnum_sp;
  151.     static int  first = 1;
  152.  
  153.     if(!strcmp(axes,"pop")) { pop = 1; inst = 0; }
  154.     if(!strcmp(axes,"inst")) { pop = 0; inst = 1; }
  155.     if((tp->cur_fld > 1 && tp->cur_fld < 4) && tp->cur_fld != 6) return ;
  156.     if(genotypes)
  157.     {   sprintf(data,"%s/run_info.g",directory);
  158.         info = fopen(data,"r");
  159.         if(info == NULL)
  160.         {   sprintf(data,"%s/run_info",directory);
  161.             info = fopen(data,"r");
  162.             if(info == NULL)
  163.             {   wierror(2,45,"run_info file not found");
  164.                 return ;
  165.             }
  166.             else genotypes = 0;
  167.         }
  168.     }
  169.     else
  170.     {   sprintf(data,"%s/run_info",directory);
  171.         info = fopen(data,"r");
  172.         if(info == NULL)
  173.         {   wierror(2,45,"run_info file not found");
  174.             return ;
  175.         }
  176.     }
  177.     barst_setup();
  178.     species_array_setup(&tnum_sp);
  179.     fclose(info);
  180.     if(num_sp > 22) num_sp = 22;
  181.     if(first) first = 0;
  182.     else vdelete(whint,whbe);
  183.     whint = wigen(1,56,num_sp + 1,23,FRSINGLE,"run info");
  184.     visible(whint,YES,NO);
  185.     vatputf(whint,0,1,"species = %d",tnum_sp);
  186.     for(i = 0; i < num_sp; i++)
  187.     {   vatputf(whint,i + 1,1,"%5d", sp[i].size);
  188.         if(genotypes) vatputf(whint,i + 1,6,"%s", sp[i].label);
  189.         if(pop) vatputf(whint,i + 1,10,"%u", sp[i].max);
  190.         if(inst) vatputf(whint,i + 1,10,"%ld", sp[i].min);
  191.     }
  192.     visible(whbe,YES,YES);
  193.     if(sp[0].size < 57 && sp[1].size > 56)
  194.     {   siz_x = sp[1].size; sprintf(lab_x,sp[1].label);
  195.         siz_y = sp[0].size; sprintf(lab_y,sp[0].label);
  196.     }
  197.     else
  198.     {   siz_x = sp[0].size; sprintf(lab_x,sp[0].label);
  199.         siz_y = sp[1].size; sprintf(lab_y,sp[1].label);
  200.     }
  201.     if(genotypes)
  202.     {   sprintf(gen_x,"%d%s", siz_x, lab_x);
  203.         sprintf(gen_y,"%d%s", siz_y, lab_y);
  204.     }
  205.     else
  206.     {   sprintf(gen_x,"%d", siz_x);
  207.         sprintf(gen_y,"%d", siz_y);
  208.     }
  209.     vfldrfsh(ptbe,whbe);
  210. }
  211.  
  212. void tracest_setup(void)
  213. {   if(y_res == 480)
  214.     {   tr.csz = 16; tr.lbd = 10; tr.tbd = 10; tr.bti = 4; tr.tim = 4;
  215.     }
  216.     if(y_res == 200)
  217.     {   tr.csz = 8; tr.lbd = 10; tr.tbd = 5; tr.bti = 4; tr.tim = 4;
  218.     }
  219. }
  220.  
  221. void trac(void)
  222. {   struct point   p = { 0, 0 } ;
  223.     Uint   c;
  224.     FILE   *inf;
  225.     int    i, num_x, num_y, first = 1, firstr = 1, linecolor, lettercolor;
  226.     int    tnum_sp, xnum_sp, binum = 1;
  227.     char   data[81], bifile[13];
  228.     Ulong  otime = 0;
  229.  
  230.     if(genotypes)
  231.     {   sprintf(data,"%s/run_info.g",directory);
  232.         info = fopen(data,"r");
  233.         if(info == NULL)
  234.         {   sprintf(data,"%s/run_info",directory);
  235.             info = fopen(data,"r");
  236.             if(info == NULL)
  237.             {   wierror(2,45,"run_info file not found");
  238.                 return ;
  239.             }
  240.             else genotypes = 0;
  241.         }
  242.     }
  243.     else
  244.     {   sprintf(data,"%s/run_info",directory);
  245.         info = fopen(data,"r");
  246.         if(info == NULL)
  247.         {   wierror(2,45,"run_info file not found");
  248.             return ;
  249.         }
  250.     }
  251.     tracest_setup();
  252.     species_array_setup(&xnum_sp);
  253.     fclose(info);
  254.     for(i = 0; i < num_sp; i++)
  255.     {   if(genotypes)
  256.         {   if(sp[i].size == siz_x && !strcmp(sp[i].label,lab_x))
  257.             { if(pop) xlpl = sp[i].max; if(inst) xlpl = sp[i].min; }
  258.             if(sp[i].size == siz_y && !strcmp(sp[i].label,lab_y))
  259.             { if(pop) ylpl = sp[i].max; if(inst) ylpl = sp[i].min; }
  260.         }
  261.         else
  262.         {   if(sp[i].size == siz_x)
  263.             { if(pop) xlpl = sp[i].max; if(inst) xlpl = sp[i].min; }
  264.             if(sp[i].size == siz_y)
  265.             { if(pop) ylpl = sp[i].max; if(inst) ylpl = sp[i].min; }
  266.         }
  267.     }
  268.     num_x = num_y = 0;
  269.     sscanf(ifile,"%[^.]", bifile);
  270.     sprintf(info_file,"%s/%s", directory, ifile);
  271.     inf = fopen(info_file,"r");
  272.     if(inf == NULL)
  273.     {   wierror(2,45,"run file not found");
  274.         return ;
  275.     }
  276.     if(scr)
  277.     {   setgraphmode(graphics_mode);
  278.         lettercolor = getmaxcolor();
  279.         if(lettercolor > 2)
  280.             linecolor = lettercolor - 1;
  281.         else if(lettercolor > 1)
  282.             linecolor = lettercolor - 1;
  283.         else linecolor = lettercolor;
  284.         if(y_res == 480) settextstyle(0,0,2);
  285.         if(y_res == 200) settextstyle(0,0,1);
  286.         sprintf(data,"T = 0");
  287.         outtextxy(tr.lbd, tr.tbd, data);
  288.         if(pop)
  289.         {   if(genotypes) sprintf(data,"Xp(%d%s)=%d",siz_x,lab_x,(int) xlpl);
  290.             else sprintf(data,"Xp(%i)=%i", siz_x, (int) xlpl);
  291.             outtextxy(tr.lbd + 165, tr.tbd, data);
  292.             if(genotypes) sprintf(data,"Yp(%d%s)=%d",siz_y,lab_y,(int) ylpl);
  293.             else sprintf(data,"Yp(%i)=%i", siz_y, (int) ylpl);
  294.             outtextxy(tr.lbd + 410, tr.tbd, data);
  295.         }
  296.         if(inst)
  297.         {   if(genotypes) sprintf(data,"Xi(%d%s)=%ld",siz_x,lab_x,(long) xlpl);
  298.             else sprintf(data,"Xi(%i)=%ld", siz_x, (long) xlpl);
  299.             outtextxy(tr.lbd + 165, tr.tbd, data);
  300.             if(genotypes) sprintf(data,"Yi(%d%s)=%ld",siz_y,lab_y,(long) ylpl);
  301.             else sprintf(data,"Yi(%i)=%ld", siz_y, (long) ylpl);
  302.             outtextxy(tr.lbd + 410, tr.tbd, data);
  303.         }
  304.     }
  305.     setcolor(linecolor);
  306.     for(;;)
  307.     {   if(fgets(data,80,inf) == NULL)
  308.         {   fclose(inf);
  309.             binum++;
  310.             sprintf(data,"%s/%s.%d", directory, bifile, binum);
  311.             inf = fopen(data,"r");
  312.             if(inf == NULL)
  313.                 break ;
  314.             if(fgets(data,80,inf) == NULL)
  315.                 break ;
  316.         }
  317.         if(!t_read(data, &lo, &firstr, &gent))
  318.         {   sscanf(data,"%*s%*s%d%*s%*s%lu%*s%*s%lu",
  319.                 &tnum_sp, &lo.ctime, &lo.time);
  320.             for(i = 0; i < tnum_sp; i++) fgets(data,80,inf);
  321.             continue;
  322.         }
  323.         if(lo.ctime > otime)
  324.         {   setfillstyle(SOLID_FILL,0);
  325.             setcolor(lettercolor);
  326.             sb.left = (tr.bti * tr.csz) + tr.lbd;
  327.             sb.top = tr.tbd;
  328.             sb.right = (tr.tim * tr.csz) + sb.left;
  329.             sb.bottom = sb.top + tr.csz;
  330.             bar(sb.left, sb.top, sb.right, sb.bottom);
  331.             sprintf(data,"%i", (int) lo.ctime);
  332.             outtextxy(sb.left, sb.top, data);
  333.             setcolor(linecolor);
  334.             sline(&p);
  335.             otime = lo.ctime;
  336.         }
  337.         if(lo.size == siz_x && (!genotypes || !strcmp(lo.label,lab_x)))
  338.         {   if(lo.bd == 'b') num_x++;
  339.             if(lo.bd == 'd') num_x--;
  340.         }
  341.         if(lo.size == siz_y && (!genotypes || !strcmp(lo.label,lab_y)))
  342.         {   if(lo.bd == 'b') num_y++;
  343.             if(lo.bd == 'd') num_y--;
  344.         }
  345.         if((lo.size == siz_x && (!genotypes || !strcmp(lo.label,lab_x))) ||
  346.         (lo.size == siz_y && (!genotypes || !strcmp(lo.label,lab_y))))
  347.         {   p.x = (float) num_x; p.y = (float) num_y;
  348.             if(inst) { p.x *= siz_x; p.y *= siz_y; }
  349.             p.x = (p.x - xnpl) / xlpl; p.y = (p.y - ynpl) / ylpl;
  350.             if(first) { sline(&p); first = 0; }
  351.             else cline(&p);
  352.         }
  353.         if(gfkbhit())
  354.         {   c = getkey();
  355.             if(c == 'p' || c == 'P') getkey();  /* P or p key */
  356.             if(c == ESC) break ;                /* Esc key */
  357.             if(c == 'g' || c == 'G')            /* G or g key */
  358.                 DumpScreen2Gif("image.gif",VGA,VGAHI,VGAHI,VGAHI);
  359.         }
  360.     }
  361.     fclose(inf);
  362.     if(scr)
  363.     {   vbeep();
  364.         while(1)
  365.         {   if(gfkbhit())
  366.             {   c = getkey();
  367.                 if(c == ESC) break ;                /* Esc key */
  368.                 if(c == 'g' || c == 'G')            /* G or g key */
  369.                     DumpScreen2Gif("image.gif",VGA,VGAHI,VGAHI,VGAHI);
  370.             }
  371.         }
  372.         restorecrtmode();
  373.     }
  374. }
  375.