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

📄 output_seed.c

📁 解吸SEED格式的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
		if (fwrite(buff, 1, num_bytes, out_fptr) != num_bytes)		{			free(buff);            		fclose(fptr);             		fclose(out_fptr); 			return 0;		}	}	fclose(fptr);	fptr = fopen(ABBREV_FNAME, "r");    	while ((num_bytes = fread(buff, 1, LRECL, fptr)) > 0)    	{		/* update control header record count */        	sprintf(wrkstr, "%06d", (ftell(out_fptr) / LRECL) + 1);          	memcpy(buff, wrkstr, strlen(wrkstr));         	if (fwrite(buff, 1, num_bytes, out_fptr) != num_bytes)		{			free(buff);            		fclose(fptr);             		fclose(out_fptr);             		return 0;		}    	}	fclose(fptr);    	while (s_list_ptr)    	{        	sprintf(fname, "%s.%s", 			STATION_FRONT_NAME, 			s_list_ptr->station);		    		fptr = fopen(fname, "r");		while ((num_bytes = fread(buff, 1, LRECL, fptr)) > 0)    		{			/* update control header record count */         		sprintf(wrkstr, "%06d", 				(ftell(out_fptr) / LRECL) + 1);            		memcpy(buff, wrkstr, strlen(wrkstr));           		if (fwrite(buff, 1, num_bytes, out_fptr) != num_bytes)			{				free(buff);            			fclose(fptr);             			fclose(out_fptr);             			return 0;			}    		}     		fclose(fptr);        	s_list_ptr = s_list_ptr->next;    	}		/* while stations */	fptr = fopen(FILE_70_NAME, "r");     	while ((num_bytes = fread(buff, 1, LRECL, fptr)) > 0)    	{		/* update control header record count */         	sprintf(wrkstr, "%06d", (ftell(out_fptr) / LRECL) + 1);            	memcpy(buff, wrkstr, strlen(wrkstr));           	if (fwrite(buff, 1, num_bytes, out_fptr) != num_bytes)		{			free(buff);            		fclose(fptr);             		fclose(out_fptr);             		return 0;		}    	}     	fclose(fptr);	/* now the data file */	fptr = fopen(DATA_FILE, "r");    	while ((num_bytes = fread(buff, 1, LRECL, fptr)) > 0)    	{        	/* update control header record count */         	sprintf(wrkstr, "%06d", (ftell(out_fptr) / LRECL) + 1);            	memcpy(buff, wrkstr, strlen(wrkstr));           	if (fwrite(buff, 1, num_bytes, out_fptr) != num_bytes)        	{            		free(buff);			fclose(fptr);			fclose(out_fptr);            		return 0;        	}    	}        	fclose(fptr);	fclose(out_fptr);	free(buff);	return 1;	}/* ------------------------------------------------------------------------ */int patch_indexes(){	if (!patch_70())		return 0;	/* now patch the volume header indexes for station recs */	if (!patch_vol_header())		return 0;	return 1;			}/* ------------------------------------------------------------------------- */int patch_vol_header(){	char buff[800]; /* must be large enough for max size blk 10 */	char tmp_fname[200];	char wrkstr[100];	int i, ix;     FILE *fptr, *fptr_tmp;	fptr = fopen(VOL_FNAME, "r");    if (fptr == NULL)    {        fprintf(stderr, "Error! patch_vol_header: unable to open volume header output file: %s\n", FILE_70_NAME);        perror("patch_vol_header");        return 0;    }    sprintf(tmp_fname, "%s.tmp", VOL_FNAME);    fptr_tmp = fopen(tmp_fname, "w");    if (fptr_tmp == NULL)    {        fprintf(stderr, "Error! patch_vol_header: unable to open temp volume header file\n");        perror("patch_vol_header");        return 0;    }	/* read in and transfer the data record part */	if (fread(buff, 1, 8, fptr) != 8)       /* refer to SEED manual */    {        fprintf(stderr, "Error! patch_vol_header: bad read\n");        perror("patch_vol_header");        return 0;    }	 /* out to temp file */    if (fwrite(buff, 1, 8, fptr_tmp) != 8)    {        perror("patch_vol_header");        return 0;    } 	/* read the block 10 - output to temp file */	if (fread(buff, 1, 7, fptr) != 7) 		/* refer to SEED manual */	{		fprintf(stderr, "Error! patch_vol_header: bad read\n");		perror("patch_vol_header");		return 0;	}	buff[7] = 0;	ix = atoi(&buff[3]) - 7;		/* record size - refer to manual */	/* out to temp file */	if (fwrite(buff, 1, 7, fptr_tmp) != 7)	{		perror("patch_vol_header");		return 0;	}	/* now the rest */	if (fread(buff, 1, ix, fptr) != ix)       /* */      {        fprintf(stderr, "Error! patch_vol_header: bad read\n");         perror("patch_vol_header");         return 0;     }        /* out to temp file */     if (fwrite(buff, 1, ix, fptr_tmp) != ix)    {        perror("patch_vol_header");         return 0;    }		/* now the block 11 */	if (fread(buff, 1, 10, fptr) != 10)       /* refer to manual */      {          fprintf(stderr, "Error! patch_vol_header: bad read\n");            perror("patch_vol_header");            return 0;      } 		/* extract and use the number of stations */	buff[10] = 0;	ix = atoi(&buff[7]);		/* refer to manual */	/* don't forget to write to temp */	if (fwrite(buff, 1, 10, fptr_tmp) != 10)       {          perror("patch_vol_header");            return 0;      }	for (i = 0; i < ix; i++)	{		int station_loc;		if (fread(buff, 1, 11, fptr) != 11)       /* sta ID and seq #*/    	{          	fprintf(stderr, "Error! patch_vol_header: bad read\n");            	perror("patch_vol_header");            	return 0;      	} 		sprintf(wrkstr, "%5.5s", buff);				station_loc = scan_stations(wrkstr);		station_loc /= LRECL;		/* since rdseed starts at rec # 1 - add one to total */		station_loc += 1;		sprintf(&buff[5], "%06d", station_loc);		if (fwrite(buff, 1, strlen(buff), fptr_tmp) != strlen(buff))        	{           	perror("patch_vol_header");             	return 0;       	} 	}		/* for i to num_stations */	/* continue with blockette 12 */	/* we always write 63 byte block 12s */	if (fread(buff, 1, 63, fptr) != 63)           {        fprintf(stderr, "Error! patch_vol_header: bad read\n");        perror("patch_vol_header");        return 0;    }  	ix = get_file_size(VOL_FNAME) + get_file_size(ABBREV_FNAME);	ix += get_all_stations_fsize();	ix /= LRECL;	/* since rdseed starts at rec # 1 - add one to total */ 	ix += 1;	sprintf(&buff[57], "%06d", ix);	/* seq # starts at byte 57 */		/* out to temp file */    if (fwrite(buff, 1, 63, fptr_tmp) != 63)    {        perror("patch_vol_header");        return 0;    }       /* now the rest - blank fill until LRECL boundary */	while ((ix = fread(buff, 1, sizeof(buff), fptr)) != 0)		if (fwrite(buff, 1, ix, fptr_tmp) != ix)		{			perror("patch_vol_header");        	return 0;		}	fclose(fptr);	fclose(fptr_tmp);	rename(tmp_fname, VOL_FNAME);	return 1; }/* ------------------------------------------------------------------------- */int patch_70(){int num_bytes;		int where, xx;	struct local_type74 *t_74;	struct station_list *s_list_ptr = s_listhead;	char buff[4096];	char wrkstr[200], tmp_fname[200];	FILE *fptr, *fptr_tmp;	/* figure out the logical record offsets of the data block , so we can 	 * update the timespans later - mearly means adding up the file sizes	 * of the header files.	 * Note: file 70 lacks the record header (8 bytes per LRECL) so	 *       add it into the soup. Also hasn't been buffed up to the 	 * 	     LRECL boundary....	 */	where = get_file_size(VOL_FNAME) + 				get_file_size(ABBREV_FNAME) + get_file_size(FILE_70_NAME);	/* add in the stations, could be many */	where += get_all_stations_fsize();	/* Notice, we need to add in the block 70s size to the data record     	 * offset added later     	 */    	where += 54;	/* Notice, add in the 8 bytes per LRECLs too */	where += (((get_file_size(FILE_70_NAME) / LRECL) + 1) * 8);	/* since FILE_70_NAME is the only file which hasn't been buffed up to	 * the LRECL boundary, compute it here 	 */	/* added in the 54 bytes to be added later */	xx = get_file_size(FILE_70_NAME) + 54;	if (xx < LRECL)		where += LRECL - xx;	else		where += (LRECL - (xx % LRECL));	/* where += (where % LRECL); */	/* "where" is the # bytes, make into LRECLs */	where /= LRECL; 	/* add one because rdseed subtracts one - don't ask why... */	where += 1;    	fptr = fopen(FILE_70_NAME, "r");    	if (fptr == NULL)	{		fprintf(stderr, "Error! patch_70: unable to open timespan output file: %s\n", FILE_70_NAME);		perror("patch_70"); 		return 0; 	}	sprintf(tmp_fname, "%s.tmp", FILE_70_NAME);	fptr_tmp = fopen(tmp_fname, "w"); 	if (fptr_tmp == NULL)	{		fprintf(stderr, "Error! patch_70: unable to open temp timespan output file\n"); 		perror("patch_70"); 		return 0; 	}	/* writeout the block 70 - always 54 bytes in length */    sprintf(wrkstr, "0700054%1s%4d,%03d,%02d:%02d:%02d.%04d~%4d,%03d,%02d:%02d:%02d.%04d~",                type70_head ? type70_head->flag ? type70_head->flag :"P" :"P",                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_tmp, wrkstr, strlen(wrkstr), 'T'))    	{		fprintf(stderr, "Error! output_seed_volume: unable to write block 70 output file\n");         	perror("patch_70");         	return 0;    	}/*	while (fread(&t_74, 			type10.version < 2.3 ? sizeof(t_74) - 2 : sizeof(t_74), 			1, fptr) == 1)    	{        	int ix;*/	/* read in blockette type and length */	while (fread(buff, 7, 1, fptr) == 1)    	{        	int ix, type, length;				sprintf(wrkstr, "%3.3s", buff);		type = atoi(wrkstr);		sprintf(wrkstr, "%4.4s", &buff[3]);                length = atoi(wrkstr);		if (type < 70 || type > 80)		{			fprintf(stderr, "patch_70s(), Bad blockette scanned, blockette :%d\nUnable to continue\n", type);			fclose(fptr);			return 0;		}		/* 10000 is arbitrary */                if (length <= 0 || length > 10000)                {                         fprintf(stderr, "patch_70s(), Bad blockette length scanned, blockette :%d, length: %d\nUnable to continue\n", type, length);			fclose(fptr);                         return 0;                }		/* read in the rest of the story */ 		if (fread(&buff[7],length - 7, 1, fptr) != 1)		{			fprintf(stderr, "patch_70s(), Unable to continue, bad read (I/O)\n");			perror("patch_70()");			fclose(fptr);                         return 0;		}		switch (type)		{			case 71:				if (!out_to_disk(fptr_tmp, buff,							length, 'T'))                                {       fprintf(stderr, "Error! output_seed_volume: unable to write block 70 output file\n");                                         perror("patch_70");                                         return 0;				}				break;				case 74:				t_74 = (struct local_type74 *)buff;		         			memcpy(wrkstr, 					t_74->start_index, 					sizeof(t_74->start_index));        			wrkstr[sizeof(t_74->start_index)] = 0;            			ix = atoi(wrkstr);         			sprintf(wrkstr, "%06d", ix + where);        			memcpy(t_74->start_index, 					wrkstr, 						strlen(wrkstr));        			/* ------------- */        			memcpy(wrkstr, 					t_74->end_index, 					sizeof(t_74->end_index));        			wrkstr[sizeof(t_74->end_index)] = 0;				/* ### took out the ++1 add one so 				 *      it points past the T rec 				 */         			ix = atoi(wrkstr);  				/* ix++; */         			sprintf(wrkstr, "%06d", ix + where);        			memcpy(t_74->end_index, 					wrkstr, 					strlen(wrkstr));         			/* out to temp file */         			if (!out_to_disk(fptr_tmp, t_74, 						  type10.version < 2.3 ? 						sizeof(*t_74) - 2:						     sizeof(*t_74), 'T'))        			{       fprintf(stderr, "Error! output_seed_volume: unable to write block 70 output file\n"); 

⌨️ 快捷键说明

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