📄 spstoa.c
字号:
/* sps to ascii converter. Converts an sps data file to an ascii file * suitable for mailing or movement across different machine types. * Original program by Joe Buck, modified for SPS by Alan Parker. * * 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." * */#ifdef SCCS static char *sccs_id = "@(#)spstoa.c 1.3 5/6/86 EPI";#endif#include <stdio.h>#include <sps/sps.h>#include "tagdef.h"char *Program = "spstoa";char *in_file = "<stdin>";char *cvt_tt();main (argc, argv)char **argv;{ FILE * istrm = stdin, *ostrm = stdout; struct header *h; register int i; if (argc > 1 && strcmp (argv[1], "-") != 0) { TRYOPEN (Program, argv[1], "r", istrm); in_file = argv[1]; } if (argc > 2 && strcmp (argv[2], "-") != 0) { TRYOPEN (Program, argv[2], "w", ostrm); } if ((h = read_header (istrm)) == NULL) { NOTSPS (Program, in_file); } dumphead (ostrm, h, 1); (void) fflush (ostrm); for (i = 0; i < h->common.ndrec; i++) dumprec (istrm, ostrm, h); exit (0);}dumphead (o, h, first)register FILE * o;register struct header *h;int first;{ register int i; char sbuf[100];/* Headers start with { and end with }, and may be nested */ fprintf (o, "{\n");/* * common part of header */ fprintf (o, "%02x %x\n", TAG_type, h->common.type); fprintf (o, "%02x %x\n", TAG_check, h->common.check); if (h->common.date[0]) fprintf (o, "%02x %.26s\n", TAG_date, h->common.date); if (h->common.hdvers[0]) fprintf (o, "%02x %.8s\n", TAG_hdvers, h->common.hdvers); if (h->common.prog[0]) fprintf (o, "%02x %.16s\n", TAG_prog, h->common.prog); if (h->common.vers[0]) fprintf (o, "%02x %.8s\n", TAG_vers, h->common.vers); if (h->common.progdate[0]) fprintf (o, "%02x %.26s\n", TAG_progdate, h->common.progdate); if (h->common.ndrec) fprintf (o, "%02x %x\n", TAG_ndrec, h->common.ndrec); if (h->common.tag) fprintf (o, "%02x %x\n", TAG_tag, h->common.tag); if (h->common.ndouble) fprintf (o, "%02x %x\n", TAG_ndouble, h->common.ndouble); if (h->common.nfloat) fprintf (o, "%02x %x\n", TAG_nfloat, h->common.nfloat); if (h->common.nlong) fprintf (o, "%02x %x\n", TAG_nlong, h->common.nlong); if (h->common.nshort) fprintf (o, "%02x %x\n", TAG_nshort, h->common.nshort); if (h->common.nchar) fprintf (o, "%02x %x\n", TAG_nchar, h->common.nchar); for (i=0; i<NSPARES && h->common.spares[i]; i++) fprintf (o, "%02x %x\n%x\n", TAG_spare, i, h->common.spares[i]);/* * variable part of header */ for (i = 0; i < MAX_SOURCES && h->variable.source[i]; i++) fprintf (o, "%02x %s\n", TAG_source, h->variable.source[i]); if (h->variable.typtxt) fprintf (o, "%02x %s\n", TAG_typtxt, cvt_tt (h->variable.typtxt)); if (first == 1) { sprintf (sbuf, "Converted from %s by spstoa.\n",in_file); add_comment(h,sbuf); } if (h->variable.comment) fprintf (o, "%02x %s\n", TAG_comment, cvt_tt (h->variable.comment)); if (h->variable.refer) fprintf (o, "%02x %s\n", TAG_refer, h->variable.refer);/* * type specific part of header */ switch (h->common.type) { case FT_ANA: fprintf(o, "%02x %x\n", TAG_start, h->hd.ana->start); fprintf(o, "%02x %x\n", TAG_nan, h->hd.ana->nan); fprintf(o, "%02x %x\n", TAG_frmlen, h->hd.ana->frmlen); fprintf(o, "%02x %x\n", TAG_order_vcd, h->hd.ana->order_vcd); fprintf(o, "%02x %x\n", TAG_order_unvcd, h->hd.ana->order_unvcd); fprintf(o, "%02x %x\n", TAG_p_offset, h->hd.ana->p_offset); fprintf(o, "%02x %x\n", TAG_piq_method, h->hd.ana->piq_method); fprintf(o, "%02x %x\n", TAG_rcq_method, h->hd.ana->rcq_method); fprintf(o, "%02x %x\n", TAG_pwq_method, h->hd.ana->pwq_method); fprintf(o, "%02x %x\n", TAG_lpq_method, h->hd.ana->lpq_method); fprintf(o, "%02x %x\n", TAG_win_type, h->hd.ana->win_type); fprintf(o, "%02x %x\n", TAG_coh_method, h->hd.ana->coh_method); fprintf(o, "%02x %.7g\n", TAG_src_sf, h->hd.ana->src_sf); fprintf(o, "%02x %x\n", TAG_a_method, h->hd.ana->a_method); fprintf(o, "%02x %.7g\n", TAG_dcrem, h->hd.ana->dcrem); fprintf(o, "%02x %x\n", TAG_psynch, h->hd.ana->psynch); fprintf(o, "%02x %x\n", TAG_maxpulses, h->hd.ana->maxpulses); fprintf(o, "%02x %x\n", TAG_maxlpc, h->hd.ana->maxlpc); fprintf(o, "%02x %x\n", TAG_maxraw, h->hd.ana->maxraw); fprintf(o, "%02x %x\n", TAG_matsiz, h->hd.ana->matsiz); fprintf(o, "%02x %g\n", TAG_rms_fullscale, h->hd.ana->rms_fullscale); fprintf(o, "%02x %x\n", TAG_sinc_flg, h->hd.ana->sinc_flg); for (i=0; i<ANA_SPARES && h->hd.ana->spares[i]; i++) fprintf (o, "%02x %x\n%x\n", TAG_spare, i, h->hd.ana->spares[i]); if (h->hd.ana->pre_emp) dump_z(o, TAG_pre_emp, h->hd.ana->pre_emp); break; case FT_PIT: fprintf(o, "%02x %x\n", TAG_start, h->hd.pit->start); fprintf(o, "%02x %x\n", TAG_nan, h->hd.pit->nan); fprintf(o, "%02x %x\n", TAG_stepsz, h->hd.pit->stepsz); fprintf(o, "%02x %x\n", TAG_u_pflt_order, h->hd.pit->u_pflt_order); fprintf(o, "%02x %x\n", TAG_v_pflt_order, h->hd.pit->v_pflt_order); fprintf(o, "%02x %x\n", TAG_win_type, h->hd.pit->win_type); fprintf(o, "%02x %x\n", TAG_coh_method, h->hd.pit->coh_method); fprintf(o, "%02x %.7g\n", TAG_src_sf, h->hd.pit->src_sf); fprintf(o, "%02x %x\n", TAG_dcrem, h->hd.pit->dcrem); fprintf(o, "%02x %x\n", TAG_p_method, h->hd.pit->p_method); fprintf(o, "%02x %x\n", TAG_pt_wsize, h->hd.pit->pt_wsize); fprintf(o, "%02x %g\n", TAG_uv_thresh, h->hd.pit->uv_thresh); fprintf(o, "%02x %x\n", TAG_min_pp, h->hd.pit->min_pp); fprintf(o, "%02x %x\n", TAG_max_pp, h->hd.pit->max_pp); fprintf(o, "%02x %x\n", TAG_wflt_order, h->hd.pit->wflt_order); fprintf(o, "%02x %g\n", TAG_coh_window_frac, h->hd.pit->coh_window_frac); fprintf(o, "%02x %x\n", TAG_pb_offset, h->hd.pit->pb_offset); fprintf(o, "%02x %g\n", TAG_harmonic_mult, h->hd.pit->harmonic_mult); fprintf(o, "%02x %g\n", TAG_tm_uv_thresh, h->hd.pit->tm_uv_thresh); fprintf(o, "%02x %g\n", TAG_am_uv_thresh, h->hd.pit->am_uv_thresh); fprintf(o, "%02x %g\n", TAG_hp_thresh, h->hd.pit->hp_thresh); fprintf(o, "%02x %x\n", TAG_pulse_search, h->hd.pit->pulse_search); fprintf(o, "%02x %g\n", TAG_gain_halt, h->hd.pit->gain_halt); fprintf(o, "%02x %x\n", TAG_min_coh_len, h->hd.pit->min_coh_len); fprintf(o, "%02x %x\n", TAG_max_coh_len, h->hd.pit->max_coh_len); for (i=0; i<PIT_SPARES && h->hd.pit->spares[i]; i++) fprintf (o, "%02x %x\n%x\n", TAG_spare, i, h->hd.pit->spares[i]); if (h->hd.pit->prefilter) dump_z (o, TAG_prefilter, h->hd.pit->prefilter); if (h->hd.pit->lpf) dump_z (o, TAG_lpf, h->hd.pit->lpf); break; case FT_SD: fprintf(o, "%02x %x\n", TAG_equip, h->hd.sd->equip); fprintf(o, "%02x %g\n", TAG_max_value, h->hd.sd->max_value); fprintf(o, "%02x %.7g\n", TAG_sf, h->hd.sd->sf); fprintf(o, "%02x %.7g\n", TAG_src_sf, h->hd.sd->src_sf); fprintf(o, "%02x %x\n", TAG_synt_method, h->hd.sd->synt_method); fprintf(o, "%02x %.7g\n", TAG_scale, h->hd.sd->scale); fprintf(o, "%02x %.7g\n", TAG_dcrem, h->hd.sd->dcrem); fprintf(o, "%02x %x\n", TAG_q_method, h->hd.sd->q_method); fprintf(o, "%02x %x\n", TAG_v_excit_method, h->hd.sd->v_excit_method); fprintf(o, "%02x %x\n", TAG_uv_excit_method, h->hd.sd->uv_excit_method); if(h->hd.sd->spare1) fprintf(o, "%02x %x\n", TAG_spare1, h->hd.sd->spare1); fprintf(o, "%02x %x\n", TAG_nchan, h->hd.sd->nchan); fprintf(o, "%02x %x\n", TAG_synt_interp, h->hd.sd->synt_interp); fprintf(o, "%02x %x\n", TAG_synt_pwr, h->hd.sd->synt_pwr); fprintf(o, "%02x %x\n", TAG_synt_rc, h->hd.sd->synt_rc); fprintf(o, "%02x %x\n", TAG_synt_order, h->hd.sd->synt_order); for (i=0; i<SD_SPARES && h->hd.sd->spares[i]; i++) fprintf (o, "%02x %x\n%x\n", TAG_spare, i, h->hd.sd->spares[i]); if (h->hd.sd->prefilter) dump_z (o, TAG_prefilter, h->hd.sd->prefilter); if (h->hd.sd->de_emp) dump_z (o, TAG_de_emp, h->hd.sd->de_emp); break; default: fprintf(stderr,"spstoa: unknown header type %d",h->common.type); exit (1); } for (i = 0; i < MAX_SOURCES && h->variable.srchead[i]; i++) dumphead (o, h->variable.srchead[i]); fprintf (o, "}\n");}dumprec (in, out, h)FILE * in, *out;struct header *h;{ double dbuf[1024]; float fbuf[1024]; long lbuf[1024]; short sbuf[1024]; char cbuf[1024]; register int i; long pos; if (h->common.tag) { if (!fread ((char *) &pos, sizeof pos, 1, in)) bomb (); fprintf (out, "%lx \n", pos); } if (h->common.ndouble) { if (!fread ((char *) dbuf, sizeof (double), h->common.ndouble, in)) bomb (); for (i=0; i< h->common.ndouble; i++) fprintf(out, "%.16g \n", dbuf[i]); } if (h->common.nfloat) { if (!fread ((char *) fbuf, sizeof (float), h->common.nfloat, in)) bomb (); for (i=0; i< h->common.nfloat; i++) fprintf(out, "%.8g \n", fbuf[i]); } if (h->common.nlong) { if (!fread ((char *) lbuf, sizeof (long), h->common.nlong, in)) bomb (); for (i=0; i< h->common.nlong; i++) fprintf(out, "%ld \n", lbuf[i]); } if (h->common.nshort) { if (!fread ((char *) sbuf, sizeof (short), h->common.nshort, in)) bomb (); for (i=0; i< h->common.nshort; i++) fprintf(out, "%d \n", sbuf[i]); } if (h->common.nchar) { if (!fread (cbuf, sizeof (char), h->common.nchar, in)) bomb (); for (i=0; i< h->common.nchar; i++) fprintf(out, "%x \n", cbuf[i]); } return;}dump_z (o, tag, z)FILE * o;int tag;struct zfunc *z;{ register int i; fprintf (o, "%02x %d %d ", tag, z->nsiz, z->dsiz); for (i = 0; i < z->nsiz; i++) fprintf (o, "%.7g ", z->zeros[i]); for (i = 0; i < z->dsiz; i++) fprintf (o, "%.7g ", z->poles[i]); fputc ('\n', o);}char *cvt_tt (s)char *s;{ register char *p = s; while (*p) { if (*p == '\n') *p = '\r'; p++; } return s;}bomb () { fprintf (stderr, "%s: error reading %s\n", Program, in_file); exit (1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -