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

📄 output_data.c

📁 seed格式数据解压程序,地震分析人员必备
💻 C
字号:
/*===========================================================================*//* UTIG DMC        |            output_data                |  SEED output    *//*===========================================================================*//*	Name:		output_data.c	Purpose:	outputs time segments in a single time span to an				open output SEED format file	Usage:		err = output_data( ofile, nlvol, plvol )	Input:		FILE	ofile	open output SEED file				int nlvol	number of nodes in lvol list				struct lvol *plvol linked list containing the					segment information	Output:		err	contains error codes, 0 if none	Externals:	Precl	physical record length				Lrecl logical record length	Warnings:	Errors:			Fatals:	Called by:	flush_output_volume	Calls to:	open_logrec, put_logrec				fopen, setbuf, read	Algorithm:		Notes:			Problems:	Assume that fseek pointers are byte pointers.				the start and end offsets in lvol are fseek				pointers, but numeric comparison is done in the				while loop below. This works under Unix.	References:		Language:	Sun OS 3.5	Revisions:	mm/dd/yy  pgmr name  change*/#include "sys/param.h"#include "output.h"/* ------------------------------------------------------------------- */extern struct logbuf { /* internal to logrec.c and output_data.c */        int seqno;      /* sequence number last written, 0..999999 */        int lrecl;      /* logical record size, 0 = no memory buffer */        int precl;      /* physical record size, 0 = no memory buffer */        char *base;     /* base addr of this buffer */        struct io_buf buf;      /* where is it, and how much left? */        } buffer[];/* ------------------------------------------------------------------- */struct io_buf flush_buff();extern char *get_net_code();static char prev_fname[MAXPATHLEN];static int ifd;			/* file descriptor for ifile */static FILE *ifile;			/* input file pointer */void init_output_data(){	strcpy(prev_fname, "");	ifd = 0;	ifile = NULL;}int output_data( ofile, nlvol, plvol )FILE *ofile;		/* output file pointer, already open */int nlvol;		/* number of nodes plvol points to */struct lvol *plvol;	/* pointer to linked list of nodes which			 * will contribute to this logical volume			 */{	int err;			/* error status code */	register int n;			/* counter */	register struct	lvol *p;	/* pointer */	struct io_buf buf;		/* used with logrec package */	int	len;			/* number of bytes read from file */	char	errmsg[MSGLENGTH+1];	/* text of built error message */	char	*network_code;int i;	int default_Lrecl;/* * announce ourselves! */	if( Debug >= D_MIN ) fprintf( stderr,"[output_data] begin\n" );/* * find a buffer address from the buffering package. If this is the * first time it has been used on this file (it should NOT be, except * perhaps for testing) then set up this information. */	default_Lrecl = Lrecl;	buf = put_logrec( ofile, NULL, 0, 0, &err );	if( err ) return error_handler( FATAL,"[output_data] no initial buffer");	if( buf.addr == NULL )	{		buf = open_logrec( ofile, Lrecl, Precl, err );		if( err )			return error_handler( FATAL,"[output_data] open_logrec failed");	}/* * for each node, open the file, seek to the start location, read the * segment (probably in serveral pieces of Precl bytes) and write it. * If the file can't be opened, then report it and continue. */	p = plvol;	p = plvol;	while( nlvol-- )	{		if( Debug >= D_SOME ) fprintf( stderr,			"[output_data] node: %s <%.5s %.3s> %d to %d\n",			p->name, p->scan.station, p->scan.channel,			p->start_offset, p->end_offset );		if (strcmp(prev_fname, p->name) != 0)		{			if (strcmp(prev_fname, "") != 0)				fclose(ifile);			if( (ifile = fopen( p->name, "r")) == NULL )			{				sprintf(errmsg,					"[output_data] could not find file: %s %.5s %.3s",					p->name, p->scan.station, p->scan.channel );							strcpy(prev_fname, "");				if ((err=error_handler(ERROR, errmsg))) 					return(err);			}			/* Lrecl = p->lrecl; */			buffer[fileno(ofile)].lrecl = p->lrecl;			setbuf(ifile, NULL);/* make it unbuffered */			ifd = fileno( ifile ); 			strcpy(prev_fname, p->name);		}		if( fseek( ifile, p->start_offset, 0 ) < 0 )		{			sprintf( errmsg, "[output_data] seek err on %s", p->name );			error_handler( WARNING, errmsg );		}		n = p->start_offset;	 /* ASSUME BYTE OFFSET */		if( p->start_offset >= p->end_offset )		{			sprintf( "[output_data pointer order on %s", p->name );			error_handler( ERROR, errmsg );		}		while( n < p->end_offset )		{			if( buf.len > ( p->end_offset - n ) )				len = p->end_offset - n;			else				len = buf.len;			len = read( ifd, buf.addr, len ); 			if( len < 0 )			{				sprintf( errmsg,					"[output_data] input io error on %s", p->name );				error_handler( WARNING, errmsg );			}			if( len > 0 )		/* if not eof */			{#if 0				/* put in the network code */				if (SEED_Version >= 23)        			{					char * ptr = buf.addr;										/* loop thru 4096 block */					while (ptr < buf.addr + len)					{						memcpy(ptr + 18,						       p->scan.network,						       2);								ptr += Lrecl;					}		/* while */        			}#endif				buf = put_logrec(ofile, 						 buf.addr, 						 len, 0, &err );				if (err) 					error_handler( WARNING, "[output_data] put_logrec error" );				n += len;			}			else			{				n = p->end_offset;/* premature eof, continue */				sprintf( errmsg, "[output_data] end pointer error %s",					p->name );				error_handler( WARNING, errmsg );			}		}		if( Debug >= D_SOME )			fprintf( stderr, "[output_data] done node %s\n", p->name );	/*	fclose( ifile ); */		/* if the new record length is greater than the one we 		 * just work with, pad to the new lrecl boundary  		 */		if ((p->lrecl < default_Lrecl) && ((len % default_Lrecl) != 0))		{			int bytes_to_pad, fd;			fd = fileno(ofile);			/* len holds how many bytes we've written out in the			 * buffer				 */			bytes_to_pad = default_Lrecl-(len % default_Lrecl);			/* make sure we dont go over buffer */			if (buf.len - bytes_to_pad < 0)			{				memset(buf.addr, ' ', buf.len);				buf = put_logrec(ofile,                                         	buf.addr,                                         	buf.len, 0, &err );				bytes_to_pad -= buf.len;			}			memset(buf.addr, ' ', bytes_to_pad);			memset(buffer[fd].buf.addr, 					' ', bytes_to_pad);                       	buf = put_logrec(ofile,                                         buf.addr,                                         bytes_to_pad, 0, &err );                      	if (err) 	error_handler(WARNING, "[output_data] put_logrec error");			len = 0;			}	/* if time to pad */		p = p->next;		/* if the new logical record size is different from the		 *previous one, output the physical record size, as the		 * buffering system can't handle multiple sizes	  	 */		if (p)		if (p->lrecl != Lrecl && buf.len < Precl)		{			buf = flush_buff(ofile, len);			len = 0;		}		if( Debug >= D_MAX ) 			fprintf( D_OUT,"[output_data] last LR used=%d\n",					set_logrec(ofile,-1) );	}/* * the entire list of segments has been output for the timespan. */	if( Debug >= D_MIN ) fprintf( stderr, "[output_data] end\n" );	return( err );}

⌨️ 快捷键说明

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