📄 plotsd.c
字号:
/*--------------------------------------------------------------+| ENTROPIC PROCESSING, INC. || || This material contains proprietary software of Entropic || Processing, Inc. Any reproduction, distribution, or || publication without the the prior written permission of || Entropic Processing, Inc. is strictly prohibited. Any || public distribution of copies of this work authorized in || writing by Entropic Processing, Inc. must bear the notice || || "Copyright 1986 Entropic Processing, Inc." || |+---------------------------------------------------------------+| || plotsd -- plot sample data in a form suitable for plotas || || Joseph T. Buck, EPI || adapted from a program by Shankar Narayan. || Converted 1986 Apr 22 by Rod Johnson to read new SPS format. || Modified for SPS Common by Ajaipal S. Virdy on 9/2/86 || Modified for -m, -y, and -Y options by John Shore on 9/19/86 |+--------------------------------------------------------------*/#ifdef SCCS static char *sccs_id = "@(#)plotsd.c 1.7 12/17/86 EPI";#endif#include <stdio.h>#include <sps/sps.h>#include <sps/sd.h>#define SYNTAX USAGE("plotsd [-{ps} range] [-y range] [-Y range] [-m maxpoints] [-t text] file")#define MAX_FLOAT 1.0e38#define MIN_FLOAT -MAX_FLOAT#define MAXTEXT 10#define TRUE 1#define FALSE 0char *malloc();int atoi();void plotscale();main(argc, argv)int argc;char **argv;{ extern optind; extern char *optarg; int c; int nan; int start_p, last_p; int start_s, last_s; int beginplot, endplot; int xdp, ydp; int i, iy, numpoints; int maxpoints = 3000; /*maximum number of points to plot*/ /*if nan>maxpoints, points are skipped*/ int ntext = 0; int pflag = 0, yflag = 0, p_default=0, p_stat; int yexact = 0; char *srange = NULL; int sflag = 0; int isf; char *text[MAXTEXT]; char *prange = NULL; char *filename = NULL; float *data; int interval; double xmin, xmax; double ymin = -15000, ymax = 15000; float yminf, ymaxf; double xstep, ystep; FILE *istrm; struct header *h;/* parse command line for parameters */ while ((c = getopt(argc, argv, "p:s:t:y:Y:m:")) != EOF) switch (c) { case 'p': prange = optarg; pflag++; break; case 's': srange = optarg; sflag++; break; case 't': if (ntext < MAXTEXT) text[ntext++] = optarg; else { fprintf(stderr, "plotsd: Too many -t options\n"); exit(1); } break; case 'y': frange_switch(optarg, &ymin, &ymax); yflag++; break; case 'Y': frange_switch(optarg, &ymin, &ymax); yflag++; yexact = 1; break; case 'm': maxpoints = atoi(optarg); break; default: SYNTAX; } if (argc != optind) filename = argv[optind]; read_params(NULL,SC_CHECK_FILE,filename); if (filename == NULL) { if(symtype("filename") == ST_UNDEF) { (void)fprintf(stderr,"plotsd: no input file\n"); exit(1); } filename = getsym_s("filename"); } TRYOPEN("plotsd", filename, "r", istrm); if ((h = read_header(istrm)) == NULL) NOTSPS("plotsd", filename); if (h->common.type != FT_SD) { (void) fprintf (stderr, "plotsd: %s is not a sampled-data file.\n", filename); exit (1); } if (pflag && sflag) { (void) fprintf (stderr, "plotsd: conflicting options: -p and -s\n"); exit (1); } isf = h->hd.sd->sf; start_p = 1; last_p = h->common.ndrec; start_s = (start_p - 1) / isf; last_s = (last_p + isf - 1) / isf; if (!pflag && !sflag) { if (symtype("start") != ST_UNDEF) start_p = getsym_i("start"); if (symtype("nan") != ST_UNDEF) last_p = start_p+getsym_i("nan") - 1; } if (pflag) range_switch (prange, &start_p, &last_p, 0); if (sflag) { range_switch (srange, &start_s, &last_s, 0); start_p = start_s * isf + 1; last_p = last_s * isf; if (last_p <= start_p) last_p += isf; } if (start_p >= last_p){ fprintf(stderr, "plotsd: start point after end point!\n"); exit(1); } nan = last_p - start_p + 1; (void) putsym_s("filename",filename); (void) putsym_s("prog","plotsd"); (void) putsym_i("start",start_p); (void) putsym_i("nan",nan); #ifdef DEBUG(void) fprintf (stderr,"plotsd: start_p = %d, nan = %d, last_p = %d, filename = %s\n",start_p, nan, last_p, filename);#endif/* * Whew! * Begin program: * */#ifdef DEBUG(void) fprintf (stderr,"plotsd: wrote all symbols\n");#endif if (last_p > h->common.ndrec) { fprintf(stderr, "plotsd: only %d points in file\n", h->common.ndrec); exit(1); } skiprec(istrm, start_p - 1, size_rec(h)); if ( (data = (float *) malloc((unsigned) nan * sizeof(float)) ) == NULL ) { fprintf(stderr, "plotsd: can't allocate memory for %d data points\n", nan); exit(1); }#ifdef DEBUG(void) fprintf (stderr,"plotsd: getting sampled data record\n");#endif get_sd_recf(data, nan, h, istrm); if (nan < maxpoints || maxpoints == 0) { interval = 1; numpoints = nan; } else { interval = nan / maxpoints; numpoints = nan / interval; } if (!yflag) { yminf = MAX_FLOAT; ymaxf = MIN_FLOAT; for (i = 0; i < nan; i++) { if (data[i] < yminf) yminf = data[i]; else if (data[i] > ymaxf) ymaxf = data[i]; } ymin = (double) yminf; ymax = (double) ymaxf; }#ifdef DEBUG(void) fprintf (stderr,"plotsd: plotting points\n");#endif xmin = start_p; xmax = last_p; xstep = xmax; plotscale(xmin, xmax, 1.0, &xmin, &xmax, &xstep, &xdp); if (yexact) plotexscale(ymin, ymax, 1.0, &ymin, &ymax, &ystep, &ydp); else plotscale(ymin, ymax, 1.0, &ymin, &ymax, &ystep, &ydp); draw_box(xmin, xmax, xstep, xdp, ymin, ymax, ystep, ydp); printf("c 2\n"); plot_dataf(data, numpoints, xmin, xmax, ymin, ymax, start_p, interval); printf("c 5\nm 3400 500\nt 5 1\nFile: %s\n", filename); iy = 3600; for (i=0; i<ntext; i++) { printf("c 5\nm %d 500\nt 5 1\n%s\n", iy, text[i]); iy += 200; } print_time(200, 4400); if ( (beginplot = (int) xmin) == 0 ) beginplot = 1; endplot = (int) xmax; (void) putsym_i ("beginplot", beginplot); (void) putsym_i ("endplot", endplot); exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -