📄 ,mlplot.c
字号:
exit(0);/*NOTREACHED*/} /* end main */double *allo_gen_recd(hd) struct header *hd;{ double *rec; TRYALLOC(double,get_rec_len(hd),rec) return rec;}drawaxes(ulow, vlow, xlow, ylow, deltax, deltay, xscale, yscale, xticint, yticint, charsp, axflag, line_plotter)long ulow;long vlow;long xlow;double ylow;long deltax;double deltay;long xscale;double yscale;long xticint;double yticint;long charsp;void (*line_plotter)(); /* pointer to a function, either tek_plotline or gps_plotline */{ long uhigh = ulow + deltax * xscale; long vhigh = vlow + ROUND_OFF(deltay * yscale); long vzero = vlow + ROUND_OFF(-ylow * yscale); long dx; double dy; long u; long v; char label[LBL_MAX]; double fmod(); /* draw a rectangular box which is the drawing frame */ DRAW(ulow, vlow, uhigh, vlow, line_plotter) DRAW(uhigh, vlow, uhigh, vhigh, line_plotter) DRAW(uhigh, vhigh, ulow, vhigh, line_plotter) DRAW(ulow, vhigh, ulow, vlow, line_plotter) if (axflag && vlow < vzero && vzero < vhigh) DRAW(ulow, vzero, uhigh, vzero, line_plotter) for ( dx = (xticint - 1) - (xlow + xticint - 1) % xticint; dx <= deltax; dx += xticint ) { u = ulow + dx * xscale; DRAW(u, vlow, u, vlow - ROUND_OFF(charsp/3.0), line_plotter) Sprintf(label, "%ld", xlow + dx); text( u - charsp*strlen(label)/2, vlow - 2*charsp, charsp, 0, label, line_plotter ); } for ( dy = 0; (v = vlow + ROUND_OFF(dy * yscale)) <= vhigh; dy += yticint ) { DRAW(ulow, v, ulow - ROUND_OFF(charsp/3.0), v, line_plotter)/* * This is the only line I changed. * It used to be %lg instead of %6.2g * */ Sprintf(label, "%lg", ylow + dy); text( ulow - charsp*strlen(label) - charsp/2, v - ROUND_OFF(charsp/3.0), charsp, 0, label, line_plotter ); }} /* end drawaxes() */#define HDR_MAX 250printheader(hdrleft, hdrright, hdrbase, charsp, sdname, tagname, xscale, line_plotter)long hdrleft;long hdrright;long hdrbase;long charsp;char *sdname;char *tagname;long xscale;void (*line_plotter)(); /* pointer to a function, either tek_plotline or gps_plotline */{ char hdrtxt[HDR_MAX];/* GLOBAL Variable referenced: page_num, num_of_files */ if (sdname != NULL) Sprintf(hdrtxt, "Sample file: %s (%d pixel%s/point) page %d", sdname, xscale, (xscale==1) ? "" : "s", page_num); else Sprintf(hdrtxt, "%d sampled data files plotted (%d pixel%s/point) page %d", num_of_files, xscale, (xscale==1) ? "" : "s", page_num); text(hdrleft, hdrbase, charsp, 0, hdrtxt, line_plotter); if (tagname != NULL) { Sprintf(hdrtxt, "Tagged file: %s", tagname); text(hdrleft, hdrbase - ROUND_OFF(10*charsp/6.0), charsp, 0, hdrtxt, line_plotter); } gettime(hdrtxt); text( hdrright - charsp*strlen(hdrtxt), hdrbase, charsp, 0, hdrtxt, line_plotter );} /* end printheader() */gettime(str)char *str;{ long time(); long tloc; char *ctime(); char *tptr; int i; (void) time(&tloc); tptr = ctime(&tloc); for (i=0; i<4; i++) str[i] = tptr[i+20]; for (i=4; i<17; i++) str[i] = tptr[i-1]; str[17] = '\0';}/* * The following DEFINE'S are for writing to a Tektronix 4010 device. * See Appendix A of MASSCOMP's * Data Presentation Application Programming Manual. */#define ESC '\033'#define FF '\014'#define GS '\035'#define US '\037'#define HI(A) (040 | ((07600 & (A)) >> 7))#define LOY(A) (0140 | ((0174 & (A)) >> 2))#define LOX(A) (0100 | ((0174 & (A)) >> 2))#define EXTRA(A,B) (0140 | ((03 & (B)) << 2) | (03 & (A)))voidtek_plotline(n, u, v)long n;long u[];long v[];{ long i; char hiy, loy, hix, lox, extra; char newhiy, newloy, newhix, newextra; if (n > 0) { putchar(GS); putchar(hiy = HI(*v)); putchar(extra = EXTRA(*u, *v)); putchar(loy = LOY(*v)); putchar(hix = HI(*u)); putchar(lox = LOX(*u)); if (n == 1) putchar(lox); for (i=2, u++, v++; i<=n; i++, u++, v++) { newhiy = HI(*v); if (newhiy != hiy) putchar(hiy = newhiy); newextra = EXTRA(*u, *v); newloy = LOY(*v); newhix = HI(*u); if (newextra != extra || newloy != loy || newhix != hix) { if (newextra != extra) putchar(extra = newextra); putchar(loy = newloy); if (newhix != hix) putchar(hix = newhix); } putchar(LOX(*u)); } putchar(US); }} /* end tek_plotline() */voidtek_plotpoints(n, u, v)long n;long u[];long v[];{ long i; char hiy, loy, hix, lox, extra; char newhiy, newloy, newhix, newextra; if (n > 0) { putchar(GS); putchar(hiy = HI(*v)); putchar(extra = EXTRA(*u, *v)); putchar(loy = LOY(*v)); putchar(hix = HI(*u)); putchar(lox = LOX(*u)); putchar(lox); for (i=2, u++, v++; i<=n; i++, u++, v++) { putchar(GS); newhiy = HI(*v); if (newhiy != hiy) putchar(hiy = newhiy); newextra = EXTRA(*u, *v); newloy = LOY(*v); newhix = HI(*u); if (newextra != extra || newloy != loy || newhix != hix) { if (newextra != extra) putchar(extra = newextra); putchar(loy = newloy); if (newhix != hix) putchar(hix = newhix); } putchar(lox = LOX(*u)); putchar(lox); } putchar(US); }} /* end tek_plotpoints() *//* * The following are macros and functions for writing Masscomp * UNIX Graphic Primitive String (GPS) commands. *//* Macros to pack data into the three graphic primitive word types that occur in a GPS metafile. Byte order is not necessarily correct for machines other than Masscomp. (Documentation on the GPS format is not clear on that point.) *//* PUT? writes to stdout */#define PUT1(A,B) {short sh_P = (A)<<12 | (B)&0x0fff; \ (void) fwrite((char*) &sh_P, sizeof(short), 1, stdout);}#define PUT2(A) {short sh_P = (A); \ (void) fwrite((char*) &sh_P, sizeof(short), 1, stdout);}#define PUT3(A,B) {short sh_P = (A)<<8 | (B)&0x00ff; \ (void) fwrite((char*) &sh_P, sizeof(short), 1, stdout);}/* FD_PUT? writes to file specified by outfp file pointer */#define FD_PUT1(A,B) {short sh_P = (A)<<12 | (B)&0x0fff; \ (void) fwrite((char*) &sh_P, sizeof(short), 1, outfp);}#define FD_PUT2(A) {short sh_P = (A); \ (void) fwrite((char*) &sh_P, sizeof(short), 1, outfp);}#define FD_PUT3(A,B) {short sh_P = (A)<<8 | (B)&0x00ff; \ (void) fwrite((char*) &sh_P, sizeof(short), 1, outfp);}/* Generate Masscomp Unix GPS line-drawing command. */#define MAX_POINTS 2046voidgps_plotline(n, u, v)long n; /* Number of points. */long u[], v[]; /* Vectors of horiz. & vert. coords. */{ int i, j, loop, residue; int npoints; /* number of points to plot *//* * GLOBAL Variables referenced: nflag, outdir, outfp, * P0, Q0, and FACTOR */ loop = n / MAX_POINTS + 1; residue = n % MAX_POINTS; for (j = 1; j <= loop; j++) { if (j == loop) npoints = residue; else npoints = MAX_POINTS; if ( !nflag ) PUT1(0, 2 + 2*npoints) /* Command code & length */ if ( outdir != NULL ) FD_PUT1(0, 2 + 2*npoints) /* Command code & length */ for (i = 1; i <= npoints; i++, u++, v++) { if ( !nflag ) { /* nflag suppresses output to stdout */ PUT2(*u * FACTOR + P0) /* x Point coordinates. */ PUT2(*v * FACTOR + Q0) /* y Point coordinates. */ } if ( outdir != NULL ) { /* write output into directory */ FD_PUT2(*u * FACTOR + P0) /* x Point coordinates. */ FD_PUT2(*v * FACTOR + Q0) /* y Point coordinates. */ } } if ( !nflag ) PUT3(20, 0) /* Bundle number. */ if ( outdir != NULL ) FD_PUT3(20, 0) /* Bundle number. */ } /* end for loop */} /* end procedure gps_plotline() *//* * * void * gps_plotpoints(n, u, v) * int n; * int u[], v[]; * { * int i; * PUT1(0, 2 + 2* n) * * for (i = 1; i <= n; i++) {PUT2(* u++) PUT2(* v++)} * PUT3(20, 0) * } * */gps_null_comment(f) FILE *f;{ if(f == stdout) PUT1(15, 1) else FD_PUT1(15, 1)}#define NEWSTROKE(p) ((p)&0200)#define LASTPOINT(p) ((p)&010)#define U_COORD(p) (((p)&0160) >> 4)#define V_COORD(p) ((p)&07)#define ST_MAX 50extern char *ascii[];text(u0, v0, sp, rot, str, line_plotter)long u0;long v0;long sp;int rot;char *str;void (*line_plotter)(); /* pointer to a function, either tek_plotline or gps_plotline */{ double sin(); double cos(); double theta, cosrot, sinrot; long u[ST_MAX], v[ST_MAX], u1 = u0, v1 = v0, usp, vsp, du, dv, lower, u_coord, v_coord; int ch; char *strokes, point; int i; theta = rot * 3.14159265358979323846/180; cosrot = cos(theta); sinrot = sin(theta); usp = ROUND_OFF(sp*cosrot); vsp = ROUND_OFF(sp*sinrot); du = ROUND_OFF(sp*cosrot/6); dv = ROUND_OFF(sp*sinrot/6); while ((ch = *str++) != '\0') { if (ch < ' ' || ch >= '\177') switch(ch) { case '\b': u1 -= usp; v1 -= vsp; break; default: break; } else { strokes = ascii[ch - ' ']; lower = *strokes++ == 'd' ? 2 : 0; u[0] = u1 + du; v[0] = v1 + dv; i = 1; do { point = *strokes++; if (NEWSTROKE(point)) { if (i > 1) (*line_plotter)((long) i, u, v); i = 0; } u_coord = U_COORD(point); v_coord = V_COORD(point) - lower; u[i] = u1 + du*u_coord - dv*v_coord; v[i] = v1 + dv*u_coord + du*v_coord; i++; } while (!LASTPOINT(point)); if (i > 1) (*line_plotter)((long) i, u, v); u1 += usp; v1 += vsp; } }} /* end text() */init_tek_plot() /* initialize the Imagen Laser Printer */{ (void) printf("@document(%s, %s, %s, %s)", "imagespace (0 3000 0 2400)", "imagesize (10.0 8.0)", "window (10.5 8.0)", "at (0.25 10.75 cc)" );}#define PATH_LEN 200 /* directory path length */init_gps_page(){ char name[PATH_LEN];/* * GLOBAL Variables referenced: * outdir, outfp, page_num and debug_level */ if (outdir != NULL) { Sprintf(name, "%s/page%d", outdir, page_num); if ( (outfp = fopen(name, "w")) == NULL ) ERROR2("could not open", name); if (debug_level > 3) Fprintf(stderr, "%s: init_gps_page: opening %s\n", ProgName, name); gps_null_comment(outfp); }}tek_termpage(){ putchar(ESC); putchar(FF);}allo_d_matrix(rows, columns)int rows;int columns;{ double **d_mat_alloc(); if ((data = (double **) d_mat_alloc(rows, columns)) == NULL ) { Fprintf(stderr, "mlplot: d_mat_alloc: could not allocate memory for matrix.\n"); exit(1); } if ((u = (long **) d_mat_alloc(rows, columns)) == NULL ) { Fprintf(stderr, "mlplot: d_mat_alloc: could not allocate memory for matrix.\n"); exit(1); } if ((v = (long **) d_mat_alloc(rows, columns)) == NULL ) { Fprintf(stderr, "mlplot: d_mat_alloc: could not allocate memory for matrix.\n"); exit(1); }}allo_d_array(rows) int rows;{ char *calloc(); if ((yhigh = (double *) calloc((unsigned) rows, sizeof(double))) == NULL) { Fprintf(stderr, "%s: calloc: could not allocate memory for array.\n", ProgName); exit(1); } if ((ylow = (double *) calloc((unsigned) rows, sizeof(double))) == NULL) { Fprintf(stderr, "%s: calloc: could not allocate memory for array.\n", ProgName); exit(1); } if ((yscale = (double *) calloc((unsigned) rows, sizeof(double))) == NULL) { Fprintf(stderr, "%s: calloc: could not allocate memory for array.\n", ProgName); exit(1); } if ((yticint = (double *) calloc((unsigned) rows, sizeof(double))) == NULL) { Fprintf(stderr, "%s: calloc: could not allocate memory for array.\n", ProgName); exit(1); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -