home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: Science
/
Science.zip
/
ABCPLOT.ZIP
/
MAIN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-04-02
|
9KB
|
198 lines
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <process.h>
#define num_error -9
#define option -4
#define ok 2
#define MAXLENGTH 80 /* Maximum length of filenames */
#define MAXCURVE 10 /* Maximum number of curves . */
#define tempfil1 "plot_tmp.zz1" /* Working file if data in std input */
#define tempfil2 "plot_tmp.zz2" /* Working file, used in subrtn. COUNT */
/*---------------------------------------------------------------------------*/
/* C front end for the ABCPLOT program */
/* DATE : 11/3/88 */
/* AUTHOR : RYAN RUMANANG */
/* */
/* MAIN : This is the main driver for the "abcplot" program . The purpose of */
/* this driver is to parse the command issued by the user, then call the */
/* fortran modules of abcplot. */
/* Modification History: */
/* April 2 1991 modified by Robert L. Dougherty */
/* -n option added to allow output of data as numbers. */
/* Arguments are no longer case-sensitive. */
/* December 5 1989 modified by Robert L. Dougherty */
/* adapted to MS-DOS (microsoft compilers). */
/* Note: Lines #151-153 are system dependent for MS-DOS. */
/* The "del" command should be modified if running on other computers. */
/* April 29 1988 modified by Rudy Ting Liang */
/* Old version: User has to provide the data file. */
/* Command format: abcplot <datafile> [options] */
/* Modified version: The program can accept data from a process. */
/* Format: <process name> | abcplot [options] */
/* */
/* November 3 1988 modified by Robert L. Dougherty */
/* -s switch added. If present, it initializes the iswtch parameter */
/* to 1, which signals the subroutines to switch the x and y axes. */
/*---------------------------------------------------------------------------*/
main(argc,argv)
int argc ;
char *argv[] ;
{
FILE *fdata; /* file pointer to data file */
extern void fortran abcplt (char near *, long near *, long near *, long near *, long near *, long near *, long near *, long near *, char near *) ;
int status, index, check_arg();
long i,j, ncurve, ix, icat, iy[MAXCURVE] ,itype, iswtch, itext;
char fname[MAXLENGTH], outfile[MAXLENGTH], line[MAXLENGTH] ;
char *command;
short flag=0; /* indicate if temporary file is used */
ncurve = 1 ; /* Default values . */
ix = 1 ;
itype = 1 ;
for(i=0;i<MAXCURVE;i++) iy[i] = 0 ;
iy[0] = 2;
icat=0;
iswtch=0;
itext=0;
/* The following block checks for user options . */
if (argc == 1 || argv[1][0] == '-') { /* data from standard input */
fdata = fopen(tempfil1,"w"); /* open file for data */
while (gets(line) != NULL) { /* do until eof */
fputs(line,fdata); /* copy data from standard input */
fputc('\n',fdata); /* to a temporary file */
}
fclose(fdata);
strcpy(fname,tempfil1); /* Get the input file name. */
for(j=strlen(tempfil1);j<MAXLENGTH;j++) fname[j] = ' ' ;
flag = 1;
index = 1;
}
else { /* user provides data file */
strcpy(fname,argv[1]); /* Get the input file name. */
for(i=0;fname[i] != '\0'; i++) ; /* Strip-off null character for compa- */
for(j=i;j<MAXLENGTH;j++) fname[j] = ' ' ; /* tability with the FORTRAN routines */
index = 2;
}
while(index < argc) {
if(!strcmpi(argv[index],"-x")) { /* '-x' option ? */
if(index+1 >= argc ) break ;
status = check_arg(argv[++index]) ;
if(status == num_error)
error("in x-option ...\n") ;
else if(status == ok)
ix = atoi(argv[index++]) ;
}
else if(!strcmpi(argv[index],"-o")) { /* '-o' option ? */
itype = 0 ;
if(index+1 >= argc)
error("Need output file name\n");
strcpy(outfile,argv[++index]) ;
for(i=0;outfile[i] != '\0';i++) ;
for(j=i;j < MAXLENGTH;j++)
outfile[j] = ' ' ;
index++ ;
}
else if(!strcmpi(argv[index],"-c")) { /* '-c' option ? */
if(index+1 >= argc ) break ;
status = check_arg(argv[++index]) ;
if(status == num_error)
error("in c-option ...\n") ;
else if(status == ok)
icat = atoi(argv[index++]) ;
if(icat == ix)
error("in c-option ...\n") ;
}
else if(!strcmpi(argv[index],"-y")) { /* '-y' option ? */
status = ncurve = j = 0 ;
index++ ;
while((status != num_error) && (status != option) && (index < argc)) {
status = check_arg(argv[index]) ;
switch(status) {
case num_error : error("in y-options");
case option : break ;
case ok : iy[j++] = atoi(argv[index++]) ;
ncurve++ ;
if(iy[j-1] <= 0)
error("Y values must be > 0") ;
if(ncurve >MAXCURVE)
error("number of curves must be < 10");
break ;
default : break ;
}
}
if(ncurve <= 0) ncurve = 1 ;
}
else if(!strcmpi(argv[index],"-s")) { /* '-s' option ? */
iswtch = 1 ;
if(index+1 >= argc ) break ;
status = check_arg(argv[++index]) ;
if(status == num_error)
error("in s-option ...\n") ;
else if(status == ok)
iswtch = 1 ;
}
else if(!strcmpi(argv[index],"-n")) { /* '-n' option ? */
itext = 1 ;
if(index+1 >= argc ) break ;
status = check_arg(argv[++index]) ;
if(status == num_error)
error("in t-option ...\n") ;
else if(status == ok)
itext = 1 ;
}
else error("ILLEGAL OPTION") ;
}
abcplt(fname, &ncurve, &ix, iy, &icat, &itype, &iswtch, &itext, outfile);
if (flag == 1) { /* created a temporary data file */
fname[strlen(tempfil1)] = '\0'; /* put a null character at end */
/* the following three lines are used to remove a file. */
/* NOTE: they are system dependent; only runs on MS-DOS computers! */
command = "del "; /* generate command to delete */
strcat(command,fname); /* the created temporary data */
system(command); /* file */
}
}
/*--------------------------------------------------------------------------*/
/* ERROR : This routine simply prints a string given by its input parameter */
/*--------------------------------------------------------------------------*/
error(str)
char *str ;
{
printf("ERROR ! %s\n",str) ;
exit(1) ;
}
/*--------------------------------------------------------------------------*/
/* CHECK_ARG : This routine checks an argument. If the argument starts with */
/* a '-' then it should be treated as another option flag . Otherwise, the*/
/* argument should consist of digits. A flag is returned according to the */
/* argument . */
/*--------------------------------------------------------------------------*/
int check_arg(inarg)
char inarg[] ;
{
int len ,i ;
len = strlen(inarg) ;
if(inarg[0] == '-') return(option) ;
else {
for(i=0;i < len;i++)
if(!isdigit(inarg[i])) return(num_error) ;
}
return(ok) ;
}