home *** CD-ROM | disk | FTP | other *** search
- #include "globals.h"
- #include "file.h"
-
- /* default stack size in large memory model is 4000 */
- #if PC
- extern unsigned _stklen = 12000;
- #endif
-
-
- main (argc, argv)
- int argc;
- char *argv[];
- {
- FILE *fpin; /* data input file */
- FILE *fpstg; /* stage data file */
- FILE *fpseq; /* cell seq data file */
- FILE *fpmcl; /* multicell stages data file */
- double days; /* current days value from daystr */
- double third; /* 1/3 of length of initial stage */
- char cellstrs[MAXIP][MAXIPLEN]; /* array of cell name input string */
- char daystrs[MAXIP][MAXIPLEN]; /* array of days input strings, file ip */
- char opstr[MAXLEN]; /* tells when #days inputted exceeds */
- /* time left til release (fwd), or */
- /* time since entered (bwd), or */
- /* if input was unrecognized */
- char opstr1[MAXLEN]; /* these 2 strings tell when a cell was */
- char opstr2[MAXLEN]; /* ejact but still are tracking stgs */
- char stgfil[FILELEN]; /* cycle stage data filename */
- char seqfil[FILELEN]; /* cell sequence data filename */
- char mclfil[FILELEN]; /* multi-cell stage info filename */
- char ipfil[MAXLEN]; /* batch mode input file name */
- char opfil[FILELEN]; /* output file name */
- int initseq; /* initial cell's index # in cell seq */
- int initst; /* initial cell's stage */
- int index; /* stage index */
- int cell[4]; /* final cells reached, starting from */
- /* beginning, 1/3, 2/3, and end of */
- /* initial stage */
- int trials; /* # of initial cells to run */
- int moveok[4]; /* for fwd/bwd moves */
- int i; /* loop index */
- int go; /* boolean: continue? */
- int ok, okcell, oknum; /* boolean: for input error checking */
- int badipfil; /* boolean var */
- int once; /* boolean: header printed to file yet? */
- int val, oldval; /* return vals from menu functions */
- int newspec; /* =1 if animal has been changed */
- int epi; /* =1 if any cell of the current batch */
- /* i/p went into epididymis */
- int endspot; /* which 3d of stage did move end in? */
-
- /************************************************************************/
- /** test for correct number of arguments **/
- /************************************************************************/
-
- if (argc > 2) {
- printf("\n\tUsage: %s ", argv[0]);
- printf("[ <batch_file_name> ]\n");
- printexit(100);
- }
-
- /* set tab strings and defaults */
- strcpy(tab4, " ");
- strcpy(tab, " ");
- strcpy(tab2, " ");
- strcpy(opfil, "None");
- Animal = strdup("None"); /* does AUTOmagic malloc */
- NewCycleTime = 0;
- FILEq = 0;
- FILECOPY= 0;
- #if PC
- HARDCOPY = 0;
- introprint = 0;
- #endif
-
- /************************************************************************/
- /** print out title page info, if PC, set up screen **/
- /************************************************************************/
- #if PC
- wholewin();
- clrscr();
- makedisplay();
- #if (DEBUG > 3)
- makeactivewin(1);
- gotoxy(1, 5);
- cprintf("%smain: core left = %lu", tab, coreleft());
- hitreturn(1);
- clrscr1(1);
- #endif
- #endif
- printintro(1, 0);
-
- /************************************************************************/
- /** get input file pointer **/
- /************************************************************************/
-
- badipfil = 0;
- interactive = 1;
- /* see if valid batch file specified */
- if (argc == 2) {
- strcpy(ipfil, argv[1]);
- if (getipfile(ipfil, &fpin, 'F', 'I'))
- badipfil = 1;
- else
- interactive = 0;
- }
-
- /************************************************************************/
- /** set up temp file pointer (output holder) **/
- /************************************************************************/
- #if PC
- sprintf(TMPFIL, "TMPout.out");
- tmpfp = fopen(TMPFIL, "w");
- #endif
-
- /************************************************************************/
- /** start main menu/computation loop **/
- /************************************************************************/
-
- ok = 1;
- epi = 0;
- trials = 0;
- newspec = 0;
- val = 101; /* start at general menu */
- oldval = val;
- while (val) {
- switch (val) {
-
- /**************************/
- /* general menu */
- /**************************/
- case 101:
- #if PC
- clrscr1(3);
- #endif
- once = 0; /* controls printing of results hdr */
- oldval = val;
- val = generalmenu(opfil);
- break;
-
- /**************************/
- /* help menu */
- /**************************/
- case 102:
- #if PC
- clrscr1(3);
- #endif
- oldval = val;
- val = helpmenu();
- break;
-
- /**************************/
- /* animal menu */
- /**************************/
- case 103:
- #if PC
- clrscr1(3);
- #endif
- oldval = val;
- val = animalmenu(&fpstg, &fpseq, &fpmcl,
- stgfil, seqfil, mclfil, &newspec);
- if (! val && newspec) {
- #if (DEBUG > 4)
- #if PC
- clrscr1(1);
- gotoxy(1, 5);
- cprintf("%smain: about to printoutputhdr", tab);
- hitreturn(1);
- #else
- printf("\tmain: about to printoutputhdr\n");
- #endif
- #endif
- val = printoutputhdr(argc, argv, &badipfil, interactive, ok,
- ipfil, opfil, stgfil, seqfil);
- } /* if */
- break;
-
- /**************************/
- /* cycle length menu */
- /**************************/
- case 104:
- #if PC
- clrscr1(3);
- #endif
- oldval = val;
- val = cyclemenu();
- if (! val)
- val = 105; /* cell i/p menu next */
- break;
-
- /**************************/
- /* display menu */
- /**************************/
- /* this is not very useful a menu, since you can display
- the stage and cell seq dat from within the cell i/p
- and days i/p menu -- but it can't hurt to have this */
- case 114:
- #if PC
- clrscr1(3);
- #endif
- oldval = val;
- val = displaymenu();
- break;
-
- /**************************/
- /* cell input menu */
- /**************************/
- case 105:
- #if PC
- clrscr1(3);
- #endif
- oldval = val;
- if (interactive) {
- once = 0; /* controls printing of results header */
- val = getusrcells(cellstrs, &trials);
- } else {
- val = 0;
- trials = 1; /* batch i/p file */
- }
- if (! val)
- val = 106; /* valid cells: get user days next */
- break;
-
- /**************************/
- /* days input menu */
- /**************************/
- case 106:
- #if PC
- clrscr1(3);
- #endif
- oldval = val;
- if (interactive)
- val = getusrdays(cellstrs, daystrs, trials);
- else
- val = 0;
-
- if (! val) {
- if (interactive)
- val = 105; /* valid days: get more cells next */
- else
- val = 106; /* batch mode: stay here til EOF */
-
- i = 0;
- while (i < trials) {
- if (interactive)
- go = 1;
- else
- /* get file input (one <cellname,days> pair at a time)
- go = 0 when EOF encountered in fpin */
- go = getfileip(cellstrs[i], daystrs[i], fpin);
-
- if (go) {
- /* if interactive, parsecellstr will return 1 since user
- input was already checked by parsecellstr in getusrcells */
- okcell = parsecellstr(cellstrs[i], &initseq, &initst, opstr);
- if (interactive) {
- oknum = 1;
- days = atof(daystrs[i]);
- } else {
- oknum = numstrq(daystrs[i]);
- if (oknum)
- days = atof(daystrs[i]);
- else
- days = 0.0; /* any dummy value */
- } /* !interactive */
-
- /* the index into the cycle stage info array is one less
- than the stage of a cell, since the 1st stage is 1 and
- the 1st array index is 0 */
- index = initst - 1;
- third = stage[index] / 3.0; /* divide stage into thirds */
- if (days >= 0) { /* forward */
- if (okcell && oknum)
- forward(initseq, index, third, days, cell,
- moveok, &endspot, opstr);
- printresults('F', days, daystrs[i], cell, cellstrs[i], moveok,
- okcell, oknum, endspot, opstr, &once, &epi,
- opstr1, opstr2);
- } else { /* backward */
- if (okcell && oknum)
- backward(initseq, index, third, fabs(days), cell,
- moveok, &endspot, opstr);
- printresults('B', days, daystrs[i], cell, cellstrs[i], moveok,
- okcell, oknum, endspot, opstr, &once, &epi,
- opstr1, opstr2);
- } /* if days */
- printline(3, LNWID, '-');
- } else { /* ! go */
- val = 110; /* batch done: exit! */
- } /* if go */
-
- i++;
- } /* while i */
-
- if (interactive && epi) {
- printepi();
- epi = 0; /* reset epi */
- }
- #if PC
- if (interactive)
- hitreturn(1);
- if (HARDCOPY) {
- togglepr();
- printresHARD();
- }
- #endif
- } /* if ! val */
- break;
-
- /**************************/
- /* toggle file */
- /**************************/
- case 107:
- val = oldval; /* go back to where we were */
- if (FILEq)
- FILECOPY = FILECOPY ^ 1;
- else {
- #if PC
- clrscr1(3);
- cprintf("%s%s: Output not currently being saved to file <stages.out>.", tab, ERRSTR);
- gotoxy(1, 2);
- cprintf("%s Use General Menu, `Printer and File Options'", tab);
- gotoxy(1, 3);
- cprintf("%s to select an output file.", tab);
- if (HARDCOPY) {
- fprintf(stdprn, "\n\t%s: Output not currently being saved to file <stages.out>.\n",
- ERRSTR);
- }
- #else
- printf("\t%s: Output not currently being saved to file <stages.out>.", ERRSTR);
- #endif
- helpopfile();
- }
- printFILECOPY();
- break;
-
- #if PC
- /**************************/
- /* toggle printer */
- /**************************/
- case 108:
- val = oldval; /* go back to where we were */
- #if PC
- togglepr();
- #endif
- break;
-
- /**************************/
- /* makedisplay */
- /**************************/
- case 109:
- val = oldval; /* go back to where we were */
- makedisplay();
- break;
- #endif
-
- /**************************/
- /* exit */
- /**************************/
- case 110:
- if (! interactive && epi)
- /* batch had a cell go epi */
- printepi();
- printexit(0);
-
-
- /**************************/
- /* default */
- /**************************/
- default:
- #if PC
- clrscr1(1);
- gotoxy(1, 5);
- cprintf("%s%s: Abnormal input.", tab, ERRSTR);
- gotoxy(1, 7);
- cprintf("%s%s Returning to General Menu.", tab, NULLERRSTR);
- cprintf("");
- #else
- printf("");
- #endif
- val = 101;
- } /* switch val */
- } /* while val */
- return(0);
- } /* main */