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

📄 testsegy.cpp

📁 segy读写程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    printf("  Job identification number:.................%10d\n",i4(_binhed,1));
    printf("* Line number:...............................%10d\n",i4(_binhed,5));
    printf("* Reel number:...............................%10d\n",i4(_binhed,9));
    printf("* # data traces per record:..................%10d\n",i2(_binhed,13));
    printf("* # aux  traces per record:..................%10d\n",i2(_binhed,15));
    printf("* Sample interval (microseconds) for reel:...%10d\n",i2(_binhed,17));
    printf("  Sample interval (microseconds) for field:..%10d\n",i2(_binhed,19));
    printf("* Number samples per data trace for reel:....%10d\n",i2(_binhed,21));
    printf("  Number samples per datat trace for field:..%10d\n",i2(_binhed,23));
    printf("* Data sample format code:...................%10d\n",i2(_binhed,25));
    printf("* CDP fold:..................................%10d\n",i1(_binhed,27));
    printf("* Trace sorting code:........................%10d\n",i2(_binhed,29));
    printf("  Vertical sum code:.........................%10d\n",i2(_binhed,31));
    printf("  Sweep frequency at start:..................%10d\n",i2(_binhed,33));
    printf("  Sweep frequency at end:....................%10d\n",i2(_binhed,35));
    printf("  Sweep length (milliseconds)................%10d\n",i2(_binhed,37));
    printf("  Sweep type code:...........................%10d\n",i2(_binhed,39));
    printf("  Trace number of sweep channel:.............%10d\n",i2(_binhed,41));
    printf("  Sweep trace taper length at start (ms):....%10d\n",i2(_binhed,43));
    printf("  Sweep trace taper length at end   (ms):....%10d\n",i2(_binhed,45));
    printf("  Taper type:................................%10d\n",i2(_binhed,47));
    printf("  Corellated data traces:....................%10d\n",i2(_binhed,49));
    printf("  Binary gain recoverd:......................%10d\n",i2(_binhed,51));
    printf("  Amplitude recovery method:.................%10d\n",i2(_binhed,53));
    printf("  Measuriment system (1-m / 2-feet):.........%10d\n",i2(_binhed,55));
    printf("  Impulse signal:............................%10d\n",i2(_binhed,57));
    printf("  Vibratory polarity code:...................%10d\n",i2(_binhed,59));
    printf("\n");
}

void TxtHeadShow()
{
    if(_f==NULL) return;

    char  s[128];
    int   n;

    memset(s,0,128);

    for(n=0;n<40;n++)
     {
        memcpy(s,_txthed+n*80,80);
        ebasd(s,s);
        printf("%s\n",s);
     }
}

float GetSample(int idx)
{
    float   smp;
    int*    xmp = (int*)&smp;
    float*  dat = (float*)(_inptrc+240);

    short*       int2ptr = (short*)       dat;
    int*         int4ptr = (int*)         dat;
    signed char* int1ptr = (signed char*) dat;

    if(_frmt==1)
     {
        smp =  dat[idx];
        ibm2ieee(&smp,1);
     }
    else if(_frmt==2)
     {
        smp = swapi4(int4ptr[idx]);
     }
    else if(_frmt==3)
     {
        smp = swapi2(int2ptr[idx]);
     }
    else if(_frmt==4)
     {
        smp = dat[idx];
     }
    else if(_frmt==5)
     {
        *xmp = swapi4(int4ptr[idx]);
     }
    else if(_frmt==6)
    {
        smp = int1ptr[idx];
    }
    else
        smp = 0;

    return smp;
}


void ReadTrace(int n)
{
    char buf[128];
    int  l;

    if(_f==NULL) return;

    if(n==0)
    {
      printf("read trace# (1-%d): ",_ntr);
      fgets(buf,127,stdin);

      if(sscanf(buf,"%d",&n)<1 || n<1 || n>_ntr)
      {
          printf("Bad trace number %s\n",buf);
          return;
      }
    }

    fseek(_f,3600+(n-1)*_trl,SEEK_SET);
    l = fread(_inptrc, 1, _trl, _f );

    _ctr = n;

    for(n=0;n<_nsmp;n++) _data[n] =  GetSample(n);
}

void OpenFile()
{
    char  name[MAXPATH]="";
    int   l;

    if(_f) fclose(_f);

    printf("file name: ");
    fgets(name,511,stdin);

    if(strcmp(name,"\n")==0) strcpy(name,"test10.sgy");

    _f = fopen(name,"rb");

    if(_f)
    {
        fseek(_f,0,SEEK_END);
        l = ftell(_f);

        fseek(_f,0,SEEK_SET);

        fread(_txthed,1,3200,_f);
        fread(_binhed,1, 400,_f);

        _si   = i2(_binhed, 17)/1000000.;
        _nsmp = i2(_binhed, 21);
        _frmt = i2(_binhed, 25);

        if(_si   <= 0        ) goto ERR;
        if(_nsmp <= 0        ) goto ERR;
        if(_frmt<1 || _frmt>6) goto ERR;

        if     (_frmt==3) _smpl=2;
        else if(_frmt==6) _smpl=1;
        else              _smpl=4;

        _trl = 240+_nsmp*_smpl; if(_trl <= 240) goto ERR;

       _ntr=(l-3600)/(_trl);

       printf("-----------------\n");
       printf("File: %s\n",name);
       printf("Sample interval  : %g\n",_si);
       printf("Number of samples: %d\n",_nsmp);
       printf("Data format      : %d\n",_frmt);
       printf("Number of traces : %d\n",_ntr);

       ReadTrace(1);

       return;
ERR:
        printf("Bad format\n");
        fclose(_f); _f=NULL; return;
    }
    else
    {
        printf("cannot open file %s\n",name);
    }
}


int help()
{
    printf("o - open file\n");
    printf("a - show text header\n");
    printf("b - show bin header\n");
    printf("t - show trace header\n");
    printf("d - show trace data\n");
    printf("r - read other trace\n");
    printf("q - quit the program\n");
}

int main(int argc, char* argv[])
{
    char cmd [512];

    help();

    for(;;)
    {
        if(_f) printf("(trace#%d) enter command (o a b t d r q) :",_ctr);
        else   printf("(no file) enter command (o q) :");

        fgets(cmd,511,stdin);

        if(strcmp(cmd,"q\n")==0) break;

        if(strcmp(cmd,"o\n")==0) OpenFile();

        if(strcmp(cmd,"a\n")==0) TxtHeadShow();

        if(strcmp(cmd,"b\n")==0) BinHeadShow();

        if(strcmp(cmd,"t\n")==0) TrcHeadShow();

        if(strcmp(cmd,"d\n")==0) TrcDataShow();

        if(strcmp(cmd,"r\n")==0) ReadTrace(0);
    }

    if(_f) fclose(_f);
    return 0;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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