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

📄 get_scaninfo.c

📁 seed格式数据解压程序,地震分析人员必备
💻 C
字号:
/*===========================================================================*//* DMC Interim out |            get_scaninfo.c             |   Scan_phase    *//*===========================================================================*//*	Name:		get_scaninfo.c	Purpose:	retrieve a subset of SEED data header info from a given buffer				containing one data record	Usage:		void get_scaninfo ()				char *buf				struct input_time *end_tspan;				struct input_scan *scan;				struct input_time *rec_start;				struct input_time *rec_end;				long *interval;				get_scaninfo (buf, scan, rec_start, rec_end, interval)	Input:		char *buf;		ptr->data record hdr			struct input_time *end_tspan;	ptr->tspan end time	Output:		struct input_scan *scan;ptr->scan subset of data hdr			struct input_time *rec_start;	ptr->start time of data record			struct input_time *rec_end;ptr->end time of data record			long *interval;		ptr->data sample interval													(fracsec/samp)	Externals:	Debug - setting of environment variable DEBUG (globals.h)	Messages:	None	Warnings:	None	Errors:		None	Fatals:		None	Called by:		Calls to:	add_time	adds delta e-04 sec to struct input_time	Algorithm:		Notes:		Assumes input buffer data in cpu-compatible byte order	Problems:	None known	Debug:		level D_MIN -				level D_MED -				level D_MAX -	References:	none	Language:	ANSI standard C, under Sun OS 3.5	Revisions:	03/06/89  Kevin MacKenzie  original version				10jul90	mw	bugfix						fix 0 sample interval channel's end time				19apr91	mw	bugfix						"duration" in units of e-4 sec overflows						for 100 sec sample interval data. This causes						end times earlier than start times. Change to						duration in seconds, use add_longtime.*/                   /*=====================================*//*=================|                                       |=================*/                   /*=====================================*/#include "output.h"#define isaleap(year) (((year%100 != 0) && (year%4 == 0)) || (year%400 == 0))void get_scaninfo (buf, end_tspan, scan, rec_start, rec_end, interval, fname)char *buf;			/* ptr->data record hdr */struct input_time *end_tspan;	/* ptr->time of end of current tspan */struct input_scan *scan;	/* ptr->scan subset of data record hdr */struct input_time *rec_start;	/* ptr->start time of data record */struct input_time *rec_end;	/* ptr->end time of data record */long *interval;			/* ptr->data sample interval(fracsec/samp)*/char *fname;			/* used for error reporting */{	struct input_data_logrec  *rec; /* log rec header plus data rec header */	float frate;		/* data sample rate, e-04 sec/samp */	register long	lrate;	/* data sample rate, e-04 sec/samp */	long duration;		/* time duration of data rec, e-04 sec *//* * compute end time of the data record from its header info * There is a special case for log or aux channels, where we * don't have a sample interval. In this case we must use * an end time derived from the timespan. */	rec = (struct input_data_logrec *) buf;	if (bytes_need_swapping(buf))	{		/* swap the bytes */		rec->hdr.scan.time.year    = swap_2byte(rec->hdr.scan.time.year);		rec->hdr.scan.time.day     = swap_2byte(rec->hdr.scan.time.day);		rec->hdr.scan.time.fracsec = swap_2byte(rec->hdr.scan.time.fracsec); 		rec->hdr.full.nsamples	   = swap_2byte(rec->hdr.full.nsamples);		rec->hdr.full.sample_rate  = swap_2byte(rec->hdr.full.sample_rate);		rec->hdr.full.sample_rate_multiplier =						 swap_2byte(rec->hdr.full.sample_rate_multiplier);		rec->hdr.full.number_time_corrections =						swap_4byte(rec->hdr.full.number_time_corrections);		rec->hdr.full.bod  = swap_2byte(rec->hdr.full.bod);		rec->hdr.full.bofb = swap_2byte(rec->hdr.full.bofb);	}	*scan = rec->hdr.scan;	*rec_start = rec->hdr.full.time;/* Do time correction */	if ((rec->hdr.full.activity_flags & 0x02) == 0)	{/*		printf("%02x %s %02d:%02d:%02d.%05d + %05d = ", input_data_hdr->activity_flags, this_channel, rec_start->hour, rec_start->minute, rec_start->second, rec_start->fracsec, input_data_hdr->number_time_corrections); */		rec_start->fracsec += rec->hdr.full.number_time_corrections;		while ((rec_start->fracsec >= 10000) || (rec_start->fracsec < 0)) {		if (rec_start->fracsec >= 10000)		{			rec_start->second += rec_start->fracsec/10000;			rec_start->fracsec = rec_start->fracsec%10000;			if (rec_start->second >= 60)			{				rec_start->minute += rec_start->second/60;				rec_start->second = rec_start->second%60;				if (rec_start->minute >= 60)				{					rec_start->hour += rec_start->minute/60;					rec_start->minute = rec_start->minute%60;					if (rec_start->hour >= 24)					{						rec_start->day += rec_start->hour/24;						rec_start->hour = rec_start->hour%24;						if (rec_start->day > (isaleap(rec_start->year) ? 366 : 365))						{							rec_start->year += 1;							rec_start->day = 1;						}					}				}			}		}		else if (rec_start->fracsec < 0)		{			rec_start->second -= 1;			rec_start->fracsec += 10000;			if (rec_start->second < 0)			{				rec_start->minute -= 1;				rec_start->second += 60;				if (rec_start->minute < 0)				{					rec_start->hour -= 1;					rec_start->minute += 60;					if (rec_start->hour < 0)					{						rec_start->day -= 1;						rec_start->hour += 24;						if (rec_start->day == 0)						{							rec_start->year -= 1;							rec_start->day = (isaleap(rec_start->year) ? 366 : 365);						}					}				}			}		}		}/*		printf("%02d:%02d:%02d.%05d\n", rec_start->hour, rec_start->minute, rec_start->second, rec_start->fracsec);  */	}	scan->time = *rec_start; /* Save correct time in scan header */		lrate = rec->hdr.full.sample_rate;	if( lrate != 0 )	{		if (lrate > 0)		{			if (rec->hdr.full.sample_rate_multiplier > 0)				frate = lrate * rec->hdr.full.sample_rate_multiplier;			else if (rec->hdr.full.sample_rate_multiplier < 0)				frate = (float)lrate /					(float)(-rec->hdr.full.sample_rate_multiplier);			else			{				frate = lrate;	/* multiplier == 0 should not happen? */				fprintf( D_OUT,					"[get_scaninfo] sample rate mult zero? %.5s %.3s %d %d\n",					rec->hdr.full.station, rec->hdr.full.channel,					rec->hdr.full.sample_rate,					rec->hdr.full.sample_rate_multiplier );			}		}		else		{			if (rec->hdr.full.sample_rate_multiplier > 0)				frate = ((double)rec->hdr.full.sample_rate_multiplier)/ ((double)(-lrate));			else if (rec->hdr.full.sample_rate_multiplier < 0)				frate = (double)rec->hdr.full.sample_rate_multiplier/ (double)lrate;			else			{				frate = lrate;	/* multiplier == 0 should not happen? */				fprintf( D_OUT,					"[get_scaninfo] sample rate mult zero? %.5s %.3s %d %d\n",					rec->hdr.full.station, rec->hdr.full.channel,					rec->hdr.full.sample_rate,					rec->hdr.full.sample_rate_multiplier );			}		}		if (rec->hdr.full.number_blockettes)					if (parse_type100 (&rec->hdr.full, &frate, fname)) 			{				if (frate == 0)                                {                                         fprintf(stderr, "Warning: get_scaninfo(), bad sample rate found in blockette 100!\n");                                        fprintf(stderr, "Net/stn/chn/loc:%2.2s, %5.5s, %3.3s, %2.2s\n",                                                scan->network,                                                scan->station,                                                scan->channel,                                                scan->location);                                         fprintf(stderr, "\tfor time:%d,%d,%d:%d:%d\n", 							scan->time.year,                                                        scan->time.day,							scan->time.hour,                                                        scan->time.minute,                                                        scan->time.second);                                         frate = lrate;                                }                                else				lrate = 999;			}		*interval = (1e4 / frate);		duration = ((float)(rec->hdr.full.nsamples))/ frate;  /*seconds*//* *			will it fit in 31 bits of e-4 msec *			and still be able to have up to a day of seconds added? */		if( duration < (214748-86400) )		{/*			duration = ((double)(rec->hdr.full.nsamples)*10000.0)/(double)frate; */  /* e-4 seconds*/			duration = (int) (((double)((rec->hdr.full.nsamples-1)*10000))/(double)frate);  /* e-4 seconds*/			*rec_end = add_time (*rec_start, duration);		}		else		{			*rec_end = add_longtime (*rec_start, duration);		}	}	else	{		*rec_end = *rec_start;			*interval = 20;	}	return;}/*===========================================================================*//* SEED reader     |            parse_type100              |     data block  *//*===========================================================================*//*	Name:		parse_type100	Purpose:	parse a data record header for blockette 100s.	Usage:		void parse_type100 ();				char *input_data_ptr;				float *sample_rate;				parse_type100 (input_data_ptr, &sample_rate);	Input:		pointer to beginning of data record header	Output:		none	Externals:	none	Warnings:	none	Errors:		none	Called by:	process_data	Calls to:	none	Algorithm:	search through data record blockettes for blockette 100 sample rate	Notes:		none	Problems:	none known	References:	none	Language:	C, hopefully ANSI standard	Author:		Allen Nance	Revisions:	09/18/92  Allen Nance  Initial version*/parse_type100 (input_data_ptr, sample_rate, fname)char *input_data_ptr;		/* ptr to start of data record */float *sample_rate;		/* ptr to returned sample rate */char *fname;			/* for error reporting */{	struct input_data_hdr *input_data_hdr;	/* fixed data header */	struct data_blk_100 *blk_100;		/* blockette 100 pointer */	int i;					/*counter */	/* point to beginning data header structure */	input_data_hdr = (struct input_data_hdr *) input_data_ptr;	blk_100 = (struct data_blk_100 *) (input_data_ptr + (input_data_hdr->bofb - 8));/*	printf("data blk next %d\n", blk_100->hdr.next_blk_byte); */	while (blk_100->hdr.next_blk_byte != 0)	{		if (blk_100->hdr.type == 100)		{			*sample_rate = blk_100->sample_rate;			return(1);		}		if ( ((blk_100->hdr.next_blk_byte%4)!=0) ||		     (blk_100->hdr.next_blk_byte < (sizeof(struct input_data_hdr)+8)) )		{			fprintf (stderr, "WARNING (parse_type100):  ");			fprintf (stderr, "invalid byte pointer = %04x, in %.5s,%.3s at %4d,%3d,%2d:%2d:%2d\n",				blk_100->hdr.next_blk_byte, input_data_hdr->station,				input_data_hdr->channel, input_data_hdr->time.year,				input_data_hdr->time.day, input_data_hdr->time.hour,				input_data_hdr->time.minute, input_data_hdr->time.second);			fprintf (stderr, "\tData blockette 100 parsing will be ignored.\n");			fprintf(stderr, "\tfile name: %s\n", fname);			break;		}		blk_100 = (struct data_blk_100 *) (input_data_ptr+(blk_100->hdr.next_blk_byte-8));	}	return(0);}

⌨️ 快捷键说明

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