⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scatplot.c

📁 speech signal process tools
💻 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."           ||								|+---------------------------------------------------------------+|								|| scatplot - generate a scatter plot in a form suitable for	||	     plotas						||								|| by Ajaipal S. Virdy, EPI		  			|+--------------------------------------------------------------*/#ifdef SCCS    static char *sccs_id = "@(#)scatplot.c	1.1 1/6/87 EPI";#endif#include <stdio.h>#include <sps/sps.h>#include <sps/sd.h>#define SYNTAX USAGE("scatplot [-p range] [-e elements] [-s symbols] [-x range] [-y range] [-t text] [-X text] [-Y text] file1 file2 ...")#define MAX_FLOAT 1.0e38#define MIN_FLOAT -MAX_FLOAT#define	MAX_SYMBOLS 10#define	MAX_FILES 10#define MAXTEXT 1/* * The folling defines are the coordinates of the upper left hand corner * and the lower right corner which define the drawing frame. * * The coordinate system is defined as follows: * *		 *		--------------------------------- *		|(0,0)		      (0,lowerx)| *		|				| *		|				| *		|				| *		|	(y1,x1)			| *		|				| *		|				| *		|(lowery,0)	 (lowery,lowerx)| *		--------------------------------------> increasing x *		| *		| *		v increasing y * */#define	DEF_UPPER_X 600		/* this number shouldn't be modified */#define	DEF_UPPER_Y 600		/* this number shouldn't be modified */#define	DEF_LOWER_X 6000	/* this can be adjusted */#define	DEF_LOWER_Y 4100	/* this can be adjusted, also */#define	CHAR_SIZE 35#define	COM_CHARS 157	/* maximum number of characters that fit on a line */#define	TRUE	1#define FALSE	0#define	ODD(n)	((((n/2) * 2) == n) ? 0 : 1)int	atoi();char	*calloc();double	**d_mat_alloc();char	*get_cmd_line();long	*grange_switch();char	*malloc();void	plotscale();char	*savestring();char	*strncpy();int	strlen();extern int	optind;extern char	*optarg;char	*ProgName = "scatplot";main (argc, argv)int argc;char **argv;{    int		c;    /*     *  C O M M A N D     *  L I N E     *  O P T I O N S     */    char	*erange = NULL;    int		eflag = 0;    long	*elem_array;    long	nelem = 1;    char	*prange = NULL;    int		pflag = 0;    int		start_p, last_p;    int		nan;    int		xflag = 0;    int		yflag = 0;    char	symbol[MAX_FILES];    char	*symbols;    char	*default_str = "xo*abcdefghijkl";    int		nsym = 0;    int		sflag = 0;    char	*text[MAXTEXT];    int		ntext = 0;    int		tflag = 0;    char	*xtext = NULL;    char	Xflag = 0;    char	*ytext = NULL;    char	Yflag = 0;    int		debug_level = 0;    /*     * I N P U T     * F I L E S     *     */    char	*files[MAX_FILES];    FILE	*filep[MAX_FILES];    int		i_file;    int		nfiles;    struct header *h[MAX_FILES];    /*     * T E M P O R A R Y     * V A R I A B L E S     *     */    int		i;    int		iy;    int		xdp, ydp;    double	*data;    double	**xdata;    double	**ydata;    double	xmin[MAX_FILES], x_min, xlow;    double	xmax[MAX_FILES], x_max, xhigh;    double	ymin[MAX_FILES], y_min, ylow;    double	ymax[MAX_FILES], y_max, yhigh;    double	xstep, ystep;    /*     *  P L O T T I N G     *   V A R I A B L E S     */    int		upperx = DEF_UPPER_X;    int		uppery = DEF_UPPER_Y;    int		lowerx = DEF_LOWER_X;    int		lowery = DEF_LOWER_Y;    int		max_rec;    int		i_ele;    int		nchars;    int		plot_tags = NO;    long	tag;    char	command_line[300];    char	txtbuf[300];    char	*tmpptr;/* parse command line for parameters */    sprintf (command_line, "%% %s", get_cmd_line (argc, argv));    while ((c = getopt(argc, argv, "e:p:s:x:y:t:X:Y:Q:")) != EOF)	switch (c)         {	    case 'e':		erange = optarg;		if (eflag) {		   (void) fprintf (stderr,		   "%s: please give only one -e option.\n", ProgName);		   exit (1);		}		elem_array = grange_switch (erange, &nelem);		if ( ODD(nelem) ) {		   (void) fprintf (stderr,		   "%s: -e option: even number of elements required.\n",		   ProgName);		   exit (1);		}		eflag++;		break;	    case 'p':		prange = optarg;		pflag++;		break;	    case 's':		symbols = optarg;		nsym = strlen (symbols);		sflag++;		break;	    case 'x':		frange_switch (optarg, &x_min, &x_max);		xflag++;		break;	    case 'y':		frange_switch (optarg, &y_min, &y_max);		yflag++;		break;	    case 'X':		xtext = optarg;		Xflag++;		break;	    case 'Y':		ytext = optarg;		Yflag++;		break;	    case 't':		tflag++;	        if (ntext < MAXTEXT)		    text[ntext++] = optarg;		else                {		    fprintf(stderr, "plotsd: Too many -t options\n");		    exit(1);		}		break;	    case 'Q':		debug_level = atoi (optarg);		break;	    default:		SYNTAX;	}    if (!eflag) {	(void) fprintf (stderr,	"%s: please specify an element range with the -e option.\n",	ProgName);	exit (1);    }    for (i = 0; i < nelem; i++) {	if (debug_level > 5)	   (void) fprintf (stderr,	   "%s: elem_array[%d] = %ld\n", ProgName, i, elem_array[i]);	elem_array[i] -= 1;	if (elem_array[i] == -1)	   plot_tags = YES;    }    nfiles = argc - optind;    if (sflag)	if (nsym != nfiles) {	   (void) fprintf (stderr,	   "%s: -s option: please specify exactly %d symbols.\n",	   ProgName, nfiles);	   exit (1);	}    for (i_file = 0; i_file < nfiles; i_file++) {	if (i_file == 0) {	   if (strcmp (argv[optind], "-") == 0) {		files[0] = "<standard input>";		filep[0] = stdin;	   } else		files[0] = argv[optind++];	} else		files[i_file] = argv[optind++];	if (strcmp (files[0], "<standard input>") != 0)	   TRYOPEN (ProgName, files[i_file], "r", filep[i_file])	if ((h[i_file] = read_header (filep[i_file])) == NULL)	   NOTSPS (ProgName, files[i_file])	if (sflag)	   symbol[i_file] = *symbols++;	else	   symbol[i_file] = *default_str++;	if (plot_tags)	   if (h[i_file]->common.tag == NO) {		(void) fprintf (stderr,		"%s: data is not tagged in %s, cannot plot element 0.\n",		ProgName, files[i_file]);		exit (1);	   }	if (debug_level > 1) {	   (void) fprintf (stderr,	   "%s: files[%d] is %s, symbol is %c\n",	   ProgName, i_file, files[i_file], symbol[i_file]);	   fflush (stderr);	}    }  /* end for (i_file = 0; i_file < nfiles; i_file++) */    start_p = 1;    last_p = h[0]->common.ndrec;    if (pflag) range_switch (prange, &start_p, &last_p, 0);    if (start_p > last_p){	(void) fprintf (stderr,	"%s: start point after end point.\n", ProgName);	exit(1);    }    nan = last_p - start_p + 1;    if (debug_level > 3) {	(void) fprintf (stderr,	"%s: start_p = %d, nan = %d, last_p = %d\n",	ProgName, start_p, nan, last_p);    }    for (i_file = 0; i_file < nfiles; i_file++) {	if (i_file == 0)	   max_rec = get_rec_len (h[i_file]);	else if (get_rec_len (h[i_file]) > max_rec)		max_rec = get_rec_len (h[i_file]);	if (last_p > h[0]->common.ndrec)	{	   (void) fprintf(stderr, "%s: only %d points in %s\n",	   ProgName, h[i_file]->common.ndrec, files[i_file]);	   exit(1);	}	skiprec (filep[i_file], start_p - 1, size_rec(h[i_file]));    }    if (debug_level > 2) {	(void) fprintf (stderr,	"%s: allocating data for %d (max_rec) points.\n",	ProgName, max_rec);    }/* * Allocate memory for data, xdata and ydata. * * data is an array of size max_rec, * xdata and ydata are matrices of size nfiles by nan. * */    if ((data = (double *) calloc (max_rec, sizeof(double))) == NULL )    {	(void) fprintf (stderr,	"%s: calloc: can't allocate memory for %d data points\n",	ProgName, max_rec);	exit (1);    }    if ((xdata = (double **) d_mat_alloc (nfiles, nan)) == NULL) {	(void) fprintf (stderr,	"%s: d_mat_alloc: could not allocate memory for xdata.\n",	ProgName);	exit (1);    }    if ((ydata = (double **) d_mat_alloc (nfiles, nan)) == NULL) {	(void) fprintf (stderr,	"%s: d_mat_alloc: could not allocate memory for ydata.\n",	ProgName);	exit (1);    }    if (debug_level > 2) {	(void) fprintf (stderr,	"%s: getting data record from input files\n", ProgName);    }    for (i = 0; i < nan; i++) {	for (i_file = 0, i_ele = 0; i_file < nfiles; i_file++, i_ele += 2) {	    if (get_gen_recd (data, &tag, h[i_file], filep[i_file]) == EOF)	    {		(void) fprintf (stderr,		"%s: only %d records read in %s\n",		ProgName, i, files[i_file]);		exit (1);	    }	    if (i_ele >= nelem)		i_ele = nelem - 2;	    if (elem_array[i_ele] == -1)		xdata[i_file][i] = tag;	    else		xdata[i_file][i] = data[elem_array[i_ele]];	    if (elem_array[i_ele + 1] == -1)		ydata[i_file][i] = tag;	    else		ydata[i_file][i] = data[elem_array[i_ele + 1]];	   if (xflag) {		xmin[i_file] = x_min;		xmax[i_file] = x_max;	   }	   else	      if (i == 0)		 xmin[i_file] = xmax[i_file] = xdata[i_file][i];	      else		if (xdata[i_file][i] < xmin[i_file])		   xmin[i_file] = xdata[i_file][i];		else		  if (xdata[i_file][i] > xmax[i_file])		     xmax[i_file] = xdata[i_file][i];	   if (yflag) {		ymin[i_file] = y_min;		ymax[i_file] = y_max;	   }	   else	      if (i == 0)		 ymin[i_file] = ymax[i_file] = ydata[i_file][i];	      else		if (ydata[i_file][i] < ymin[i_file])		   ymin[i_file] = ydata[i_file][i];		else		  if (ydata[i_file][i] > ymax[i_file])		     ymax[i_file] = ydata[i_file][i];	    if (debug_level > 8)		(void) fprintf (stderr,		"%s: i = %d, i_file = %d, i_ele = %d\nxdata = %g, ydata = %g\nxmin = %g, ymin = %g\n\n",		ProgName, i, i_file, i_ele, xdata[i_file][i],		ydata[i_file][i], xmin[i_file], ymin[i_file]);	}  /* end for (i_file = 0; i_file < nfiles; i_file++) */    }  /* end for (i = 0; i < nan; i++) */    if (debug_level > 3)	(void) fprintf (stderr,	"%s: plotting points\n", ProgName);    for (i_file = 0; i_file < nfiles; i_file++) {	if (debug_level > 3)	   (void) fprintf (stderr,	   "%s: i_file = %d, xmin = %g, xmax = %g, ymin = %g, ymax = %g\n",	   ProgName, i_file, xmin[i_file], xmax[i_file],	   ymin[i_file], ymax[i_file]);	xlow = xmin[i_file];	xhigh = xmax[i_file];	xstep = xhigh;	ylow = ymin[i_file];	yhigh = ymax[i_file];	if (xlow == xhigh) {	   (void) fprintf (stderr,	   "\n\n%s: fatal error: constant element in %s at element %d.\n",	   ProgName, files[i_file], elem_array[i_file * 2] + 1);	   (void) fprintf (stderr,	   "%s: please use the -x option", ProgName);	   if (ylow == yhigh)		(void) fprintf (stderr,	" and the -y option.\n");	   exit (1);	}	if (ylow == yhigh) {	   (void) fprintf (stderr,	   "\n\n%s: fatal error: constant element in %s at element %d.\n",	   ProgName, files[i_file], elem_array[i_file * 2 + 1] + 1);	   (void) fprintf (stderr,	   "%s: please use the -y option.\n", ProgName);	   exit (1);	}	if (xflag)	   plotexscale(xlow, xhigh, 1.0, &xlow, &xhigh, &xstep, &xdp);	else	   plotscale(xlow, xhigh, 1.0, &xlow, &xhigh, &xstep, &xdp);	if (yflag)	   plotexscale(ylow, yhigh, 1.0, &ylow, &yhigh, &ystep, &ydp);	else	   plotscale(ylow, yhigh, 1.0, &ylow, &yhigh, &ystep, &ydp);	if (i_file == 0) {	   draw_box(xlow, xhigh, xstep, xdp, ylow, yhigh, ystep, ydp,		    upperx, uppery, lowerx, lowery);	   printf("c 2\n");	}	plot_letter (xdata[i_file], ydata[i_file], nan, 5,		     xlow, xhigh, ylow, yhigh, symbol[i_file],		     upperx, uppery, lowerx, lowery);    }    /*     * Print command line on top of page.     * Break up the line into two lines if it is greater than COM_CHARS     * characters long.     */    if (strlen (command_line) > COM_CHARS) {	printf ("c 5\nm 375 %d\nd 375 %d\n", upperx, lowerx);	strncpy (txtbuf, command_line, COM_CHARS);	txtbuf[COM_CHARS] = '\0';	tmpptr = &command_line[COM_CHARS];	printf ("c 5\nm 300 %d\nt 2 1\n%s\n", upperx, txtbuf);	if (strlen (tmpptr) > COM_CHARS)	   (void) fprintf (stderr,	   "%s: command line too long: truncating string.\n",	   ProgName);	printf ("c 5\nm 350 %d\nt 2 1\n%s\n", upperx, tmpptr);    } else {	printf ("c 5\nm 325 %d\nd 325 %d\n", upperx, lowerx);	printf ("c 5\nm 300 %d\nt 2 1\n%s\n", upperx, command_line);    }    /*     * If the -t option was given, place the text above the graph,     * otherwise print the default string there.  Likewise for the     * -X and -Y options.     */    if (tflag)	printf ("c 5\nm 500 %d\nt 5 1\n%s\n", upperx, text[0]);    else	if (nfiles > 1)	   printf ("c 5\nm 500 %d\nt 5 1\nScatter Plot of %d SPS Files\n",	   upperx, nfiles); 	else	   printf ("c 5\nm 500 %d\nt 5 1\nFile: %s\n", upperx, files[0]);    if ( !Xflag ) {	if (nelem == 2)	   if (elem_array[0] == -1)	      xtext = savestring ("tag");	   else {	      sprintf (txtbuf, "element%ld\n", elem_array[0] + 1);	      xtext = savestring (txtbuf);	   }    }    nchars = strlen (xtext);    printf ("c 5\nm %d %d\nt 5 1\n", lowery + 350,    (lowerx - upperx) / 2 + upperx - nchars * CHAR_SIZE);    printf ("%s\n", xtext);    if ( !Yflag ) {	if (nelem == 2)	   if (elem_array[1] == -1)	      ytext = savestring ("tag");	   else {	      sprintf (txtbuf, "element%ld\n", elem_array[1] + 1);	      ytext = savestring (txtbuf);	   }    }    nchars = strlen (ytext);    printf ("c 5\nm %d 90\nt 5 2\n",    (lowery - uppery) / 2 + uppery + nchars * CHAR_SIZE);    printf ("%s\n", ytext);    print_time(500, 4600);    exit(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -