genplot.c
来自「speech signal process tools」· C语言 代码 · 共 1,724 行 · 第 1/3 页
C
1,724 行
/* * This material contains unpublished, proprietary software of * Entropic Research Laboratory, Inc. Any reproduction, distribution, * or publication of this work must be authorized in writing by Entropic * Research Laboratory, Inc., and must bear the notice: * * "Copyright (c) 1986-1990 Entropic Speech, Inc. * "Copyright (c) 1990-1996 Entropic Research Laboratory, Inc. * All rights reserved" * * The copyright notice above does not evidence any actual or intended * publication of this source code. * * Written by: Ajaipal S. Virdy * Checked by: * Revised by: * * Plot "generic" ESPS files in multiline format. * */static char *sccs_id = "@(#)genplot.c 3.9 1/18/97 ESI/ERL";#include <stdio.h>#include <ctype.h>#include <esps/unix.h>#include <esps/esps.h>#include <esps/sd.h>#include <esps/fea.h>#include <esps/esignal_fea.h>#include "genplot.h"#define PMODE 0640 /* default directory protection */#define M_CONN 1 /* default: connected lines on plot */#define M_POINT 2 /* plot individual data points */#define M_VERT 3 /* plot vertical lines connected to x-axis */#define NOAXIS 0 /* do not draw x-axis */#define AXIS 1 /* draw x-axis */#define CHR_GRID_TOP 7#define CHR_GRID_BOT -3#define CHR_GRID_RT 6/* * The following are *default* settings for the Imagen Laser Printer * with 300 dots/inch. Note: some of the settings can be changed by * command line options. * * U and V correspond to X and Y axes, respectively. * * The drawing frame is the rectangular box in which the graph is * plotted. * */#define DEF_PAGEHEIGHT 2400 /* pageheight set to 8.0 inches */#define DEF_PAGEWIDTH 3000 /* pagewidth set to 10.0 inches */#define DEF_DELTAV 400 /* height of drawing frame (rectangular box) */#define DEF_DELTAU 2400 /* width of drawing frame */#define DEF_U0 345 /* origin location for first frame */#define DEF_V0 1675 /* origin location for first frame */#define DEF_VSHIFT 500 /* difference between each frame origin */#define DEF_XTICINT 100 /* mark tics on abscissa every 100th sample */#define DEF_Y_SUBDIV 4 /* divide ordinate into 4 intervals */#define DEF_XSCALE 4 /* 4 pixels/point */#define DEF_MAXLINES 4 /* draw 4 frames on a page */#define DEF_TTL_CHARSP 30 /* title character spacing */#define DEF_COM_CHARSP 20 /* command line character spacing */#define DEF_LBL_CHARSP 24 /* label character spacing */#define DEF_X_TTLBASE 75 /* x title base */#define DEF_Y_TTLBASE 35 /* y title base */#define DEF_HDRBASE 2135 /* header base *//* * Type of functions to use (see -f option) */#define NONE 0#define SQRT 1#define LOG 2/* * The following defines apply to MASSCOMP Universe coordinate system. */#define MC_UNIVERSE 65535#define MC_REGION MC_UNIVERSE/5#define MC_U_ORIGIN -31767 /* horizontal coordinate */#define MC_V_ORIGIN -21592 /* vertical coordinate */#define MAX_PAGES 25 /* only 25 regions can be displayed */#define MC_U0 -31767;#define MC_V0 -31767;#define COM_CHARS 150 /* No. of characters of command line to */ /* put on one printed line. */#define MAX_COM_LEN 2*COM_CHARS /* Fit command on two printed lines. */#define COM_FMT "%% %.298s" /* Truncate string to MAX_COM_LEN, */ /* allowing two chars for initial "% ". *//* * MACROS used in this program: */#define ERROR(text) {Fprintf(stderr, "%s: %s\n", ProgName, text); exit(1);}#define ERROR2(text1,text2) {Fprintf(stderr, "%s: %s %s\n", \ ProgName, text1, text2); exit(1);}#define SYNTAX USAGE( \"genplot [-e range]... [-f function][-i range]... [-l int][-m{cpv}]\n\[-n][-o outdir][-r range][-s start][-t title][-x debug level][-y range]\n\[-z][-E][-T device][-V title][-X scale] file")#define TRYALLOC(type,num,var) { \ if (((var) = (type *) malloc((unsigned)(num)*sizeof(type)))==NULL) \ { Fprintf(stderr, "%s: can't allocate memory for %d points.\n", \ ProgName, (int)(num)); \ exit(1); }}/* math routines accessed */double sqrt();double log();/* ESPS functions referenced */int getopt();void lrange_switch();void frange_switch();long *grange_switch();long *fea_range_switch();short get_rec_len();int get_gen_recd();char *get_cmd_line();char *e_temp_name();/* G L O B A L V A R I A B L E S */char *ProgName = "genplot";int page_num; /* current page (region) being printed */char *outdir = NULL; /* write pages in this directory */FILE *outfp; /* file pointer for storing pages in directory */int nflag = 0; /* suppress output to stdout if this flag's set */char *device = "gps"; /* default output format */int gps = YES; /* gps format (default) */int tek = NO; /* tektronix format (incl. imagen) */int imagen = NO; /* imagen format */int debug_level = 0;long **u; /* x-coordinate value to plot in a drawing frame */long **v; /* y-coordinate value to plot in a drawing frame */double *data; /* array to store records read from an ESPS file */double *ylow; /* minimum ordinate */double *yhigh; /* maximum ordinate */double *yticint; /* interval for marking tics on y-axis */double *yscale; /* y-axis scaling/division */long P0 = MC_U0;long Q0 = MC_V0;double **Elem_Matrix; /* matrix to store records for each element */long *Tag_Array; /* array to store Tags for each element */char *func_codes[] = { "NONE", "SQRT", "LOG", NULL };char *env_bundle;int gps_bundle = 20;/* plotting functions */int gps_plotline();int tek_plotline();void tek_plotpoints();/* pointer to determine which function to use for plotting */int (*plotting_func)();/* * B E G I N * M A I N * P R O G R A M */main (argc, argv) int argc; char *argv[];{ extern int optind; /* used by getopt() */ extern char *optarg; /* used by getopt() */ int ch; /* used for parsing command line */ FILE *infile = stdin; char *infilename = "<stdin>"; struct header *hd; /* pointer to ESPS header for input file */ /* * C O M M A N D * L I N E * O P T I O N * * V A R I A B L E S * */ char *rrange = NULL; /* range of records to plot */ long firstrec; /* first record to plot */ long lastrec; /* last record to plot */ long nrec; /* number of records to plot */ long ndrec; /* number of records in file */ char *yrange = NULL; /* ordinate range */ int yflag = 0; int ahi_flag = 0, alo_flag = 0; double alow = -DBL_MAX; /* lower ordinate limit */ double ahigh = DBL_MAX; /* upper ordinate limit */ char *erange = "1"; /* element range */ int eflag = 0; /* default */ long first_ele; /* first element to plot */ long last_ele; /* last element to plot */ long *elem_array; long nelem = 1; char **fea_fields; /* field specification given with -e or -i */ char **fea_names; long *fea_indices; int nfld = 0; char *irange = NULL; /* item range */ int iflag = 0; long first_itm; long last_itm; long *item_array; long nitem = 0; int function_type = 0; /* type of function to use */ long start = 1; /* offset starting record */ int mode = M_CONN; /* default mode for plotting points */ int axflag = AXIS; /* default: plot x-axis (y=0) */ int Eflag = 0; /* plot element vs. tags */ /* * I N D I C E S * F O R * A R R A Y S * A N D * L O O P S */ int i, j; /* temporary indices */ int index; /* index to Elem_Matrix and Tag_Array */ long i_ele; /* temporary element index */ long tag; /* variable to store tags */ long x; /* temporary index */ long xmin; /* starting sample number for a frame */ long xmax; /* number of samples to plot in a frame */ long xlow; /* sample number at beginning of each frame */ long xinc; /* no. of samples to increment each frame */ int nlines = 0; /* frame number being plotted on a page */ int line_num = 0; /* frame number being plotted on a page */ /* number of frames to plot on a page */ int maxlines = DEF_MAXLINES; /* * V A R I A B L E S * U S E D * F O R * P L O T T I N G * */ long u0 = DEF_U0; /* x-coordinate of drawing frame */ long v0 = DEF_V0; /* y-coordinate of drawing frame */ long xticint = DEF_XTICINT; long xscale = DEF_XSCALE; long ulow; /* left border of drawing frame */ long vlow; /* bottom border of drawing frame */ long old_vlow; /* temporary variable */ long deltav = DEF_DELTAV; long deltau = DEF_DELTAU; /* distance between frames on a page */ long vshift = DEF_VSHIFT; /* character size for labeling text */ long lbl_charsp = DEF_LBL_CHARSP; /* variables for header information */ long hdrleft = 0; long hdrright = DEF_PAGEWIDTH; long hdr_charsp = DEF_TTL_CHARSP; long hdrbase = DEF_HDRBASE; long x_ttl_center = DEF_PAGEWIDTH/2; long x_ttl_base = DEF_X_TTLBASE; long x_ttl_charsp = DEF_TTL_CHARSP; long y_ttl_center = DEF_PAGEHEIGHT/2; long y_ttl_base = DEF_Y_TTLBASE; long y_ttl_charsp = DEF_TTL_CHARSP; char *x_ttl_text = ""; /* text string for labeling abscissa */ char *y_ttl_text = ""; /* text string for labeling ordinate */ /* * V A R I A B L E S * N E E D E D T O * I M P L E M E N T * * T H E -E O P T I O N * */ long old_xmin; double delta_y; int recd_num = 0; /* * M I S C E L L A N E O U S * V A R I A B L E S * */ char element_text[15]; int continue_plotting = YES; int rec_num; /* current record number */ int n_graphs = 1; /* no. of graphs to plot */ int n_points; /* no. of points to plot in a graph */ char command_line[MAX_COM_LEN+1]; /* "+1" for terminal null */ long x_com_charsp = DEF_COM_CHARSP; char comtxt[COM_CHARS+1]; /* "+1" for terminal null */ /* function to perform device initialization */ void initialize(); if ((fea_fields = (char **) calloc((unsigned) 1, sizeof(char *))) == NULL) { Fprintf(stderr, "%s: can't allocate memory for %d points.\n", ProgName, (int)(nfld + 1)); exit(1); } Sprintf(command_line, COM_FMT, get_cmd_line(argc, argv)); /* Parse command line. Get options and determine input file. */ while ((ch = getopt(argc, argv, "e:f:i:l:m:no:r:s:t:x:y:zET:V:X:")) != EOF) switch (ch) { case 'e': eflag = 1; if (isalpha(optarg[0])) { fea_fields[nfld++] = optarg; if ((fea_fields = (char **) realloc( (char *) fea_fields, (unsigned) (nfld + 1) * sizeof(char *) ) ) == NULL) { Fprintf(stderr, "%s: can't reallocate memory for %d points.\n", ProgName, (int)(nfld + 1)); exit(1); } fea_fields[nfld] = NULL; } else erange = optarg; break; case 'f': if ((function_type = lin_search(func_codes, optarg)) == -1) { Fprintf(stderr, "%s: unknown function type %s.\n", ProgName, optarg); exit(1); } if (debug_level > 0) Fprintf(stderr, "%s: function_type = %d, func_code = %s\n", ProgName, function_type, func_codes[function_type]); break; case 'i': iflag = 1; if (isalpha(optarg[0])) { fea_fields[nfld++] = optarg; if ((fea_fields = (char **) realloc( (char *) fea_fields, (unsigned) (nfld + 1) * sizeof(char *) ) ) == NULL) { Fprintf(stderr, "%s: can't reallocate memory for %d points.\n", ProgName, (int)(nfld + 1)); exit(1); } fea_fields[nfld] = NULL; } else irange = optarg; break; case 'l': xticint = atol(optarg); break; case 'm': switch (*optarg) { case 'p': mode = M_POINT; break; case 'c': mode = M_CONN; break; case 'v': mode = M_VERT; break; default: SYNTAX; break; } break; case 'n': nflag++; break; case 'o': outdir = optarg; break; case 'r': rrange = optarg; break; case 's': start = atol(optarg); break; case 't': x_ttl_text = optarg; break; case 'x': debug_level = atoi(optarg); break; case 'y': yrange = optarg; yflag++; break; case 'z': axflag = NOAXIS; break; case 'E': Eflag++; break; case 'T': device = optarg; break; case 'V': y_ttl_text = optarg; break; case 'X': xscale = atol(optarg); break; default: SYNTAX; break; } if (optind != argc - 1) SYNTAX; if (strcmp(argv[optind], "-") != 0) { infilename = argv[optind]; TRYOPEN(ProgName, infilename, "r", infile) } else { infilename = "<stdin>"; infile = stdin; } /* Read the header. */ if ((hd = read_header(infile)) == NULL) NOTSPS(ProgName, infilename) if (get_esignal_hdr(hd)) { ERROR("sorry, Esignal format not supported."); } if (!iflag && !eflag) eflag = 1; if (iflag && eflag) { Fprintf(stderr, "%s: conflicting options, -i and -e cannot be used together.\n", ProgName); exit(1); } if (nfld > 0 && hd->common.type != FT_FEA) ERROR("named fields allowed only with FEA files.") if ((hd->common.tag == NO) && Eflag) { Fprintf(stderr, "%s: data is not tagged; cannot use -E option.\n", ProgName); exit(1); } /* perform intialization */ (void) initialize(); if (gps) { env_bundle = getenv("BUNDLE"); if (env_bundle != NULL) gps_bundle = atoi(env_bundle); } /* get the range to be plotted */ ndrec = hd->common.ndrec; if (ndrec == -1) /* Input is a pipe. */ { char *mktemp(); char *tmp_file; /* temporary file name */ FILE *tmp_strm; /* temporary stream */ char *template = "genplotXXXXXX"; int recsize; char *tmp_buf; /* * We have to determine how many records exist * in stdin. We'll do this by writing stdin * into a temporary file. */ if (debug_level == 6)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?