📄 pplain.c
字号:
/* pplain - print data from SPS file in "plain" format * * 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) 1987 Entropic Speech, Inc.; All rights reserved" * * Author: Joseph T. Buck, Entropic Speech, Inc. * Purpose: good for programs that expect data in ASCII * converted from the ESPS program of the same name * Usage: pplain [-i] [-rrange] [-erange] file * Notes: If the file has tags, element 0 counts as the tag * * Updated by: Ajaipal S. Virdy, Entropic Speech, Inc. * */#ifndef lint static char *sccs_id = "@(#)pplain.c 1.3 7/16/87 ESI";#endif#include <stdio.h>#include <ctype.h>#include <esps/esps.h>#define SYNTAX USAGE("pplain [-r range] [-e grange] [-i] file")char *Program = "pplain";char *in_file = "<stdin>";char *calloc();void exit();void perror();long *grange_switch();int get_gen_recd();short get_rec_len();extern optind;extern char *optarg;main (argc, argv)int argc;char **argv;{ int c; FILE *istrm = stdin; struct header *h; long i_ele, s_ele, e_ele; int tags, ldrec, tag_ele; long pos, irec, s_rec, e_rec; char *r_range = NULL; char *e_range = NULL; int e_flag = 0; char *format = "%g "; double *data; /* array to store data from get_gen_recd(3-ESPS) */ long *elem_array; /* array containing elements to print */ long n_elems = 0; /* number of elements to print */ int debug_level = 0; while ((c = getopt (argc, argv, "x:r:e:i:")) != EOF) { switch (c) { case 'x': debug_level = atoi (optarg); break; case 'r': r_range = optarg; break; case 'e': e_range = optarg; if (!isdigit(e_range[strlen(e_range)-1])) { Fprintf (stderr, "%s: please specify last element explicitly.\n", Program); exit (1); } elem_array = grange_switch (e_range, &n_elems); e_flag++; break; case 'i': format = "%.0f "; break; default: SYNTAX; } } if (debug_level > 5) { Fprintf (stderr, "%s: open file and read header.\n", Program); } if (argc > optind && strcmp (argv[optind], "-") != 0) { TRYOPEN (Program, argv[optind], "r", istrm); in_file = argv[optind]; } if ((h = read_header (istrm)) == NULL) { NOTSPS (Program, in_file); } if (debug_level > 4) { Fprintf (stderr, "%s: file opened, header read; now parse record range if given.\n", Program); } s_rec = 1; e_rec = h -> common.ndrec; lrange_switch (r_range, &s_rec, &e_rec, 1);/* * Old Method: * bel = 1; * eel = ldrec; * range_switch (e_range, &bel, &eel, 1); */ if (debug_level > 0) { Fprintf (stderr, "%s: now parse element range if given.\n", Program); } if (e_flag) { s_ele = elem_array[0]; e_ele = elem_array[n_elems - 1]; } else { s_ele = 1; e_ele = get_rec_len (h); } ldrec = get_rec_len (h); if (debug_level > 0) { Fprintf (stderr, "%s: s_ele = %ld, e_ele = %ld, ldrec = %ld\n", Program, s_ele, e_ele, ldrec); Fprintf (stderr, "%s: now allocate memory for data (%ld doubles).\n", Program, n_elems); } if ((data = (double *) calloc ((unsigned) ldrec, sizeof (double))) == NULL) { Fprintf (stderr, "%s: calloc: could not allocate memory for data.\n", Program); exit (1); } if (debug_level > 5) { Fprintf (stderr, "%s: memory allocated for data.\n", Program); }/* * Old Restriction: * * if (nelems > MAXL) { * Fprintf (stderr, "%s: maximum records which can be printed is %d\n", * Program, MAXL); * exit (1); * } */ tags = BOOL (h -> common.tag); if (debug_level > 5) { Fprintf (stderr, "%s: data is%s tagged, now check validity of ranges given.\n", Program, (tags == 1 ? "" : " not")); } if (s_rec <= 0 || e_rec > h -> common.ndrec) { Fprintf (stderr, "%s: record range in %s is 1 to %d\n", Program, in_file, h -> common.ndrec ); exit (1); } if (!tags && (s_ele == 0)) { Fprintf (stderr, "%s: no tags in %s; cannot print element 0.\n", Program, in_file); exit (1); } if (e_ele > ldrec) { Fprintf (stderr, "%s: only %d elements per record in %s\n", Program, ldrec, in_file); exit (1); } if (debug_level > 3) { Fprintf (stderr, "%s: skip %d records.\n", Program, s_rec - 1); }/* The cast here should not be necessary; skiprec should take a long */ skiprec (istrm, (int) (s_rec - 1), size_rec (h));/* * Old Method: * See comment below on belm1 * * belm1 = bel - 1; * if (belm1 < 0) * belm1 = 0; */ if (s_ele == 0) /* print tags */ tag_ele = 1; /* begin printing data from index 1 in elem_array */ else /* do not print tags */ tag_ele = 0; /* begin printing data from index 0 in elem_array */ if (debug_level > 3) { Fprintf (stderr, "%s: tag_ele = %d, now process main loop.\n", Program, tag_ele); } for (irec = s_rec; irec <= e_rec; irec++) { get_gen_recd (data, &pos, h, istrm); if (s_ele == 0) (void) printf ("%ld ", pos); if (e_flag) for (i_ele = tag_ele; i_ele < n_elems; i_ele++) (void) fprintf (stdout, format, data[elem_array[i_ele] - 1]); else for (i_ele = s_ele; i_ele <= e_ele; i_ele++) (void) fprintf (stdout, format, data[i_ele - 1]); (void) fputs ("\n", stdout); } exit (0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -