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

📄 output_seed.c

📁 解吸SEED格式的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*===========================================================================*//* SEED reader     |            output_seed                |    subprocedure *//*===========================================================================*//*					Problems:	none known	Language:	C, hopefully ANSI standard	Author:		Chris Laughbon		Revisions:	August 11, 95 - changed path_74 to output the record			properly*/#include "rdseed.h"					/* SEED tables and structures */#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/param.h>#define SEED_VOL_FNAME		"seed.rdseed"#define DATA_FILE 		"seed.data"#define FILE_70_NAME 		"seed.070"#define STATION_FRONT_NAME 	"seed.station_headers"#define ABBREV_FNAME 		"seed.abbrev_headers"#define VOL_FNAME		"seed.vol_headers"#define BOOL intstatic int End_recnum = 0;static int DataRecNum = 0;static int Start_recnum = 0;static int Num_time_spans = 0;/* used in type 10 generation */static struct time beg_time = {9999,0,0,0,0, 0};static struct time end_time = {0,0,0,0,0, 0};struct station_list{	char station[5];	struct station_list *next;};static struct station_list *s_listhead = NULL;static struct station_list *s_listtail = NULL; struct tspan_list {	char beg_time[23];	char end_time[23];	struct tspan_list *next;};static struct tspan_list *t_span_head = NULL;static struct tspan_list *t_span_tail = NULL;static BOOL got_a_time_series = FALSE;extern struct stn_tspan *stn_listhead;/* ---------------------------------------------------------------------- *//* absconded from structures.h, network code moved to end of record, * and the *next field was eliminated, as was the accelerator struct -  * not used. All *char were made into arrays of required size */struct          local_type74            /* time series index */{	char 	type[3];		/* block 74 */	char 	blk_length[4];		/* length */    	char    station[5];             /* station name */    	char    location[2];            /* station location */    	char    channel[3];             /* channel name */    	char    starttime[23];          /* start time of time series */    	char 	start_index[6];         /* index to start of data */    	char    start_subindex[2];      /* start subindex number */    	char    endtime[23];            /* end time of time series */    	char	end_index[6];           /* index to end of data */    	char	end_subindex[2];        /* end subindex number */    	char 	number_accelerators[3]; /* number of data pieces */    	char    network_code[2];        /* v2.3 network code */};/* --------- Prototypes ------------- */struct type50 *get_station_rec();void fix_rec_length();int get_file_size();char *get_date();/* ---------------------------------------------------------------------- */void output_seed_data_file(input_data_ptr)char *input_data_ptr;{	char orig_dir[MAXPATHLEN];	/* fixed data header part */    	struct input_data_hdr *input_data_hdr = 				(struct input_data_hdr *)input_data_ptr; 	FILE *outfile;		/* output file pointer */        getcwd(orig_dir, MAXPATHLEN);	chdir(output_dir);	if ((outfile = fopen(DATA_FILE, "a")) == NULL)	{		fprintf (stderr, "\tWARNING (output_seed):  ");		fprintf (stderr, "Output file %s is not available for writing.\n",			DATA_FILE);		fprintf (stderr, "\tExecution continuing.\n");				chdir(orig_dir);		return;	}	if (fwrite("000000", 1, 6, outfile) != 6)	{		fprintf (stderr, "\tWARNING (output_seed):  ");        	fprintf (stderr, "Output file %s is not available for writing.\n", DATA_FILE);        	fprintf (stderr, "\tExecution continuing.\n");		chdir(orig_dir);        	return;	}	if (fwrite(&input.type, 1, 1, outfile) != 1)	{		fprintf (stderr, "\tWARNING (output_seed):  ");        	fprintf (stderr, "Output file %s is not available for writing.\n", DATA_FILE);        	fprintf (stderr, "\tExecution continuing.\n");		chdir(orig_dir);        	return;	}	if (fwrite(" ", 1, 1, outfile) != 1)	{		fprintf (stderr, "\tWARNING (output_seed):  ");        	fprintf (stderr, "Output file %s is not available for writing.\n", DATA_FILE);        	fprintf (stderr, "\tExecution continuing.\n");		chdir(orig_dir);        	return;	}	if (fwrite(input_data_ptr, 1, LRECL - 8, outfile) != LRECL - 8) 	{         	fprintf (stderr, "\tWARNING (output_seed):  ");         	fprintf (stderr, "Output file %s is not available for writing.\n", DATA_FILE);         	fprintf (stderr, "\tExecution continuing.\n"); 		chdir(orig_dir);		return; 	}	fclose(outfile);	/* set the record count variable to reflect new logical record */		DataRecNum += LRECL;	if (DataRecNum % (2 << (type10.log2lrecl - 1)) == 0)	{		End_recnum++;		DataRecNum = 0;	}	chdir(orig_dir);	return;}				/* output_seed *//* -------------------------------------------------------------------------- *//* this routine is called br parse_type71() */void update_type71(b_71)char *b_71;{	FILE *fptr;        char wrkstr[20];	int length;	char orig_dir[MAXPATHLEN];        getcwd(orig_dir, MAXPATHLEN);	chdir(output_dir);	/* get block size - Always byte 3 four four bytes */	sprintf(wrkstr, "%4.4s", b_71 + 3);	length = atoi(wrkstr);        /* out to file */        fptr = fopen(FILE_70_NAME, "a");        if (fptr == NULL)        {                fprintf(stderr, "Warning!  update_type71: unable to open the file: %s.\n", FILE_70_NAME);                perror("update_type71");		chdir(orig_dir);                return;        }        if (fwrite(b_71, length, 1, fptr) != 1)        {		fprintf(stderr, "output_block_71: Unable write block 71s!\n");            	perror("update_blk_71");			chdir(orig_dir);			return;        }	chdir(orig_dir);        fclose(fptr);}/* -------------------------------------------------------------------------- *//* -------------------------------------------------------------------------- *//* this routine is called by time_span_out every time a time span is  * realized (process_data).  */void update_type74(hdr)struct data_hdr *hdr;{	FILE *fptr;	char wrkstr[20];	struct station_list *station_node;	struct tspan_list *tspan_node;	/* create a blockette 74 with record numbers as computed above */	struct local_type74 t_74;	int num_seconds;	struct time t;	char orig_dir[MAXPATHLEN];        getcwd(orig_dir, MAXPATHLEN);	/* if no station/channel information found simply exit */	if ((current_station == NULL) || (current_channel == NULL))		return;	chdir(output_dir);	if (!already_saved(hdr->station))	{		/* save station information for later use */		if ((station_node = (struct station_list *)malloc(sizeof(struct station_list))) == NULL)		{			fprintf(stderr, "update_type74: Out of Memory!! Can't output type 74s\n");			chdir(orig_dir);			return;		}		strcpy(station_node->station, hdr->station);		station_node->next = NULL;		append_linklist_element(station_node, s_listhead, s_listtail);	}	Num_time_spans++;	memset((char *)&t_74, ' ', sizeof(t_74));	sprintf(wrkstr, "074%04d", sizeof(t_74));	memcpy(t_74.type, wrkstr, 7);	memcpy(t_74.station, hdr->station, strlen(hdr->station));	memcpy(t_74.channel, hdr->channel, strlen(hdr->channel));	memcpy(t_74.location, hdr->location, strlen(hdr->location));	sprintf(t_74.starttime, "%d,%03d,%02d:%02d:%02d.%04d~",				hdr->time.year, hdr->time.day, hdr->time.hour,				hdr->time.minute, hdr->time.second, hdr->time.fracsec);	sprintf(wrkstr, "%06d", Start_recnum);	memcpy(t_74.start_index, wrkstr, 6);	memcpy(t_74.start_subindex, "01", 2);		/* need to compute ending time based on start time and number of samples	 * and the sample rate.	 */	num_seconds = hdr->nsamples / hdr->sample_rate;	/* multiply by 10000 moves past the fractional part...see timeadd() */	t = timeadd_double(hdr->time, ((double)num_seconds) * 10000);  	sprintf(t_74.endtime, "%d,%03d,%02d:%02d:%02d.%04d~",                 t.year, t.day, t.hour,                t.minute, t.second, t.fracsec);		/* save the starting time and ending time IF smaller or larger for	 * type10 volume info later */	if (timecmp(hdr->time, beg_time) < 0)		memcpy((char *)&beg_time, (char *)&hdr->time, sizeof(struct time));	if (timecmp(t, end_time) > 0)            memcpy((char *)&end_time, (char *)&t, sizeof(struct time));	/* save tspan for later update of type12 */	if ((tspan_node = (struct tspan_list *)malloc(sizeof(struct tspan_list))) == NULL)	{		fprintf(stderr, "update_type74: Out of Memory!! Can't output type 74s\n");		chdir(orig_dir);		return;	}	sprintf(tspan_node->beg_time, "%d,%03d,%d:%d:%d.%4d", 				beg_time.year, beg_time.day,			  	beg_time.hour, beg_time.minute,				beg_time.second, beg_time.fracsec);	sprintf(tspan_node->end_time, "%d,%03d,%d:%d:%d.%4d",                	end_time.year, end_time.day,                end_time.hour, end_time.minute,                end_time.second, end_time.fracsec);	tspan_node->next = NULL;   	append_linklist_element(tspan_node, t_span_head, t_span_tail);    	sprintf(wrkstr, "%06d", End_recnum - 1);     	memcpy(t_74.end_index, wrkstr, 6);	memcpy(t_74.end_subindex, "01", 2);	memcpy(t_74.number_accelerators, "000", 3);	if (type10.version >= 2.3)		memcpy(t_74.network_code, 					hdr->network,					strlen(hdr->network));	/* if this is changed, make sure to update waffle, which reads	 * these fields, stn, chn, net 	 */	printf("Writing %s %2.2s : %s from %d,%03d,%02d:%02d:%02d,%04d to %d,%03d,%02d:%02d:%02d,%04d\n", hdr->station, 			type10.version >= 2.3 ?				hdr->network:				"NA",		 	hdr->channel, 			hdr->time.year,			hdr->time.day,			hdr->time.hour,			hdr->time.minute,			hdr->time.second,			hdr->time.fracsec,                	t.year,                	t.day,                 	t.hour,                 	t.minute,                 	t.second,                 	t.fracsec);                  					/* out to file */	fptr = fopen(FILE_70_NAME, "a");		if (fptr == NULL)	{		fprintf(stderr, "Warning!  update_type70: unable to open the file: %s.\n", FILE_70_NAME);			perror("update_type74");		chdir(orig_dir);		return;	}	if (fwrite(&t_74, 			type10.version < 2.3 ? sizeof(t_74) - 2 :sizeof(t_74), 			1, fptr) != 1)    	{            	fprintf(stderr, "output_block_74: Unable write block 74s!\n");            	perror("update_blk_74");		chdir(orig_dir);		return;	}	/* reset the starting recnum to be the ending */	Start_recnum = End_recnum;	fclose(fptr);	got_a_time_series = TRUE;	/* flag output_seed_volume so it knows 								 * that we got at least 1 time series 								 */	chdir(orig_dir);	return;	}/* ------------------------------------------------------------------------ *//* - output blockettes 	volume * -                  	abbreviations * -    	   	station/channel/responses * -                   	blockette 74s * -   		   	data file * */void output_seed_volume(){	char orig_dir[MAXPATHLEN];        getcwd(orig_dir, MAXPATHLEN);	chdir(output_dir);	if (!got_a_time_series)	{		chdir(orig_dir);		return;	}		/* open up the output volume */	if (!output_volume_headers())	{		chdir(orig_dir);		return;	}	if (!output_abbrev_headers())	{		chdir(orig_dir);		return;	}	if (!output_station_headers())	{		chdir(orig_dir);		return;	}	/* fix up the various record indexes */	if (!patch_indexes())	{		chdir(orig_dir);		return;	}	/* wow - ready to pack em together into a volume */	if (!pack_em())	{		fprintf(stderr, "Error! output_seed_volume: unable to pack output seed file!\n");		perror("output_seed_volume");	}	free_station_list(&s_listhead); 	clean_up_output_seed();  	Start_recnum = 0;	End_recnum = 0;	Num_time_spans = 0;	chdir(orig_dir);	return;}/* ------------------------------------------------------------------------- *//* ------------------------------------------------------------------------- */int pack_em(){	FILE *fptr;	FILE *out_fptr;	char *buff; 	char fname[200];	char wrkstr[200];    	struct station_list *s_list_ptr = s_listhead;    	int num_bytes = 0;	if ((buff = malloc(LRECL)) == 0)	{		fprintf(stderr, "Error! pack_em: no memory for buffer\n");		perror("pack_em");		return 0;	}	out_fptr = fopen(SEED_VOL_FNAME, "w");	fptr = fopen(VOL_FNAME, "r");	while ((num_bytes = fread(buff, 1, LRECL, fptr)) > 0)	{		/* one last thing we need to do is to update the control	     	 * header with the current record count		 */		sprintf(wrkstr, "%06d", (ftell(out_fptr) / LRECL) + 1);		memcpy(buff, wrkstr, strlen(wrkstr));

⌨️ 快捷键说明

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