home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #if PC
- #include <bios.h>
- #endif
- #include "main.h"
- #include "header.h"
- #include "pcwins.h"
-
- /* files included:
- getipfile
- getstgdat
- getCyclelen
- getseqdat
- getusrstr
- getusrstrlist
- getusrcells
- getusrdays
- getfileip
- parsecellstr
- getcellstg
- */
-
- /********************************/
- /* function: getipfile */
- /********************************/
- /* takes user input as filename and if nonzero length, tries to
- open a file of that name. if fopen fails, asks the user to
- specify another file to try, or to specify no file desired.
- returns 0 if valid file
- !0 if no file was opened */
- getipfile (ipfil, pfp, iptype, mandatoryq, ftype)
- char *ipfil; /* the name of the file finally opened */
- FILE **pfp;
- char iptype; /* filename supplied (F) or entered */
- /* interactively (I) */
- int mandatoryq; /* if=1, then file must be specified */
- char ftype; /* C=cycle stage dat
- I=input file (batch mode)
- S=cell sequence dat */
- {
- int i, go, help, len, quit;
- char fname[MAXLEN], c;
- #if PC
- int val;
- #endif
-
- if (iptype == 'F')
- /* filename supplied in var ipfile */
- strcpy(fname, ipfil);
- else {
- /* get a filename interactively;
- user-friendly asking-message printed by calling function */
- #if PC
- val = getusrstr(fname);
- if (HARDCOPY)
- fprintf(stdprn, "%s\n", fname);
- if (val) return(val);
- #else
- getusrstr(fname);
- #endif
- if (FILEq && FILECOPY)
- fprintf(fpout, "%s\n", fname);
- }
-
- /* strip input string of leading/trailing whitespace */
- stripwhitesp(fname);
-
- go = 1;
- while (go && ((*pfp = fopen(fname, "r"))==NULL)) {
- /* maybe it wasn't a filename i/p but a char-accel */
- if ((strcmp(fname, "q")==0) || (strcmp(fname, "Q")==0))
- go = 0;
- else {
- if (fname[0]=='?') {
- help = 1;
- if ((ftype=='C') || (ftype=='S'))
- helpipfil(ftype);
- else
- helpipfil1(ipfil);
- } else
- help = 0;
-
- #if PC
- msgwin();
- gotoxy(1, 1);
- clreol1(3);
- gotoxy(1, 1);
- if (! help) {
- printf("%s%s: File ", tab, ERRSTR);
- printf("<%s> does not exist.", fname);
- gotoxy(1, 2);
- }
- cprintf("%sPlease enter a new filename", tab);
- if (HARDCOPY) {
- if (! help) {
- fprintf(stdprn, "\n\t%s: File ", ERRSTR);
- fprintf(stdprn, "<%s> does not exist.\n", fname);
- }
- fprintf(stdprn, "\tPlease enter a new filename");
- }
- #else
- if (! help) {
- printf("\n\t%s: File ", ERRSTR);
- printf("<%s> does not exist.\n", fname);
- }
- printf("\tPlease enter a new filename");
- #endif
- if (FILEq && FILECOPY) {
- if (! help) {
- fprintf(fpout, "\n\t%s: File ", ERRSTR);
- fprintf(fpout, "<%s> does not exist.\n", fname);
- }
- fprintf(fpout, "\tPlease enter a new filename");
- }
-
- if (! mandatoryq) {
- /* not mandatory that a file be entered: `no file' option ok */
- #if PC
- cprintf(", or");
- gotoxy(1, 3);
- cprintf("%stype <return> if no file is desired.", tab);
- if (HARDCOPY) {
- fprintf(stdprn, ", or\n\ttype <return> ");
- fprintf(stdprn, "if no file is desired.\n");
- }
- #else
- printf(", or\n\ttype <return> ");
- printf("if no file is desired.\n");
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, ", or\n\ttype <return> ");
- fprintf(fpout, "if no file is desired.\n");
- }
- } else { /* mandatoryq */
- /* must have a filename specified */
- #if PC
- cprintf(".");
- if (HARDCOPY)
- fprintf(stdprn, ":\n");
- #else
- printf(":\n");
- #endif
- if (FILEq && FILECOPY)
- fprintf(fpout, ":\n");
- } /* if mandatoryq */
-
- #if PC
- clrscr1(2);
- cprintf("%sNew filename:", tab);
- gotoxy(1, 2);
- highvideo();
- cprintf("%s%c%c%c ", tab2, HBAR, HBAR, RTRI);
- normvideo();
- if (HARDCOPY)
- fprintf(stdprn, "\t\t==> ");
- #else
- printf("\t\t==> ");
- #endif
- if (FILEq && FILECOPY)
- fprintf(fpout, "\t\t==> ");
-
- /* get new filename */
- #if PC
- val = getusrstr(fname);
- if (HARDCOPY)
- fprintf(stdprn, "%s\n", fname);
- if (val) return(val);
- #else
- getusrstr(fname);
- if (FILEq && FILECOPY)
- fprintf(fpout, "%s\n", fname);
- #endif
-
- len = strlen(fname);
- if (!mandatoryq && !len)
- go = 0;
- } /* if ! Q */
- } /* while */
-
- if (*pfp != NULL) { /* good file opened */
- #if PC
- /* not enough room in msgwin() with "file not found.." error msgs
- to print out this message on the pc terminal. oh well */
- if (HARDCOPY)
- fprintf(stdprn, "\n\tFile <%s> opened successfully.\n", fname);
- #else
- printf("\n\tFile <%s> opened successfully.\n", fname);
- #endif
- if (FILEq && FILECOPY)
- fprintf(fpout, "\n\tFile <%s> opened successfully.\n", fname);
- strcpy(ipfil, fname);
- return(0);
- } else {
- /* only other way out of while loop was if go=0 */
- switch (ftype) {
-
- case 'I': /* no batch file necessary */
- #if PC
- clrscr1(3);
- cprintf("%sNo batch file opened; input must be entered interactively.", tab);
- if (HARDCOPY)
- fprintf(stdprn, "\n\tNo batch file opened; input must be entered interactively.\n");
- #else
- printf("\n\tNo batch file opened; input must be entered interactively.\n");
- #endif
- if (FILEq && FILECOPY)
- fprintf(fpout, "\n\tNo batch file opened; input must be entered interactively.\n");
- break;
-
- case 'C': /* stage file mandatory but user defers */
- #if PC
- clrscr1(3);
- cprintf("%sNo animal stage length data file opened.", tab);
- if (HARDCOPY)
- fprintf(stdprn, "\tNo animal stage length data file opened.\n");
- #else
- printf("\tNo animal stage length data file opened.\n");
- #endif
- if (FILEq && FILECOPY)
- fprintf(fpout, "\tNo animal stage length data file opened.\n");
- break;
-
- case 'S': /* sequence file mandatory but user defers */
- #if PC
- cprintf("%sNo animal cell sequence data file opened.", tab);
- if (HARDCOPY)
- fprintf(stdprn, "\tNo animal cell sequence data file opened.\n");
- #else
- printf("\tNo animal cell sequence data file opened.\n");
- #endif
- if (FILEq && FILECOPY)
- fprintf(fpout, "\tNo animal cell sequence data file opened.\n");
- break;
- } /* switch */
- return(1);
- } /* *pfp==NULL */
- } /* getipfile */
-
- /********************************/
- /* function: getstgdat */
- /********************************/
- /* reads from the file xxx.stg to get the cycle stage data */
- getstgdat (stgfil, fpstg)
- char *stgfil;
- FILE *fpstg;
- {
- int i, j; /* char array indices */
- int diff; /* tmp var */
- char c; /* temp char var */
-
- i = 0;
- j = 0;
- numrefs = 0;
- while ((c=getc(fpstg)) != '*') {
- if (j >= (MAXLEN-1)) {
- #if PC
- clrscr1(3);
- cprintf("%s%s: Reference line too long in file ", tab, ERRSTR);
- cprintf("<%s>: truncated", stgfil);
- if (HARDCOPY) {
- fprintf(stdprn, "\n\t%s: Reference line too long ", ERRSTR);
- fprintf(stdprn, "in file <%s>:", stgfil);
- fprintf(stdprn, "\n\t%s Line truncated.\n", NULLERRSTR);
- }
- #else
- printf("\t%s: Reference line too long in file ", ERRSTR);
- printf("<%s>:\n", stgfil);
- printf("\t%s Line truncated.\n\n", NULLERRSTR);
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\n\t%s: Reference line too long ", ERRSTR);
- fprintf(fpout, "in file <%s>:", stgfil);
- fprintf(fpout, "\n\t%s Line truncated.\n", NULLERRSTR);
- }
- while ((c=getc(fpstg)) != '\n'); /* get to end of line */
- } /* if j */
-
- if (c == '\n') {
- ref[i][j] = '\0'; /* finish this ref line */
- i++; /* start new ref line */
- j = 0; /* reset j for new line */
- if (i <= MAXLINES)
- numrefs++; /* incr # ref lines */
- } else {
- ref[i][j++] = c; /* build ref info line */
- }
- } /* while */
-
- if ((diff=(i - MAXLINES)) > 0) {
- #if PC
- msgwin();
- gotoxy(1, 2);
- cprintf("%s%s: Too many reference ", tab, ERRSTR);
- cprintf("lines in file <%s>:", stgfil);
- gotoxy(1, 3);
- cprintf("%s%s %d line", tab, NULLERRSTR, diff);
- if (diff > 1) cprintf("s");
- cprintf(" omitted.");
- if (HARDCOPY) {
- fprintf(stdprn, "\n\t%s: Too many reference ", ERRSTR);
- fprintf(stdprn, "lines in file <%s>:", stgfil);
- fprintf(stdprn, "\n\t%s %d line", NULLERRSTR, diff);
- if (diff > 1) fprintf(stdprn, "s");
- fprintf(stdprn, " omitted.\n");
- }
- #else
- printf("\t%s: Too many reference ", ERRSTR);
- printf("lines in file <%s>:", stgfil);
- printf("\n\t%s %d line", NULLERRSTR, diff);
- if (diff > 1) printf("s");
- printf(" omitted.\n\n");
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\n\t%s: Too many reference ", ERRSTR);
- fprintf(fpout, "lines in file <%s>:", stgfil);
- fprintf(fpout, "\n\t%s %d line", NULLERRSTR, diff);
- if (diff > 1) fprintf(fpout, "s");
- fprintf(fpout, " omitted.\n");
- }
- } /* if diff */
-
- /* read cycle time - this is in days */
- fscanf(fpstg, "%lf", &CycleTime);
- #if PC
- sep1win(); /* turn on Cycle Length annunciator */
- #endif
- OldCycleTime = CycleTime; /* initialize OldCycleTime */
- fscanf(fpstg, "%d", &NumStages);
- MaxStage = NumStages - 1;
-
- /* allocate NumStages spaces for stage lengths */
- stage = (double *) malloc((unsigned) (NumStages * sizeof(double)));
- /* read stage lengths (these are in % of CycleTime) and convert to days */
- for ( i=0; i<NumStages; i++ ) {
- fscanf(fpstg, "%lf", &stage[i]);
- stage[i] = stage[i] * CycleTime / 100;
- }
-
- /* read epididymis transit times (this is days) */
- fscanf(fpstg, "%lf", &EpiTime);
- } /* getstgdat */
-
- /********************************/
- /* function: getCyclelen */
- /********************************/
- /* asks user to input new CycleTime, or use default */
- getCyclelen ()
- {
- char dummy[MAXLEN]; /* user input string */
- int i, val, ok;
-
- ok = 0;
- while (! ok) {
- #if PC
- clrscr1(2);
- cprintf("%sNew Cycle Length (in days):", tab);
- gotoxy(1, 2);
- highvideo();
- cprintf("%s%c%c%c ", tab2, HBAR, HBAR, RTRI);
- normvideo();
- val = getusrstr(dummy);
- if (HARDCOPY) {
- fprintf(stdprn, "\n\tNew Cycle Length (in days):\n");
- fprintf(stdprn, "\t\t==> %s\n\n", dummy);
- }
- if (val) return(val); /* keyboard accel pressed */
- #else
- printf("\n\tNew Cycle Length (in days):\n");
- getusrstr(dummy);
- printf("\t\t==> %s\n\n", dummy);
- #endif
-
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\n\tNew Cycle Length (in days):\n");
- fprintf(fpout, "\t\t==> %s\n\n", dummy);
- }
- switch (dummy[0]) {
- case '?':
- helpcyclelenip();
- break;
- default: /* it's a new Cycle length, if it's a valid # */
- if (! numstrq(dummy)) {
- #if PC
- clrscr1(3);
- cprintf("%s%s: Invalid number syntax <%s>", tab, ERRSTR, dummy);
- if (HARDCOPY) {
- fprintf(stdprn, "\t%s: Invalid number syntax <%s>.\n",
- ERRSTR, dummy);
- }
- #else
- printf("\t%s: Invalid number syntax <%s>.\n", ERRSTR, dummy);
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\t%s: Invalid number syntax <%s>.\n",
- ERRSTR, dummy);
- }
- } else { /* it's a valid number input */
- OldCycleTime = CycleTime;
- CycleTime = atof(dummy);
- ok = 1;
- NewCycleTime = 1; /* global var */
- /* set Cycle length annunciator */
- #if PC
- sep1win();
- #endif
- /* transform old stage[i] vals (days) to new ones */
- for ( i=0; i<NumStages; i++ )
- stage[i] = stage[i] * CycleTime / OldCycleTime;
- } /* if numstr) */
- } /* dummy != ? */
- } /* while ! ok */
- return(0);
- } /* getCyclelen */
-
- /********************************/
- /* function: getseqdat */
- /********************************/
- /* reads from the file xxx.seq to get the cell sequence data */
- getseqdat (seqfil, fpseq)
- char *seqfil;
- FILE *fpseq;
- {
- int i; /* char array indices */
- int ok; /* boolean */
- unsigned len; /* actual length of string t */
- char c; /* temp char var */
- char temp[MAXLEN]; /* temp str: holds CellNames */
-
- /* the cell sequence filename is in var seqfil, if needed */
- /* determine number of cells in cell sequence */
- NumCellSeq = 0;
- while (fscanf(fpseq, "%*s") != EOF)
- NumCellSeq++;
- /* subtract epididymis time: its not part of the cycle */
- NumCellSeq -= 1;
- rewind(fpseq);
- MaxCellIndex = NumCellSeq - 1;
-
- /* allocate NumCellSeq+1 spaces for cell names
- "+1" since we add one for epididymis */
- CellNames =
- (char **) malloc((unsigned) ((NumCellSeq+1) * sizeof(char *)));
- for ( i=0; i<NumCellSeq; i++ ) {
- fscanf(fpseq, "%s", temp);
- len = strlen(temp);
- CellNames[i] =
- (char *) malloc((unsigned) ((len+1) * sizeof(char)));
- strupper(temp);
- strcpy(CellNames[i], temp);
- }
- /* get "epididymis" name string */
- fscanf(fpseq, "%s", temp);
- len = strlen(temp);
- CellNames[MaxCellIndex+1] =
- (char *) malloc((unsigned) ((len+1) * sizeof(char)));
- strcpy(CellNames[MaxCellIndex+1], temp);
- } /* getseqdat */
-
- #if PC
- /********************************/
- /* function: getusrstr */
- /********************************/
- /* gets one user input string: PC version
- checks to see if an F-key was typed
-
- bioskey() described in turbo c v2.0 ref guide
- bit manipulations from _the peter norton programmer's
- guide to the ibm pc_, pp127-135, microsoft press, 1985
-
- return 0 if string input
- return 100+k if F-k pressed */
- getusrstr (input)
- char *input; /* char str input if no F key */
- {
- int key; /* 32-bit val of key pressed */
- int keylo; /* key bits 0-7 */
- int keyhi; /* key bits 8-15 */
- int i, go, x, y;
- char c;
-
- i = 0;
- go = 1;
- y = wherey();
- while (go) {
- while (bioskey(1)==0); /* sit & spin */
- x = wherex();
- key = bioskey(0);
- keylo = key & 0x000000FF;
- keyhi = (key & 0x0000FF00) >> 8; /* right shift 8 bits */
- switch (keylo) {
- case 0: /* Fkey? */
- switch (keyhi) {
- case 59: /* F1 */
- return(101);
- case 60: /* F2 */
- return(102);
- case 61: /* F3 */
- return(103);
- case 62: /* F4 */
- return(104);
- case 63: /* F5 */
- return(105);
- case 64: /* F6 */
- return(106);
- case 65: /* F7 */
- return(107);
- case 66: /* F8 */
- return(108);
- case 67: /* F9 */
- return(109);
- case 68: /* F10 */
- return(110);
- default: /* undefined special key */
- input[0] = '\0';
- return(200);
- } /* switch */
- break;
- case 8: /* backspace */
- if (i > 0) {
- i--;
- gotoxy(x-1, y);
- clreol1(2);
- gotoxy(x-1, y);
- }
- break;
- case 13: /* return */
- input[i] = '\0';
- return(0); /* success: got string */
- case 32: /* kill spaces: single string input */
- gotoxy(x, y);
- printf("%c", keylo);
- break;
- default: /* ASCII char */
- gotoxy(x, y);
- printf("%c", keylo);
- input[i++] = keylo;
- } /* switch keylo */
- } /* while */
- } /* getusrstr */
-
- #else
-
- /********************************/
- /* function: getusrstr */
- /********************************/
- /* gets one user input string */
- getusrstr (input)
- char *input;
- {
- int i;
- char c;
-
- i = 0;
- while ((c=getc(stdin)) != '\n')
- if (c != ' ')
- input[i++] = c;
- input[i] = '\0';
- } /* getusrstr */
-
- #endif
-
- #if PC
- /********************************/
- /* function: getusrstrlist */
- /********************************/
- /* gets a list user-input strings: PC version
-
- return 0 if string input
- return 100+k if F-k pressed */
- getusrstrlist (strings, pnum)
- char strings[][MAXLEN]; /* list of strings if no F key */
- int *pnum; /* num of strings input */
- {
- int key; /* 32-bit val of key pressed */
- int keylo; /* key bits 0-7 */
- int keyhi; /* key bits 8-15 */
- int i, j, k, any, go, x, y, last;
- char c;
- char input[2*MAXLEN]; /* for reading i/p linearly */
-
- i = 0;
- *pnum = 0;
- y = wherey();
- go = 1;
- while (go) {
- while (bioskey(1)==0); /* sit & spin */
- x = wherex();
- key = bioskey(0);
- keylo = key & 0x000000FF;
- keyhi = (key & 0x0000FF00) >> 8; /* right shift 8 bits */
- switch (keylo) {
- case 0: /* Fkey? */
- switch (keyhi) {
- case 59: /* F1 */
- return(101);
- case 60: /* F2 */
- return(102);
- case 61: /* F3 */
- return(103);
- case 62: /* F4 */
- return(104);
- case 63: /* F5 */
- return(105);
- case 64: /* F6 */
- return(106);
- case 65: /* F7 */
- return(107);
- case 66: /* F8 */
- return(108);
- case 67: /* F9 */
- return(109);
- case 68: /* F10 */
- return(110);
- default: /* undefined special key */
- strings[0][0] = '\0';
- return(200);
- } /* switch keyhi */
- break;
- case 8: /* backspace */
- if (i > 0) {
- i--;
- gotoxy(x-1, y);
- clreol1(2);
- gotoxy(x-1, y);
- }
- break;
- case 13: /* return */
- input[i] = '\0';
- last = i;
- go = 0;
- default: /* ASCII char */
- gotoxy(x, y);
- printf("%c", keylo);
- /* first build flat array of input, so can ^H over it */
- input[i++] = keylo;
- } /* switch keylo */
- } /* while go */
-
- /* now build array of strings from input */
- i = 0;
- j = 0;
- any = 0;
- for ( k=0; k<=last; k++ ) {
- if (whitespq(input[k])) { /* whitespace=space/tab/CR */
- if (any && j) {
- strings[i][j] = '\0'; /* end this cellname str */
- (*pnum)++;
- i++; /* start next cellname str */
- j = 0;
- }
- } else { /* ! whitespace */
- any = 1;
- strings[i][j++] = input[k]; /* build new cellname */
- }
- } /* for i */
- return(0);
- } /* getusrstrlist */
-
- #else
-
- /********************************/
- /* function: getusrstrlist */
- /********************************/
- /* gets a list user-input strings */
- getusrstrlist (strings, pnum)
- char strings[][MAXLEN];
- int *pnum;
- {
- int i, j, any, go;
- char c;
-
- i = 0;
- j = 0;
- any = 0;
- *pnum = 0;
- go = 1;
- while (go && (c=getc(stdin)) != '\n') {
- /* build array of cellnames */
- if (whitespq(c)) { /* whitespace = space or tab */
- if (any) {
- strings[i][j] = '\0'; /* end this cellname str */
- (*pnum)++; /* incr # trials */
- i++; /* start next cellname str */
- }
- j = 0;
- /* skip whitespace */
- while (whitespq(c=getc(stdin)));
-
- if (c != '\n') { /* if more besides whitesp... */
- any = 1;
- strings[i][j++] = c; /* build new cellname str */
- } else { /* last chars were just whitesp */
- go = 0;
- (*pnum)--;
- }
- } else { /* ! whitespq */
- any = 1;
- strings[i][j++] = c; /* build this cellname str */
- } /* if */
- } /* while */
-
- (*pnum)++;
- strings[i][j] = '\0'; /* end the last cellname str */
- } /* getusrstrlist */
-
- #endif
-
- /********************************/
- /* function: getusrcells */
- /********************************/
- /* gets list of initial cell names interactively
-
- if PC: returns 0 if number ok
- 100+k if special key pressed (e.g., F-key) */
- getusrcells (cellstr, ptrials)
- char cellstr[][MAXLEN];
- int *ptrials;
- {
- int i, stop, ok;
- int stgdaton; /* =1 if stg dat on screen */
- int seqdaton; /* =1 if seq dat on screen */
- int dum1, dum2, dum4; /* dummy vars for parsecellstr */
- char dum3[MAXLEN]; /* dummy str for parsecellstr */
- /* dummy string so cellstr isn't wiped out if user wants
- to use same cells over again */
- char dummy[MAXIP][MAXLEN];
- #if PC
- int any, j, val;
- #endif
-
- if (strcmp(Animal, "None")==0) {
- #if PC
- topline(" Cell Input Menu ");
- clrscr1(1);
- gotoxy(1, 5);
- cprintf("%sNo animal has been selected yet.", tab);
- gotoxy(1, 6);
- cprintf("%sPlease use the Animal Menu to select an animal.", tab);
- if (HARDCOPY) {
- fprintf(stdprn, "\n\tNo animal has been selected yet.\n");
- fprintf(stdprn, "\tPlease use the Animal Menu to select an animal.\n");
- }
- hitreturn(1);
- #else
- printf("\n\tNo animal has been selected yet.\n");
- printf("\tPlease use the Animal Menu to select an animal.\n");
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\n\tNo animal has been selected yet.\n");
- fprintf(fpout, "\tPlease use the Animal Menu to select an animal.\n");
- }
- return(103); /* goto animalmenu */
- }
-
- ok = 0;
- cellmenu();
- #if PC
- stgdaton = 0;
- seqdaton = 0;
- #endif
- while (! ok) {
- #if PC
- clrscr1(2);
- cprintf("%sInitial cell name, or menu choice (F for menu):", tab);
- gotoxy(1, 2);
- highvideo();
- cprintf("%s%c%c%c ", tab2, HBAR, HBAR, RTRI);
- normvideo();
- val = getusrstrlist(dummy, &dum4);
- if (HARDCOPY) {
- fprintf(stdprn, "\n\tInitial cell name, or menu choice ");
- fprintf(stdprn, "(F for menu):\n\t\t==> ");
- for ( i=0; i<dum4; i++ )
- fprintf(stdprn, "%s ", dummy[i]);
- fprintf(stdprn, "\n");
- }
- if (val==108) {
- togglepr();
- if (stgdaton) printstgdatHARD();
- if (seqdaton) printseqdatHARD();
- } else {
- if (val) return(val);
- }
- #else
- printf("\n\tInitial cell name, or menu choice (F for menu):\n");
- printf("\t\t==> ");
- getusrstrlist(dummy, &dum4);
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\n\tInitial cell name, or menu choice ");
- fprintf(fpout, "(F for menu):\n\t\t==> ");
- for ( i=0; i<dum4; i++ )
- fprintf(fpout, "%s ", dummy[i]);
- fprintf(fpout, "\n");
- }
-
- stop = 0;
- if (dummy[0][1]=='\0') {
- stop = 1;
- /* user input is prob a char-accel */
- switch (toupper(dummy[0][0])) {
- case 'A': /* general menu */
- return(101);
- case 'B': /* goto help menu */
- return(102);
- case 'C': /* goto animalmenu */
- return(103);
- case 'D': /* goto cycle length menu */
- return(104);
- case 'E': /* display menu */
- return(114);
- case 'F': /* cell input menu */
- cellmenu();
- #if PC
- stgdaton = 0;
- seqdaton = 0;
- #endif
- break;
- case 'G': /* days input menu */
- return(106);
- case 'H':
- printstgdat();
- #if PC
- stgdaton = 1;
- seqdaton = 0;
- #endif
- break;
- case 'I':
- printseqdat();
- #if PC
- seqdaton = 1;
- stgdaton = 0;
- #endif
- break;
- case 'X':
- printexit(7);
- case '?':
- helpcellip();
- #if PC
- stgdaton = 0;
- seqdaton = 0;
- #endif
- break;
- default: /* not a char-accel: parse it */
- stop = 0;
- } /* switch */
- } /* if */
-
- if (! stop) { /* parse input... */
- ok = dum4; /* if no trials, then ok=0 too */
- #if PC
- any = 0;
- #endif
- for ( i=0; i<dum4; i++ ) {
- strupper(dummy[i]);
- if (! parsecellstr(dummy[i], &dum1, &dum2, dum3)) {
- #if PC
- if (! any)
- clrscr1(3);
- if ((any+1) >= MSGLNS) {
- hitreturn(3);
- clrscr1(3);
- any = 0;
- }
- gotoxy(1, any+1);
- any++;
- printf("%s%s: Invalid cell ", tab, ERRSTR);
- printf("syntax <%s>.", dummy[i]);
- if (HARDCOPY) {
- fprintf(stdprn, "\t%s: Invalid cell ", ERRSTR);
- fprintf(stdprn, "syntax <%s>.\n", dummy[i]);
- }
- #else
- printf("\t%s: Invalid cell ", ERRSTR);
- printf("syntax <%s>.\n", dummy[i]);
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\t%s: Invalid cell ", ERRSTR);
- fprintf(fpout, "syntax <%s>.\n", dummy[i]);
- }
- ok = ok && 0;
- } else
- strcpy(cellstr[i], dummy[i]);
- } /* for i */
-
- } /* if ! stop */
-
- } /* while !ok */
- *ptrials = dum4;
- return(0);
- } /* getusrcells */
-
- /********************************/
- /* function: getusrdays */
- /********************************/
- /* gets list of days interactively
- if PC: returns 0 if number ok; 100+k if F-key pressed */
- getusrdays (cellstr, daystrs, trials)
- char cellstr[][MAXLEN], daystrs[][MAXLEN];
- int trials;
- {
- int i, stop, ok, count, diff;
- char dummy[MAXIP][MAXLEN];
- #if PC
- int any, j, val;
- int stgdaton; /* =1 if stg data on screen */
- int seqdaton; /* =1 if seq data on screen */
- #endif
-
- if (strcmp(Animal, "None")==0) {
- #if PC
- topline(" Days Input Menu ");
- clrscr1(1);
- gotoxy(1, 5);
- cprintf("%sNo animal has been selected yet.", tab);
- gotoxy(1, 6);
- cprintf("%sPlease use the Animal Menu to select an animal.", tab);
- if (HARDCOPY) {
- fprintf(stdprn, "\n\tNo animal has been selected yet.\n");
- fprintf(stdprn, "\tPlease use the Animal Menu to select an animal.\n");
- }
- hitreturn(1);
- #else
- printf("\n\tNo animal has been selected yet.\n");
- printf("\tPlease use the Animal Menu to select an animal.\n");
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\n\tNo animal has been selected yet.\n");
- fprintf(fpout, "\tPlease use the Animal Menu to select an animal.\n");
- }
- return(103); /* goto animalmenu */
- } /* if */
-
- if (trials==0) {
- #if PC
- clrscr1(1);
- gotoxy(1, 5);
- cprintf("%sNo initial cells have been selected yet.", tab);
- gotoxy(1, 6);
- cprintf("%sPlease use the Cell Input Menu to select initial cells.", tab);
- if (HARDCOPY) {
- fprintf(stdprn, "\n\tNo initial cells have been selected yet.\n");
- fprintf(stdprn, "\tPlease use the Cell Input Menu to select initial cells.\n");
- }
- hitreturn(1);
- #else
- printf("\n\tNo initial cells have been selected yet.\n");
- printf("\tPlease use the Cell Input Menu to select initial cells.\n");
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\n\tNo initial cells have been selected yet.\n");
- fprintf(fpout, "\tPlease use the Cell Input Menu to select initial cells.\n");
- }
- return(105); /* goto cell input */
- } /* if */
-
- ok = 0;
- printusrcells(cellstr, trials);
- #if PC
- stgdaton = 0;
- seqdaton = 0;
- #endif
- daysmenu();
- while (! ok) {
- #if PC
- clrscr1(2);
- cprintf("%sNumber of days, or menu choice (G for menu):", tab);
- gotoxy(1, 2);
- highvideo();
- cprintf("%s%c%c%c ", tab2, HBAR, HBAR, RTRI);
- normvideo();
- val = getusrstrlist(dummy, &count);
- if (HARDCOPY) {
- fprintf(stdprn, "\n\tNumber of days, or menu choice ");
- fprintf(stdprn, "(G for menu):\n\t\t==> ");
- for ( i=0; i<count; i++ )
- fprintf(stdprn, "%s ", dummy[i]);
- fprintf(stdprn, "\n");
- }
- if (val==108) {
- togglepr();
- if (stgdaton) printstgdatHARD();
- if (seqdaton) printseqdatHARD();
- } else {
- if (val) return(val);
- }
- #else
- printf("\n\tNumber of days, or menu choice (G for menu):\n");
- printf("\t\t==> ");
- getusrstrlist(dummy, &count);
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\n\Number of days, or menu choice ");
- fprintf(fpout, "(G for menu):\n\t\t==> ");
- for ( i=0; i<count; i++ )
- fprintf(fpout, "%s ", dummy[i]);
- fprintf(fpout, "\n");
- }
-
- /* echo the days ip to file and printer */
-
- stop = 0;
- if (dummy[0][1]=='\0') {
- /* user input is prob a char-accel */
- stop = 1;
- switch (toupper(dummy[0][0])) {
- case 'A': /* general menu */
- return(101);
- case 'B': /* help menu */
- return(102);
- case 'C': /* animal menu */
- return(103);
- case 'D': /* cycle length menu */
- return(104);
- case 'E': /* display menu */
- return(114);
- case 'F': /* cell input menu */
- return(105);
- case 'G': /* days input menu */
- daysmenu();
- #if PC
- stgdaton = 0;
- seqdaton = 0;
- #endif
- break;
- case 'H':
- printstgdat();
- #if PC
- stgdaton = 1;
- seqdaton = 0;
- #endif
- break;
- case 'I':
- printseqdat();
- #if PC
- seqdaton = 1;
- stgdaton = 0;
- #endif
- break;
- case 'J': /* show input cells */
- printusrcells(cellstr, trials);
- break;
- case 'X':
- printexit(6);
- case '?':
- helpdaysip();
- #if PC
- stgdaton = 0;
- seqdaton = 0;
- #endif
- break;
- default: /* not a char-accel: parse it */
- stop = 0;
- break;
- } /* switch */
- } /* if */
-
- if (! stop) {
- diff = trials - count;
- #if PC
- clrscr1(3);
- #endif
- if (diff > 0) {
- ok = 0;
- #if PC
- cprintf("%s%s: List of days ", tab, ERRSTR);
- cprintf("is %d too short.", diff);
- if (HARDCOPY) {
- fprintf(stdprn, "\t%s: List of days ", ERRSTR);
- fprintf(stdprn, "is %d too short.\n", diff);
- }
- #else
- printf("\t%s: List of days ", ERRSTR);
- printf("is %d too short.\n", diff);
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\t%s: List of days ", ERRSTR);
- fprintf(fpout, "is %d too short.\n", diff);
- }
- } /* if diff */
- if (diff < 0) {
- #if PC
- cprintf("%s%s: List of days ", tab, ERRSTR);
- cprintf("is %d too long.", abs(diff));
- if (HARDCOPY) {
- fprintf(stdprn, "\t%s: List of days ", ERRSTR);
- fprintf(stdprn, "is %d too long.\n", abs(diff));
- }
- #else
- printf("\t%s: List of days ", ERRSTR);
- printf("is %d too long.\n", abs(diff));
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\t%s: List of days ", ERRSTR);
- fprintf(fpout, "is %d too long.\n", abs(diff));
- }
- } /* if diff */
- if (diff==0) ok = 1;
- #if PC
- j = 0;
- any = 0;
- #endif
- for ( i=0; i<count; i++ ) {
- if (! numstrq(dummy[i])) {
- #if PC
- if (! any) {
- if (diff) /* line 1 has "list of days too..." */
- j = 2;
- else
- j = 1;
- }
- any++;
- if (j >= MSGLNS) {
- hitreturn(3);
- clrscr1(3);
- /* but now after clrscr, go to line 1 */
- j = 1;
- }
- gotoxy(1, j);
- clreol1(3);
- gotoxy(1, j++);
- cprintf("%s%s: Invalid number ", tab, ERRSTR);
- cprintf("syntax <%s>.", dummy[i]);
- if (HARDCOPY) {
- fprintf(stdprn, "\t%s: Invalid numb", ERRSTR);
- fprintf(stdprn, "er syntax <%s>.\n", dummy[i]);
- }
- #else
- printf("\t%s: Invalid numb", ERRSTR);
- printf("er syntax <%s>.\n", dummy[i]);
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\t%s: Invalid numb", ERRSTR);
- fprintf(fpout, "er syntax <%s>.\n", dummy[i]);
- }
- ok = ok && 0;
- } else
- strcpy(daystrs[i], dummy[i]);
- } /* for */
- if (! ok) count = 0;
- } /* if ! stop */
- } /* while !ok */
- return(0);
- } /* getusrdays */
-
- /********************************/
- /* function: getfileip */
- /********************************/
- /* gets initial cells and days from a file, batch-mode style
- returns 1 while not EOF
- returns 0 if EOF */
- getfileip(cellstr, daystr, fpin)
- char *cellstr, *daystr;
- FILE *fpin;
- {
- if (fscanf(fpin, "%s %s", cellstr, daystr) != EOF) {
- strupper(cellstr);
- return(1);
- } else
- return(0);
- } /* getfileip */
-
- /********************************/
- /* function: parsecellstr */
- /********************************/
- /* parses the user-input cellname:
- 1/ checks validity (match any from the cell sequence file?)
- 2/ if so, finds its cell sequence # and stage #, returns 1
- 3/ if not, returns 0 */
- parsecellstr (str, pseq, pst, opstr)
- char *str;
- int *pseq, *pst;
- char *opstr;
- {
- int i, found;
-
- /* look for the cell string in the list of known cell names*/
- i = 0;
- found = 0;
- while ((! found) && (i <= MaxCellIndex)) {
- if (strcmp(str, CellNames[i++])==0) {
- found = 1;
- *pseq = --i; /* cell sequence # */
- *pst = getcellstg(CellNames[i]); /* cell stage # */
- if (*pst==-1) /* bad cell name format */
- found = 0; /* shouldn't happen! */
- }
- }
-
- if ((! found) && (i > MaxCellIndex)) {
- sprintf(opstr, " %s: Unrecognized input cell <%s>",
- ERRSTR, str);
- *pseq = INVALID;
- *pst = INVALID;
- return(0); /* not ok */
- } else {
- sprintf(opstr, " ");
- return(1); /* ok */
- }
- } /* parsecellstr */
-
- /********************************/
- /* function: getcellstg */
- /********************************/
- /* parses a cell's namestring to extract its stage number.
- this assumes all cells are named in the syntax:
- name-nn where nn is the stage number
- if bad number format discovered, return -1
- else return stage number
-
- the special case of epididymis has to be handled separately */
- getcellstg (str)
- char *str;
- {
- int len, i, j;
- char temp[10]; /* holds digits of the stage # */
- #if PC
- static int k=1;
- #endif
-
- if (strcmp(str, CellNames[MaxCellIndex+1])==0)
- return(MaxCellIndex+1); /* in epididymis */
-
- len = strlen(str);
- i = 0;
- while ((i <= len) && (str[i++] != '-'));
- if (str[--i] != '-') {
- #if PC
- if (k >= MSGLNS) {
- hitreturn(3);
- clrscr1(3);
- k = 1;
- }
- msgwin();
- gotoxy(1, k);
- clreol1();
- gotoxy(1, k++);
- cprintf("%s%s: Bad cell name <%s>: `-' expected", tab, ERRSTR, str);
- if (HARDCOPY) {
- fprintf(stdprn, "\t%s: Bad cell name <%s>: ", ERRSTR, str);
- fprintf(stdprn, "`-' expected\n");
- }
- #else
- printf("\t%s: Bad cell name <%s>: `-' expected\n", ERRSTR, str);
- #endif
- if (FILEq && FILECOPY) {
- fprintf(fpout, "\t%s: Bad cell name <%s>: ", ERRSTR, str);
- fprintf(fpout, "`-' expected\n");
- }
- return(-1);
- } else {
- j = 0;
- while (i <= len)
- temp[j++] = str[++i];
- return(atoi(temp));
- }
- } /* getcellstg */