Category : Science and Education
Archive   : LAPLACE.ZIP
Filename : GRID.C

 
Output of file : GRID.C contained in archive : LAPLACE.ZIP
/*
grid - generate display file for the grid corresponding to
CONTOUR's input file

link with CONTOUR2

*/

#include
#include

#define BUFSIZE 128
#define VERSION "1.00"

FILE *ifile=stdin, *ofile=stdout;

double xmin, ymin, xmax, ymax, ex, ey;

int w, h;
char oname[40], buf[BUFSIZE];

main(argc,argv) int argc; char **argv;
{ double x, y, xs, ys;
int i;

read_data(argc, argv);
printf(";");
x=xmin;
xs=xmax+.5*ex;
for (i=0; i {out(x,ymin); out(x,ymax);
x += ex;
i++;
if(i>=w) break;
out(x, ymax); out(x, ymin);
x += ex;
}
y=ymin;
ys=ymax+.5*ey;
for (i=0; i {out(xmax, y); out(xmin, y);
y += ey;
i++;
if(i>=h) break;
out(xmin,y); out(xmax, y);
y += ey;
}
printf(" \"\"\n");
}

out(x, y) double x, y;
{ int error;
error=fprintf(ofile,"\n%8.3g %8.3g",x,y);
if(error==-1)
{fprintf(stderr,"output file error\n");
fclose(ofile);
exit(1);
}
}

read_data(argc,argv) int argc; char **argv;
{ int i, j, k, length;
double xx, yy, d, *pd, sum;
char *s, *t;

if(argc>1 && streq(argv[1], "?")) help();
if(argc>1 && *argv[1]!='-')
{argc--; argv++; /* advance to file name */
ifile=fopen(*argv, "r");
if(ifile==0) {printf("file %s not found\n", *argv); exit(1);}
}
argc--; argv++; /* advance to first switch if any */
/* open output file */
if(argc>0 && *argv[0]!='-')
{strcpy(oname, argv[0]);
argc--; argv++;
unlink(oname);
if((ofile=fopen(oname, "w"))==0)
{fprintf(stderr, "can\'t open output file %s", oname);
exit(1);
}
}
/*
sample data file header...
0. 3. 10 minimum and maximum y values, width of grid
0. 3. 10 minimum and maximum y values, height of grid

*/
if(mygets(buf,BUFSIZE,ifile,ofile)==0)
{printf("failure on reading input file header");
exit(1);
}
sscanf(buf,"%F %F %d",&xmin,&xmax,&w);
if(mygets(buf,BUFSIZE,ifile,ofile)==0)
{printf("failure on reading input file header");
exit(1);
}
sscanf(buf,"%F %F %d",&ymin,&ymax,&h);
if(w<2 || h<2)
{printf("invalid data header... width or height too small\n");
exit(1);
}
ex=(xmax-xmin)/(w-1);
ey=(ymax-ymin)/(h-1);
if(ex==0. || ey==0.)
{printf("invalid data header... xmin==xmax or ymin==ymax\n");
exit(1);
}
}

help()
{ fprintf(stderr,"grid version %s",VERSION);
fprintf(stderr,"\nusage: grid [file]\n");
exit();
}



  3 Responses to “Category : Science and Education
Archive   : LAPLACE.ZIP
Filename : GRID.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/