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

📄 segy.c

📁 将地震数据存储为segy格式
💻 C
字号:
//将程序中的数据存为SEGY格式

#include <stdio.h>
#include <math.h>
#define M1 1500//采样点数
#define us  6000//采样间隔
#define ap   5//振幅
#define nsp  3//炮数
#define nl   2//层数


main()
{
	FILE *fpo,*fpi,*test;
	int pos,tc,tend;  //保存文件位置
	int i,j,k,l,n,dn;//dn数据个数dat[dn]
	int f;
	float ff;
	int *th;
	float *td;
	float dat[nsp*24*nl];
	
	fpo=fopen("ttt","r");
//	printf("open ttt success\n");
	fpi=fopen("segy.sgy","wb+");
	test=fopen("test","w");
//	printf("open segy.segy success\n");
	for(i=0;i<nsp*24*nl;i++)
	fscanf(fpo,"%f",&dat[i]);
    dn=0;
	for(i=0;i<nsp;i++)//每一炮
	{	
		k=0;
		for(j=0;j<24;j++)//每一道
		{   
			pos=ftell(fpi);
			f=i*24+j+1;
			th=&f;
			fwrite(th,4,1,fpi);//1-4

			
			pos=pos+4*2;
			fseek(fpi,pos,0);
			f=i*24+j+1;
			th=&f;
			fwrite(th,4,1,fpi);//9-12
		
			pos=pos+4;
			fseek(fpi,pos,0);
			f=++k;
			th=&f;
			fwrite(th,4,1,fpi);//13-16

			
			pos=pos+4;
			fseek(fpi,pos,0);
			f=i+1;
			th=&f;
			fwrite(th,4,1,fpi);//17-20
				
			pos=pos+4*3;
			fseek(fpi,pos,0);
			f=1;
			th=&f;
			fwrite(th,2,1,fpi);//29-30

			
			pos=pos+4*2;
			fseek(fpi,pos,0);
			f=200-i*50;
			th=&f;
			fwrite(th,4,1,fpi);//37-40
			
			pos=pos+4*9;
			fseek(fpi,pos,0);
			f=i*500;
			th=&f;
			fwrite(th,4,1,fpi);//73-76
			
			pos=pos+4;
			fseek(fpi,pos,0);
			f=0;
			th=&f;
			fwrite(th,4,1,fpi);//77-80
			
			pos=pos+4;
			fseek(fpi,pos,0);
			f=2000+j*200;
			th=&f;
			fwrite(th,4,1,fpi);//81-84
			
			pos=pos+4;
			fseek(fpi,pos,0);
			f=0;
			th=&f;
			fwrite(th,4,1,fpi);//85-88
			
			pos=pos+4;
			fseek(fpi,pos,0);
			f=1;
			th=&f;
			fwrite(th,2,1,fpi);//89-90
			
			pos=pos+4*6+2;
			fseek(fpi,pos,0);
			f=M1;
			th=&f;
			fwrite(th,2,1,fpi);//115-116
		
			pos=pos+2;
			fseek(fpi,pos,0);
			f=us;
			th=&f;
			fwrite(th,2,1,fpi);//117-118
			
			pos=pos+4*23;
/*			fseek(fpi,pos,0);
			f=24;
			th=&f;
			fwrite(th,2,1,fpi);//209-210   */
			
			pos=pos+4*7;
	/*		fseek(fpi,pos,0);
			f=24;
			th=&f;
			fwrite(th,4,1,fpi);//237-240   */
			
			pos=pos+4;
			////dao头定义结束
			////////////////////////////////////////////////////////////////////
			//printf("i= %d,j= %d save ok\n",i,j);
			tc=pos;
			fseek(fpi,tc,0);
			for(n=0;n<M1;n++)
			{
				
				ff=1;
				td=&ff;
				fseek(fpi,tc,0);
				fwrite(td,4,1,fpi);
				tc=tc+4;
            	//fprintf(fpi,"%d",*td);
			}//初始化
			tend=tc;
			tc=pos;
		//	printf("%d\n",tc);

		    for(l=0;l<nl;l++)//对每一层
			{
			    tc=pos;
				n=(int)(dat[dn]*1000/(us/1000)+0.5);//四舍五入取整,i炮,j道
fprintf(test,"%d\n",n);
				tc=tc+(n-1)*4;
				fseek(fpi,tc,0);
				ff=ap;
				td=&ff;
				fwrite(td,4,1,fpi);
				dn++;
				
	//fprintf(fpi,"%d",*td);
			//	printf("write ap at n=%d success\n",n);

			}
			tc=tend;
			pos=tc;
			fseek(fpi,tc,0);
		//	printf("%d\n",tc);

		}
	}
	fclose(fpo);
	fclose(fpi);
}

⌨️ 快捷键说明

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