?? seg2sgey.cpp
字號(hào):
//這個(gè)SEGY格式轉(zhuǎn)換程序不作字節(jié)交換并且不記錄輔助道。
// Cvtseg.cpp for gqz240
//#define INCL_DOS
//#define INCL_SUBchar
//#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include "math.h"
#include "string.h"
#define MAXSAMP 16384 // max of 16k byte samples
#define MAXTRACES 16384 // SEG-2 limit
#define STRINGWIDTH 100 // allow up 100 char per keyword
#define MAXKEYWORDS 100 //
#define MAXPARMS 10 //
//char *fpath = "E:\\yuncheng\\"; // add 2 lines by ytl
short NumAux = 0;
short outhead[120]; // output traceheader
long *outheadl; // used when referncing outhead as a long array
float *outheadf; // used when referncing outhead as a floating point array
char *outheadc; // used when referncing outhead as a char array
//short i,j,k,kk,kk1,m,ssn,fstart,fend,count;
char string1[200];
FILE *f1,*f2;
char temp; //
//
char prefix[STRINGWIDTH],start[10],end[10],exten[10],fname[STRINGWIDTH];
char outfile[STRINGWIDTH],answer[10];
long tracepointers[MAXTRACES]; //
unsigned long numsamples,datalength;
//
char segykeyword[MAXKEYWORDS][STRINGWIDTH];
char input[STRINGWIDTH],inputbuf[STRINGWIDTH];
short segyfunction[MAXKEYWORDS],segyheader[MAXKEYWORDS],totalkeys;
double segyparms[MAXKEYWORDS][MAXPARMS];
short segyreelheader[1800];//
short first = 1;
FILE *keyfile;
char *token;
short reverse = 0; //
double dinbuf[MAXSAMP];
long *linbuf;
short *iinbuf;
float *finbuf;
unsigned char *cinbuf;
long outbuf[MAXSAMP]; //
//
short blockid,revnum,pointerbytecount,numtrace;
unsigned short blockleng;
char stringtermcount,stringterm1,stringterm2;
char linetermcount,lineterm1,lineterm2;
char reserved[19];
short stringlength;
unsigned char datatype;
short ftmp,fcomp;
void readsegykeys();
void keycheck();
void ieee2ibm(float *,short );
void main()
{
short i,j,k,kk,kk1,m,ssn,fstart,fend,count;
iinbuf = (short *)&dinbuf[0]; // used for interger input (16 bit)
finbuf = (float *)&dinbuf[0]; // used for float point (4 byte)
linbuf = (long *)&dinbuf[0]; // used for long int (32 bit)
cinbuf = (unsigned char *)&dinbuf[0]; //used for 20 bitpacked
outheadl = (long *)&outhead[0];
outheadf = (float *)&outhead[0];
system ("cls"); // clear screen
printf(" SEG2SEGY V1.1 - OS/2 - MSDOS\n\n");
printf(" 地震數(shù)據(jù)轉(zhuǎn)換實(shí)用程序\n\n");
// printf(" Seicmic Data Conversion Utility\n");
// printf(" Copyright Kansas Geological Survey 1987-1990\n");
// printf(" WELCOME OPRATPR TO THE SEG-2->SEG-Y PRE-PROCESSOR\n");
printf(" 歡迎您使用 SEG-2->SEG-Y 予處理程序\n");
printf("\n\n這個(gè)SEGY格式轉(zhuǎn)換程序不作字節(jié)交換并且不記錄輔助道。");
printf
("\n\n This program converts the SEG-2 data files to SEG-Y file format\n");
printf
(" NOTE:SEG-Y file is in fixed 32 bit int & byte reversed for main-frames\n");
printf("\n Program assumes there are 1 or more files to convert");
printf("\n with similar names containing ASCENDING numbers,i.e");
printf("\n SEG00001.DAT,SEG00002.DAT,... SEG00099.DAT ");
printf("\n\n Press RETURN when ready to proceed,CTRL-C to abort");
gets(answer);
system("cls");
startovr:
printf("\n\n Enter the PREFIX name of the files,(i.e SEG) -> ");
gets(prefix);
badext:
printf("\n Please enter the EXTENSION of the files if present.i.e .DAT ");
printf("\n Iclude the (PERIOD) in name! -> ");
gets(exten);
if(4 < strlen(exten))
{
system("cls");
printf("\nEXTENSION CAN'T BE MORE THAN 3 LETTERS");
goto startovr;
}
if(strlen(exten) && exten[0] != '.')
{
printf("\nFirst character of an EXTENSION must be a period(.)\n");
goto badext;
}
tryagain:
printf("\n Next enter the file numbers for the records to be");
printf("\n changed. For instance if ther are to be 3 files");
printf("\n converted named SEG00014,SEG00015,AND SEG00016,the first");
printf("\n number you should enter is 000014,then when asked for ending");
printf("\n enter 00016.\n REMEMBER TO ENTER LEADING 0's i.e.00014 not 14");
printf("\n\n Please enter STARTING number ->");
gets(start);
printf("\n Please enter ENDING number ->");
gets(end);
// if(strlen(start) != strlen(end))
// {
// system("cls");
// printf("\n\n Invalid numbers try again\n");
// goto tryagain;
// } delete 6 lines by ytl 000720
fstart = atoi(start);
fend = atoi(end);
// if(fstart > fend)
// {
// system("cls");
// printf("\n\n Only ABCENDING file numbers!\n");
// goto tryagain;
// }delete 6 lines by ytl 000720
system("cls");
printf("\n You have chosen files :\n\n");
printf("%s%s%s",prefix,start,exten);
printf(" through %s%s%s\n\n",prefix,end,exten);
printf("Is this correct? (y/n) -> ");
gets(answer);
if(answer[0]=='n' || answer[0]=='N')
{
system("cls");
goto startovr;
}
printf("\nPlease enter the name of the output file(i.e file name.extensoin). -> ");
gets(outfile);
f2 = fopen(outfile,"wb"); //
if(f2 == NULL)
{
printf("**OUTPUT FILE OPEN FAILURE**\n**ABORTING**\n");
exit(1);
}
// fclose(f2); //////////////////////
printf("\nPlease enter the STARTING Shot Sequence Number(SSN) ->");
gets(answer);
ssn = atoi(answer);
system("cls");
readsegykeys(); // read in segy key words and save them
printf
("\n\nDo you want the input files deleted as they are converted?([n]/y) -> ");
answer[0] = '\0';
gets(answer);
fcomp = 0; // add 11 lines by ytl 000720
if(fstart > fend)
{
ftmp = fstart;
fstart = fend;
fend = ftmp;
fcomp = 1;
kk1 = fend;
}
else
kk1 = fstart;
for(kk=fstart; kk<=fend; kk++) // start a big loop!
{
fname[0] = '\0';
strcat(fname,prefix);
if(strlen(start))
itoa(kk1,start,10);
// count = strlen(end)-strlen(start);
//
// for(m=1; m<=count; m++)
// {
// strrev(start);
// strcat(start,"0");
// strrev(start);
// } delete 8 lines by ytl 000720
// strcat(fname,fpath); // new add 1 lines by ytl 000623
strcat(fname,start); //
strcat(fname,exten);
printf("\nWording on %s\n",fname);
f1 = fopen(fname,"rb");
if(f1 == NULL)
{
printf("\n***SYSTEM REPORTS ERROR OPENING FILE %s***",fname);
printf("Skipping to next file number\n");
if(fcomp) // add 4 lines by ytl 000714
kk1--;
else
kk1++;
continue;
}
fread(&blockid,2,1,f1);
//
if(blockid == 0x553a)
{
reverse = 1;
printf("Byte reverse data not allowed.\n");
exit(1);
}
if(blockid != 0x3a55)
{
printf("Not SEG-2 data can not continue\n");
exit(1);
}
fread(&revnum,2,1,f1);
fread(&pointerbytecount,2,1,f1);
fread(&numtrace,2,1,f1);
printf("Data revision number = %d\n",revnum);
printf("Nunber of trace = %d\n",numtrace);
fread(&stringtermcount,1,1,f1);
fread(&stringterm1,1,1,f1);
fread(&stringterm2,1,1,f1);
fread(&linetermcount,1,1,f1);
fread(&lineterm1,1,1,f1);
fread(&lineterm2,1,1,f1);
//
fread(&reserved,1,18,f1);
//
//
//
if(numtrace != (pointerbytecount/4))
{
printf("Number of trace and number of trace pointers do not match\n");
printf("Number of pointers = %d\n",pointerbytecount/4);
printf("Due to this inconsistency processing must stop\n");
exit(1);
}
// ok new read in the list
fread(tracepointers,4,numtrace,f1);
/* The next block is the FILE DESCRIPTOR BLOCK.It is a set of strings, each terminaterd
by the string _term_character(s).Each string is preceded by 1 WORD which is the byte
count for the string+termchar+2.(2 for the length of the word giving the count.) A
value of 0 represents the end of the block.
*/
fread(&stringlength,2,1,f1);
while(0 != stringlength)
{
fread(string1,1,stringlength-2,f1);
keycheck();
fread(&stringlength,2,1,f1);
}
for(j=0; j<numtrace-2; j++)
{
printf("trace-%d- ",j+1);
fseek(f1,tracepointers[j],SEEK_SET); // SEEK_SET: go to beginning of data block
fread(&blockid,2,1,f1);
if(blockid == 0x2244)
{
reverse = 1;
printf("Reversed data not allowed at this time\n");
exit(1);
}
if(blockid != 0x4422)
{
printf("Not SEG-2 data can not process %x\n",blockid);
exit(1);
}
fread(&blockleng,2,1,f1);
fread(&datalength,4,1,f1);
fread(&numsamples,4,1,f1);
/*
1 = 16 bit fixed. (INT)
2 = 32 bit fixed. (LONG)
3 = 20 bit packed floating.
4 = 32 bit ieee floating point.(FLOAT)
5 = 64 bit ieee floating point.(DOUBLE)
*/
fread(&datatype,1,1,f1);
if(datatype > 5 || datatype < 1)
{
printf("Data type %d not avilable/valid\n",(short)datatype);
break;
}
outhead[57] = numsamples;
fread(reserved,1,19,f1);
fread(&stringlength,2,1,f1);
while(0 != stringlength)
{
fread(string1,1,stringlength-2,f1);
keycheck();
fread(&stringlength,2,1,f1);
}
printf("\n");
fseek(f1,blockleng+tracepointers[j],SEEK_SET); // go to beginning of seicmic data
switch(datatype)
{
case 1:
{
fread(iinbuf,2,(short)numsamples,f1);
for(k=0; k<numsamples; k++)
outbuf[k] = iinbuf[k];
break;
}
case 2:
{
fread(linbuf,4,(short)numsamples,f1);
for(k=0; k<numsamples; k++)
outbuf[k] = linbuf[k];
break;
}
case 3:
{
unsigned short totalbytes,subpointer;
unsigned short expo;
long longdat;
totalbytes = (numsamples * 5)/2;
fread(cinbuf,1,totalbytes,f1);
for(k=0; k<(numsamples); )
{
subpointer = (k / 4) * 5;
expo = (unsigned short)iinbuf[subpointer++];
for(i=0; i<4; i++)
{
if(0x8000 & iinbuf[subpointer])
longdat = 0xffff8000;
else
longdat = 0;
longdat = longdat | ((long)iinbuf[subpointer++] << (0x000f & expo));
expo >>= 4;
outbuf[k++] = longdat;
}
}
break;
}
case 4:
{
fread(finbuf,4,(short)numsamples,f1);
for(k=0; k<numsamples; k++)
outbuf[k] = finbuf[k];
break;
}
case 5:
{
fread(dinbuf,8,(short)numsamples,f1);
for(k=0; k<numsamples; k++)
outbuf[k] = dinbuf[k];
break;
}
} // end switch
//
//
//
//
//
// if(outheadl[2] == 0) // delete 1 line by ytl
outheadl[2] = (long)kk1;
//
//
// if(outhead[14] == 0) delete 1 line by ytl
outhead[14] = (long)1; // seismic data.
if(NumAux != 0 && j == numtrace-2) // add 4 lines by ytl 000712
outhead[14] = (long)4;
if(NumAux != 0 && j == numtrace-1)
outhead[14] = (long)5;
/* if(j == numtrace-1 && outhead[87] == 0)
{
outhead[87] = 1;
ssn = ssn + 1;
} delte by ytl 000712 */
outheadl[9] = (long)(abs(outhead[93]-outhead[92]));
outhead[85] = outhead[86] = (short)(1+labs((long)outhead[92] - outheadl[3]));
if(first == 1)
{
first = 0;
segyreelheader[1606] = numtrace-NumAux-2; // was numtrace
segyreelheader[1607] = NumAux; // add 2 lines by ytl 000629
segyreelheader[1627] = 1; // meters
segyreelheader[1608] = outhead[58];
segyreelheader[1609] = outhead[58];
segyreelheader[1610] = numsamples;
segyreelheader[1611] = numsamples;
segyreelheader[1612] = 2;
/* for(k=1600; k<1606; k+=2) // delete for yuncheng 062001
{
outheadc = (char*)&segyreelheader[k];
temp = outheadc[3];
outheadc[3] = outheadc[0];
outheadc[0] = temp;
temp = outheadc[2];
outheadc[2] = outheadc[1];
outheadc[1] = temp;
}
for(k=1606; k<1630; k++)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -