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

📄 get_chnl_hdr.c

📁 seed格式数据解压程序,地震分析人员必备
💻 C
字号:
/*===========================================================================*//* DMC Interim out |              get_chnl_hdr              |    SEED Headers *//*===========================================================================*//*	Name:	get_chnl_hdr	Purpose:concatenate all SEED channel id (type 52), channel response and		sensitivity (types 53-58), and channel comment (type 59)		blockettes preparatory to building a SEED station control header	Usage:	int get_chnl_hdr ();		char *stnname;		char *chnlname;		char *bottom;		char *top;		int error;		error = get_chnl_hdr (stnname, chnlname, start, end, 					&bottom, &top);	Input:	stnname = string containing station call letters, e.g. "ANMO"		chnlname = string containing channel name, e.g. "BBZ"		start = start of desired time window		end =  end of desried time window	Output:	bottom = pointer to beginning of station header for station		top = pointer to end of station header for station		error = error value; FALSE if no error, nonzero otherwise.  It			contains values of MESSAGE, WARNING, ERROR, or FATAL 				(see constants.h) 	Externals:Debug - environment varible to set debug response level			Lrecl - logical record length (globals.h)	Messages:No station comments found for station; no action taken	Warnings:none	Errors:	No station info available for station; return null ptrs and 0				count to caller	Fatals:	Unable to realloc sufficient space; quit immediately	Called by:		Calls to:build_stn_path - construct path to station files		build_chnl_path - construct path to channel files		load_data - fetch blockettes from blockette files		patch_field - update a data entry in a blockette		error_handler - handle error conditions	Algorithm:		Notes:	This uses pointers-to-pointers to pass the alterred values		of "bottom" and "top" back to the caller; all		work is performed internally using a local pointer		"localptr", and the mapping of addresses for "stn_hdr" and		"top" is done at the very end.		This routine assumes that relevant information resides in		files called something/B052 and something/B059.	Problems:none known	Debug:	level D_MIN - print out start and finish notices		level D_MED - show files opened and closed, memory allocation		level D_MAX - show contents of read files	References:	none	Language: C, more or less ANSI standard, under Sun OS 3.5	Revisions:02/25/89  Dennis O'Neill  original version		05/04/89  Kevin MacKenzie  changed return status to error and			removed count as it is available from *top-*bottom		05/04/89  Kevin MacKenzie  added patching of blockette 052 with			correct count of blockette 059s.		06/26/89 mw fix patch code; shorten maxlen arg.			bottom may not stay the same across			load_data calls. Patch the last 052			seen, not the first, nor at *bottom.		16apr91		mw		bugfix			zero clen[4] to prevent garbage seen		11/02/93 cl added 2.3 support in the way of making			    sure the location code is blank*/#include "output.h"#define TRIM_STR(s)\{\        char *ch_ptr;\        while((ch_ptr = strchr(s, ' ')) != NULL)\                *ch_ptr = 0;\}char *scan_last_52();int get_chnl_hdr (stnname, chnlname, start, end, bottom, top)char *stnname;			/* station/network name 	*/char *chnlname;			/* channel name 	*/struct input_time start;	/* start time of volume 	*/struct input_time end;		/* end time of volume 		*/char **bottom;			/* ptr to start of stn hdr 	*/char **top;			/* ptr above stn hdr 		*/{	int error;				/* return error status */	char stnpath[PATHLENGTH+1];		/* path to station info */	char chnlpath[PATHLENGTH+1];		/* path to channel info */	char infilename[PATHLENGTH+1];		/* name of input file */	FILE *infile;				/* input file ptr */	char message[MSGLENGTH+1];		/* message buffer */	char c;					/* input stream char */	int i;					/* general use integer */	int count052;				/* count of B052s copied */	int count059;				/* count of B059s copied */	char *p, *p052;				/* ptr to start of first B052 */	char clen[4+1];				/* length of blockette, chars */	int	 blen;				/* ditto */	char stn[10];	char net[3];	char loc[3];	char chn[4];	if (Debug >= D_MIN) fprintf (D_OUT, "[get_chnl_hdr] Started.\n");	error = FALSE;	clen[4] = '\0';                   /*=====================================*//*=================|  construct channel header files path  |=================*/                   /*=====================================*/	strncpy(stn, stnname, 5);	stn[5] = '\0';	strncpy(net, &stnname[5], 2);	net[2] = '\0';	strncpy(chn, chnlname, 3);        chn[3] = '\0';	strcpy(loc, &chnlname[3]);	loc[2] = 0;	if (error = build_stn_path (trim_str(stn), net, Header_path, stnpath))	{		sprintf (message,			"[get_chnl_hdr] Bad station pathname for station %s channel %s.\n", 			stnname, chnlname);		error = error_handler (ERROR, message);		return ( error );	}	if (error = build_chnl_path (chn, trim_str(loc), stnpath, chnlpath))	{		sprintf (message,			"[get_chnl_hdr] Bad channel pathname for station %s channel %s.\n", 			stnname, chn);		error = error_handler (ERROR, message);		return ( error );	}                   /*=====================================*//*=================| load channel id, rspns (type 5x) info |=================*/                   /*=====================================*/	/* construct file name */	sprintf (infilename, "%s/B052", chnlpath);	/* open file for reading, load info into memory */	if( error = load_data (infilename, start, end, bottom, top, &count052) )	{		sprintf (message,		"[get_chnl_hdr] No channel info available, station %.5s channel %s for network %2s location %2s.\n", stnname, chnlname, net, loc);		error = error_handler (ERROR, message);		return ( error );	}                   /*=====================================*//*=================|  load channel comment (type 59) info  |=================*/                   /*=====================================*/	/* construct file name */	sprintf (infilename, "%s/B059", chnlpath);	/* open file for reading, load info into memory */	error = load_data (infilename, start, end, bottom, top, &count059); 	if (Debug >= D_MIN)		fprintf (D_OUT, "[get_chnl_hdr] Found %d valid B059s.\n", count059);/*	if (error)	{		sprintf (message,	"[get_chnl_hdr] No channel comments available, station %s channel %s.\n",			stnname, chnlname);		*error = error_handler (MESSAGE, message);	}*/	error = 0;                   /*=====================================*//*=================|  update channel header comment count  |=================*/                   /*=====================================*//* * note that we patch the first blockette 52 read (there could be more than * one for the required time window in addition to possible updates) with * the correct count of station comment (blockette 059s) whether zero or * otherwise.  this is not explicitly correct as the effective dates for a * given comment may more appropriately overlap one of the other blockette * 052s.  we assume the count fields in the other blockette 052s are set to * zero. * * don't use *bottom until after last load_data call - may be moved by * realloc! *bottom points to a B050 anyway, not a B052 blockette! */	p052 = scan_last_52(*bottom, *top);	if (p052 == NULL)        {            sprintf (message,                    "[get_chnl_hdr] Failed to load in channel info for station: %s\n", stnname);            error = error_handler(ERROR, message);            return (error);        }	if( p052 != NULL )		error = patch_field (p052, 1, 75, 50, count059, "%4.4d");                   /*=====================================*//*=================|               clean up                |=================*/                   /*=====================================*/	if (Debug >= D_MIN) fprintf (D_OUT, "[get_chnl_hdr] Completed.\n");	return (error);}				  /* ====================================== *//* ===============|              scan ending 52              |============== */				  /* ====================================== */char *scan_last_52(bottom, top)char *bottom;char *top;{	char *p = NULL;	char clen[10];	while (bottom < top)              /* find last 052 blockette */    	{        	if(strncmp(bottom, "052", 3) == 0) 			p = bottom;    /* match = 0 */		memset(clen, 0, sizeof(clen));		memcpy(clen, bottom + 3, 4);        	bottom += atoi(clen);		if (atoi(clen) == 0)			return ((char *) NULL);    	}	return p;	}int scan_chnl_recs(bottom, top, s, c, loc)char *bottom;char *top;char *s, *c;char *loc;{	char *p = NULL;	char clen[10];	/* loop thru the text looking for B52s, could be updates */	while (bottom < top)                     {                if(strncmp(bottom, "052", 3) == 0)		{			if ((*(bottom + 7) == ' ') && 			   (*(bottom + 8) == ' '))			{				memcpy(bottom + 7, loc, 2);			}		}                memset(clen, 0, sizeof(clen));                sscanf(bottom+3, "%4c", clen );                bottom += atoi(clen);                if (atoi(clen) == 0)                        return(0);        }	return(1);}int dump_bottom(b,t)char *b;char *t;{	while (b <= t)	{		printf("%c", *b++);	}	printf("\n");}

⌨️ 快捷键说明

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