Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!bloom-beacon!eru!luth!sunic!mcsun!hp4nl!eutrc3!euteal!michel From: michel@es.ele.tue.nl (& Berkelaar) Newsgroups: alt.sources Subject: graph3d, part 2/3 Message-ID: Date: 13 Oct 89 08:58:57 GMT Sender: michel@ele.tue.nl Distribution: alt Organization: Eindhoven University of Technology, Eindhoven, The Netherlands Lines: 1521 Here is part two: --------------- #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # If this archive is complete, you will see the following message at the end: # "End of archive 2 (of 3)." # # Contents: # Makefile direct-tek.c find-tek.c hat.c hills.c pswrap.c # read_matrix.c showfloat.c stdoutpipe.c surface.c read_matrix.h # showfloat.h # # Wrapped by tap@cs.utoronto.ca on Wed Oct 11 23:48:18 1989 # PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f Makefile -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"Makefile\" else echo shar: Extracting \"Makefile\" \(890 characters\) sed "s/^X//" >Makefile <<'END_OF_Makefile' X# Compile with floating point flag if your machine has it! X X# If your make does not define LINK.c, uncomment the following line X#LINK.c= $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) $(LDFLAGS) $(LDFLAGS) X XCFLAGS = -O2 XCLIBS = -lm X Xdefault: all X Xall: hills graph3d surface graph3d-tek hat pswrap X Xpswrap: pswrap.o X $(LINK.c) -o pswrap pswrap.o -lm X Xhat: hat.o X $(LINK.c) -o hat hat.o -lm X Xhat2: hat2.o X $(LINK.c) -o hat2 hat2.o -lm X Xhills: hills.o X $(LINK.c) -o hills hills.o -lm X Xgraph3d: graph3d.o direct-tek.o stdoutpipe.o X $(LINK.c) -o graph3d graph3d.o direct-tek.o stdoutpipe.o -lm -lplot X Xgraph3d-tek: graph3d.o direct-tek.o stdoutpipe.o X $(LINK.c) -o graph3d-tek graph3d.o direct-tek.o stdoutpipe.o -lm -l4014 X Xsurface: surface.o read_matrix.o showfloat.o X $(LINK.c) -o surface surface.o read_matrix.o showfloat.o -lm X Xshowfloat: showfloat.o X $(LINK.c) -DMAIN showfloat.c -o showfloat END_OF_Makefile if test 890 -ne `wc -c direct-tek.c <<'END_OF_direct-tek.c' X#include X#include X#include X#include X X/* X * direct-tek - change `out' to be a stream for writing directly to a tek X * terminal, under certain conditions. X * The conditions are: X * (1) my_name ends in "-tek" X * (2) the integer 'dont_change_out' is zero X * (3) the print mode is X * There are three ways of getting the name of the tek terminal X * (1) the char * variable 'use_tty' contains the name X * (2) the environment variable 'TEK_TTY' contains the name X * (3) the file '$HOME/.tek-tty' contains the name X */ X X/* X * MAXHOSTNAMELEN is defined in , but only since sunOS 4.O X */ X#ifndef MAXHOSTNAMELEN X#define MAXHOSTNAMELEN 64 X#endif X Xextern char *use_tty; Xextern int dont_change_out; Xextern char *my_name; Xextern FILE *out; Xextern int force_tty; Xextern int errno; Xextern char *sys_errlist[]; X XCheckTekTerminal() X{ X FILE *f; X char *home,*getenv(),*machine; X int error; X char tektty[MAXHOSTNAMELEN+MAXPATHLEN]; X char tekhost[MAXHOSTNAMELEN]; X char host[MAXHOSTNAMELEN]; X char file[MAXPATHLEN]; X char command[200]; X char *comargv[4]; X struct stat statbuf; X /* X * don't do it if we don't end in "-tek" or have been prohibited X */ X if (dont_change_out || strcmp(my_name+strlen(my_name)-4,"-tek")) { X if (use_tty != NULL) X fprintf(stderr,"%s: tty option ignored\n",my_name); X return; X } X /* X * get the tty name from the environment or from a file X */ X if (use_tty==NULL) { X if (!(use_tty=getenv("TEK_TTY"))) { X home = getenv("HOME"); X if (!home) {error=1;goto cant_find_tty;} X strcpy(file,home); X strcat(file,"/.tek-tty"); X if (!(f=fopen(file,"r"))) {error=2;goto cant_find_tty;} X use_tty=fgets(tektty,MAXPATHLEN+MAXHOSTNAMELEN,f); X fclose(f); X } X } X X /* X * check that we found something (and strip the \n) X */ X if (use_tty==NULL || use_tty[0]==0) {error=3;goto cant_find_tty;} X if (use_tty[strlen(use_tty)-1]=='\n') use_tty[strlen(use_tty)-1]=0; X X /* X * split it into machine and filename X */ X if (index(use_tty,':')) { X if (sscanf(use_tty,"%[^:]:%s",tekhost,tektty)!=2) { X fprintf(stderr,"%s: bad tty name format \"%s\"\n",my_name,use_tty); X } else { X machine = tekhost; X use_tty = tektty; X } X } else { X machine = NULL; X } X X /* X * if the tekhost is the same as our host, don't bother with machine X */ X gethostname(host,MAXHOSTNAMELEN); X if (machine!=NULL && !strcmp(machine,host)) machine=NULL; X X /* X * Put the tty file name in file[] X * if the ttyname does not being with a . or a / assume it is of the X * form X or ttyX, and convert it to /dev/ttyX X */ X file[0]=0; X if (use_tty[0]!='.' && use_tty[0]!='/') { X if (strncmp("tty",use_tty,3)) X strcpy(file,"/dev/tty"); X else X strcpy(file,"/dev/"); X strcat(file,use_tty); X } else { X strcpy(file,use_tty); X } X X /* X * Now, do the dirty work X * If we have a remote machine, use popen & rsh cat, X * otherwise just open a file. X * Close stdout first, so that the fd 1 gets associated with our new stream. X */ X if (machine==NULL) { X /* fprintf(stderr,"machine==NULL, openning \"%s\"\n",file); */ X if (stat(file,&statbuf)) {error=4;goto cant_find_tty;} X if (!force_tty && statbuf.st_uid!=getuid()) {error=6; goto cant_find_tty;} X close(1); X if (!(out=fopen(file,"w"))) {error=5;goto cant_find_tty;} X } else { X comargv[0]="/usr/ucb/rsh"; X comargv[1]=machine; X if (!force_tty) X sprintf(command,"if (-o %s) then \nexec cat > %s \nelse \necho not owner of %s \nexit 1 \nendif",file,file,file); X else X sprintf(command,"exec cat > %s",file); X comargv[2]=command; X comargv[3]=0; X stdoutpipe(comargv,1); X } X return; X X cant_find_tty: X fprintf(stderr,"%s: Can't find location of Tektronics window, reason:\n",my_name); X switch (error) { X case 1: X fprintf(stderr,"HOME environment variable is not set: can't look up tek tty\n"); X break; X case 2: X fprintf(stderr,"Can't open file \"%s\"\n",file); X break; X case 3: X fprintf(stderr,"NULL tektronics device name, check $TEK_TTY and ~/.tek-tty\n"); X break; X case 4: X fprintf(stderr,"Can't find tektronics device: \"%s\": %s\n",file,sys_errlist[errno]); X break; X case 5: X fprintf(stderr,"Can't open tektronics device for writing: \"%s\": %s\n",file,sys_errlist[errno]); X break; X case 6: X fprintf(stderr,"Not owner of \"%s\" - use `-forcetty` to write\n",file); X break; X } X exit(1); X} END_OF_direct-tek.c if test 4489 -ne `wc -c find-tek.c <<'END_OF_find-tek.c' X/* X * If (1) my_name ends in `-tek' X * (2) stdout is a terminal, X * (3) the flag `to_stdout' is not set X * it trys to set stdout to be tek-window. X * X * It looks first in ./.tek-tty then in $HOME/.tek-tty X * for the name of a tty device, X * and if it finds one, it checks that that tty belongs to X * the user running this process. This check can be overridden X * by the flag `force-tek-tty' X */ X X#include X#include X Xint find_tek_tty(to_stdout,force) Xint to_stdout; Xint force; X{ X char *getenv(); X char *home,*tek,buffer[MAXPATHLEN]; X int found_tek=0; X path = getenv("HOME"); X if ( to_stdout X || !isatty(1) X || strcmp("-tek",my_name+length(my_name)-4)) return; X X tek = getenv("TEKTTY"); X home = getenv("HOME"); X X if (tek) { X if (found_tek(tek,force)) return; X strcpy(buffer,home); X strcat(buffer,"/"); X strcat(buffer,tek); X if (found_tek(buffer,force)) return; X } X if (found_tek(".tek-tty",force)) return; X strcpy(buffer,home); X strcat(buffer,"/.tek-tty"); X if (found_tek(buffer,force)) return; X} X Xfound_tek(name,force) Xchar *name; Xint force; X{ X if X} END_OF_find-tek.c if test 1124 -ne `wc -c hat.c <<'END_OF_hat.c' X/* X * generates a mexican hat X * usage: hat grid-size radius X * the radius should be given in radians X * the grid size is the number of points along each axis X */ X X#include X#include X Xdouble sigmoid(x) Xdouble x; X{ X return 1/(1 + exp(x)); X} X Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X double radius=20; X double x,y,inc,z; X int i,j,points; X if (argc<2) { X fprintf(stderr,"usage: %s grid-points [radius]\n\"%s 60 20\" is good\n",argv[0],argv[0]); X exit(1); X } X points = atoi(argv[1]); X if (argc>2) X radius = atof(argv[2]); X if (radius==0 || points<2) { X fprintf(stderr,"%s: radius is 0 or number of points is < 2\n",argv[0]); X exit(1); X } X inc = radius/points; X x = -radius/2; X printf("%d %d\n",points,points); X for (i=0;ihills.c <<'END_OF_hills.c' X/*******************************************************\ X* * X* @(#)hills.c 1/13/89 * X* Author: Tony Plate * X* Copyright (C) 1989 Tony Plate * X* This program may be freely distributed and * X* used, provided that this copyright notice is * X* retained intact. There is no warranty with * X* this software. * X* * X\*******************************************************/ X#include X#define DB(X) X/* X * hills - toy program - generate a matrix with hills - randomly X * two arguments, edge of matrix & number of hills X */ X Xint max(x,y) int x,y; { if (x > y) return x; else return y; } Xint min(x,y) int x,y; { if (x < y) return x; else return y; } Xint iab(x) int x; { if (x >= 0) return x; else return -x; } X Xint inbounds(array,d,x,y) Xint *array,d,x,y; X{ X DB( printf("[%2d %2d ",x,y); ) X if ((x<0) || (x>=d) || (y<0) || (y>=d)) { X DB( printf("--] "); ) X return 0; X } else { X DB( printf("%2d] ",array[x*d + y]); ) X return array[x*d + y]; X } X} X Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X int d,n_hills,*array,height,i,j,x,y,corrected,new; X height = 5; X if (argc < 3) { X fprintf(stderr,"usage: %s size n-hills [height [seed]]\n",argv[0]); X exit(1); X } X d = atoi(argv[1]); X n_hills = atoi(argv[2]); X if (argc > 3) height = atoi(argv[3]); X srandom(getpid()); X if (argc > 3) srandom(atoi(argv[4])); X array = (int*)calloc(sizeof(int),d * d); X for (i=0;i 0;n_hills--) { X x = random() % d; X y = random() % d; X array[x*d+y]=height; X /* X for (i=max(x-height,0);i<=min(x+height,d);i++) X for (j=max(y-height,0);j<=min(x+height,d);j++) { X array[i*d+j] = max(array[i*d+j],min(height-iab(i-x),height-iab(j-y))); X } X */ X } X do { X corrected = 0; X for (i=0;ipswrap.c <<'END_OF_pswrap.c' X/* X * pswrap - put a prologue and epilogue around a postscript file X */ X#include X#include X#include X#include X Xint ps_box_size = 10000; /* the diagram is assumed to be in a 10000x10000 box */ Xchar *title = "standard input"; Xint font_size = 200; Xint font_size_set = 0; Xfloat x_pos = 1; /* prfloating size and position, in inches */ Xfloat y_pos = 1; Xfloat x_size = 6; Xfloat y_scale = 1; Xint x_pack; Xint y_pack; Xfloat page_bottom = 1; Xfloat page_height = 9; /* from bottom, the date will go just above this */ Xfloat page_margin = 1; Xfloat page_width = 6; /* from margin */ Xint n_diagrams = 0; Xint do_date = 1; Xchar *diag[100]; Xchar *my_name; Xchar *user; Xchar *date; X Xchar *options_description[] = { X"-nodate : don't display the date", X"-fontsize N : set the fontsize used in the diagrams", X"-y_scale S : set the ratio height:width", X NULL X}; X Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X struct timeval tv; X struct timezone tz; X gettimeofday(&tv,&tz); X date = ctime(&tv.tv_sec); X my_name = argv[0]; X process_options(argv); X find_best_packing(); X print_diagrams(); X} X Xprint_diagrams() X{ X char **p = diag; X float x,y; X int i,j; X y = page_bottom + page_height - x_size*y_scale; X x = page_margin; X /* font size gets smaller as drawing boxes get smaller, but not unreadable */ X if (!font_size_set) font_size = (sqrt(x_size)*ps_box_size)/81.65; X header(); X i = j = 0; X while (*p) { X printf("%% file: %s of %d, position %g %g, scale %g %g\n",*p,n_diagrams,x,y,x_size,x_size*y_scale); X printf("save 72 72 scale %g %g translate\n",x,y); X printf("%g %g scale save\n",x_size,x_size*y_scale); X printf("1 %d div 1 %d div scale\n",ps_box_size,ps_box_size); X printf("[] 0 setdash 1 setlinewidth\n"); X cat(*p); X printf("restore restore\n"); X /* fprintf(stderr,"i=%d x_pack=%d j=%d y_pack=%d\n",i,x_pack,j,y_pack); */ X if (++i max_size) { X max_size = x_size; X max_size_x_pack = x_pack; X max_size_y_pack = y_pack; X } X } X x_pack = max_size_x_pack; X y_pack = max_size_y_pack; X x_size = max_size; X if ((x_pack+1)*x_size <= page_width) x_pack++; X} X X/* X * return 1 if prefix is an unambigous prefix of the option 'word' X */ X Xprefix(prefix,word) Xchar *prefix,*word; X{ X int matches,len; X char **option; X len = strlen(prefix); X if (strncmp(prefix,word,len)) return 0; X if (strlen(word) == len) return 1; X /* we've got a prefix match, check for ambiguity */ X matches = 0; X option = options_description; X while (*option) { X if (option[0][0]=='-' && !strncmp(prefix,option[0]+1,len)) X matches++; X option++; X } X if (matches==1) return 1; X else return 0; X} X Xprint_options() X{ X char **p = options_description; X while (*p) printf("%s\n",*p++); X} X Xerror(s,p) X{ X char str[200]; X fprintf(stderr,sprintf(str,"%s: %s\n",my_name,s),p); X exit(1); X} END_OF_pswrap.c if test 6751 -ne `wc -c read_matrix.c <<'END_OF_read_matrix.c' X/*******************************************************\ X* * X* @(#)read_matrix.c 1/2/89 * X* Author: Tony Plate * X* Copyright (C) 1989 Tony Plate * X* This program may be freely distributed, * X* provided that this copyright notice is * X* retained intact. There is no warranty * X* with this software. * X* * X\*******************************************************/ X X#include X/* X * one function that will read in a matrix, (and allocate space for it) X */ X Xfloat *read_matrix(x_dim,y_dim) Xint *x_dim,*y_dim; X{ X float v,*matrix; X int x,y,r,stop; X int long_matrix = 0; /* true if we don't know the # of y lines */ X if (scanf(" %d",x_dim)!=1) { X fprintf(stderr,"read_matrix: couldn't read x dimensions\n"); X return NULL; X } X if (scanf(" *%c",&x)==1) { X long_matrix = 1; X } else if (scanf(" %d",y_dim)!=1) { X fprintf(stderr,"read_matrix: couldn't read y dimension\n"); X return NULL; X } X if (!long_matrix) { X if (*x_dim<=0 || *y_dim<=0) { X fprintf(stderr,"read_matrix: bad dimensions %d %d\n",*x_dim,*y_dim); X return NULL; X } X matrix = (float *) calloc(*x_dim * *y_dim , sizeof(float)); X if (matrix==NULL) { X fprintf(stderr,"read_matrix: can't allocate space\n"); X return NULL; X } X for (y=0;y<*y_dim;y++) X for (x=0;x<*x_dim;x++) X if (scanf(" %f",&v)!=1) { X fprintf(stderr,"read_matrix: can't read value row=%d,col=%d\n",y,x); X return NULL; X } else matrix[y*(*x_dim) + x] = v; X } else { X if (*x_dim<=0) { X fprintf(stderr,"read_matrix: bad x dimensions %d\n",*x_dim); X return NULL; X } X *y_dim = 1; X matrix = (float *) calloc(*x_dim * *y_dim , sizeof(float)); X if (matrix==NULL) { X fprintf(stderr,"read_matrix: can't allocate space\n"); X return NULL; X } X stop = 0; X for (y=0;!stop;y++) { X for (x=0;x<*x_dim;x++) { X if (scanf(" %f",&v)!=1) { X if (x!=0) { X fprintf(stderr,"read_matrix: can't read value row=%d,col=%d\n",y,x); X return NULL; X } else { X stop = 1; X break; X } X } else { X if (y==*y_dim) { X (*y_dim)++; X matrix = (float *) realloc(matrix,*x_dim * *y_dim * sizeof(float)); X if (matrix==NULL) { X fprintf(stderr,"read_matrix: can't reallocate space\n"); X return NULL; X } X } X matrix[y*(*x_dim) + x] = v; X } X } X } X } X return matrix; X} END_OF_read_matrix.c if test 2372 -ne `wc -c showfloat.c <<'END_OF_showfloat.c' X#include X#include "showfloat.h" X X/* X * sn(d) returns a three character representation of the floating point X * number 'd'. It just represents values between -1.0 & +1.0, it was X * designed so that probability matrices could be printed compactly. X * If a number is less than 0.1, but greater than or equal to 0.01, it is X * represented as :n (double decimal point) X * output d X * ^^ > 1.0 X * ++ = 1.0 100 % X * nn = 0.nn nn% X * .n = 0.00n n/10 of % X * :n = 0.000n n/100 of % X */ Xint sign(d) Xdouble d; X{ X if (d<0) return -1; X else return 1; X} X Xchar *sn(d) Xdouble d; X{ X char *res,c,p; X int i; X static char str[40]; X if (d < -1.0) res = " __"; X else if (d > 1.0) res = " ^^"; X else { X res = str; X i = 100 * (d + sign(d)*0.005); X if ((i != 0) && (fabs(d) >= 0.0095)) { X sprintf(str,"%3d",i); X if (i == 100) res = " =1"; X if (i == -100) res = "=-1"; X } X else { X i = 1000 * (d + sign(d)*0.0005); X p = '.'; X if (i==0 || fabs(d) < 0.00095) {p=':'; i = 10000 * (d+sign(d)*0.00005);} X c = ' '; X if (i < 0) { i = -i; c = '-'; } X sprintf(str,"%c%c%1d",c,p,i); X if (i == 0) res = " 0"; X } X } X return res; X} X Xchar *tn(x) Xdouble x; X{ X static char str[40]; X sprintf(str," %g",x); X return str; X} X X#ifdef MAIN Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X double x,atof(); X x = atof(argv[1]); X printf("%s == %s\n",sn(x),tn(x)); X} X#endif END_OF_showfloat.c if test 1479 -ne `wc -c stdoutpipe.c <<'END_OF_stdoutpipe.c' X/* X * like popen(command,"w"), except that stdout is out end of the pipe X */ X#include Xextern char *my_name; X Xstdoutpipe(argv,killme) Xchar *argv[]; Xint killme; X{ X int pipes[2]; X int r; X extern int errno; X extern char *sys_errlist[]; X int parent_pid = getpid(); X pipe(pipes); X if (pipe(pipes)!=0) { X fprintf(stderr,"%s: couldn't create pipe: %s\n",my_name,sys_errlist[errno]); X exit(1); X } X if (r=fork()) { X /* parent */ X if (r<0) { X fprintf(stderr,"%s: fork failed: %s\n",my_name,sys_errlist[errno]); X exit(1); X } X /* make stdout the write to the pipe */ X dup2(pipes[1],1); X } else { X /* child - make stdin come from the pipe */ X dup2(pipes[0],0); X execv(argv[0],argv); X fprintf(stderr,"%s: exec failed: %s: %s\n",my_name,argv[0],sys_errlist[errno]); X if (killme) kill(parent_pid,9); X exit(1); X } X} END_OF_stdoutpipe.c if test 868 -ne `wc -c surface.c <<'END_OF_surface.c' X/*******************************************************\ X* * X* @(#)surface.c 1/2/89 * X* Author: Tony Plate * X* Copyright (C) 1989 Tony Plate * X* This program may be freely distributed, * X* provided that this copyright notice is * X* retained intact. There is no warranty * X* with this software. * X* * X\*******************************************************/ X X/* X * read a matrix, and output it in one of 4 formats: X * The X and Y directions are used for the positions of values, the Z direction X * is used to represent the value. X */ X X#include X#include X#include X#include "read_matrix.h" X Xchar *options_description[] = { X"Options: (an unambiguous substring is sufficient)", X"-array : display as a matrix (same format as input)", X"-ascii : ascii format", X"-binary : binary output (default)", X"-brief : display as a matrix, using brief format numbers", X"-delimit : only take material from inside the", X" two lines containing the string ", X"-grid : draw 3d grid lines (default)", X"-help : display this information", X"-histogram : histogram style", X"-polygon : sqare polygons", X"-squaregrid : change the y upper bound so that the grid is square", X"-suppresstext : suppress text following the array", X"-transpose : transpose the x and y-axis", X"-triangle : triangular polygons", X"-unit : the input surface is in the XY unit square", X"-x : specify the X bounds of the input surface", X"-xlines : just draw the lines in the x-direction", X"-y : specify the Y bounds of the input surface", X"-ylines : just draw the lines in the y-direction", XNULL X}; X X X#define DB(X) Xenum {ARRAY,GRID,X_GRID,Y_GRID,BRIEF,TRIANGLES,SQUARES} output_format; Xint transpose=0; Xint histogram=0; Xint squaregrid=0; Xint text_follow=1; Xfloat xlow=0; Xfloat xhigh=0; Xfloat ylow=0; Xfloat yhigh=0; Xint x_dim,y_dim; X Xenum {ASCII,BINARY} number_format=BINARY; X#define LEN 16384 Xchar str[LEN]; X Xprint_options() X{ X char **p; X p = options_description; X while (*p) printf("%s\n",*p++); X} X X Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X int x,y,label_found; X char *p,*label,*my_name; X float *matrix; X my_name = argv[0]; X output_format = GRID; X label = NULL; X while (*(++argv)) { X p = argv[0]; X if (*p == '-') { X p++; X if (prefix(p,"array")) X output_format = ARRAY; X else if (prefix(p,"ascii")) X number_format = ASCII; X else if (prefix(p,"binary")) X number_format = BINARY; X else if (prefix(p,"brief")) X output_format = BRIEF; X else if (prefix(p,"delimit")) X label = *(++argv); X else if (prefix(p,"grid")) X output_format = GRID; X else if (prefix(p,"help")) { X print_options(); X exit(0); X } else if (prefix(p,"histogram")) X histogram = 1; X else if (prefix(p,"polygon")) X output_format = SQUARES; X else if (prefix(p,"transpose")) X transpose = 1; X else if (prefix(p,"triangle")) X output_format = TRIANGLES; X else if (prefix(p,"x")) { X if (argv[1]==NULL || argv[2]==NULL) { X fprintf(stderr,"%s: expected two numbers after -x\n",my_name); X exit(1); X } X xlow = atof(argv[1]); X xhigh = atof(argv[2]); X argv++; X argv++; X } else if (prefix(p,"y")) { X if (argv[1]==NULL || argv[2]==NULL) { X fprintf(stderr,"%s: expected two numbers after -y\n",my_name); X exit(1); X } X ylow = atof(argv[1]); X yhigh = atof(argv[2]); X argv++; X argv++; X } else if (prefix(p,"unit")) { X xlow = 0; xhigh = 1; X ylow = 0; yhigh = 1; X } else if (prefix(p,"xlines")) X output_format = X_GRID; X else if (prefix(p,"ylines")) X output_format = Y_GRID; X else if (prefix(p,"squaregrid")) X squaregrid = 1; X else if (prefix(p,"suppresstext")) X text_follow = 0; X else goto bad_option; X } else { X X bad_option: X fprintf(stderr,"%s: bad or ambiguous option: %s\nType \"%s -help\" to see list of options\n",my_name,argv[0],my_name); X exit(1); X } X } X if (label!=NULL) { X /* X * find the label string in the file X */ X label_found=0; X while (!label_found && fgets(str,LEN,stdin)!=NULL) X if (substring(label,str)) label_found=1; X if (!label_found) { X fprintf(stderr,"%s: label %s not in input\n",my_name,label); X exit(1); X } X } X if ((matrix = read_matrix(&x_dim,&y_dim))==NULL) exit(1); X if (xlow==0 && xhigh==0) xhigh = x_dim; X if (ylow==0 && yhigh==0) yhigh = y_dim; X if (squaregrid) { X yhigh = y_dim*(xhigh - xlow)/x_dim + ylow; X } X if (transpose) { X int old_x,old_y,i,start; X float tmp,new_tmp; X char *done; X done = (char*)calloc(x_dim,y_dim); X /* X * this is a difficult transpose to do in place, X * because the array may not be square. X * we do it by a permutation - work out where 0,1 goes, etc. X */ X start = 0; X while (start < x_dim*y_dim) { X i = start; X old_y = i / x_dim; X old_x = i % x_dim; X tmp = matrix[i]; X /* printf("(%d",i); */ X do { X done[i]++; X i = old_x * y_dim + old_y; X /* printf(",%d",i); */ X new_tmp = matrix[i]; X matrix[i] = tmp; X tmp = new_tmp; X old_y = i / x_dim; X old_x = i % x_dim; X } while (i!=start); X /* printf(")\n"); */ X while (done[start] && start0) { X point_next('m'); X for (x=0;x<=x_dim;x++) { X if (x>0) X point('n',x,y,matrix[(y-1)*x_dim + x-1]); X if (x0) point('n',x,y,matrix[y*x_dim + x-1]); X if (x0) { X point_next('m'); X for (y=0;y<=y_dim;y++) { X if (y>0) point('n',x,y,matrix[(y-1)*x_dim + x-1]); X if (y0) point('n',x,y,matrix[(y-1)*x_dim + x]); X if (yread_matrix.h <<'END_OF_read_matrix.h' X/*******************************************************\ X* * X* @(#)read_matrix.h 1/2/89 * X* Author: Tony Plate * X* Copyright (C) 1989 Tony Plate * X* This program may be freely distributed, * X* provided that this copyright notice is * X* retained intact. There is no warranty * X* with this software. * X* * X\*******************************************************/ Xfloat *read_matrix(); END_OF_read_matrix.h if test 430 -ne `wc -c showfloat.h <<'END_OF_showfloat.h' Xchar *sn(); /* sn(double) - returns a 3 char string, to represent X a number in the range -1.0 to +1.0. */ Xchar *tn(); /* returns and ordinary %g representation */ X END_OF_showfloat.h if test 193 -ne `wc -c