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

📄 seg2sgey.cpp

📁 地震勘探数据格式之间的相互转换的源码程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				{
					outheadc = (char*)&segyreelheader[k];
					temp = outheadc[0];
					outheadc[0] = outheadc[1];
					outheadc[1] = temp;
				}*/
				fwrite(segyreelheader,1,3600,f2);
			}
			//
			//
			//
			//
			//
			//
			//
			//
			//
			//
/*			for(k=0; k<7; k++)	// convert byte 0--27 delete for yuncheng
			{
					outheadc = (char*)&outheadl[k];
					temp = outheadc[3];
					outheadc[3] = outheadc[0];
					outheadc[0] = temp;
					temp = outheadc[2];
					outheadc[2] = outheadc[1];
					outheadc[1] = temp;
			}
			for(k=9; k<17; k++)	// convert byte 36--67
			{
					outheadc = (char*)&outheadl[k];
					temp = outheadc[3];
					outheadc[3] = outheadc[0];
					outheadc[0] = temp;
					temp = outheadc[2];
					outheadc[2] = outheadc[1];
					outheadc[1] = temp;
			}
			for(k=18; k<22; k++)	// convert byte 72--87
			{
					outheadc = (char*)&outheadl[k];
					temp = outheadc[3];
					outheadc[3] = outheadc[0];
					outheadc[0] = temp;
					temp = outheadc[2];
					outheadc[2] = outheadc[1];
					outheadc[1] = temp;
			}
			//
			for(k=14; k<18; k++)  // convert byte 28--35
			{
					outheadc = (char*)&outhead[k];
					temp = outheadc[0];
					outheadc[0] = outheadc[1];
					outheadc[1] = temp;
			}
			for(k=34; k<36; k++)  // convert byte 68--71
			{
					outheadc = (char*)&outhead[k];
					temp = outheadc[0];
					outheadc[0] = outheadc[1];
					outheadc[1] = temp;
			}
			for(k=44; k<90; k++)  // convert byte 88--179
			{
					outheadc = (char*)&outhead[k];
					temp = outheadc[0];
					outheadc[0] = outheadc[1];
					outheadc[1] = temp;
			}  */
			if(120 != (k = fwrite(outhead,2,120,f2)))
			{
				printf("Write failure during header write\n");
				exit(-1);
			}
/*			for(k=0; k<numsamples; k++)	// delete for yuncheng 062001
			{
					outheadc = (char*)&outbuf[k];
					temp = outheadc[3];
					outheadc[3] = outheadc[0];
					outheadc[0] = temp;
					temp = outheadc[2];
					outheadc[2] = outheadc[1];
					outheadc[1] = temp;
			}*/ // for yuncheng  062001 
			if((short)numsamples != (k = fwrite(outbuf,4,(short)numsamples,f2)))
			{
				printf("Write failure during trace write\n");
				exit(-1);
			}
		}  // end trace loop
		fclose(f1);
		if((answer[0] == 'y') || (answer[0] == 'Y'))
		{
			printf("Deleting %s\n",fname);
			i = unlink(fname);
			if(i)
				printf("  DELETE FAILED ON %s!\n",fname);
		}
		outhead[87] = 0;
		if(fcomp)	// add 4 lines by ytl 000714
			kk1--;
		else
			kk1++;
	} // end of "for (kk=fstart; kk<=fend; kk++)"
	fclose(f2);	// NEW ADD
}

void readsegykeys()
{
	short i,j,k;
	char keypath[STRINGWIDTH];  //

	_searchenv("SEGYKEYW.ORD","PATH",keypath);
	keyfile = fopen(keypath,"rb");

	if(keyfile == NULL)
	{
		printf("segy keyword file SEGYKEYW.ORD not found.Can not continue\n");
		exit(1);
	}
	i = 0;
	while(fgets(input,STRINGWIDTH,keyfile))
	{
		j = 0;
//		aa = strlen(input);
		if(strlen(input) > STRINGWIDTH)
		{
			printf("String too long!\n");
			exit(1);
		}
// ok now must parse the data if left most character = "*"
// then this line is a comment and should be ignored.
		if(input[0] == 42)  // 42 = *
		{
			continue;
		}
		strcpy(inputbuf,input);  //
		token = strtok(inputbuf," ");
		//
		strncpy(&segykeyword[i][0],token,1+strlen(token));
		//
		token = strtok(NULL," ");
		segyfunction[i] = atoi(token);  //
		token = strtok(NULL," ");
		segyheader[i] = atoi(token);
		token = strtok(NULL," ");
		j = 0;
		while(token != NULL)
		{
			segyparms[i][j] = atof(token);
			token = strtok(NULL," ");
			j++;
			if(j > MAXPARMS)
			{
				printf("Too many parameters in %s keyword\n",&segykeyword[i][0]);
				printf("No more than &d allowed per function\n",j-1);
				exit(-1);
			}
		}  // end parameter extraction while loop
		i++;
	}  //end keyword string while loop
	totalkeys = i;
}
void keycheck()
{
	short i,j,k;
	short matchfound;
	char string2[STRINGWIDTH];
	unsigned short aa;

	strcpy(string2,string1);
	matchfound = 0;
	for(i=0; i<totalkeys; i++)
	{
		strcpy(string1,string2);
		aa = strlen(&segykeyword[i][0]);
		if(0 == strnicmp(string1,&segykeyword[i][0],aa))//strlen(&segykeyword[i][0])));
		{
			matchfound = 1;
			switch(segyfunction[i])
			{
			case 0:
				{
					break;
				}
			case 1:
				{
					token = strtok(string1," ");
					token = strtok(NULL," ");
					//
					//
					//
					outhead[segyheader[i]-1] = atof(token) *segyparms[i][0];
					break;
				}
			case 2:
				{
					token = strtok(string1," ");
					token = strtok(NULL," ");
					if(0 == strcmpi("AS_ACQUIRED",token))
					{
						segyreelheader[segyheader[i]-1] = 1;
					}
					if(0 == strcmpi("CDP_GATHER",token))
					{
						segyreelheader[segyheader[i]-1] = 2;
					}
					if(0 == strcmpi("CDP_STACK",token))
					{
						segyreelheader[segyheader[i]-1] = 4;
					}
					if(0 == strcmpi("COMMON_OFFSET",token))
					{
						segyreelheader[segyheader[i]-1] = 3;
					}
					if(0 == strcmpi("COMMON_RECEIVER",token))
					{
						segyreelheader[segyheader[i]-1] = 1;
					}
					if(0 == strcmpi("COMMON_SOURCE",token))
					{
						segyreelheader[segyheader[i]-1] = 1;
					}
					break;
				}
			case 3:
				{
//					strncpy((char*)[segyreelheader[80*(segyheader[i]-1)],string1,80);
					strncpy((char*)&segyreelheader[80*(segyheader[i]-1)],string1,80);
					break;
				}
			case 4:
				{
					token = strtok(string1," ");
					outhead[segyheader[i]-1] = 1;
					token = strtok(NULL," ");
					if(0 == strcmpi("SEICMIC_DATA",token))
					{
						outhead[segyheader[i]-1] = 1;
					}
					if(0 == strcmpi("DEAD",token))
					{
						outhead[segyheader[i]-1] = 2;
					}
					if(0 == strcmpi("TEST_DATA",token))
					{
						outhead[segyheader[i]-1] = 3;
					}
					if(0 == strcmpi("UPHOLE",token))
					{
						outhead[segyheader[i]-1] = 5;
					}
					if(0 == strcmpi("RADAR_DATA",token))
					{
						outhead[segyheader[i]-1] = 1;
					}
					break;
				}
			case 5:
				{
//					strcpy(string1,string2);
					token = strtok(string1," ");
//					token = strtok(NULL," ");
					if(segyheader[i] == 0)
					{
						short paramcount = 1;
						short headindex;
						token = strtok(NULL," ");
						while(token != NULL && paramcount < 10)
						{
							headindex = segyparms[i][paramcount]-1;
							outhead[headindex] = atof(token) * segyparms[i][0];
							paramcount++;
							token = strtok(NULL," ");
						}
					}
					if(segyheader[i] == 1)
					{
						short paramcount = 1;
						short headindex;
						long *outpoint;
						token = strtok(NULL," ");
						while(token != NULL && paramcount < 10)
						{
							headindex = segyparms[i][paramcount] - 2;
							outpoint = (long*)&outhead[headindex];
							outpoint[0] = (long)(atof(token) * segyparms[i][0]);
							paramcount++;
							token = strtok(NULL," ");
						}
					}
					if(segyheader[i] == 2)
					{
						short paramcount = 1;
						short headindex;
						float *outpoint;
						token = strtok(NULL," ");
						while(token != NULL && paramcount < 10)
						{
							headindex = segyparms[i][paramcount] - 2;
							outpoint = (float*)&outhead[headindex];
							outpoint[0] = (float)(atof(token) * segyparms[i][0]);
							paramcount++;
							ieee2ibm(outpoint,0);
							token = strtok(NULL," ");
						}
					}
					break;
				} // enf case 5
			default:
				{
					printf("Function %d not defined.\n",segyfunction[i]);
					break;
				}
			} // end case switch
		}  // end if
	}  // end i loop
		if(!matchfound)
			printf("No match found for %s\n",string1);
}  //end of keysegy
void ieee2ibm(float *input,short swap)
{
	unsigned char *cbuf,exp,tem;
	unsigned long *umantis;
	long expl;
	unsigned long usignl;
	umantis = (unsigned long*)&input[0];
	cbuf = (unsigned char*)&input[0];
	//
	usignl = *umantis & 0x80000000;
	exp = (*umantis >> 23);
	*umantis= ((*umantis | 0x00800000)) &0x00ffffff;
	exp = (exp-127) + 1;
	//
	//
	//
	if(exp % 4)
	{
		*umantis = *umantis >> (exp % 4);
		exp = exp +4;
	}
	exp = exp >> 2;
	exp = exp + 64;
	expl = exp;
	expl = (expl << 24) & 0x7f000000;
	*umantis = *umantis | expl | usignl;
	if(swap)
	{
		tem = cbuf[0];
		cbuf[0] = cbuf[3];
		cbuf[3] = tem;
		tem = cbuf[1];
		cbuf[1] = cbuf[2];
		cbuf[2] = tem;
	}
}
ibm2ieee(float *input,short swap)
{
	unsigned char *cbuf,expp,tem,sign;
	unsigned long *umantis,expll,signl;
//	unsigned long usignl;
	long *mantis;
	short shift;

	
	cbuf = (unsigned char*)&input[0];
	umantis = (unsigned long*)&input[0];
	mantis = (long*)&input[0];
	//
	if(swap)
	{
		tem = cbuf[0];
		cbuf[0] = cbuf[3];
		cbuf[3] = tem;
		tem = cbuf[1];
		cbuf[1] = cbuf[2];
		cbuf[2] = tem;
	}
	//
	expp = *mantis >> 24;
	*mantis = (*mantis) << 8;
	shift = 1;
	while(*mantis > 0 && shift < 23)
	{
		*mantis = *mantis << 1;
		shift++;
	}
	*mantis = *mantis << 1;
	sign = expp & 0x80;
	expp = expp & 0x7f;
	if(expp != 0)
	{
		expp = expp -64;
		*umantis = *umantis >> 9;
		expll = 0x7f + (expp * 4 - shift);
		expll = expll << 23;
		if(sign)
			*umantis = expll | *mantis | 0x80000000;
		else
			*umantis = expll | *mantis;
	}
}

⌨️ 快捷键说明

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