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

📄 rsanpu1.txt

📁 从磁带机读取地震纪录原始代码,包括地震数据格式,2格式等
💻 TXT
字号:
/* rtape.c
   Read SEG2 format tape.
   UNIX version.
   1997.5.1
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <malloc.h>
#include <fcntl.h>
#define LEN 32768

void ffskip( char *tape, int nSkip );
int getFileNumber( char *filename );
void chkhostid(void);

FILE *outfile;
int infile;
char str[LEN];

void main( int argc, char *argv[] )
{
   int  i, j, ret, EOT=0;
   int  bsh, esh, msh, nSkip, debug;
   int  flag;
   long offset;
   char ch1, ch2, fname[64], cmd[64];

   if( argc == 1 )
   {
      printf("\n Usage: rsanpu <tape> [shot [skip]]\n\n");
      exit( 1 );
   }

   bsh = 0;
   if( argc > 2)
      bsh = atoi( argv[2] );
   esh = bsh;

   nSkip = 0;
   if( argc > 3 )
      nSkip = atoi( argv[3] );

   if( strrchr( argv[1], 'n' ) == NULL )
      strcat( argv[1], "n" );
    
   sprintf( cmd, "mt -f %s rewind", argv[1] );
   system( cmd );

   if( nSkip > 0 )
   {
      ffskip( argv[1], nSkip );
      esh = esh + nSkip;
   }

   chkhostid();

   while( 1 )
   {
      if( (infile = open( argv[1], O_RDONLY )) == -1 )
      {
          printf(" Don't open the file: %s!\n", argv[1] );
          exit( 1 );
      }

      if( (outfile = fopen( "temp_seg2.dat", "wb+" )) == NULL )
      {
         printf(" Don't open the file: temp_seg2.dat!\n" );
         exit( 1 );
      }



      /* read 256 bytes first for sanpu's data */
      ret = read( infile, str, 256, infile );




      flag = 1;
      while( 1 )
      {
         ret = read( infile, str, LEN, infile );

         if( flag == 1 )
         {
            j = 1;
            ch1 = str[0];
            for( i = 1; i < ret; i++ )
            {
               j++;
               ch2 = str[i];
               /*printf("%2x%2x\n", ch1, ch2 );*/
               if( ch1 == 0x55 && ch2 == 0x3a )
               {
                  flag = 0;
                  break;
               }
               ch1 = ch2;
            }

            if( flag == 0 )
            {
               j = j - 2;
               if( j > 0 )
               {
                  for( i = j; i < ret; i++ )
                     str[i-j] = str[i];
                  ret = ret - j;
                  str[ ret ] = '\0';
               }
            }
            else
               continue;
         }

         if( ret > 0 )
         {
            EOT = 0;
            fwrite( str, 1, ret, outfile );
         }
         else
            break;
      }

      close( infile );

      offset = 0L;
      fseek( outfile, offset, SEEK_END );
      offset = ftell( outfile );

      fclose( outfile );

      if( offset > 0 )
      {
         if( bsh <= 0 )
         {
            msh =  getFileNumber( "temp_seg2.dat" );
            sprintf( fname, "%04d.dat", msh );
         }
         else
            sprintf( fname, "%04d.dat", esh );

         printf( " Output filename: %s\n", fname );
         strcpy( cmd, "mv temp_seg2.dat " );
         strcat( cmd, fname );
         system( cmd );
      }

      esh = esh + 1;
      flag =  1;

      EOT++;

      if( EOT == 2 )
      {
         sprintf( cmd, "mt -f %s rewind&", argv[1] );
         system( cmd );
         break;
      }
   }

   unlink("temp_seg2.dat");
}

void ffskip( char *tape, int nSkip )
{
   int i, j;

   for( j=0; j<nSkip; j++ )
   {
      if( (infile = open( tape, O_RDONLY )) == -1 )
      {
          printf(" Don't open the file: %s!\n", tape );
          exit( 1 );
      }

      while( 1 )
      {
         i = read( infile, str, LEN, infile );

         if( i == 0 )
         {
            close( infile );
            break;   
         }
      }
   }
}


int getFileNumber( char *filename )
{
   union
   {
      char      c_val[4];
      short int i_val[2];
      long  int l_val;
      float     f_val;
   } val;

   FILE *infile;
   int  i,j,k,l,ktr,kntr,len,msh,tblk;
   long int lp, lptr[320];
   char ch, str[700], buf[700];

   if( (infile = fopen( filename, "rb" )) == NULL )
      return( 0 );

   for( i = 0; i < 700; i++ )
      str[i] = fgetc( infile );

   val.c_val[0] = str[7];
   val.c_val[1] = str[6];
   kntr = val.i_val[0];

   k=32;
   for( i=0; i<kntr; i++)
   {
      val.c_val[0] = str[k+3];
      val.c_val[1] = str[k+2];
      lptr[i] = val.l_val;
      k=k+4;
   }

   /* read traces */

   ktr = 0;

   /* get 'tblk' first */
   lp = lptr[ktr];
   fseek( infile, lp, 0 );

   for(i=0;i<320;i++)
      str[i] = fgetc( infile );

   val.c_val[0] = str[3];
   val.c_val[1] = str[2];
   tblk = val.i_val[0];

   /* read trace entirely */
   lp = lptr[ktr];
   fseek( infile, lp, 0 );

   for(i = 0;i < tblk; i++)
      str[i] = fgetc( infile );

   i = 32;
   for(;;)
   {
      msh = 0;

      ch = str[i];
      for (k=2; k<ch; k++)
         buf[k-2] = str[i+k];

      if( strncasecmp( buf, "RAW_RECORD", 10 ) == 0 )
      {
         /* printf("RAW_RECORD: %s\n", buf ); */
         len = strlen( buf );
         k = 0;
         for( j=0; j<len; j++ )
         {
            if( isdigit( buf[j] ) )
              buf[k++] = buf[j];
         }
         buf[k] = '\0';
         msh = atoi( buf );
         break;
      }

      i = i + ch;
      if( buf[ch-4] == 0x0a || buf[ch-4] == 0x00 )
          break;
   }

   fclose( infile );
   return( msh );
}


void chkhostid(void)
{ 
  long lid;
  lid=gethostid();
  if (lid!=0x7235c21aL && lid!=0x727359c0L) {
     printf("\n Illegal user !\n");
     exit(-1);
  }
} 

⌨️ 快捷键说明

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