home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Education
/
collectionofeducationcarat1997.iso
/
SCIENCE
/
STAGES12.ZIP
/
INPUTS1.C
< prev
next >
Wrap
Text File
|
1991-04-21
|
23KB
|
893 lines
#include "header.h"
#if PC
#include <bios.h>
#endif
#include "file.h"
unsigned long coreleft(void);
/* functions included:
getipfile
getstgdat
getCyclelen
getseqdat
getmcldat
getusrstr
*/
/********************************/
/* function: getipfile */
/********************************/
/* there are 2 times when getipfile is called:
1/ to open a batch i/p file
2/ to open animal data files.
in case 1/, if file can't be found, do prompt for another file,
but it isn't mandatory to have one (if none given, then interactive
use assumed).
in case 2/, don't ask user for new filename: just exit w/error msg.
the user doesn't know anything about which files are correct to use.
returns 0 if good file opened,
else returns 1. */
getipfile (ipfil, pfp, iptype, ftype)
char *ipfil; /* the name of the file finally opened */
FILE **pfp;
char iptype; /* filename supplied (F) or entered */
/* interactively (I) */
char ftype; /* C=cycle stage dat
I=input file (batch mode)
S=cell sequence dat */
{
int go, help, mandatory;
char fname[2*FILELEN];
#if PC
int val;
#endif
switch (ftype) {
case 'I':
mandatory = 0;
break;
case 'S':
case 'C':
mandatory = 1;
break;
default: /* shouldn't */
#if PC
clrscr1(1);
gotoxy(1, 5);
cprintf("%sgetipfile: Illegal ftype=<%c>", tab, ftype);
gotoxy(1, 7);
cprintf("%s Sorry, aborting.", tab);
printexit(329);
#else
printf("\tgetipfile: Illegal ftype=<%c>\n", ftype);
printf("\t Sorry, aborting.\n");
#endif
} /* switch */
#if (DEBUG > 4)
#if PC
clrscr1(1);
gotoxy(1, 5);
cprintf("%sin getipfile:", tab);
gotoxy(1, 7);
cprintf("%sipfil=<%s>", tab2, ipfil);
gotoxy(1, 8);
cprintf("%siptype=<%c>", tab2, iptype);
gotoxy(1, 9);
cprintf("%sftype=<%c>", tab2, ftype);
hitreturn(1);
#endif
#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[0]);
go = 1;
while (go && ((*pfp = fopen(fname, "r"))==NULL)) {
if ((ftype=='C') || (ftype=='S')) {
#if (DEBUG > 4)
#if PC
clrscr1(1);
gotoxy(1, 5);
cprintf("%sfile <%s> not opened", tab, fname);
hitreturn(1);
#else
printf("\tfile <%s> not opened\n", fname);
#endif
#endif
helpipfil(ftype);
printexit(330);
} else {
if (fname[0]=='?') {
help = 1;
helpipfil1(ipfil);
} else {
help = 0;
}
}
if (! mandatory) {
#if PC
clrscr1(3);
gotoxy(1, 1);
if (! help) {
printf("%s%s: File ", tab, ERRSTR);
printf("<%s> cannot be opened.", fname);
gotoxy(1, 2);
}
cprintf("%sPlease enter a new filename, or", tab);
gotoxy(1, 3);
cprintf("%s type <Enter> if no file is desired.", tab);
clrscr1(2);
cprintf("%sNew filename:", tab);
gotoxy(1, 2);
highvideo();
cprintf("%s%c%c%c ", tab2, HBAR, HBAR, RTRI);
normvideo();
val = getusrstr(fname);
stripwhitesp(&fname[0]);
if (HARDCOPY) {
if (! help) {
fprintf(stdprn, "\n\t%s: File ", ERRSTR);
fprintf(stdprn, "<%s> cannot be opened.\n", fname);
}
fprintf(stdprn, "\tPlease enter a new filename, or\n");
fprintf(stdprn, "\t type <Enter> if no file is desired.\n");
fprintf(stdprn, "\t\t==> ");
fprintf(stdprn, "%s\n", fname);
}
if (val) return(val);
#else
if (! help) {
printf("\n\t%s: File ", ERRSTR);
printf("<%s> cannot be opened.\n", fname);
}
printf("\tPlease enter a new filename, or\n");
printf("\t type <Enter> if no file is desired.\n");
printf("\t\t==> ");
getusrstr(fname);
stripwhitesp(&fname[0]);
#endif
if (FILEq && FILECOPY) {
if (! help) {
fprintf(fpout, "\n\t%s: File ", ERRSTR);
fprintf(fpout, "<%s> cannot be opened.\n", fname);
}
fprintf(fpout, "\tPlease enter a new filename, or");
fprintf(fpout, "\t type <Enter> if no file is desired.\n");
fprintf(fpout, "\t\t==> ");
fprintf(fpout, "%s\n", fname);
}
/* not mandatory: can enter no filename */
if (strlen(fname)==0)
go = 0;
} else { /* mandatory: animal file: fail! */
#if PC
clrscr1(1);
gotoxy(1, 5);
cprintf("%sgetipfile: Internal error: File <%s> ", tab, fname);
cprintf("cannot be opened.");
gotoxy(1, 7);
cprintf("%s Sorry, aborting.", tab);
if (HARDCOPY) {
fprintf(stdprn, "\t%s: Internal error: File <%s> ", ERRSTR, fname);
fprintf(stdprn, "cannot be opened.\n\tSorry, aborting.\n\n");
}
#else
printf("\t%s: Internal error: File <%s> ", ERRSTR, fname);
printf("cannot be opened.\n\tSorry, aborting.\n\n");
#endif
if (FILEq && FILECOPY) {
fprintf(fpout, "\t%s: Internal error: File <%s> ", ERRSTR, fname);
fprintf(fpout, "cannot be opened.\n\tSorry, aborting.\n\n");
}
printexit(331);
} /* if mandatory */
} /* while */
#if (DEBUG > 4)
#if PC
clrscr1(1);
gotoxy(1, 5);
cprintf("%sgetipfile: done with while loop", tab);
hitreturn(1);
#else
printf("\tgetipfile: done with while loop\n");
#endif
#endif
if (go==0) {
/* no 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");
hitreturn(1);
#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");
#if (DEBUG > 4)
#if PC
clrscr1(1);
gotoxy(1, 5);
cprintf("%sfile <%s> not opened", tab, fname);
hitreturn(1);
#else
printf("\tfile <%s> not opened\n", fname);
#endif
#endif
return(1);
} else {
#if (DEBUG > 4)
#if PC
clrscr1(1);
gotoxy(1, 5);
cprintf("%sfile <%s> opened", tab, fname);
hitreturn(1);
#else
printf("\tfile <%s> opened\n", fname);
#endif
#endif
return(0); /* good file opened */
} /* *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;
static int once=0; /* =1 if malloc'd once already */
#if (DEBUG > 4)
long int j;
#endif
/* if gotstgdat at least once already, free up allo'c space */
if (once) {
free1((char *) stage);
#if (DEBUG > 4)
#if PC
clrscr1(1);
gotoxy(1, 3);
cprintf("%sgetstgdat: free(stage)", tab);
hitreturn(1);
#else
printf("\tgetstgdat: free(stage)\n");
#endif
} else {
#if PC
clrscr1(1);
#else
printf("\tgetstgdat: stage not freed\n");
#endif
#endif
} /* else */
/* read cycle time - this is in days */
fscanf(fpstg, "%lf", &CycleTime);
/* DefaultCycleTime is always that value read from the *.stg file */
DefaultCycleTime = CycleTime;
#if PC
printCycleTime(); /* turn on Cycle Length annunciator */
#endif
OldCycleTime = CycleTime; /* initialize OldCycleTime */
fscanf(fpstg, "%d", &NumStages);
MaxStage = NumStages - 1;
#if (PC && (DEBUG > 4))
makeactivewin(1);
gotoxy(1, 5);
cprintf("%sgetstgdat: getting data from file <%s>", tab, stgfil);
gotoxy(1, 6);
cprintf("%s CycleTime = <%lf>", tab, CycleTime);
gotoxy(1, 7);
cprintf("%s NumStages = <