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

📄 gri2sgy.c

📁 一个读写SGY格式的程序
💻 C
📖 第 1 页 / 共 2 页
字号:
                      gri_head.RSTRCC = trace_head.STA_CORR_DETECT;
                      gri_head.XCOSHP = trace_head.X_CORRD_SOURCE;
                      gri_head.YCOSHP = trace_head.Y_CORRD_SOURCE;
                      gri_head.XCOREC = trace_head.X_CORRD_DETECT;
                      gri_head.YCOREC = trace_head.Y_CORRD_DETECT;
                      gri_head.AMPMAX=-1;
                      gri_head.FORMAT=4;

           /*************    handle shot_num,trace_num,cmp,offset , max and min value   **************/

                    if(trace_head.IDENT_NUM > MAX_IDENT_NUM) { MAX_IDENT_NUM = trace_head.IDENT_NUM ;}
                    if(trace_head.IDENT_NUM < MIN_IDENT_NUM) {  MIN_IDENT_NUM = trace_head.IDENT_NUM;}

                    if(trace_head.TRACE_NUM > MAX_TRACE_NUM) { MAX_TRACE_NUM = trace_head.TRACE_NUM ;}
                    if(trace_head.TRACE_NUM < MIN_TRACE_NUM) {  MIN_TRACE_NUM = trace_head.TRACE_NUM;}

                    if(trace_head.CMP > MAX_CMP) { MAX_CMP = trace_head.CMP ;}
                    if(trace_head.CMP < MIN_CMP) {  MIN_CMP = trace_head.CMP;}

                    if(trace_head.SOURCE_to_DETECT_DISTANCE> MAX_OFFSET) { MAX_OFFSET = trace_head.SOURCE_to_DETECT_DISTANCE;}
                    if(trace_head.SOURCE_to_DETECT_DISTANCE< MIN_OFFSET) {  MIN_OFFSET = trace_head.SOURCE_to_DETECT_DISTANCE;}
          
                 /*********    write the above value to the grisys output file  *********/
          
                      if(fwrite(&gri_head,sizeof(struct GRISYS_DATA_TRACE_HEADER),1,outfile)!=1)
                        {
                           printf("can't write gri_trace_header to the file %s.\n",out_filename);
                           exit(FAILED);
                         }
     

                      /***** write seismic data. **********/

                          if(fwrite(ALLOC_VAR,4,trace_head.LTRSAM,outfile)!=trace_head.LTRSAM)
                           {
                                printf("write seismic data failed!\n");
                                exit(FAILED);
                            }

                  /**********   end writing *************/ 


                      free(ALLOC_VAR);
                 }

               printf("There is total %d traces.\n",inum - 1);

             /********** end reading the infile *************/

       /***********    print out some result message   **************/

            printf("ident_num range is %10d ----- %10d.\n",MIN_IDENT_NUM,MAX_IDENT_NUM);
            printf("cmp       range is %10d ----- %10d.\n",MIN_CMP,MAX_CMP);
            printf("trace_num range is %10d ----- %10d.\n",MIN_TRACE_NUM,MAX_TRACE_NUM);
            printf("offset    range is %10d ----- %10d.\n",MIN_OFFSET,MAX_OFFSET);
}

     /**********  end exchanging segy ----- grisys ****************/




/**************************************   GRISYS --> SEGY   **************************************************/
/**************************************   GRISYS --> SEGY   **************************************************/
/**************************************   GRISYS --> SEGY   **************************************************/
/**************************************   GRISYS --> SEGY   **************************************************/
/**************************************   GRISYS --> SEGY   **************************************************/
/**************************************   GRISYS --> SEGY   **************************************************/
/**************************************   GRISYS --> SEGY   **************************************************/
/**************************************   GRISYS --> SEGY   **************************************************/
/**************************************   GRISYS --> SEGY   **************************************************/

   else            
     {  
       printf("grisys------segy.\n"); 
       strcat(SEGY,argv[1]);


             /*************  construct the output filename  **************/

                if(argv[2] == NULL) {
                  printf("out file is %s\n",SEGY);
                  outfile=fopen(SEGY,"wb");
                  out_filename = SEGY;
                 }
                else {
                  printf("out file is %s\n",argv[2]);
                  outfile=fopen(argv[2],"wb");
                  out_filename = argv[2];
                 }

             

             /************* ignore the SEGY 3600 bytes   ******************/
             
                    fwrite(EBCDIC_HEADER,3200,1,outfile);

             /**************  read some grisys header for segy id header *****************/
               printf("len_gri_da_header=%4d\n",sizeof(struct GRISYS_DATA_TRACE_HEADER));
               printf("len_bin_header=%4d\n",sizeof(struct BINARY_HEADER));
               printf("len_trace_header=%4d\n",sizeof(struct TRACE_HEADER));

               printf("float     size is %d\n",sizeof(float ));
               printf("int       size is %d\n",sizeof(int ));
               printf("short int size is %d\n",sizeof(short int ));
               printf("long  int size is %d\n",sizeof(long int ));
               

                      if(fread(&gri_head,sizeof(struct GRISYS_DATA_TRACE_HEADER),1,infile)!=1)
                          {
                          /*
                            printf("reading complete.\n");
                          */
                           exit(FAILED);
                           }

                    
 
                      bin_header.NUMER_of_RECORD_TRACE  = 9999;
                      bin_header.VERTICAL_STACK_CODE    = 1;
                      bin_header.SAMPLE_INTERVAL_HERE   = gri_head.SAMINT * 1000;
                      bin_header.SAMPLE_INTERVAL_RAW    = gri_head.SAMINT * 1000;
                      bin_header.NUM_of_SAMP_POINT_HERE = gri_head.TRACEL/gri_head.SAMINT;
                      bin_header.NUM_of_SAMP_POINT_RAW  = gri_head.TRACEL/gri_head.SAMINT;
                      bin_header.SORT_CODE              = 1;
                      bin_header.FORMAT_CODE_SAMPLE     = 1;
                      bin_header.UNIT_of_LENGTH         = 1;
                      bin_header.COMPRESS_VERSION       = 0;

           /************* print some message  *********************/

                printf("smaple point number is %10d.\n",bin_header.NUM_of_SAMP_POINT_HERE);
                printf("sample interval is %10dms.\n",bin_header.SAMPLE_INTERVAL_HERE/1000);

            /******************  write segy id header  ***************************/

                      if(fwrite(&bin_header,sizeof(struct BINARY_HEADER),1,outfile)!=1)
                        {
                           printf("can't write segy_id_headerto the file %s.\n",out_filename);
                           exit(FAILED);
                         }

           printf("OUT BINARY_HEADER ok!!!\n");
                      
           /*******************  set the pointer at the begin of id header  *************************/

                  fseek(infile,0L,0);
                  fseek(outfile,3600L,0);

            /**************   starting exchanging     *********************/
 
                   inum=0;

           while(feof(infile)==0 )
                    {
/*
                        inum+=1;
*/                        
                /************   read grisys trace header  ******************/

                      if(fread(&gri_head,sizeof(struct GRISYS_DATA_TRACE_HEADER),1,infile)!=1)
                          {
                            printf("reading complete.\n");
                            break;                    
                           }


                 /***** alloc some memory for seismic data_set   ********/

                    if((ALLOC_VAR=(float *)malloc((gri_head.TRACEL/gri_head.SAMINT)*4L+20L))==NULL)

                           {
                               printf("INPUT GRISYS DATA-------> FMT3 !!!\n");
                               printf("alloc failed!\n");
                               exit(FAILED);
                           }

                 /***** read a few seismic trace.  *******/

                          if(fread(ALLOC_VAR,4,gri_head.TRACEL/gri_head.SAMINT,infile) != gri_head.TRACEL/gri_head.SAMINT)
                           {
                                printf("read seismic data failed!\n");
                                exit(FAILED);
                            }
/*
           printf("IN  DATA ok!!!\n");
p=&gri_head;
for(i=0;i<128;i++,p++){
printf("%6d,",*p);
if((i%10)==0) printf("\n");
}
*/


                  /********  assign grisys  value to the segy trace_header   *********/
                             
                trace_head.TRACE_SEQ_LINE_NUM        = 20000;                           
                trace_head.LTRSAM                    = gri_head.TRACEL/ gri_head.SAMINT; /*hd1 or 10*/
                trace_head.SAMPLE_INTERVAL           = gri_head.SAMINT * 1000;           /*hd9      */
                trace_head.IDENT_NUM                 = gri_head.NUMSHP;                  /*hd2      */
                trace_head.CMP                       = gri_head.NUMCMP;                  /*hd4      */
                trace_head.SHOTPOINT_NUM             = gri_head.RPSHP4/4;                /*hd21chu4 */ 
              /*  trace_head.TRACE_ID_CODE             = (14 - gri_head.TRACEV)/2; */
                trace_head.TRACE_ID_CODE             = 1;                                /*hd11     */
              /*  trace_head.LAG_TIME_A                = gri_head.DELAYT; */
                trace_head.MUTE_START_TIME           = gri_head.FSTSAM;                  /*hd6      */
                trace_head.TRACE_NUM                 = gri_head.TRACEN;                  /*hd17     */
                trace_head.SOURCE_to_DETECT_DISTANCE = gri_head.OFFSET;                  /*hd20     */
                trace_head.WATER_DEPTH_SOURCE        = gri_head.DEPSHP;
                trace_head.WATER_DEPTH_DETECT        = gri_head.DEPREC;
                trace_head.STA_CORR_SOURCE           = gri_head.RSTSHP;
                trace_head.STA_CORR_DETECT           = gri_head.RSTRCC;
                trace_head.X_CORRD_SOURCE            = gri_head.XCOSHP;                  /*hd62     */
                trace_head.Y_CORRD_SOURCE            = gri_head.YCOSHP;                  /*hd63     */
                trace_head.X_CORRD_DETECT            = gri_head.XCOREC;                  /*hd64     */
                trace_head.Y_CORRD_DETECT            = gri_head.YCOREC;                  /*hd65     */
                trace_head.SECONDARY_SORT_INDEX      = gri_head.NUMLIN;                  /*hd68 or 19*/
                trace_head.PRIMARY_SORT_INDEX        = gri_head.NUMCMP;                  /*hd4      */
                trace_head.STATION_NUM_SOURCE        = gri_head.RPSHP4/4;                /*hd21chu4 */
                trace_head.STATION_NUM_DETECT        = gri_head.NUMREP;                  /*hd18     */
 

           /*************    handle shot_num,trace_num,cmp,offset , max and min value   **************/

                if(gri_head.NUMSHP > MAX_IDENT_NUM) { MAX_IDENT_NUM = gri_head.NUMSHP;}
                if(gri_head.NUMSHP < MIN_IDENT_NUM) {  MIN_IDENT_NUM = gri_head.NUMSHP;}

                if(gri_head.NUMCMP > MAX_CMP) { MAX_CMP = gri_head.NUMCMP;}
                if(gri_head.NUMCMP < MIN_CMP) {  MIN_CMP = gri_head.NUMCMP;}

                if(gri_head.TRACEN > MAX_TRACE_NUM) { MAX_TRACE_NUM = gri_head.TRACEN;}
                if(gri_head.TRACEN < MIN_TRACE_NUM) {  MIN_TRACE_NUM = gri_head.TRACEN;}

                if(gri_head.OFFSET > MAX_OFFSET) { MAX_OFFSET = gri_head.OFFSET;}
                if(gri_head.OFFSET < MIN_OFFSET) {  MIN_OFFSET = gri_head.OFFSET;}

         /*********    write the above value to the  segy output file  *********/

                      if(fwrite(&trace_head,sizeof(struct TRACE_HEADER),1,outfile)!=1)
                        {
                           printf("can't write segy_trace_header to the file %s.\n",out_filename);
                           exit(FAILED);
                         }

                       /***** write seismic data. **********/

                          if(fwrite(ALLOC_VAR,4,gri_head.TRACEL/gri_head.SAMINT,outfile) != gri_head.TRACEL/gri_head.SAMINT)
                           {
                                printf("write seismic data failed!\n");
                                exit(FAILED);
                            }

						  printf("trace=%4d\n",inum);
/*
                   printf("CMP=%4d\n",gri_head.NUMCMP);
*/
                 free(ALLOC_VAR);

                 inum+=1;

               }

             printf("There is total %d traces.\n",inum);

             /********** end reading the infile *************/

       /***********    print out some result message   **************/

            printf("ident_num range is %10d ----- %10d.\n",MIN_IDENT_NUM,MAX_IDENT_NUM);
            printf("cmp       range is %10d ----- %10d.\n",MIN_CMP,MAX_CMP);
            printf("trace_num range is %10d ----- %10d.\n",MIN_TRACE_NUM,MAX_TRACE_NUM);
            printf("offset    range is %10d ----- %10d.\n",MIN_OFFSET,MAX_OFFSET);

       }
     /**********  end exchanging grisys ------ segy  ****************/


             fclose(infile);
             fclose(outfile);
}

⌨️ 快捷键说明

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