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

📄 output_seed.c

📁 解吸SEED格式的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
            fprintf(stderr, "output_abbrev_header: Unable to write output file!\n");                                                                                       perror("output_abbrev_header");            fclose(fptr);              return 0;           }                     type33_ptr = type33_ptr->next;         memset(buff, 0, sizeof(buff));        }       /* while type33_ptr */ 	while (type34_ptr)    {           sprintf(buff, "0340000%03d%s~%s~",                    type34_ptr->code, 					type34_ptr->name == NULL ? "" : type34_ptr->name, 					type34_ptr->description == NULL ? 							"" : type34_ptr->description);   		fix_rec_length(buff);         /* out to disk */   		if (!out_to_disk(fptr, buff, strlen(buff), 'A'))        {               fprintf(stderr, "output_abbrev_header: Unable to write output file!\n");                                                                                        perror("output_abbrev_header");             fclose(fptr);               return 0;        }         type34_ptr = type34_ptr->next;        memset(buff, 0, sizeof(buff));     }       /* while type34_ptr */ 	while (type35_ptr)    {           sprintf(buff, "0350000%03d%04d",                    type35_ptr->code, type35_ptr->number_beams);		ch_ptr = buff + strlen(buff);		for (i = 0; i < type35_ptr->number_beams; i++)		{			sprintf(ch_ptr, "%-5s%2s%3s%04d%1.3f",				type35_ptr->beam[i].station,				type35_ptr->beam[i].location,				type35_ptr->beam[i].channel,				type35_ptr->beam[i].subchannel,				type35_ptr->beam[i].weight);			ch_ptr = buff + strlen(buff);		} 		fix_rec_length(buff);         /* out to disk */           if (!out_to_disk(fptr, buff, strlen(buff), 'A'))             {               fprintf(stderr, "output_abbrev_header: Unable to open output file!\n");                                                                                        perror("output_abbrev_header");             fclose(fptr);               return 0;        }         type35_ptr = type35_ptr->next;        memset(buff, 0, sizeof(buff));     }       /* while type35_ptr */	if (!fill_to_LRECL(fptr))    {        fprintf(stderr, "output_abbrev_header: Unable to write header!\n");        perror("output_abbrev_header");    }	fclose(fptr);	return 1; }/* ------------------------------------------------------------------------- */int output_volume_headers(){	FILE *fptr;	char buff[15000];		/* holds each blockette as it is built 							 * needs to de big enough to hold 							 * blks 10, 11, 12 */	char *c_ptr = buff;	char *xc_ptr;	char wrkstr[250];	struct station_list *s_list_ptr;	struct tspan_list *t_list_ptr;	if ((fptr = fopen(VOL_FNAME, "w")) == NULL)	{		fprintf(stderr, "output_volume_header: Unable to open output file!\n");		perror("output_volume_header");		return 0;	}	/* build the Volume header blockettes, 10, 11, 12 */	/* type 10 */	sprintf(c_ptr, "0100000");	c_ptr = buff + strlen(buff);  			/* type plus size */	sprintf(c_ptr, "%04.1f%02d", type10.version, type10.log2lrecl);	c_ptr = buff + strlen(buff);	sprintf(c_ptr, "%4d,%03d,%02d:%02d:%02d.%04d~", 				beg_time.year, beg_time.day, beg_time.hour,				beg_time.minute, beg_time.second, beg_time.fracsec);	c_ptr = buff + strlen(buff);	sprintf(c_ptr, "%4d,%03d,%02d:%02d:%02d.%04d~",                    end_time.year, end_time.day, end_time.hour,                end_time.minute, end_time.second, end_time.fracsec);     	c_ptr = buff + strlen(buff);        /* sizeof time field */		if (type10.version > 2.2)	{		sprintf(c_ptr, "%s~", get_date(wrkstr, sizeof(wrkstr)));		c_ptr = buff + strlen(buff);			sprintf(c_ptr, "%s~", type10.organization);		c_ptr = buff + strlen(buff);		sprintf(c_ptr, "%s~", type10.volume_label);		c_ptr = buff + strlen(buff);	}	else		/* create some fields */	{		sprintf(c_ptr, "%s~", get_date(wrkstr, sizeof(wrkstr)));		c_ptr = buff + strlen(buff); 		sprintf(c_ptr, "%s~", "IRIS DMC"); 		c_ptr = buff + strlen(buff); 		sprintf(c_ptr, "%s~", "generated by rdseed"); 		c_ptr = buff + strlen(buff);	}	fix_rec_length(buff);	/* blockette 11s */	sprintf(c_ptr, "0110000%03d", get_num_stations());	/* remember the record length spot */	xc_ptr = c_ptr;	c_ptr = buff + strlen(buff);	s_list_ptr = s_listhead;	while (s_list_ptr)    	{		/* leave the sequence number at zero for now, fix up later */		sprintf(c_ptr, "%-5s000000", s_list_ptr->station);		c_ptr = buff + strlen(buff);		s_list_ptr = s_list_ptr->next;    	}	fix_rec_length(xc_ptr);	/* now do type 12s */	sprintf(c_ptr, "01200630001%4d,%03d,%02d:%02d:%02d.%04d~%4d,%03d,%02d:%02d:%02d.%04d~000000",                beg_time.year, beg_time.day, beg_time.hour,                beg_time.minute, beg_time.second, beg_time.fracsec,                end_time.year, end_time.day, end_time.hour,                end_time.minute, end_time.second, end_time.fracsec);		if (!out_to_disk(fptr, buff, strlen(buff), 'V'))	{		fprintf(stderr, "output_volume_header : Unable to write volume header!\n");		perror("output_volume_headers");		return 0;	}	if (!fill_to_LRECL(fptr))	{		fprintf(stderr, "output_volume_header : Unable to write volume header!\n");         perror("output_volume_header");	}	fclose(fptr);	return 1; }/* ------------------------------------------------------------------------ */int out_to_disk(fptr, buffer, n, type)FILE *fptr;char *buffer;int n;			/* number of chars to write 		*/char type;		/* holds 'V' for volume, 'S' etc... */{	int i, ix;	char wrkstr[200];	/* if we are in range of 7 chars of a logical record break,	 * stop and fill with blanks to logical record, then     * proceed. 7 = sizeof blockette type + blockette size     */	if (spans_LRECL(fptr, 7))	{		fill_to_LRECL(fptr);		/* make new control header - continuous by definition */		sprintf(wrkstr, "%06d%c*", (ftell(fptr) / LRECL) + 1, type);         if (fwrite(wrkstr, 1, strlen(wrkstr), fptr) != strlen(wrkstr))        {            fprintf(stderr, "output_seed : Unable to write seed volume!\n");            perror("out_to_disk");             return 0;        }	}	/* is it time for a control header? */	if (((ftell(fptr) % LRECL) == 0) || (ftell(fptr) == 0))	{				sprintf(wrkstr, "%06d%c ", (ftell(fptr) / LRECL) + 1, type);		if (fwrite(wrkstr, 1, strlen(wrkstr), fptr) != strlen(wrkstr))		{			fprintf(stderr, "output_seed : Unable to write seed volume!\n");			perror("out_to_disk"); 			return 0;		}	}	i = 0;	while (i < n)	{		/* is it time for a control header? */		if ((ftell(fptr) % LRECL) == 0)		{			sprintf(wrkstr, "%06d%c*", (ftell(fptr) / LRECL) + 1, type);          		if (fwrite(wrkstr, 				   1, 				   strlen(wrkstr), fptr) != strlen(wrkstr))         		{            			fprintf(stderr, "output_seed : Unable to write seed volume!\n");             			perror("out_to_disk");              			return 0;         		}		}		/* if time for control header */		if ((ix = fputc(buffer[i], fptr)) != (int)((unsigned char)buffer[i]))		{			fprintf(stderr, "output_seed : Unable to write seed volume!\n");                			perror("out_to_disk");    			return 0;		}		i++;	}			/* while i < n */	return 1;}/* ----------------------------------------------------------------------- */int already_saved(station)char *station;{	struct station_list *s_list_ptr = s_listhead;	while (s_list_ptr)	{		if (strcmp(s_list_ptr->station, station) == 0)			return 1;	/* found it */		s_list_ptr = s_list_ptr->next;	}		return 0;}/* ----------------------------------------------------------------------- */int scan_stations(s)char *s;{	char fname[200];	    struct station_list *s_list_ptr = s_listhead;    int i;		/* start here */	i = get_file_size(VOL_FNAME) + get_file_size(ABBREV_FNAME);     while (s_list_ptr)    {   		if (strncmp(s_list_ptr->station, s, strlen(s_list_ptr->station)) == 0)			return i;		sprintf(fname, "%s.%s", STATION_FRONT_NAME, s_list_ptr->station);		i += get_file_size(fname);        s_list_ptr = s_list_ptr->next;     }   	/* got here, than error, not in list */	fprintf(stderr, "Error! scan_stations: unable to patch station index in block 11 for station %s\n", s_list_ptr->station);     return 0;}/* ----------------------------------------------------------------------- */#include <dirent.h>/* erase the working files - reset some variables for next time around */int clean_up_output_seed(){	DIR *dirp;	struct dirent *dp;		char orig_dir[MAXPATHLEN];        getcwd(orig_dir, MAXPATHLEN);	chdir(output_dir);	unlink(DATA_FILE);	unlink(FILE_70_NAME);	unlink(ABBREV_FNAME);	unlink(VOL_FNAME);	dirp = opendir(".");   	for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))   		if (strstr(dp->d_name, STATION_FRONT_NAME)) 			unlink(dp->d_name);	closedir(dirp);	memset((char *)&beg_time, 0, sizeof(struct time));	beg_time.year = 9999;	memset((char *)&end_time, 0, sizeof(struct time)); 	got_a_time_series = FALSE;	chdir(orig_dir);	return 1;}/* ----------------------------------------------------------------------- */int get_all_stations_fsize(){	char fname[200];        struct station_list *s_list_ptr = s_listhead;    int num_bytes = 0;         while (s_list_ptr)    {          sprintf(fname, "%s.%s", STATION_FRONT_NAME, s_list_ptr->station);         num_bytes += get_file_size(fname);         s_list_ptr = s_list_ptr->next;     }       return num_bytes;}/* ------------------------------------------------------------------------- */int get_num_stations(){    struct station_list *s_list_ptr = s_listhead;	int i = 0;    while (s_list_ptr)    {   		i++;        s_list_ptr = s_list_ptr->next;    }        return i; }/* ------------------------------------------------------------------------- */int get_num_tspans(){    struct tspan_list *t_list_ptr = t_span_head;    int i = 0;    while (t_list_ptr)    {        i++;        t_list_ptr = t_list_ptr->next;    }    return i;} /* ----------------------------------------------------------------------- */void fix_rec_length(b)char *b;{	char wrkstr[10];	sprintf(wrkstr,"%04d", strlen(b));	memcpy(b + 3, wrkstr, strlen(wrkstr));	return;}int fill_to_LRECL(fptr)FILE *fptr;{	if ((ftell(fptr) % LRECL) != 0)	{		while((ftell(fptr) % LRECL))		{			if (fputc(' ', fptr) != ' ')				return 0;					}	}	return 1;}/* --------------------------------------------------------------------- */int spans_LRECL(fptr, span)FILE *fptr;int span;{        int where;        where = ftell(fptr);        if (((where + span) / LRECL) > (where / LRECL))                if ((where + span) % LRECL) /* land right on boundary */                        return TRUE;        return FALSE;}/* --------------------------------------------------------------------- */int get_file_size(f)char *f;{	struct stat s;	stat(f, &s);	return s.st_size;}/* ---------------------------------------------------------------------- */int free_station_list(s_node)struct station_list **s_node;{	if (*s_node)	{		free_station_list(&((*s_node)->next));		free(*s_node);		*s_node = NULL;	}    return 1;}/* ---------------------------------------------------------------------- */

⌨️ 快捷键说明

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