home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / EDUCATIO / STAGES12.ZIP / INPUTS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-25  |  32.8 KB  |  1,258 lines

  1. #include <stdio.h>
  2. #if PC
  3.   #include <bios.h>
  4. #endif
  5. #include "main.h"
  6. #include "header.h"
  7. #include "pcwins.h"
  8.  
  9. /* files included:
  10.            getipfile
  11.         getstgdat
  12.                 getCyclelen
  13.         getseqdat
  14.         getusrstr
  15.         getusrstrlist
  16.         getusrcells
  17.         getusrdays
  18.         getfileip
  19.         parsecellstr
  20.         getcellstg
  21. */        
  22.  
  23. /********************************/
  24. /*     function: getipfile    */
  25. /********************************/
  26. /* takes user input as filename and if nonzero length, tries to
  27.    open a file of that name.  if fopen fails, asks the user to
  28.    specify another file to try, or to specify no file desired.
  29.    returns 0 if valid file
  30.           !0 if no file was opened */
  31. getipfile (ipfil, pfp, iptype, mandatoryq, ftype)
  32.   char *ipfil;        /* the name of the file finally opened    */
  33.   FILE **pfp;
  34.   char iptype;        /* filename supplied (F) or entered    */
  35.               /* interactively (I)            */
  36.   int mandatoryq;    /* if=1, then file must be specified    */
  37.   char ftype;        /* C=cycle stage dat
  38.                I=input file (batch mode)
  39.                S=cell sequence dat            */
  40. {
  41.   int i, go, help, len, quit;
  42.   char fname[MAXLEN], c;
  43. #if PC
  44.   int val;
  45. #endif
  46.  
  47.   if (iptype == 'F')
  48.     /* filename supplied in var ipfile */
  49.     strcpy(fname, ipfil);
  50.   else {
  51.     /* get a filename interactively;
  52.        user-friendly asking-message printed by calling function    */
  53. #if PC
  54.     val = getusrstr(fname);
  55.     if (HARDCOPY)
  56.       fprintf(stdprn, "%s\n", fname);
  57.     if (val) return(val);
  58. #else
  59.     getusrstr(fname);
  60. #endif
  61.     if (FILEq && FILECOPY)
  62.       fprintf(fpout, "%s\n", fname);
  63.   }
  64.  
  65.   /* strip input string of leading/trailing whitespace */
  66.   stripwhitesp(fname);
  67.  
  68.   go = 1;
  69.   while (go && ((*pfp = fopen(fname, "r"))==NULL)) {
  70.     /* maybe it wasn't a filename i/p but a char-accel */
  71.     if ((strcmp(fname, "q")==0) || (strcmp(fname, "Q")==0))
  72.       go = 0;
  73.     else {
  74.       if (fname[0]=='?') {
  75.     help = 1;
  76.     if ((ftype=='C') || (ftype=='S'))
  77.       helpipfil(ftype);
  78.     else
  79.       helpipfil1(ipfil);
  80.       } else
  81.     help = 0;
  82.  
  83. #if PC
  84.       msgwin();
  85.       gotoxy(1, 1);
  86.       clreol1(3);
  87.       gotoxy(1, 1);
  88.       if (! help) {
  89.     printf("%s%s: File ", tab, ERRSTR);
  90.     printf("<%s> does not exist.", fname);
  91.     gotoxy(1, 2);
  92.       }
  93.       cprintf("%sPlease enter a new filename", tab);
  94.       if (HARDCOPY) {
  95.     if (! help) {
  96.       fprintf(stdprn, "\n\t%s: File ", ERRSTR);
  97.       fprintf(stdprn, "<%s> does not exist.\n", fname);
  98.     }
  99.     fprintf(stdprn, "\tPlease enter a new filename");
  100.       }
  101. #else
  102.       if (! help) {
  103.     printf("\n\t%s: File ", ERRSTR);
  104.     printf("<%s> does not exist.\n", fname);
  105.       }
  106.       printf("\tPlease enter a new filename");
  107. #endif
  108.       if (FILEq && FILECOPY) {
  109.     if (! help) {
  110.       fprintf(fpout, "\n\t%s: File ", ERRSTR);
  111.       fprintf(fpout, "<%s> does not exist.\n", fname);
  112.     }
  113.     fprintf(fpout, "\tPlease enter a new filename");
  114.       }
  115.       
  116.       if (! mandatoryq) {
  117.     /* not mandatory that a file be entered: `no file' option ok */
  118. #if PC
  119.     cprintf(", or");
  120.     gotoxy(1, 3);
  121.     cprintf("%stype <return> if no file is desired.", tab);
  122.     if (HARDCOPY) {
  123.       fprintf(stdprn, ", or\n\ttype <return> ");
  124.       fprintf(stdprn, "if no file is desired.\n");
  125.     }
  126. #else
  127.     printf(", or\n\ttype <return> ");
  128.     printf("if no file is desired.\n");
  129. #endif
  130.     if (FILEq && FILECOPY) {
  131.       fprintf(fpout, ", or\n\ttype <return> ");
  132.       fprintf(fpout, "if no file is desired.\n");
  133.     }
  134.       } else {    /* mandatoryq */
  135.     /* must have a filename specified */
  136. #if PC
  137.     cprintf(".");
  138.     if (HARDCOPY)
  139.       fprintf(stdprn, ":\n");
  140. #else
  141.     printf(":\n");
  142. #endif
  143.     if (FILEq && FILECOPY)
  144.       fprintf(fpout, ":\n");
  145.       } /* if mandatoryq */
  146.     
  147. #if PC
  148.       clrscr1(2);
  149.       cprintf("%sNew filename:", tab);
  150.       gotoxy(1, 2);
  151.       highvideo();
  152.       cprintf("%s%c%c%c ", tab2, HBAR, HBAR, RTRI);
  153.       normvideo();
  154.       if (HARDCOPY)
  155.     fprintf(stdprn, "\t\t==> ");
  156. #else
  157.       printf("\t\t==> ");
  158. #endif
  159.       if (FILEq && FILECOPY)
  160.     fprintf(fpout, "\t\t==> ");
  161.     
  162.       /* get new filename */
  163. #if PC
  164.       val = getusrstr(fname);
  165.       if (HARDCOPY)
  166.     fprintf(stdprn, "%s\n", fname);
  167.       if (val) return(val);
  168. #else
  169.       getusrstr(fname);
  170.       if (FILEq && FILECOPY)
  171.     fprintf(fpout, "%s\n", fname);
  172. #endif
  173.  
  174.       len = strlen(fname);
  175.       if (!mandatoryq && !len)
  176.     go = 0;
  177.     } /* if ! Q */
  178.   } /* while */
  179.  
  180.   if (*pfp != NULL) {        /* good file opened */
  181. #if PC
  182.     /* not enough room in msgwin() with "file not found.." error msgs
  183.        to print out this message on the pc terminal.  oh well */
  184.     if (HARDCOPY)
  185.       fprintf(stdprn, "\n\tFile <%s> opened successfully.\n", fname);
  186. #else
  187.     printf("\n\tFile <%s> opened successfully.\n", fname);
  188. #endif
  189.     if (FILEq && FILECOPY)
  190.       fprintf(fpout, "\n\tFile <%s> opened successfully.\n", fname);
  191.     strcpy(ipfil, fname);
  192.     return(0);
  193.   } else {
  194.     /* only other way out of while loop was if go=0 */
  195.     switch (ftype) {
  196.  
  197.     case 'I':            /* no batch file necessary */
  198. #if PC
  199.       clrscr1(3);
  200.       cprintf("%sNo batch file opened; input must be entered interactively.", tab);
  201.       if (HARDCOPY)
  202.     fprintf(stdprn, "\n\tNo batch file opened; input must be entered interactively.\n");
  203. #else
  204.       printf("\n\tNo batch file opened; input must be entered interactively.\n");
  205. #endif
  206.       if (FILEq && FILECOPY)
  207.     fprintf(fpout, "\n\tNo batch file opened; input must be entered interactively.\n");
  208.       break;
  209.  
  210.     case 'C':        /* stage file mandatory but user defers */
  211. #if PC
  212.       clrscr1(3);
  213.       cprintf("%sNo animal stage length data file opened.", tab);
  214.       if (HARDCOPY)
  215.     fprintf(stdprn, "\tNo animal stage length data file opened.\n");
  216. #else
  217.       printf("\tNo animal stage length data file opened.\n");
  218. #endif
  219.       if (FILEq && FILECOPY)
  220.     fprintf(fpout, "\tNo animal stage length data file opened.\n");
  221.       break;
  222.  
  223.     case 'S':        /* sequence file mandatory but user defers */
  224. #if PC
  225.       cprintf("%sNo animal cell sequence data file opened.", tab);
  226.       if (HARDCOPY)
  227.     fprintf(stdprn, "\tNo animal cell sequence data file opened.\n");
  228. #else
  229.       printf("\tNo animal cell sequence data file opened.\n");
  230. #endif
  231.       if (FILEq && FILECOPY)
  232.     fprintf(fpout, "\tNo animal cell sequence data file opened.\n");
  233.       break;
  234.     } /* switch */
  235.     return(1);
  236.   } /* *pfp==NULL */
  237. } /* getipfile */
  238.  
  239. /********************************/
  240. /*     function: getstgdat    */
  241. /********************************/
  242. /* reads from the file xxx.stg to get the cycle stage data */
  243. getstgdat (stgfil, fpstg)
  244.   char *stgfil;
  245.   FILE *fpstg;
  246. {
  247.   int i, j;        /* char array indices            */
  248.   int diff;        /* tmp var                */
  249.   char c;        /* temp char var             */ 
  250.   
  251.   i = 0;
  252.   j = 0;
  253.   numrefs = 0;
  254.   while ((c=getc(fpstg)) != '*') {
  255.     if (j >= (MAXLEN-1)) {
  256. #if PC
  257.       clrscr1(3);
  258.       cprintf("%s%s:  Reference line too long in file ", tab, ERRSTR);
  259.       cprintf("<%s>: truncated", stgfil);
  260.       if (HARDCOPY) {
  261.     fprintf(stdprn, "\n\t%s:  Reference line too long ", ERRSTR);
  262.     fprintf(stdprn, "in file <%s>:", stgfil);
  263.     fprintf(stdprn, "\n\t%s   Line truncated.\n", NULLERRSTR);
  264.       }
  265. #else
  266.       printf("\t%s:  Reference line too long in file ", ERRSTR);
  267.       printf("<%s>:\n", stgfil);
  268.       printf("\t%s   Line truncated.\n\n", NULLERRSTR);
  269. #endif
  270.       if (FILEq && FILECOPY) {
  271.     fprintf(fpout, "\n\t%s:  Reference line too long ", ERRSTR);
  272.     fprintf(fpout, "in file <%s>:", stgfil);
  273.     fprintf(fpout, "\n\t%s   Line truncated.\n", NULLERRSTR);
  274.       }
  275.       while ((c=getc(fpstg)) != '\n');    /* get to end of line    */
  276.     } /* if j */
  277.  
  278.     if (c == '\n') {
  279.       ref[i][j] = '\0';        /* finish this ref line */
  280.       i++;            /* start new ref line     */
  281.       j = 0;            /* reset j for new line */
  282.       if (i <= MAXLINES)
  283.     numrefs++;        /* incr # ref lines     */
  284.     } else {
  285.       ref[i][j++] = c;        /* build ref info line    */
  286.     }
  287.   } /* while */
  288.  
  289.   if ((diff=(i - MAXLINES)) > 0) {
  290. #if PC
  291.     msgwin();
  292.     gotoxy(1, 2);
  293.     cprintf("%s%s:  Too many reference ", tab, ERRSTR);
  294.     cprintf("lines in file <%s>:", stgfil);
  295.     gotoxy(1, 3);
  296.     cprintf("%s%s   %d line", tab, NULLERRSTR, diff);
  297.     if (diff > 1) cprintf("s");
  298.     cprintf(" omitted.");
  299.     if (HARDCOPY) {
  300.       fprintf(stdprn, "\n\t%s:  Too many reference ", ERRSTR);
  301.       fprintf(stdprn, "lines in file <%s>:", stgfil);
  302.       fprintf(stdprn, "\n\t%s   %d line", NULLERRSTR, diff);
  303.       if (diff > 1) fprintf(stdprn, "s");
  304.       fprintf(stdprn, " omitted.\n");
  305.     }
  306. #else
  307.     printf("\t%s:  Too many reference ", ERRSTR);
  308.     printf("lines in file <%s>:", stgfil);
  309.     printf("\n\t%s   %d line", NULLERRSTR, diff);
  310.     if (diff > 1) printf("s");
  311.     printf(" omitted.\n\n");
  312. #endif
  313.     if (FILEq && FILECOPY) {
  314.       fprintf(fpout, "\n\t%s:  Too many reference ", ERRSTR);
  315.       fprintf(fpout, "lines in file <%s>:", stgfil);
  316.       fprintf(fpout, "\n\t%s   %d line", NULLERRSTR, diff);
  317.       if (diff > 1) fprintf(fpout, "s");
  318.       fprintf(fpout, " omitted.\n");
  319.     }
  320.   } /* if diff */
  321.  
  322.   /* read cycle time - this is in days */
  323.   fscanf(fpstg, "%lf", &CycleTime);
  324. #if PC
  325.   sep1win();            /* turn on Cycle Length annunciator */
  326. #endif
  327.   OldCycleTime = CycleTime;        /* initialize OldCycleTime */
  328.   fscanf(fpstg, "%d", &NumStages);
  329.   MaxStage = NumStages - 1;
  330.  
  331.   /* allocate NumStages spaces for stage lengths */
  332.   stage = (double *) malloc((unsigned) (NumStages * sizeof(double)));
  333.   /* read stage lengths (these are in % of CycleTime) and convert to days */
  334.   for ( i=0; i<NumStages; i++ ) {
  335.     fscanf(fpstg, "%lf", &stage[i]);
  336.     stage[i] = stage[i] * CycleTime / 100;
  337.   }
  338.  
  339.   /* read epididymis transit times (this is days) */
  340.   fscanf(fpstg, "%lf", &EpiTime);
  341. } /* getstgdat */
  342.  
  343. /********************************/
  344. /*     function: getCyclelen    */
  345. /********************************/
  346. /* asks user to input new CycleTime, or use default */
  347. getCyclelen ()
  348. {
  349.   char dummy[MAXLEN];        /* user input string */
  350.   int i, val, ok;
  351.  
  352.   ok = 0;
  353.   while (! ok) {
  354. #if PC
  355.     clrscr1(2);
  356.     cprintf("%sNew Cycle Length (in days):", tab);
  357.     gotoxy(1, 2);
  358.     highvideo();
  359.     cprintf("%s%c%c%c ", tab2, HBAR, HBAR, RTRI);
  360.     normvideo();
  361.     val = getusrstr(dummy);
  362.     if (HARDCOPY) {
  363.       fprintf(stdprn, "\n\tNew Cycle Length (in days):\n");
  364.       fprintf(stdprn, "\t\t==> %s\n\n", dummy);
  365.     }
  366.     if (val) return(val);        /* keyboard accel pressed */
  367. #else
  368.     printf("\n\tNew Cycle Length (in days):\n");
  369.     getusrstr(dummy);
  370.     printf("\t\t==> %s\n\n", dummy);
  371. #endif
  372.  
  373.     if (FILEq && FILECOPY) {
  374.       fprintf(fpout, "\n\tNew Cycle Length (in days):\n");
  375.       fprintf(fpout, "\t\t==> %s\n\n", dummy);
  376.     }
  377.     switch (dummy[0]) {
  378.     case '?':
  379.       helpcyclelenip();
  380.       break;
  381.     default:  /* it's a new Cycle length, if it's a valid # */
  382.       if (! numstrq(dummy)) {
  383. #if PC
  384.         clrscr1(3);
  385.         cprintf("%s%s:  Invalid number syntax <%s>", tab, ERRSTR, dummy);
  386.         if (HARDCOPY) {
  387.           fprintf(stdprn, "\t%s:  Invalid number syntax <%s>.\n",
  388.                   ERRSTR, dummy);
  389.         }
  390. #else
  391.         printf("\t%s:  Invalid number syntax <%s>.\n", ERRSTR, dummy);
  392. #endif
  393.         if (FILEq && FILECOPY) {
  394.           fprintf(fpout, "\t%s:  Invalid number syntax <%s>.\n",
  395.                   ERRSTR, dummy);
  396.         }
  397.       } else {  /* it's a valid number input */
  398.     OldCycleTime = CycleTime;
  399.         CycleTime = atof(dummy);
  400.     ok = 1;
  401.     NewCycleTime = 1;        /* global var */
  402.     /* set Cycle length annunciator */
  403. #if PC
  404.     sep1win();
  405. #endif
  406.     /* transform old stage[i] vals (days) to new ones */
  407.     for ( i=0; i<NumStages; i++ )
  408.       stage[i] = stage[i] * CycleTime / OldCycleTime;
  409.       } /* if numstr) */
  410.     } /* dummy != ? */
  411.   } /* while ! ok */
  412.   return(0);
  413. } /* getCyclelen */
  414.  
  415. /********************************/
  416. /*     function: getseqdat    */
  417. /********************************/
  418. /* reads from the file xxx.seq to get the cell sequence data */
  419. getseqdat (seqfil, fpseq)
  420.   char *seqfil;
  421.   FILE *fpseq;
  422. {
  423.   int i;        /* char array indices            */
  424.   int ok;        /* boolean                */
  425.   unsigned len;        /* actual length of string t         */
  426.   char c;        /* temp char var             */
  427.   char temp[MAXLEN];    /* temp str: holds CellNames         */
  428.  
  429.   /* the cell sequence filename is in var seqfil, if needed */
  430.   /* determine number of cells in cell sequence */
  431.   NumCellSeq = 0;
  432.   while (fscanf(fpseq, "%*s") != EOF)
  433.     NumCellSeq++;
  434.   /* subtract epididymis time: its not part of the cycle */
  435.   NumCellSeq -= 1;
  436.   rewind(fpseq);
  437.   MaxCellIndex = NumCellSeq - 1;
  438.  
  439.   /* allocate NumCellSeq+1 spaces for cell names
  440.    "+1" since we add one for epididymis */
  441.   CellNames =
  442.     (char **) malloc((unsigned) ((NumCellSeq+1) * sizeof(char *)));
  443.   for ( i=0; i<NumCellSeq; i++ ) {
  444.     fscanf(fpseq, "%s", temp);
  445.     len = strlen(temp);
  446.     CellNames[i] =
  447.       (char *) malloc((unsigned) ((len+1) * sizeof(char)));
  448.     strupper(temp);
  449.     strcpy(CellNames[i], temp);
  450.   }
  451.   /* get "epididymis" name string */
  452.   fscanf(fpseq, "%s", temp);
  453.   len = strlen(temp);
  454.   CellNames[MaxCellIndex+1] =
  455.       (char *) malloc((unsigned) ((len+1) * sizeof(char)));
  456.   strcpy(CellNames[MaxCellIndex+1], temp);
  457. } /* getseqdat */
  458.  
  459. #if PC
  460. /********************************/
  461. /*     function: getusrstr    */
  462. /********************************/
  463. /* gets one user input string: PC version
  464.    checks to see if an F-key was typed
  465.  
  466.    bioskey() described in turbo c v2.0 ref guide
  467.    bit manipulations from _the peter norton programmer's
  468.    guide to the ibm pc_, pp127-135, microsoft press, 1985
  469.  
  470.    return 0 if string input
  471.    return 100+k if F-k pressed */
  472. getusrstr (input)
  473.   char *input;        /* char str input if no F key    */
  474. {
  475.   int key;        /* 32-bit val of key pressed     */
  476.   int keylo;        /* key bits 0-7            */
  477.   int keyhi;        /* key bits 8-15        */
  478.   int i, go, x, y;
  479.   char c;
  480.   
  481.   i = 0;
  482.   go = 1;
  483.   y = wherey();
  484.   while (go) {
  485.     while (bioskey(1)==0);        /* sit & spin */
  486.     x = wherex();
  487.     key = bioskey(0);
  488.     keylo = key & 0x000000FF;
  489.     keyhi = (key & 0x0000FF00) >> 8;    /* right shift 8 bits */
  490.     switch (keylo) {
  491.     case 0:    /* Fkey? */
  492.       switch (keyhi) {
  493.       case 59:        /* F1 */
  494.     return(101);
  495.       case 60:        /* F2 */
  496.     return(102);
  497.       case 61:        /* F3 */
  498.     return(103);
  499.       case 62:        /* F4 */
  500.     return(104);
  501.       case 63:        /* F5 */
  502.     return(105);
  503.       case 64:        /* F6 */
  504.     return(106);
  505.       case 65:        /* F7 */
  506.     return(107);
  507.       case 66:        /* F8 */
  508.     return(108);
  509.       case 67:        /* F9 */
  510.     return(109);
  511.       case 68:        /* F10 */
  512.     return(110);
  513.       default:        /* undefined special key */
  514.     input[0] = '\0';
  515.     return(200);
  516.       } /* switch */
  517.       break;
  518.     case 8:    /* backspace */
  519.       if (i > 0) {
  520.     i--;
  521.     gotoxy(x-1, y);
  522.     clreol1(2);
  523.     gotoxy(x-1, y);
  524.       }
  525.       break;
  526.     case 13:    /* return */
  527.       input[i] = '\0';
  528.       return(0);    /* success: got string */
  529.     case 32:    /* kill spaces: single string input */
  530.       gotoxy(x, y);
  531.       printf("%c", keylo);
  532.       break;
  533.     default:    /* ASCII char */
  534.       gotoxy(x, y);
  535.       printf("%c", keylo);
  536.       input[i++] = keylo;
  537.     } /* switch keylo */
  538.   } /* while */
  539. } /* getusrstr */
  540.  
  541. #else
  542.  
  543. /********************************/
  544. /*     function: getusrstr    */
  545. /********************************/
  546. /* gets one user input string */
  547. getusrstr (input)
  548.   char *input;
  549. {
  550.   int i;
  551.   char c;
  552.  
  553.   i = 0;
  554.   while ((c=getc(stdin)) != '\n')
  555.     if (c != ' ')
  556.       input[i++] = c;
  557.   input[i] = '\0';
  558. } /* getusrstr */
  559.  
  560. #endif
  561.  
  562. #if PC
  563. /********************************/
  564. /*     function: getusrstrlist    */
  565. /********************************/
  566. /* gets a list user-input strings: PC version
  567.  
  568.    return 0 if string input
  569.    return 100+k if F-k pressed */
  570. getusrstrlist (strings, pnum)
  571.   char strings[][MAXLEN];    /* list of strings if no F key  */
  572.   int *pnum;            /* num of strings input     */
  573. {
  574.   int key;            /* 32-bit val of key pressed     */
  575.   int keylo;            /* key bits 0-7            */
  576.   int keyhi;            /* key bits 8-15        */
  577.   int i, j, k, any, go, x, y, last;
  578.   char c;
  579.   char input[2*MAXLEN];        /* for reading i/p linearly    */
  580.  
  581.   i = 0;
  582.   *pnum = 0;
  583.   y = wherey();
  584.   go = 1;
  585.   while (go) {
  586.     while (bioskey(1)==0);        /* sit & spin */
  587.     x = wherex();
  588.     key = bioskey(0);
  589.     keylo = key & 0x000000FF;
  590.     keyhi = (key & 0x0000FF00) >> 8;    /* right shift 8 bits */
  591.     switch (keylo) {
  592.     case 0:    /* Fkey? */
  593.       switch (keyhi) {
  594.       case 59:        /* F1 */
  595.     return(101);
  596.       case 60:        /* F2 */
  597.     return(102);
  598.       case 61:        /* F3 */
  599.     return(103);
  600.       case 62:        /* F4 */
  601.     return(104);
  602.       case 63:        /* F5 */
  603.     return(105);
  604.       case 64:        /* F6 */
  605.     return(106);
  606.       case 65:        /* F7 */
  607.     return(107);
  608.       case 66:        /* F8 */
  609.     return(108);
  610.       case 67:        /* F9 */
  611.     return(109);
  612.       case 68:        /* F10 */
  613.     return(110);
  614.       default:        /* undefined special key */
  615.     strings[0][0] = '\0';
  616.     return(200);
  617.       } /* switch keyhi */
  618.       break;
  619.     case 8:    /* backspace */
  620.       if (i > 0) {
  621.     i--;
  622.     gotoxy(x-1, y);
  623.     clreol1(2);
  624.     gotoxy(x-1, y);
  625.       }
  626.       break;
  627.     case 13:    /* return */
  628.       input[i] = '\0';
  629.       last = i;
  630.       go = 0;
  631.     default:    /* ASCII char */
  632.       gotoxy(x, y);
  633.       printf("%c", keylo);
  634.       /* first build flat array of input, so can ^H over it */
  635.       input[i++] = keylo;
  636.     } /* switch keylo */
  637.   } /* while go */
  638.  
  639.   /* now build array of strings from input */
  640.   i = 0;
  641.   j = 0;
  642.   any = 0;
  643.   for ( k=0; k<=last; k++ ) {
  644.     if (whitespq(input[k])) {    /* whitespace=space/tab/CR    */
  645.       if (any && j) {
  646.     strings[i][j] = '\0';    /* end this cellname str    */
  647.     (*pnum)++;
  648.     i++;            /* start next cellname str    */
  649.     j = 0;
  650.       }
  651.     } else { /* ! whitespace */
  652.       any = 1;
  653.       strings[i][j++] = input[k];    /* build new cellname    */
  654.     }
  655.   } /* for i */
  656.   return(0);
  657. } /* getusrstrlist */
  658.  
  659. #else
  660.  
  661. /********************************/
  662. /*     function: getusrstrlist    */
  663. /********************************/
  664. /* gets a list user-input strings */
  665. getusrstrlist (strings, pnum)
  666.   char strings[][MAXLEN];
  667.   int *pnum;
  668. {
  669.   int i, j, any, go;
  670.   char c;
  671.  
  672.   i = 0;
  673.   j = 0;
  674.   any = 0;
  675.   *pnum = 0;
  676.   go = 1;
  677.   while (go && (c=getc(stdin)) != '\n') {
  678.     /* build array of cellnames */
  679.     if (whitespq(c)) {        /* whitespace = space or tab */
  680.       if (any) {
  681.     strings[i][j] = '\0';    /* end this cellname str     */
  682.     (*pnum)++;        /* incr # trials         */
  683.     i++;            /* start next cellname str     */
  684.       }
  685.       j = 0;
  686.       /* skip whitespace */
  687.       while (whitespq(c=getc(stdin)));
  688.  
  689.       if (c != '\n') {        /* if more besides whitesp...    */
  690.     any = 1;
  691.     strings[i][j++] = c;    /* build new cellname str    */
  692.       } else {            /* last chars were just whitesp */
  693.     go = 0;        
  694.     (*pnum)--;
  695.       }
  696.     } else { /* ! whitespq */
  697.       any = 1;
  698.       strings[i][j++] = c;    /* build this cellname str    */
  699.     } /* if */
  700.   } /* while */
  701.   
  702.   (*pnum)++;
  703.   strings[i][j] = '\0';        /* end the last cellname str    */
  704. } /* getusrstrlist */
  705.  
  706. #endif
  707.  
  708. /********************************/
  709. /*     function: getusrcells    */
  710. /********************************/
  711. /* gets list of initial cell names interactively
  712.    
  713.    if PC: returns 0 if number ok
  714.            100+k if special key pressed (e.g., F-key) */
  715. getusrcells (cellstr, ptrials)
  716.   char cellstr[][MAXLEN];
  717.   int *ptrials;
  718. {
  719.   int i, stop, ok;
  720.   int stgdaton;        /* =1 if stg dat on screen    */
  721.   int seqdaton;        /* =1 if seq dat on screen     */
  722.   int dum1, dum2, dum4;    /* dummy vars for parsecellstr    */
  723.   char dum3[MAXLEN];    /* dummy str for parsecellstr    */
  724.   /* dummy string so cellstr isn't wiped out if user wants
  725.      to use same cells over again */
  726.   char dummy[MAXIP][MAXLEN];
  727. #if PC
  728.   int any, j, val;
  729. #endif
  730.  
  731.   if (strcmp(Animal, "None")==0) {
  732. #if PC
  733.     topline(" Cell Input Menu ");
  734.     clrscr1(1);
  735.     gotoxy(1, 5);
  736.     cprintf("%sNo animal has been selected yet.", tab);
  737.     gotoxy(1, 6);
  738.     cprintf("%sPlease use the Animal Menu to select an animal.", tab);
  739.     if (HARDCOPY) {
  740.       fprintf(stdprn, "\n\tNo animal has been selected yet.\n");
  741.       fprintf(stdprn, "\tPlease use the Animal Menu to select an animal.\n");
  742.     }
  743.     hitreturn(1);
  744. #else
  745.     printf("\n\tNo animal has been selected yet.\n");
  746.     printf("\tPlease use the Animal Menu to select an animal.\n");
  747. #endif
  748.     if (FILEq && FILECOPY) {
  749.       fprintf(fpout, "\n\tNo animal has been selected yet.\n");
  750.       fprintf(fpout, "\tPlease use the Animal Menu to select an animal.\n");
  751.     }
  752.     return(103);    /* goto animalmenu */
  753.   }
  754.  
  755.   ok = 0;
  756.   cellmenu();
  757. #if PC
  758.   stgdaton = 0;
  759.   seqdaton = 0;
  760. #endif
  761.   while (! ok) {
  762. #if PC
  763.     clrscr1(2);
  764.     cprintf("%sInitial cell name, or menu choice (F for menu):", tab);
  765.     gotoxy(1, 2);
  766.     highvideo();
  767.     cprintf("%s%c%c%c ", tab2, HBAR, HBAR, RTRI);
  768.     normvideo();
  769.     val = getusrstrlist(dummy, &dum4);
  770.     if (HARDCOPY) {
  771.       fprintf(stdprn, "\n\tInitial cell name, or menu choice ");
  772.       fprintf(stdprn, "(F for menu):\n\t\t==> ");
  773.       for ( i=0; i<dum4; i++ )
  774.     fprintf(stdprn, "%s ", dummy[i]);
  775.       fprintf(stdprn, "\n");
  776.     }
  777.     if (val==108) {
  778.       togglepr();
  779.       if (stgdaton) printstgdatHARD();
  780.       if (seqdaton) printseqdatHARD();
  781.     } else {
  782.       if (val) return(val);
  783.     }
  784. #else
  785.     printf("\n\tInitial cell name, or menu choice (F for menu):\n");
  786.     printf("\t\t==> ");
  787.     getusrstrlist(dummy, &dum4);
  788. #endif
  789.     if (FILEq && FILECOPY) {
  790.       fprintf(fpout, "\n\tInitial cell name, or menu choice ");
  791.       fprintf(fpout, "(F for menu):\n\t\t==> ");
  792.       for ( i=0; i<dum4; i++ )
  793.     fprintf(fpout, "%s ", dummy[i]);
  794.       fprintf(fpout, "\n");
  795.     }
  796.  
  797.     stop = 0;
  798.     if (dummy[0][1]=='\0') {
  799.       stop = 1;
  800.       /* user input is prob a char-accel */
  801.       switch (toupper(dummy[0][0])) {
  802.       case 'A':        /* general menu */
  803.     return(101);
  804.       case 'B':        /* goto help menu */
  805.     return(102);
  806.       case 'C':        /* goto animalmenu */
  807.     return(103);
  808.       case 'D':        /* goto cycle length menu */
  809.     return(104);
  810.       case 'E':        /* display menu */
  811.     return(114);
  812.       case 'F':        /* cell input menu */
  813.     cellmenu();
  814. #if PC
  815.     stgdaton = 0;
  816.     seqdaton = 0;
  817. #endif
  818.     break;
  819.       case 'G':        /* days input menu */
  820.     return(106);
  821.       case 'H':
  822.     printstgdat();
  823. #if PC
  824.     stgdaton = 1;
  825.     seqdaton = 0;
  826. #endif
  827.     break;
  828.       case 'I':
  829.     printseqdat();
  830. #if PC
  831.     seqdaton = 1;
  832.     stgdaton = 0;
  833. #endif
  834.     break;
  835.       case 'X':
  836.     printexit(7);
  837.       case '?':
  838.     helpcellip();
  839. #if PC
  840.     stgdaton = 0;
  841.     seqdaton = 0;
  842. #endif
  843.     break;
  844.       default:     /* not a char-accel: parse it */
  845.     stop = 0;
  846.       } /* switch */
  847.     } /* if */
  848.  
  849.     if (! stop) {    /* parse input... */
  850.       ok = dum4;    /* if no trials, then ok=0 too */
  851. #if PC
  852.       any = 0;
  853. #endif
  854.       for ( i=0; i<dum4; i++ ) {
  855.     strupper(dummy[i]);
  856.     if (! parsecellstr(dummy[i], &dum1, &dum2, dum3)) {
  857. #if PC
  858.       if (! any)
  859.         clrscr1(3);
  860.       if ((any+1) >= MSGLNS) {
  861.         hitreturn(3);
  862.         clrscr1(3);
  863.         any = 0;
  864.       }
  865.       gotoxy(1, any+1);
  866.       any++;
  867.       printf("%s%s:  Invalid cell ", tab, ERRSTR);
  868.       printf("syntax <%s>.", dummy[i]);
  869.       if (HARDCOPY) {
  870.         fprintf(stdprn, "\t%s:  Invalid cell ", ERRSTR);
  871.         fprintf(stdprn, "syntax <%s>.\n", dummy[i]);
  872.       }
  873. #else
  874.       printf("\t%s:  Invalid cell ", ERRSTR);
  875.       printf("syntax <%s>.\n", dummy[i]);
  876. #endif
  877.       if (FILEq && FILECOPY) {
  878.         fprintf(fpout, "\t%s:  Invalid cell ", ERRSTR);
  879.         fprintf(fpout, "syntax <%s>.\n", dummy[i]);
  880.       }
  881.       ok = ok && 0;
  882.     } else
  883.       strcpy(cellstr[i], dummy[i]);
  884.       } /* for i */
  885.  
  886.     } /* if ! stop */
  887.  
  888.   } /* while !ok */
  889.   *ptrials = dum4;
  890.   return(0);
  891. } /* getusrcells */
  892.   
  893. /********************************/
  894. /*     function: getusrdays    */
  895. /********************************/
  896. /* gets list of days interactively
  897.    if PC: returns 0 if number ok; 100+k if F-key pressed */
  898. getusrdays (cellstr, daystrs, trials)
  899.   char cellstr[][MAXLEN], daystrs[][MAXLEN];
  900.   int trials;
  901. {
  902.   int i, stop, ok, count, diff;
  903.   char dummy[MAXIP][MAXLEN];
  904. #if PC
  905.   int any, j, val;
  906.   int stgdaton;            /* =1 if stg data on screen    */
  907.   int seqdaton;            /* =1 if seq data on screen    */
  908. #endif
  909.  
  910.   if (strcmp(Animal, "None")==0) {
  911. #if PC
  912.     topline(" Days Input Menu ");
  913.     clrscr1(1);
  914.     gotoxy(1, 5);
  915.     cprintf("%sNo animal has been selected yet.", tab);
  916.     gotoxy(1, 6);
  917.     cprintf("%sPlease use the Animal Menu to select an animal.", tab);
  918.     if (HARDCOPY) {
  919.       fprintf(stdprn, "\n\tNo animal has been selected yet.\n");
  920.       fprintf(stdprn, "\tPlease use the Animal Menu to select an animal.\n");
  921.     }
  922.     hitreturn(1);
  923. #else
  924.     printf("\n\tNo animal has been selected yet.\n");
  925.     printf("\tPlease use the Animal Menu to select an animal.\n");
  926. #endif
  927.     if (FILEq && FILECOPY) {
  928.       fprintf(fpout, "\n\tNo animal has been selected yet.\n");
  929.       fprintf(fpout, "\tPlease use the Animal Menu to select an animal.\n");
  930.     }
  931.     return(103);    /* goto animalmenu */
  932.   } /* if */
  933.  
  934.   if (trials==0) {
  935. #if PC
  936.     clrscr1(1);
  937.     gotoxy(1, 5);
  938.     cprintf("%sNo initial cells have been selected yet.", tab);
  939.     gotoxy(1, 6);
  940.     cprintf("%sPlease use the Cell Input Menu to select initial cells.", tab);
  941.     if (HARDCOPY) {
  942.       fprintf(stdprn, "\n\tNo initial cells have been selected yet.\n");
  943.       fprintf(stdprn, "\tPlease use the Cell Input Menu to select initial cells.\n");
  944.     }
  945.     hitreturn(1);
  946. #else
  947.     printf("\n\tNo initial cells have been selected yet.\n");
  948.     printf("\tPlease use the Cell Input Menu to select initial cells.\n");
  949. #endif
  950.     if (FILEq && FILECOPY) {
  951.       fprintf(fpout, "\n\tNo initial cells have been selected yet.\n");
  952.       fprintf(fpout, "\tPlease use the Cell Input Menu to select initial cells.\n");
  953.     }
  954.     return(105);    /* goto cell input */
  955.   } /* if */
  956.  
  957.   ok = 0;
  958.   printusrcells(cellstr, trials);
  959. #if PC
  960.   stgdaton = 0;
  961.   seqdaton = 0;
  962. #endif
  963.   daysmenu();
  964.   while (! ok) {
  965. #if PC
  966.     clrscr1(2);
  967.     cprintf("%sNumber of days, or menu choice (G for menu):", tab);
  968.     gotoxy(1, 2);
  969.     highvideo();
  970.     cprintf("%s%c%c%c ", tab2, HBAR, HBAR, RTRI);
  971.     normvideo();
  972.     val = getusrstrlist(dummy, &count);
  973.     if (HARDCOPY) {
  974.       fprintf(stdprn, "\n\tNumber of days, or menu choice ");
  975.       fprintf(stdprn, "(G for menu):\n\t\t==> ");
  976.       for ( i=0; i<count; i++ )
  977.     fprintf(stdprn, "%s ", dummy[i]);
  978.       fprintf(stdprn, "\n");
  979.     }
  980.     if (val==108) {
  981.       togglepr();
  982.       if (stgdaton) printstgdatHARD();
  983.       if (seqdaton) printseqdatHARD();
  984.     } else {
  985.       if (val) return(val);
  986.     }
  987. #else
  988.     printf("\n\tNumber of days, or menu choice (G for menu):\n");
  989.     printf("\t\t==> ");
  990.     getusrstrlist(dummy, &count);
  991. #endif
  992.     if (FILEq && FILECOPY) {
  993.       fprintf(fpout, "\n\Number of days, or menu choice ");
  994.       fprintf(fpout, "(G for menu):\n\t\t==> ");
  995.       for ( i=0; i<count; i++ )
  996.     fprintf(fpout, "%s ", dummy[i]);
  997.       fprintf(fpout, "\n");
  998.     }
  999.  
  1000.     /* echo the days ip to file and printer */
  1001.  
  1002.     stop = 0;
  1003.     if (dummy[0][1]=='\0') {
  1004.       /* user input is prob a char-accel */
  1005.       stop = 1;
  1006.       switch (toupper(dummy[0][0])) {
  1007.       case 'A':        /* general menu */
  1008.     return(101);
  1009.       case 'B':        /* help menu */
  1010.     return(102);
  1011.       case 'C':        /* animal menu */
  1012.     return(103);
  1013.       case 'D':        /* cycle length menu */
  1014.     return(104);
  1015.       case 'E':        /* display menu */
  1016.     return(114);
  1017.       case 'F':        /* cell input menu */
  1018.     return(105);
  1019.       case 'G':        /* days input menu */
  1020.     daysmenu();
  1021. #if PC
  1022.     stgdaton = 0;
  1023.     seqdaton = 0;
  1024. #endif
  1025.     break;
  1026.       case 'H':
  1027.     printstgdat();
  1028. #if PC
  1029.     stgdaton = 1;
  1030.     seqdaton = 0;
  1031. #endif
  1032.     break;
  1033.       case 'I':
  1034.     printseqdat();
  1035. #if PC
  1036.     seqdaton = 1;
  1037.     stgdaton = 0;
  1038. #endif
  1039.     break;
  1040.       case 'J':        /* show input cells */
  1041.     printusrcells(cellstr, trials);
  1042.     break;
  1043.       case 'X':
  1044.     printexit(6);
  1045.       case '?':
  1046.     helpdaysip();
  1047. #if PC
  1048.     stgdaton = 0;
  1049.     seqdaton = 0;
  1050. #endif
  1051.     break;
  1052.       default:     /* not a char-accel: parse it */
  1053.     stop = 0;
  1054.     break;
  1055.       } /* switch */
  1056.     } /* if */
  1057.  
  1058.     if (! stop) {
  1059.       diff = trials - count;
  1060. #if PC
  1061.       clrscr1(3);
  1062. #endif
  1063.       if (diff > 0) {
  1064.     ok = 0;
  1065. #if PC
  1066.     cprintf("%s%s:  List of days ", tab, ERRSTR);
  1067.     cprintf("is %d too short.", diff);
  1068.     if (HARDCOPY) {
  1069.       fprintf(stdprn, "\t%s:  List of days ", ERRSTR);
  1070.       fprintf(stdprn, "is %d too short.\n", diff);
  1071.     }
  1072. #else
  1073.     printf("\t%s:  List of days ", ERRSTR);
  1074.     printf("is %d too short.\n", diff);
  1075. #endif
  1076.     if (FILEq && FILECOPY) {
  1077.       fprintf(fpout, "\t%s:  List of days ", ERRSTR);
  1078.       fprintf(fpout, "is %d too short.\n", diff);
  1079.     }
  1080.       } /* if diff */
  1081.       if (diff < 0) {
  1082. #if PC
  1083.     cprintf("%s%s:  List of days ", tab, ERRSTR);
  1084.     cprintf("is %d too long.", abs(diff));
  1085.     if (HARDCOPY) {
  1086.       fprintf(stdprn, "\t%s:  List of days ", ERRSTR);
  1087.       fprintf(stdprn, "is %d too long.\n", abs(diff));
  1088.     }
  1089. #else
  1090.     printf("\t%s:  List of days ", ERRSTR);
  1091.     printf("is %d too long.\n", abs(diff));
  1092. #endif
  1093.     if (FILEq && FILECOPY) {
  1094.       fprintf(fpout, "\t%s:  List of days ", ERRSTR);
  1095.       fprintf(fpout, "is %d too long.\n", abs(diff));
  1096.     }
  1097.       } /* if diff */
  1098.       if (diff==0) ok = 1;
  1099. #if PC
  1100.       j = 0;
  1101.       any = 0;
  1102. #endif
  1103.       for ( i=0; i<count; i++ ) {
  1104.     if (! numstrq(dummy[i])) {
  1105. #if PC
  1106.       if (! any) {
  1107.         if (diff)    /* line 1 has "list of days too..." */
  1108.           j = 2;
  1109.         else
  1110.           j = 1;
  1111.       }
  1112.       any++;
  1113.       if (j >= MSGLNS) {
  1114.         hitreturn(3);
  1115.         clrscr1(3);
  1116.         /* but now after clrscr, go to line 1 */
  1117.         j = 1;
  1118.       }
  1119.       gotoxy(1, j);
  1120.       clreol1(3);
  1121.       gotoxy(1, j++);
  1122.       cprintf("%s%s:  Invalid number ", tab, ERRSTR);
  1123.       cprintf("syntax <%s>.", dummy[i]);
  1124.       if (HARDCOPY) {
  1125.         fprintf(stdprn, "\t%s:  Invalid numb", ERRSTR);
  1126.         fprintf(stdprn, "er syntax <%s>.\n", dummy[i]);
  1127.       }
  1128. #else
  1129.       printf("\t%s:  Invalid numb", ERRSTR);
  1130.       printf("er syntax <%s>.\n", dummy[i]);
  1131. #endif
  1132.       if (FILEq && FILECOPY) {
  1133.         fprintf(fpout, "\t%s:  Invalid numb", ERRSTR);
  1134.         fprintf(fpout, "er syntax <%s>.\n", dummy[i]);
  1135.       }
  1136.       ok = ok && 0;
  1137.     } else
  1138.       strcpy(daystrs[i], dummy[i]);
  1139.       } /* for */
  1140.       if (! ok) count = 0;
  1141.     } /* if ! stop */
  1142.   } /* while !ok */
  1143.   return(0);
  1144. } /* getusrdays */
  1145.  
  1146. /********************************/
  1147. /*     function: getfileip    */
  1148. /********************************/
  1149. /* gets initial cells and days from a file, batch-mode style
  1150.    returns 1 while not EOF
  1151.    returns 0 if EOF */
  1152. getfileip(cellstr, daystr, fpin)
  1153.   char *cellstr, *daystr;
  1154.   FILE *fpin;
  1155. {
  1156.   if (fscanf(fpin, "%s %s", cellstr, daystr) != EOF) {
  1157.     strupper(cellstr);
  1158.     return(1);
  1159.   } else
  1160.     return(0);
  1161. } /* getfileip */
  1162.  
  1163. /********************************/
  1164. /*     function: parsecellstr    */
  1165. /********************************/
  1166. /* parses the user-input cellname:
  1167.    1/ checks validity (match any from the cell sequence file?)
  1168.    2/ if so, finds its cell sequence # and stage #, returns 1
  1169.    3/ if not, returns 0 */
  1170. parsecellstr (str, pseq, pst, opstr)
  1171.   char *str;
  1172.   int *pseq, *pst;
  1173.   char *opstr;
  1174. {
  1175.   int i, found;
  1176.  
  1177.   /* look for the cell string in the list of known cell names*/
  1178.   i = 0;
  1179.   found = 0;
  1180.   while ((! found) && (i <= MaxCellIndex)) {
  1181.     if (strcmp(str, CellNames[i++])==0) {
  1182.       found = 1;
  1183.       *pseq = --i;             /* cell sequence # */
  1184.       *pst = getcellstg(CellNames[i]);    /* cell stage # */
  1185.       if (*pst==-1)            /* bad cell name format */
  1186.     found = 0;            /* shouldn't happen!    */
  1187.     }
  1188.   }
  1189.   
  1190.   if ((! found) && (i > MaxCellIndex)) {
  1191.     sprintf(opstr, "       %s:  Unrecognized input cell <%s>",
  1192.         ERRSTR, str);
  1193.     *pseq = INVALID;
  1194.     *pst = INVALID;
  1195.     return(0);    /* not ok */
  1196.   } else {
  1197.     sprintf(opstr, " ");
  1198.     return(1);    /* ok */
  1199.   }
  1200. } /* parsecellstr */
  1201.  
  1202. /********************************/
  1203. /*     function: getcellstg    */
  1204. /********************************/
  1205. /* parses a cell's namestring to extract its stage number.
  1206.    this assumes all cells are named in the syntax:
  1207.    name-nn    where nn is the stage number
  1208.    if bad number format discovered, return -1
  1209.    else return stage number
  1210.  
  1211.    the special case of epididymis has to be handled separately */
  1212. getcellstg (str)
  1213.   char *str;
  1214. {
  1215.   int len, i, j;
  1216.   char temp[10];        /* holds digits of the stage # */
  1217. #if PC
  1218.   static int k=1;
  1219. #endif
  1220.  
  1221.   if (strcmp(str, CellNames[MaxCellIndex+1])==0)
  1222.     return(MaxCellIndex+1);    /* in epididymis */
  1223.  
  1224.   len = strlen(str);
  1225.   i = 0;
  1226.   while ((i <= len) && (str[i++] != '-'));
  1227.   if (str[--i] != '-') {
  1228. #if PC
  1229.     if (k >= MSGLNS) {
  1230.       hitreturn(3);
  1231.       clrscr1(3);
  1232.       k = 1;
  1233.     }
  1234.     msgwin();
  1235.     gotoxy(1, k);
  1236.     clreol1();
  1237.     gotoxy(1, k++);
  1238.     cprintf("%s%s:  Bad cell name <%s>: `-' expected", tab, ERRSTR, str);
  1239.     if (HARDCOPY) {
  1240.       fprintf(stdprn, "\t%s:  Bad cell name <%s>: ", ERRSTR, str);
  1241.       fprintf(stdprn, "`-' expected\n");
  1242.     }
  1243. #else
  1244.     printf("\t%s:  Bad cell name <%s>: `-' expected\n", ERRSTR, str);
  1245. #endif
  1246.     if (FILEq && FILECOPY) {
  1247.       fprintf(fpout, "\t%s:  Bad cell name <%s>: ", ERRSTR, str);
  1248.       fprintf(fpout, "`-' expected\n");
  1249.     }
  1250.     return(-1);
  1251.   } else {
  1252.     j = 0;
  1253.     while (i <= len)
  1254.       temp[j++] = str[++i];
  1255.     return(atoi(temp));
  1256.   }
  1257. } /* getcellstg */
  1258.