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

📄 find_segment.c.old

📁 seed格式数据解压程序,地震分析人员必备
💻 OLD
📖 第 1 页 / 共 2 页
字号:
		*scan = save_scan;		/* time of last sample in last rec before this one */		*endtime = save_endtime;		*start_o = save_o;		if (Debug >= D_MED)		{			fprintf (D_OUT,			"[find_segment] End of segment at offset = %d\n",*end_o);			*msg = '\0';			strcat( msg, input_time_to_asc(save_scan.time) );			strcat( msg, " to " );			strcat( msg, input_time_to_asc(save_endtime) );			fprintf (D_OUT,			"[find_segment] %s\n", msg );		}		save_endtime = rec_end;	}		if (err == 0)	{		/* another valid segment in file so save info */		save_scan = rec_scan;		/* save scan info */		save_o = *end_o;		/* save start offset pointer */		segcnt++;			/* increment segment counter */		if( Debug >= D_MAX )			fprintf( D_OUT,			"[find_segment] middle of segment\n" );	}	else	{	/* no more data of interest in file so reset */		file_o = 0;	/* reset file offset pointer */		save_o = -1;	/* reset start offset pointer */		segcnt = 0;	/* reset segment counter */		if( Debug >= D_MAX )			fprintf( D_OUT,			"[find_segment] reset all\n" );	}	if (Debug >= D_MIN) fprintf (D_OUT, "[find_segment] Finished.\n");	return (err);}/* ---------------------------------------------------------------------- */void set_msg_printed_flag(x)int x;{	msg_printed = x;}/* ------------------------------------------------------------------------ */int qa_logrec(logrec)struct input_data_logrec *logrec;{	char fname[200];	char station[20];	char channel[20];	char network[10];	struct DMC_request *req;	/* compare the station and channel with the filename's	 * station/channel to determine if garbage or not!	 */	if (logrec->type != 'D')		/* always D for data */		return -1;	/* grab station and channel name from the request struct,	 * gleaned from the holding file (hfile). 	 */	req = get_current_request();	memset(station, 0, sizeof(station));	memset(channel, 0, sizeof(channel));	/* make sure station/channel have no blanks */	memcpy(station, logrec->hdr.scan.station, 			sizeof(logrec->hdr.scan.station));        memcpy(channel, logrec->hdr.scan.channel,                         sizeof(logrec->hdr.scan.channel));	TRIM_STR(station);	TRIM_STR(channel);		if (strncmp(req->entry.statn, station, strlen(station)) != 0)		return -1;	if (strncmp(req->entry.chn, channel, strlen(channel)) != 0)         	return -1;	/* check for samples being > 0 && beg_data != 0*/	if ((logrec->hdr.full.nsamples <= 0) && 			(logrec->hdr.full.bod != 0))	{		fprintf(stderr, "WARNING: qa_logrec(): Found bad sample count!\n");		return -1;	}	if (SEED_Version >= 23)	{ 		memset(network, 0, sizeof(network));		memcpy(network, 			logrec->hdr.scan.network, 			sizeof(logrec->hdr.scan.network));		TRIM_STR(network);		if (strncmp(req->entry.network, network, strlen(network)) != 0)                	return -1;#if 0		if ((logrec->hdr.scan.location[0] == ' ') && 			(logrec->hdr.scan.location[1] == ' '))			/* use the location code as found from the h file */			if (Process_location_code)				memcpy(logrec->hdr.scan.location, 						req->entry.location, 						sizeof(logrec->hdr.scan.location));#endif		if (strncmp(logrec->hdr.scan.location,				req->entry.location, 				sizeof(logrec->hdr.scan.location)) != 0)			return 0;	}	return 1;	}/* ------------------------------------------------------------------------ */int find_Lrecl(fptr, f)FILE *fptr;char *f;{	int num_bytes;	struct input_data_logrec *data_header;		char stn_name[10];	char channel[10];	char wrkstr[200];        /* grab the station/channel name from file name, use later */        /* grabs the basename */        if (strrchr(f, '/'))                strcpy(wrkstr, strrchr(f, '/') + 1);        else                strcpy(wrkstr, f);        /* file name looks like TTB01.XG.01.BHZ.95.250 */        strcpy(stn_name, strtok(wrkstr, "."));        strtok(NULL, ".");   /* skip the network */	strtok(NULL, ".");   /* ditto the loc */        strcpy(channel, strtok(NULL, ".")); 	/* since we are dealing with a station/day file, we assume that	 * the logical record size will not vary in the space of one 	 * day, might not be the safest of assumptions. But it is the same	 * strategy used by the seed_pack routines which got us here.	 */	if (fptr == NULL)	{		sprintf(wrkstr, "NULL file pointer in find_Lrecl. File %s. Assuming 4096\n", f);		error_handler(ERROR, wrkstr);		perror("find_Lrecl");		return(4096);	}	if ((num_bytes = fread(buf, 1, sizeof(buf), fptr)) <= 0)        {        	fclose(fptr);		sprintf(wrkstr, "Unable to read data file %s to check the data record length. Assuming %d\n", f, Lrecl);                 error_handler(ERROR, wrkstr);                 perror("find_Lrecl");                 return(Lrecl); 	}	/* look for the case where this data file is exactly 1 data record in length */	if (num_bytes == 1024) 	{		rewind(fptr);		return 1024;	}	data_header = (struct input_data_logrec *)&buf[1024];	if (strncmp(data_header->hdr.scan.station,			stn_name, strlen(stn_name)) == 0)		if (strncmp(data_header->hdr.scan.channel,                                channel, strlen(channel)) == 0)		{			rewind(fptr);			return 1024;		}	/* check for file having exactly one 2k record */	if (num_bytes == 2048)	{		rewind(fptr);		return 2048;	}	data_header = (struct input_data_logrec *)&buf[2048];        if (strncmp(data_header->hdr.scan.station,                        stn_name, strlen(stn_name)) == 0)                if (strncmp(data_header->hdr.scan.channel,                                 channel, strlen(channel)) == 0)		{			rewind(fptr);                         return 2048;		}		rewind(fptr);		return 4096;}/* ------------------------------------------------------------------------- */int scan_for_seg_start(fname, fptr, start, end_tspan)char *fname;FILE *fptr;struct input_time *start, *end_tspan;{        struct input_time *rec_start;   	/* start time of data record */	int now_fptr, floor_fptr, ceiling_fptr;	int filesize, cnter = 0;	if (Debug >= D_MIN)	{		fprintf(stderr, "entering scan_for_seg_start()\n");		fprintf(stderr, "filename =%s \n", fname);		fprintf(stderr, "Looking for segment %d,%d,%d:%d:%d\n",				    start->year, start->day,					start->hour, start->minute, start->second);	}	filesize = get_fsize(fname);	if (filesize / Lrecl < 50)	{		/* don't bother with scan */			return;	}	if (start->hour > 12)	{		/* starts in the middle */		now_fptr = filesize/2;	}	else	{		now_fptr = filesize / 8;	}	fseek(fptr, (now_fptr / Lrecl) * Lrecl, 0);	ceiling_fptr = filesize;	fread(buf, sizeof(buf), 1, fptr);	rec_start = (struct input_time *)&buf[20];	fseek(fptr, -Lrecl, 1);	if ((cmp_time (*start, rec_start, 100) < 0))	{		/* bail */		rewind(fptr);		return;	}	else	if ((cmp_time (*start, rec_start, 100) == 0))       	{		return;	}	floor_fptr = ftell(fptr);	now_fptr = (ceiling_fptr - floor_fptr) / 2;	now_fptr = ((int)(now_fptr / Lrecl)) * Lrecl;	fseek(fptr, now_fptr, 1);	while (1)	{		fread(buf, sizeof(buf), 1, fptr);		fseek(fptr, -Lrecl, 1);               	rec_start = (struct input_time *)&buf[20];		/* record is equal */		if (cmp_time (rec_start, *start, 100) == 0)			return;		/* record is less than request, 		 * record becomes the floor,		 * try again.		 */               	if (cmp_time (rec_start, *start, 100) < 0)		{			floor_fptr = ftell(fptr);                       	if (((ceiling_fptr - floor_fptr) / Lrecl < 10) ||                                cnter > 8)                        {                                /* close enough, bail using floor_fptr */                                 return;                         }                                        			now_fptr = (ceiling_fptr - floor_fptr) / 2;                 	now_fptr = ((int)(now_fptr / Lrecl)) * Lrecl;			fseek(fptr, now_fptr, 1); 		}		/* record is later than request,		 * record becomes ceiling, try again		 */		else                { 			ceiling_fptr = ftell(fptr); 			if (((ceiling_fptr - floor_fptr) / Lrecl < 10) ||				cnter > 8)			{				/* close enough, bail using floor_fptr */				fseek(fptr, -(ceiling_fptr - floor_fptr), 1);				return;			}			                        now_fptr = (ceiling_fptr - floor_fptr) / 2;                           now_fptr = ((int)(now_fptr / Lrecl)) * Lrecl;			fseek(fptr, -now_fptr, 1);                }		cnter++;	}		/* while cnter < 4 */	return;}/* ------------------------------------------------------------------------ */#include <sys/stat.h>int get_fsize(fname)char *fname;{	struct stat s;         stat(fname, &s);         return s.st_size; }/* ------------------------------------------------------------------------ */

⌨️ 快捷键说明

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