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

📄 copysps.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
						exit(1);					}				}			}			break;		default:			Fprintf(stderr,			 "copysps: cannot update ESPS file type code: %d\n",				f1hd->common.type);			exit(1);			break;		}		/* end switch (f2h->common.type) */		if (debug)			Fprintf(stderr,				"copysps: input files compatible; now check for fast mode.\n");		if (fast) {			/*			 * fast flag is set, append selected records to the			 * output file.			 */			if (debug)				Fprintf(stderr,					"copysps: fast mode set: append to %s.\n", f2name);			(void) fclose(f2strm);			if ((f2strm = fopen(f2name, "a+")) == NULL) {				/*				 * ugly hack to fix r+ on SYS 5.2				 * tstrm->_flag |= _IOWRT;				 */				Fprintf(stderr,					"copysps: could not open %s for appending.\n", f2name);				exit(1);			}		} else {			/*			 * We have to update outfile, but not in fast mode!			 * This means that we have to retain all header			 * information and include as a subheader the header			 * of infile. Therefore, create a temporary file to			 * store results.			 */			tmpname = e_temp_name(template);			if ((tstrm = fopen(tmpname, "w")) == NULL) {				Fprintf(stderr,				   "copysps: could not open %s\n", tmpname);				exit(1);			}			if (debug)				Fprintf(stderr,					"copysps: fast mode not set: creating tmp file %s.\n",					tmpname);		}		/* end if (fast) */		/*		 * check record_freq values		 */		{			double          record_freq = 0;			if (get_genhd_val("record_freq", f1hd, (double) 0) !=			    get_genhd_val("record_freq", f2hd, (double) 0))				(void) add_genhd_d("record_freq", &record_freq,						   (int) 1, f2hd);		}	}	/* end outfile exists */	else {			/* outfile doesn't exist */		if (debug)			Fprintf(stderr, "copysps: %s does not exit, create it.\n",				f2name);		if (strcmp(f2name, "-") == 0) {			f2strm = stdout;			f2name = savestring("<stdout>");		} else if ((f2strm = fopen(f2name, "w")) == NULL) {			Fprintf(stderr,			"copysps: could not open %s for writing.\n", f2name);			exit(1);		}		fast = 0;	/* reset fast flag if on */		f2hd = copy_header(f1hd);		f2hd->common.edr = f1hd->common.edr;		if (debug)			Fprintf(stderr,			     "copysps: copied infile header to outfile.\n");		/*		 * update start time and record freq		 */		if (rec_range == NULL)			update_waves_gen(f1hd, f2hd, (double) s_rec, 1.0);		else			update_waves_gen(f1hd, f2hd, (double) rec_range[0], 1.0);	}			/* end if (update) */	if (!fast) {		if ((debug) && !nohead)			Fprintf(stderr,			"copysps: adding source file header to outfile.\n");		if (nohead)			(void) add_source_file(f2hd, f1name, (struct header *) NULL);		else			(void) add_source_file(f2hd, f1name, f1hd);	}	if (debug)		Fprintf(stderr,			"copysps: s_rec: %d, e_rec: %d\n", s_rec, e_rec);	if (gflag)		if (rec_range[tot_rec - 1] > e_rec) {			Fprintf(stderr, "copysps: only %d records in %s\n",				f1hd->common.ndrec, f1name);			exit(1);		}	recsize1 = size_rec(f1hd);	if (recsize1 == -1) {		ERROR_EXIT("variable record size not supported")	}	(void) skiprec(f1strm, s_rec - 1, recsize1);	if (!gflag)		tot_rec = e_rec - s_rec + 1;	if (debug)		Fprintf(stderr,			"copysps: recsize1 = %ld, tot_rec = %ld\n", recsize1, tot_rec);	if (!fast) {		/* retain all new header information in				 * outfile */		(void) strcpy(f2hd->common.prog, "copysps");		(void) strcpy(f2hd->common.vers, VERSION);		(void) strcpy(f2hd->common.progdate, DATE);		if (!nohead) {			(void) add_comment(f2hd, get_cmd_line(argc, argv));		}		/*		 * If we have to update an existing file, then we should add		 * any warnings in the comment field if any inconsistencies		 * occur.		 */		if (update)			switch (f2hd->common.type) {			case FT_FEA:	/* do nothing */				break;			default:				Fprintf(stderr,					"copysps: cannot update ESPS file type code: %d\n",					f1hd->common.type);				exit(1);				break;			}	/* end switch (f2h->common.type) */		/*		 * If in update mode, then we must write header information		 * out into a temporary file (pointed to by tstrm), otherwise		 * just write it into our new outfile (pointed to by f2strm).		 */		if (debug)			Fprintf(stderr,				"copysps: writing header to %s stream.\n",				(update == 0) ? f2name : tmpname);		if (update)			(void) write_header(f2hd, tstrm);		else			(void) write_header(f2hd, f2strm);	}	if (debug)		Fprintf(stderr, "copysps: Process records\n");	/*	 * If we have to update outfile and we're not in fast mode, then we	 * have to do the following: Copy all records from outfile into a	 * temporary file.  Then append to the temporary file the the new	 * records from infile.  Finally, we'll have to get everything from	 * the temporary file back into outfile.	 */	if (update && !fast) {	/* append mode */		long            tmp_rec;		struct fea_data *tmpbuf;		if (debug)			Fprintf(stderr,"copysps: to temp ");		recsize2 = size_rec(f2hd);		if (recsize2 == -1) {			ERROR_EXIT("variable record size not supported")		}		if (recsize2 != recsize1) {			Fprintf(stderr,				"copysps: record sizes in %s and %s are different.\n",				f1name, f2name);			exit(1);		}		tmp_rec = f2hd->common.ndrec;		tmpbuf = allo_fea_rec(f2hd);		for (i = 0; i < tmp_rec; i++) {			if (get_fea_rec(tmpbuf, f2hd, f2strm) < 1) {				Fprintf(stderr, "copysps: read error on %s\n", f2name);				exit(1);			}			put_fea_rec(tmpbuf, f2hd, tstrm);			if (debug && (i%1000 == 0)) fputc('#',stderr);		}		if(debug) fputc('\n',stderr);		(void) free_fea_rec(tmpbuf);	}			/* end if (update && !fast) */	/*	 * The pointer in the input stream is now set to the correct record	 * position (because of read_header and skiprec). 	 */	cur_pos = ftell(f1strm);/* current position in f1strm (record 1) */	/* for (i = 0; i < tot_rec; i++) */	i = 0;	f1rec = allo_fea_rec(f1hd);	f2rec = allo_fea_rec(f2hd);	if (debug) 		Fprintf(stderr,"copysps: to temp or output ");	while (i < tot_rec) {		if (gflag) {			new_pos = (rec_range[i] - 1) * recsize1 + cur_pos;			if ((j = fseek(f1strm, new_pos, 0)) != 0) {				break;				/*				 * Fprintf (stderr, "copysps: seek error on				 * %s\n", f1name); exit (1);				 */			}		}		if (get_fea_rec(f1rec, f1hd, f1strm) < 1) {			break;			/*			 * Fprintf (stderr, "copysps: read error on %s\n",			 * f1name); exit (1);			 */		}		copy_fea_rec(f1rec, f1hd, f2rec, f2hd, NULL, NULL);		if (update && !fast) {			put_fea_rec(f2rec, f2hd, tstrm);		} else {			put_fea_rec(f2rec, f2hd, f2strm);		}		if (debug && (i%1000 == 0)) fputc('#',stderr);		i++;	}			/* end while (i < tot_rec) */	/* i is the total number of records processed */	if (debug)		Fprintf(stderr,			"\ncopysps: number of records processed = %d\n", i);	if (update && !fast) {		if (rename(tmpname, f2name) != 0) {			if (errno != EXDEV) {				Fprintf(stderr,					"copysps: could not rename %s to %s\n", tmpname, f2name);				exit(1);			} else {				int i;				if (debug) 					Fprintf(stderr,"copysps: from temp ");				(void) fclose(tstrm);				if ((tstrm = fopen(tmpname, "r")) == NULL) {					Fprintf(stderr, "copysps: cannot reopen temp file!\n");					exit(1);				}				(void) unlink(tmpname);				if ((f2strm = fopen(f2name, "w")) == NULL) {					Fprintf(stderr, "copysps: cannot open %s\n", f2name);					exit(1);				}				i=0;				while ((c = fgetc(tstrm)) != EOF) {					(void) fputc(c, f2strm);					if (debug && (i++%1000 == 0)) { 						fputc('#',stderr);					}				}				if(debug) 					Fprintf(stderr,					   "\ncopysps: %d bytes processed\n",i);			}		}		(void) fclose(tstrm);	}	(void) fclose(f1strm);	(void) fclose(f2strm);	/* put output file info in ESPS common */	if (strcmp(f2name, "<stdout>") != 0) {		(void) putsym_s("filename", f2name);		(void) putsym_s("prog", argv[0]);		(void) putsym_i("start", 1);		(void) putsym_i("nan", (int) (tot_rec + input_ndrec));	}	exit(0);	/* NOTREACHED */}				/* end main() */

⌨️ 快捷键说明

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