home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / EDUCATIO / STAGES12.ZIP / MAIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-21  |  10.6 KB  |  386 lines

  1. #include "globals.h"
  2. #include "file.h"
  3.  
  4. /* default stack size in large memory model is 4000 */
  5. #if PC
  6. extern unsigned _stklen = 12000;
  7. #endif
  8.  
  9.  
  10. main (argc, argv)
  11.   int argc;
  12.   char *argv[];
  13. {
  14.   FILE *fpin;            /* data input file            */
  15.   FILE *fpstg;            /* stage data file            */
  16.   FILE *fpseq;            /* cell seq data file             */
  17.   FILE *fpmcl;            /* multicell stages data file        */
  18.   double days;            /* current days value from daystr    */
  19.   double third;            /* 1/3 of length of initial stage    */
  20.   char cellstrs[MAXIP][MAXIPLEN]; /* array of cell name input string    */
  21.   char daystrs[MAXIP][MAXIPLEN];  /* array of days input strings, file ip */
  22.   char opstr[MAXLEN];        /* tells when #days inputted exceeds    */
  23.                   /*   time left til release (fwd), or    */
  24.                 /*   time since entered (bwd), or    */
  25.                 /*   if input was unrecognized        */
  26.   char opstr1[MAXLEN];        /* these 2 strings tell when a cell was */
  27.   char opstr2[MAXLEN];        /*   ejact but still are tracking stgs    */
  28.   char stgfil[FILELEN];        /* cycle stage data filename        */
  29.   char seqfil[FILELEN];        /* cell sequence data filename        */
  30.   char mclfil[FILELEN];        /* multi-cell stage info filename    */
  31.   char ipfil[MAXLEN];        /* batch mode input file name        */
  32.   char opfil[FILELEN];        /* output file name            */
  33.   int initseq;            /* initial cell's index # in cell seq    */
  34.   int initst;            /* initial cell's stage            */
  35.   int index;            /* stage index                */
  36.   int cell[4];            /* final cells reached, starting from    */
  37.                 /*   beginning, 1/3, 2/3, and end of    */
  38.                 /*   initial stage            */
  39.   int trials;            /* # of initial cells to run        */
  40.   int moveok[4];        /* for fwd/bwd moves            */
  41.   int i;            /* loop index                */
  42.   int go;            /* boolean: continue?            */
  43.   int ok, okcell, oknum;    /* boolean: for input error checking    */
  44.   int badipfil;            /* boolean var                */
  45.   int once;            /* boolean: header printed to file yet?    */
  46.   int val, oldval;        /* return vals from menu functions    */
  47.   int newspec;            /* =1 if animal has been changed    */
  48.   int epi;            /* =1 if any cell of the current batch  */
  49.                 /*   i/p went into epididymis        */
  50.   int endspot;            /* which 3d of stage did move end in?    */
  51.  
  52.   /************************************************************************/
  53.   /**    test for correct number of arguments                     **/
  54.   /************************************************************************/
  55.  
  56.  if (argc > 2) {
  57.     printf("\n\tUsage:   %s  ", argv[0]);
  58.     printf("[ <batch_file_name> ]\n");
  59.     printexit(100);
  60.   }
  61.  
  62.   /* set tab strings and defaults */
  63.   strcpy(tab4, "    ");
  64.   strcpy(tab, "        ");
  65.   strcpy(tab2, "                ");
  66.   strcpy(opfil, "None");
  67.   Animal = strdup("None");   /* does AUTOmagic malloc */
  68.   NewCycleTime = 0;
  69.   FILEq = 0;
  70.   FILECOPY= 0;
  71. #if PC
  72.   HARDCOPY = 0;
  73.   introprint = 0;
  74. #endif
  75.  
  76.   /************************************************************************/
  77.   /**    print out title page info, if PC, set up screen             **/
  78.   /************************************************************************/
  79. #if PC
  80.   wholewin();
  81.   clrscr();
  82.   makedisplay();
  83. #if (DEBUG > 3)
  84.   makeactivewin(1);
  85.   gotoxy(1, 5);
  86.   cprintf("%smain:  core left = %lu", tab, coreleft());
  87.   hitreturn(1);
  88.   clrscr1(1);
  89. #endif
  90. #endif
  91.   printintro(1, 0);
  92.  
  93.   /************************************************************************/
  94.   /**    get input file pointer                             **/
  95.   /************************************************************************/
  96.  
  97.   badipfil = 0;
  98.   interactive = 1;
  99.   /* see if valid batch file specified */
  100.   if (argc == 2) {
  101.     strcpy(ipfil, argv[1]);
  102.     if (getipfile(ipfil, &fpin, 'F', 'I'))
  103.       badipfil = 1;
  104.     else
  105.       interactive = 0;
  106.   }
  107.  
  108.   /************************************************************************/
  109.   /**    set up temp file pointer (output holder)             **/
  110.   /************************************************************************/
  111. #if PC
  112.   sprintf(TMPFIL, "TMPout.out");
  113.   tmpfp = fopen(TMPFIL, "w");
  114. #endif
  115.  
  116.   /************************************************************************/
  117.   /**    start main menu/computation loop                     **/
  118.   /************************************************************************/
  119.  
  120.   ok = 1;
  121.   epi = 0;
  122.   trials = 0;
  123.   newspec = 0;
  124.   val = 101;        /* start at general menu */
  125.   oldval = val;
  126.   while (val) {
  127.     switch (val) {
  128.  
  129.       /**************************/
  130.       /*  general menu        */
  131.       /**************************/
  132.     case 101:
  133. #if PC
  134.       clrscr1(3);
  135. #endif
  136.       once = 0;        /* controls printing of results hdr */
  137.       oldval = val;
  138.       val = generalmenu(opfil);
  139.       break;
  140.  
  141.       /**************************/
  142.       /*  help menu        */
  143.       /**************************/
  144.     case 102:
  145. #if PC
  146.       clrscr1(3);
  147. #endif
  148.       oldval = val;
  149.       val = helpmenu();
  150.       break;
  151.  
  152.       /**************************/
  153.       /*  animal menu        */
  154.       /**************************/
  155.     case 103:
  156. #if PC
  157.       clrscr1(3);
  158. #endif
  159.       oldval = val;
  160.       val = animalmenu(&fpstg, &fpseq, &fpmcl,
  161.                stgfil, seqfil, mclfil, &newspec);
  162.       if (! val && newspec) {
  163. #if (DEBUG > 4)
  164. #if PC
  165.     clrscr1(1);
  166.     gotoxy(1, 5);
  167.     cprintf("%smain:  about to printoutputhdr", tab);
  168.     hitreturn(1);
  169. #else
  170.     printf("\tmain:  about to printoutputhdr\n");
  171. #endif
  172. #endif
  173.     val = printoutputhdr(argc, argv, &badipfil, interactive, ok,
  174.                    ipfil, opfil, stgfil, seqfil);
  175.       } /* if */
  176.       break;
  177.  
  178.       /**************************/
  179.       /*  cycle length menu     */
  180.       /**************************/
  181.     case 104:
  182. #if PC
  183.       clrscr1(3);
  184. #endif
  185.       oldval = val;
  186.       val = cyclemenu();
  187.       if (! val)
  188.     val = 105;    /* cell i/p menu next */
  189.       break;
  190.  
  191.       /**************************/
  192.       /*  display menu        */
  193.       /**************************/
  194.       /* this is not very useful a menu, since you can display
  195.      the stage and cell seq dat from within the cell i/p
  196.      and days i/p menu -- but it can't hurt to have this */
  197.     case 114:
  198. #if PC
  199.       clrscr1(3);
  200. #endif
  201.       oldval = val;
  202.       val = displaymenu();
  203.       break;
  204.  
  205.       /**************************/
  206.       /*  cell input menu    */
  207.       /**************************/
  208.     case 105:
  209. #if PC
  210.       clrscr1(3);
  211. #endif
  212.       oldval = val;
  213.       if (interactive) {
  214.     once = 0;    /* controls printing of results header */
  215.     val = getusrcells(cellstrs, &trials);
  216.       } else {
  217.     val = 0;
  218.     trials = 1;    /* batch i/p file */
  219.       }
  220.       if (! val)
  221.     val = 106;    /* valid cells: get user days next */
  222.       break;
  223.  
  224.       /**************************/
  225.       /*  days input menu    */
  226.       /**************************/
  227.     case 106:
  228. #if PC
  229.       clrscr1(3);
  230. #endif
  231.       oldval = val;
  232.       if (interactive)
  233.     val = getusrdays(cellstrs, daystrs, trials);
  234.       else
  235.     val = 0;
  236.  
  237.       if (! val) {
  238.     if (interactive)
  239.       val = 105;    /* valid days: get more cells next */
  240.     else
  241.       val = 106;    /* batch mode: stay here til EOF */
  242.  
  243.     i = 0;
  244.     while (i < trials) {
  245.       if (interactive)
  246.         go = 1;
  247.       else
  248.         /* get file input (one <cellname,days> pair at a time)
  249.            go = 0 when EOF encountered in fpin */
  250.         go = getfileip(cellstrs[i], daystrs[i], fpin);
  251.  
  252.       if (go) {
  253.         /* if interactive, parsecellstr will return 1 since user
  254.            input was already checked by parsecellstr in getusrcells */
  255.         okcell = parsecellstr(cellstrs[i], &initseq, &initst, opstr);
  256.         if (interactive) {
  257.           oknum = 1;
  258.           days = atof(daystrs[i]);
  259.         } else {
  260.           oknum = numstrq(daystrs[i]);
  261.           if (oknum)
  262.         days = atof(daystrs[i]);
  263.           else
  264.         days = 0.0;    /* any dummy value */
  265.         } /* !interactive */
  266.  
  267.         /* the index into the cycle stage info array is one less
  268.            than the stage of a cell, since the 1st stage is 1 and
  269.            the 1st array index is 0 */
  270.         index = initst - 1;
  271.         third = stage[index] / 3.0;    /* divide stage into thirds */
  272.         if (days >= 0) {    /* forward */
  273.           if (okcell && oknum)
  274.         forward(initseq, index, third, days, cell,
  275.             moveok, &endspot, opstr);
  276.           printresults('F', days, daystrs[i], cell, cellstrs[i], moveok,
  277.                okcell, oknum, endspot, opstr, &once, &epi,
  278.                opstr1, opstr2);
  279.         } else {        /* backward */
  280.           if (okcell && oknum)
  281.         backward(initseq, index, third, fabs(days), cell,
  282.              moveok, &endspot, opstr);
  283.           printresults('B', days, daystrs[i], cell, cellstrs[i], moveok,
  284.                okcell, oknum, endspot, opstr, &once, &epi,
  285.                opstr1, opstr2);
  286.         } /* if days */
  287.         printline(3, LNWID, '-');
  288.       } else {    /* ! go */
  289.         val = 110;    /* batch done: exit! */
  290.       } /* if go */
  291.  
  292.       i++;
  293.     } /* while i */
  294.  
  295.     if (interactive && epi) {
  296.       printepi();
  297.       epi = 0;        /* reset epi */
  298.     }
  299. #if PC
  300.     if (interactive)
  301.       hitreturn(1);
  302.     if (HARDCOPY) {
  303.       togglepr();
  304.       printresHARD();
  305.     }
  306. #endif
  307.       } /* if ! val */
  308.       break;
  309.  
  310.       /**************************/
  311.       /*  toggle file        */
  312.       /**************************/
  313.     case 107:
  314.       val = oldval;    /* go back to where we were */
  315.       if (FILEq)
  316.     FILECOPY = FILECOPY ^ 1;
  317.       else {
  318. #if PC
  319.     clrscr1(3);
  320.     cprintf("%s%s: Output not currently being saved to file <stages.out>.", tab, ERRSTR);
  321.     gotoxy(1, 2);
  322.     cprintf("%s           Use General Menu, `Printer and File Options'", tab);
  323.     gotoxy(1, 3);
  324.     cprintf("%s           to select an output file.", tab);
  325.     if (HARDCOPY) {
  326.       fprintf(stdprn, "\n\t%s: Output not currently being saved to file <stages.out>.\n",
  327.           ERRSTR);
  328.     }
  329. #else
  330.     printf("\t%s: Output not currently being saved to file <stages.out>.", ERRSTR);
  331. #endif
  332.     helpopfile();
  333.       }
  334.       printFILECOPY();
  335.       break;
  336.  
  337. #if PC
  338.       /**************************/
  339.       /*  toggle printer    */
  340.       /**************************/
  341.     case 108:
  342.       val = oldval;    /* go back to where we were */
  343. #if PC
  344.       togglepr();
  345. #endif
  346.       break;
  347.  
  348.       /**************************/
  349.       /*  makedisplay        */
  350.       /**************************/
  351.     case 109:
  352.       val = oldval;    /* go back to where we were */
  353.       makedisplay();
  354.       break;
  355. #endif
  356.  
  357.       /**************************/
  358.       /*  exit            */
  359.       /**************************/
  360.     case 110:
  361.       if (! interactive && epi)
  362.     /* batch had a cell go epi */
  363.     printepi();
  364.       printexit(0);
  365.  
  366.  
  367.       /**************************/
  368.       /*  default        */
  369.       /**************************/
  370.    default:
  371. #if PC
  372.       clrscr1(1);
  373.       gotoxy(1, 5);
  374.       cprintf("%s%s:  Abnormal input.", tab, ERRSTR);
  375.       gotoxy(1, 7);
  376.       cprintf("%s%s   Returning to General Menu.", tab, NULLERRSTR);
  377.       cprintf("");
  378. #else
  379.       printf("");
  380. #endif
  381.       val = 101;
  382.     } /* switch val */
  383.   } /* while val */
  384.   return(0);
  385. } /* main */
  386.