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

📄 ,mlplot.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 3 页
字号:
/*----------------------------------------------------------------------+|									||   This material contains proprietary software of Entropic Speech,	||   Inc.  Any reproduction, distribution, or publication without the	||   prior written permission of Entropic Speech, Inc. is strictly	||   prohibited.  Any public distribution of copies of this work		||   authorized in writing by Entropic Speech, Inc. must bear the	||   notice								||									|| "Copyright (c) 1986, 1987 Entropic Speech, Inc. All rights reserved."	||									|+-----------------------------------------------------------------------+|									||  mlplot -- plot ESPS Sampled-Data files in multiline format		||									||  Plots ESPS Sampled-Data files at fixed x-axis scale with continua-	||  tion on additional lines as needed to accommodate the data.		||  Permits integral number of device resolution units per unit		||  interval on the x-axis.						||  									||  authors:  Rodney W. Johnson,						||            Ajaipal S. Virdy, Entropic Speech, Inc.			||									|+----------------------------------------------------------------------*/#ifdef SCCS    static char *sccs_id = "%W%  %G%";#endif#include <stdio.h>#include <esps/esps.h>#include <esps/sd.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#define LBL_MAX 50/* * 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 in. * */#define DEF_PAGEHEIGHT 2400	/* pageheight set to 7.5 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 TAG_MAXLINES 3		/* draw 3 frames on a page */#define TAG_EXTRAV 144		/* leave extra space between frames for TAG */#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_TAG_CHARSP 24	/* tag character spacing */#define DEF_X_TTLBASE 75	/* x title base */#define DEF_Y_TTLBASE 35	/* y title base */#define DEF_HDRBASE 2135	/* header base *//* * 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	FACTOR		4	/* make plot 4 times as big as IMAGEN plot */#define	MC_U0	-31767;#define	MC_V0	-31767;int	P0 = MC_U0;int	Q0 = MC_V0;/* miscellanuous define's */#define	MAX_FILES   10#define	COM_CHARS   150		/* maximum characters that fit on a page (size 24) *//* * MACROS used in this program: */char	*ProgName = "mlplot";#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( \"mlplot [-D debug level][-a range][-m{cpv}][-p range][-l][-s start][-t int]\[-o outdir][-d device][-n]\[-x scale][-z][-P file.esps][-X title][-Y title][file.sd]")#define TRYALLOC(type,num,var) { \	(var) = (type *) malloc((unsigned)(num)*sizeof(type)); \	if ((var)==NULL) { Fprintf(stderr, \		"%s:  can't allocate memory for %d points.\n", \		ProgName, (int)(num)); \	exit(1); }}#define MIN(A,B) ((A)<=(B) ? (A) : (B))#define ABS(x)   ((x > 0) ? (x) : (-x))#define ROUND_OFF(A) ((A)>=0 ? (long)((A)+0.5) : -(long)(-(A)+0.5))#define DRAW(u1,v1,u2,v2, plotline) { \	long U[2], V[2]; \	U[0] = (u1); U[1] = (u2); V[0] = (v1); V[1] = (v2); \	(*plotline)((long) 2, U, V);}/* external functions referenced */long	atol();char	*calloc();void	exit();int	fflush();char	*getenv();char    *malloc();int	mkdir();void	perror();char	*strrchr();char	*strncpy();char	*get_cmd_line();void	lrange_switch();void	frange_switch();short	get_rec_len();short	get_gen_recd();/* G L O B A L   V A R I A B L E S */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 */int	num_of_files;	/* number of sampled data files to plot */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 sampled data file */double	*ylow;		/* minimum amplitude */double	*yhigh;		/* maximum amplitude */double	*yticint;	/* interval for marking tics on y-axis */double	*yscale;	/* y-axis scaling/division *//* global function declarations */double	*allo_gen_recd();void	gps_plotline();void	tek_plotline();void	tek_plotpoints();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	*sdfile[MAX_FILES];    char	*sdfilename[MAX_FILES];    char	*sdname;    FILE	*tagfile = NULL;    char	*tagfilename = NULL;    int		Pflag = 0;    struct header *hd[MAX_FILES];    struct header *th;    double	*tag_rec;    int		i = 0;		/* temporary index */    int		index;		/* index to data */    long	tag;    long	firstrec;	/* first record to plot */    long	lastrec;	/* last record to plot */    long	nrec;		/* number of records to plot */    long	i_file;		/* temporary file index */    long	start_index = 0;	/* offset starting index */    long	start[MAX_FILES];	/* offset starting record */    char	*prange = NULL;	/* range of samples to plot */    char 	*arange = NULL;	/* ampliude range */    int		aflag = 0;    int		ahi_flag = 0,		alo_flag = 0;    char	*device = "gps"; /* default output format */    int		gps = YES;	/* gps format (default) */    int		imagen = NO;	/* imagen format */    int		mode = M_CONN;	/* default mode for plotting points */    int		axflag = AXIS;	/* default: plot x-axis (y=0) */    double	alow = -DBL_MAX;	/* lower amplitude limit */    double	ahigh = DBL_MAX;	/* upper amplitude limit */    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;		/* number of samples to increment for each frame */    int		tag_eof;	/* flag for end-of-tagged-file */     int		nlines = 0;	/* current frame number being plot on a page */    int		line_num = 0;	/* current frame number being plot on a page */    int		maxlines = DEF_MAXLINES;	/* number of frames to plot on						   a page */    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;    long	vshift = DEF_VSHIFT;	/* distance between frames on a page */    long	lbl_charsp = DEF_LBL_CHARSP;    long	tag_charsp = DEF_TAG_CHARSP;    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 */    /* miscellaneous variables needed */    double	delta_y;    char	command_line[300];    char	*file_text;    int		continue_plotting = YES;    int		lflag = 0;    long	x_com_charsp = DEF_COM_CHARSP;    double	sample_range;    char	comtxt[300];    char	*tmptxt;    /* determine which function to use for plotting */    void	(*plotting_func)();    /* initialize arrays to zero */    for (i = 0; i < MAX_FILES; i++)	start[i] = 1;    Sprintf(command_line, "%% %s", get_cmd_line(argc, argv));    /* Parse command line.  Get options and determine input file. */    while ((ch = getopt(argc, argv, "a:m:p:P:s:t:x:zX:Y:d:D:o:nl")) != EOF)	switch (ch)	{	case 'a':	    arange = optarg;	    aflag++;	    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 's':	    start[start_index++] = atol(optarg);	    break;	case 'p':	    prange = optarg;	    break;	case 'P':	    tagfilename = optarg;	    Pflag++;	    break;	case 't':	    xticint = atol(optarg);	    break;	case 'x':	    xscale = atoi(optarg);	    break;	case 'z':	    axflag = NOAXIS;	    break;	case 'X':	    x_ttl_text = optarg;	    break;	case 'Y':	    y_ttl_text = optarg;	    break;	case 'd':	    device = optarg;	    break;	case 'D':	    debug_level = atoi(optarg);	    break;	case 'o':	    outdir = optarg;	    break;	case 'n':	    nflag++;	    break;	case 'l':	    lflag++;	    break;	default:	    SYNTAX;	    break;	}    num_of_files = argc - optind;    /* Read the headers. */    for (i_file = 0; i_file < num_of_files; i_file++)    {	if (i_file == 0)	{	    if (strcmp(argv[optind], "-") == 0)	    {		sdfilename[0] = "<stdin>";		sdfile[0] = stdin;	    }	    else		sdfilename[0] = argv[optind++];	} else	    sdfilename[i_file] = argv[optind++];	if (debug_level > 1)	{	    Fprintf(stderr, "%s: sdfilename[%d] is %s\n",	    ProgName, i_file, sdfilename[i_file]);	    (void) fflush(stderr);	}	if (strcmp(sdfilename[0], "<stdin>") != 0)	    TRYOPEN(ProgName, sdfilename[i_file], "r", sdfile[i_file])	if ((hd[i_file] = read_header(sdfile[i_file])) == NULL)	    NOTSPS(ProgName, sdfilename[i_file])	if (hd[i_file]->common.type != FT_SD)	    ERROR2(sdfilename[i_file], "is not a Sampled Data file.")    }    if (tagfilename != NULL)    {	if (strcmp(tagfilename, "-") != 0)	    {TRYOPEN(ProgName, tagfilename, "r", tagfile)}	else	{	    tagfilename = "<stdin>";	    tagfile = stdin;	}	if (debug_level > 0)	    Fprintf(stderr,	    "%s: Tagged file specified: %s\n", ProgName, tagfilename);	maxlines = TAG_MAXLINES;	v0 -= TAG_EXTRAV + ROUND_OFF(10 * hdr_charsp / 6.0);	vshift += TAG_EXTRAV;	if ((th = read_header(tagfile)) == NULL)	    NOTSPS(ProgName, tagfilename)	if (!th->common.tag)	    ERROR2(tagfilename, "is not tagged.")	if (num_of_files == 0)	{	    if (strcmp(th->variable.source[0], "<stdin>") != 0)		sdfilename[0] = th->variable.source[0];	    if (debug_level > 0)		Fprintf(stderr,		"%s: Sampled Data file specified: %s\n",		ProgName, sdfilename[0]);	    num_of_files = 1;	    TRYOPEN(ProgName, sdfilename[0], "r", sdfile[0])	    if ((hd[0] = read_header(sdfile[0])) == NULL)		NOTSPS(ProgName, sdfilename[0])	    if (hd[0]->common.type != FT_SD)		ERROR2(sdfilename[0], "is not a Sampled Data file.")	}    }    if ((num_of_files == 0) && !Pflag)    {	/* No sampled data file specifed and no tagged file named;	 * therefore, assume data will be piped through stdin.	 */	sdfilename[0] = "<stdin>";	sdfile[0] = stdin;	if ((hd[0] = read_header(sdfile[0])) == NULL)	    NOTSPS(ProgName, sdfilename[0])	if (hd[0]->common.type != FT_SD)	    ERROR2(sdfilename[0], "is not a Sampled Data file.")	num_of_files = 1;    }    if (debug_level > 0)	Fprintf(stderr,	"%s: number of ESPS Sampled Data files to process: %d\n",	ProgName, num_of_files);    if (num_of_files == 1)	sdname = sdfilename[0];    if (strcmp(device, "gps") == 0)    {	gps 	= YES;	imagen 	= NO;	plotting_func = gps_plotline;	if ((outdir == NULL) && nflag)	{	    Fprintf(stderr,	    "%s: conflicting options, no output will be generated.\n",	    ProgName);	    exit(1);	}	if (outdir != NULL)     /* output will be sent into a directory */	{	    if (debug_level > 2)	    {		Fprintf(stderr, "%s: making %s directory.\n",		    ProgName, outdir);		(void) fflush(stderr);	    }	    if (mkdir(outdir, 0777) != 0 )	    {		Fprintf(stderr, "%s: could not create %s directory.\n",		    ProgName, outdir);		exit(1);	    }	}	if (!nflag)	{	    if (debug_level > 2)		Fprintf(stderr,		"%s: outputing in MASSCOMP universe coordinate system.\n",		ProgName);	    (void) fflush(stderr);	}    }    else if (strcmp(device, "imagen") == 0 )    {	imagen = YES;	gps = NO;	plotting_func = tek_plotline;	if (debug_level > 1)	{	    Fprintf(stderr,	    "%s: output will be in Tektronix 4010 format for the IMAGEN.\n",	    ProgName);	    (void) fflush(stderr);	}	if (outdir != NULL)	{	    Fprintf(stderr,	    "%s: this version doesn't support writing into a directory.\n",	    ProgName);	    exit(1);	}	if (debug_level > 2)	{	    Fprintf(stderr, "%s: initializing IMAGEN Laser printer...\n",	    ProgName);	    (void) fflush(stderr);	}	init_tek_plot();    }    else if ((strcmp(device, "tek") == 0)	       || (strcmp(device, "tektronix") == 0))    {	imagen = YES;	gps = NO;	plotting_func = tek_plotline;    }    else    {	/* incorrect device name */	Fprintf(stderr,	    "%s: can only support gps, imagen, and tektronix devices for now.\n",	    ProgName);	exit(1);    }    /* get the range to be plotted */    firstrec = start[0];    lastrec = hd[0]->common.ndrec + start[0] - 1;    lrange_switch(prange, &firstrec, &lastrec, 0);    if (firstrec < start[0]) 	firstrec = start[0];    if (lastrec > hd[0]->common.ndrec + start[0] - 1) 	lastrec = hd[0]->common.ndrec + start[0] - 1;    nrec = lastrec - firstrec + 1;    if (debug_level > 1)	Fprintf(stderr,	"%s: firstrec = %ld, lastrec = %ld, nrec = %ld.\n",	ProgName, firstrec, lastrec, nrec);    (void) fflush(stderr);    if (aflag)    {	frange_switch(arange, &alow, &ahigh);

⌨️ 快捷键说明

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