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

📄 load_data.c

📁 seed格式数据解压程序,地震分析人员必备
💻 C
字号:
/*===========================================================================*//* DMC Interim out |               load_data               |    SEED Headers *//*===========================================================================*//*	Name:		load_data	Purpose:	read data from a blockette file onto the end of the header under construction	Usage:		int load_data ()			char *infilename;                	struct input_time start;                	struct input_time end;			char *bottom;			char *top;                	int *count;			int error;			error = load_data (infilename, start, end, bottom, top, count);	Input:		infilename = string containing filename from which to get data			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 data.	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:	02/  /89  Dennis O'Neill  original version			03/06/89 Mark Wiederspahn, make pointer code cleaner				add big_buffer code			03/22/89 Mark Wiederspahn find only blockettes which				match the effective times. return				error, not length, since top-bottom				gives count.			05/03/89 Kevin MacKenzie  add blockette count			06/21/89 Mark Wiederspahn				skip the linefeed at the end of each blockette			06/27/89	mw	use %c for reading btype and blen so leading spaces do not create havoc.			26oct89	mw	bugfix					set last char of ctype,clen to null			15may90 mw	bugfix				getmore was calling big_buffer more often than				needed; but this did no harm. Proper detection				of new need to expand done now.				enhancement				allow blockette types 043-048 and 060 from				SEED version 2.1 specification.			04apr91	mw	change				Change first call to getmore as extra block				of Lrecl bytes no longer allocated.				Change getmore test so it does not needlessly call big_buffer when no new memory will be allocated.			21apr91	mw clarification of code				change all calls to big_buffer to				calls to make_room; it reads better.				remove getmore.			18mar99 Stephane Zuzlewski; Added support for blockette 062.												*/                   /*=====================================*//*=================|                                       |=================*/                   /*=====================================*/#include "output.h"#include <malloc.h>int load_data (infilename, start, end, bottom, top, count, stn)char *infilename;			/* string, filename */struct	input_time	start;		/* start time of volume */struct	input_time	end;		/* end time of volume */char **bottom;				/* ptr to hdr array */char **top;				/* ptr to hdr array */int *count;				/* count of blockettes copied */char *stn;				/* station name - only used if 					 * infilename == B050 					 */{	int error;			/* returned error status */	FILE *infile;			/* ptr to input file */	int	length;			/* total size of buffer */	int	btype;			/* blockette type */	int	blen;			/* blockette length */	int	take52;			/* result of blockette 52 */	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 */	if (Debug >= D_MIN) fprintf (D_OUT, "[load_data] Started.\n");	ctype[3] = 0;	clen[4] = 0;/* * if empty buffer, make space */	error = FALSE;    	*count = 0;	if( *bottom == NULL )	{		*top = NULL;		/* force an allocation */	}	if ((infile = fopen (infilename, "r")) != NULL)	{		if (Debug >= D_MED)			fprintf (D_OUT, "[load_data] 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. */		length = (int) (*top - *bottom);		make_room( length, 7, bottom, top );#ifdef MALLOC_DEBUGif(!malloc_verify())	fprintf( stderr,"[load_data] malloc_verify failed;\n" );#endif		while( fread( *top, sizeof(char), 7, infile ) == 7 )		{			if( Debug >= D_MAX ) 				fprintf( D_OUT,"[load_data] blockette:%.7s\n", *top );			if( sscanf( *top, "%3c%4c", ctype, clen ) != 2 )			{				sprintf(msg,					"[load_data] bad blockette\n   %s %s from %s\n", ctype, clen, infilename );				error = error_handler( ERROR,msg );			}			btype = atoi( ctype );			blen = atoi( clen );			make_room( length, blen, bottom, top );#ifdef MALLOC_DEBUGif(!malloc_verify())	fprintf( stderr,"[load_data] malloc_verify failed;\n" );#endif			if( fread( (*top)+7, sizeof(char), blen-7, infile ) != blen-7 )			{				sprintf( msg,"[load_data] bad read\n %s %s from %s\n",					ctype, clen, infilename );				error = error_handler( ERROR,msg );				break;			}			if( getc( infile ) != '\n'  )		/* skip line feed */			{				sprintf( msg,					"[load_data] bad blockette file\n no lf %s %s from %s\n",					ctype, clen, infilename );				error = error_handler( ERROR,msg );				break;			}/* * Things get sticky here because we test the times of 050, 051, 052 * and 059 (which have time stamps) but not the times of 053-058 which * logically are those of the preceding 052. Thus, 053-058 must retain the * acceptance characteristics of the preceding 052. For SEED v2.1, we * treat the occurence of 060 exactly the same as 053-058. For SEED v2.2 * we treat 061 as 053-058. For SEED v2.3 we treat 062 as 053-058. */			if( (i=is_in_twindow( *top, btype, blen, start, end )) )			{				if( (btype >= 53 && btype <= 58) ||					btype == 60 || btype == 61 || btype == 62)				{					if( take52 )					{						*top += blen;	/* keep it */						(*count)++;	/* count it */					}				}				else				{					*top += blen;	/* keeper */										(*count)++;	/* count it */				}			}			if( btype == 52 ) 				take52 = i;			length = (int) (*top - *bottom);/* assure space for next */			make_room( length, 7, bottom, top );#ifdef MALLOC_DEBUGif(!malloc_verify())	fprintf( stderr,"[load_data] malloc_verify failed;\n" );#endif		}#ifdef MALLOC_DEBUG 		if(!malloc_verify())			fprintf( stderr,"[load_data] malloc_verify failed;\n" );#endif			fclose (infile); 		if (Debug >= D_MED)			fprintf (D_OUT, "[load_data] Closed %s.\n", infilename);	}	else	{		if (Debug >= D_MED)			fprintf (D_OUT, "[load_data] Could not open %s.\n", infilename);        error = WARNING;    }	if (Debug >= D_MIN) fprintf (D_OUT, "[load_data] Completed.\n");	return (error);}

⌨️ 快捷键说明

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