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

📄 load_event.c

📁 seed格式数据解压程序,地震分析人员必备
💻 C
字号:
/*===========================================================================*//* DMC Interim out |               load_event               |    SEED Headers *//*===========================================================================*//*	Name:		load_event	Purpose:	read event from a blockette file onto the end of the header				under construction	Usage:		int load_event ()				char *infilename;				int error;				error = load_event (infilename, start, end, bottom, top, count);	Input:		infilename = string containing filename from which to get event				start = start time of desired time window                end = end time of desired time window				bottom = pointer to start of header array.					MUST HAVE BEEN malloc()'ed of size Lrecl or be					NULL so we will do it for the caller.				top = pointer to place in header to start adding event.	Output:		count = number of blockettes actually read into header array				error = error value; FALSE if no error, nonzero otherwise.					Contains values of MESSAGE, WARNING, ERROR, or FATAL 					(see constants.h) 	Externals:	Debug - setting of environment variable DEBUG (globals.h)	Messages:	none	Warnings:	file not opened; WARNING returned to caller	Errors:		none	Fatals:		unable to make sufficient space; quit immediately	Called by:	get_*_hdr - routines which construct headers	Calls to:	make_room - get contiguous buffer space				error_handler - handle error conditions	Algorithm:		Notes:		This routine gets only those blockettes which				overlap in any part with the times of the volume.				It will get only one blockette of each type 052-059				with a "null" end time. This can be called by any				"get" routine because "is_in_twindow" knows the				specific inclusion rules for each blockette.	Problems:	none known	Debug:		level D_MIN - print out start and finish notices				level D_MED -				level D_MAX -	References:	none	Language:	C, more or less ANSI standard, under Sun OS 3.5	Revisions:	03/10/93  Allen Nance  original version				adapted fromn load_data.c*/                   /*=====================================*//*=================|                                       |=================*/                   /*=====================================*/#include "output.h"extern struct blk71_list *Blk71_head;extern struct blk71_list *Blk71_tail;struct blk71_list *make_blk71();struct blk72_list *make_blk72();int load_event (infilename)char *infilename;								/* string, filename */{	int error;									/* returned error status */	FILE *infile;								/* ptr to input file */	int	btype;									/* blockette type */	int	blen;									/* blockette length */	int	i;										/* scratch use */	char ctype[3+1];							/* char version of btype */	char clen[4+1];								/* char version of blen */	char msg[100+1];							/* for errors */	int	position;								/* file position */	int	rlength;								/* read length */	struct blk71_list *current_blk71;			/* current blk 71 pointer */	struct blk72_list *current_blk72;			/* current blk 72 pointer */	char buf[10000];							/* blockette buffer */	if (Debug >= D_MIN) fprintf (D_OUT, "[load_event] Started.\n");	ctype[3] = 0;	clen[4] = 0;	error = 0;	Blk71_head = Blk71_tail = NULL;	if ((infile = fopen (infilename, "r")) != NULL)	{		if (Debug >= D_MED)			fprintf (D_OUT, "[load_event] Opened %s.\n", infilename);/* * read one blockette at a time, making sure that there is enough room * in the buffer before continuing to read the body of the blockette. * If it is a keeper, then advance the top pointer, else just read * into the same area again, overwriting the rejected blockette. * * verify the integrity of the file by checking that the next * character in the blockette file is always a linefeed. */		current_blk71 = NULL;		position = 0;		rlength = fread( buf, sizeof(char), 7, infile );		while( rlength == 7 )		{			if( Debug >= D_MAX ) fprintf( D_OUT,"[load_event] blockette:%.7s\n",				buf );			if( sscanf( buf, "%3c%4c", ctype, clen ) != 2 )			{				sprintf( msg,"[load_event] bad blockette\n   %s %s from %s\n",					ctype, clen, infilename );				error = error_handler( ERROR,msg );			}			btype = atoi( ctype );			blen = atoi( clen );			if ((btype != 71) && (btype != 72))			{				sprintf( msg,"[load_event] bad blockette\n   %s %s from %s\n",					ctype, clen, infilename );				error = error_handler( ERROR,msg );				break;			}			if (btype == 71)			{				current_blk71 = make_blk71( &Blk71_head, &Blk71_tail);				if( fread( buf+7, sizeof(char), blen-7, infile ) != blen-7 )				{					sprintf( msg,"[load_event] bad read\n %s %s from %s\n",						ctype, clen, infilename );					error = error_handler( ERROR,msg );					break;				}				current_blk71->origin_time = asc_to_input_time(buf+7);				current_blk71->start_offset = position;				current_blk71->blk_length = blen;				current_blk71->blk72_list = NULL;			}			else			{				if (current_blk71 == NULL)				{					sprintf( msg,"[load_event] Blockette 71 not found before 72\n %s %s from %s\n",						ctype, clen, infilename );					error = error_handler( ERROR,msg );					break;				}				current_blk72 = make_blk72( &(current_blk71->blk72_list));				if( fread( buf+7, sizeof(char), blen-7, infile ) != blen-7 )				{					sprintf( msg,"[load_event] bad read\n %s %s from %s\n",						ctype, clen, infilename );					error = error_handler( ERROR,msg );					break;				}				current_blk72->start_offset = position;				current_blk72->blk_length = blen;			}			if( getc( infile ) != '\n'  )		/* skip line feed */			{				sprintf( msg,					"[load_event] bad blockette file\n no lf %s %s from %s\n",					ctype, clen, infilename );				error = error_handler( ERROR,msg );				break;			}			position += blen+1;			rlength = fread( buf, sizeof(char), 7, infile );		}#ifdef MALLOC_DEBUG 		if( !malloc_verify() )fprintf( stderr,"[load_event] malloc_verify failed;\n" );#endif			fclose (infile); 		if (Debug >= D_MED)			fprintf (D_OUT, "[load_event] Closed %s.\n", infilename);	}	else	{		if (Debug >= D_MED)			fprintf (D_OUT, "[load_event] Could not open %s.\n", infilename);        error = WARNING;    }	if (Debug >= D_MIN) fprintf (D_OUT, "[load_event] Completed.\n");	return (error);}

⌨️ 快捷键说明

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