home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Education
/
collectionofeducationcarat1997.iso
/
SCIENCE
/
STAGES12.ZIP
/
INPUTS.C
< prev
next >
Wrap
Text File
|
1991-02-25
|
34KB
|
1,258 lines
#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"