//segy.cpp
#include<stdio.h>
#include <iostream>
#include <string>
#include<math.h>
#include"SEGY_RW.h"
#include <direct.h>
#pragma warning(disable:4996) //全部关掉
using namespace std;
//*********Public Functions************
//=========
void SEGY_RW::get_trace_num()
{
_fseeki64( pFileName, 0, SEEK_END );
_int64 pos=_ftelli64(pFileName);
address_file_end=pos;//for judging whether the trace number which is input by user exceeds the up limitation.
//Input_SEGY_File.seekg(0.0, ios::end);
//_int64 pos = Input_SEGY_File.tellg();
//Calculate how many traces in this record.
TraceNumber =int( (pos - SEGY_ASCII_HDR_SIZE - SEGY_VOLUMN_HDR_SIZE) / (volumn_hdr.samples_per_trace *4 + SEGY_TRACE_HDR_SIZE) ) ;
//cout<<"posgetNum: "<<address_file_end<<endl;
}
//=======
//Translate the ECBICD text to ASCII text for display
char SEGY_RW::swapEBCDICcodeToASCIIcode(unsigned char c)
{
char t;
switch(c)
{
//转换空格及非字符和数字
case 12: t=12; break;
case 13: t=13; break;
case 64: t=32; break;
case 74: t=99; break;
case 75: t=46; break;
case 76: t=60; break;
case 77: t=40; break;
case 78: t=43; break;
case 80: t=38; break;
case 90: t=33; break;
case 91: t=36; break;
case 92: t=42; break;
case 93: t=41; break;
case 94: t=59; break;
case 96: t=45; break;
case 97: t=47; break;
case 107:t=44; break;
case 108:t=37; break;
case 109:t=95; break;
case 110:t=62; break;
case 111:t=63; break;
case 122:t=58; break;
case 123:t=35; break;
case 124:t=64; break;
case 125:t=39; break;
case 126:t=61; break;
case 127:t=34; break;
//转换从a~i
case 129:t=97; break;
case 130:t=98; break;
case 131:t=99; break;
case 132:t=100;break;
case 133:t=101;break;
case 134:t=102;break;
case 135:t=103;break;
case 136:t=104;break;
case 137:t=105;break;
//转换从j~q
case 145:t=106;break;
case 146:t=107;break;
case 147:t=108;break;
case 148:t=109;break;
case 149:t=110;break;
case 150:t=111;break;
case 151:t=112;break;
case 152:t=113;break;
case 153:t=114;break;
//转换从r~z
case 162:t=115;break;
case 163:t=116;break;
case 164:t=117;break;
case 165:t=118;break;
case 166:t=119;break;
case 167:t=120;break;
case 168:t=121;break;
case 169:t=122;break;
//转换从A~I
case 193:t=65; break;
case 194:t=66; break;
case 195:t=67; break;
case 196:t=68; break;
case 197:t=69; break;
case 198:t=70; break;
case 199:t=71; break;
case 200:t=72; break;
case 201:t=73; break;
//转换从J~Q
case 209:t=74; break;
case 210:t=75; break;
case 211:t=76; break;
case 212:t=77; break;
case 213:t=78; break;
case 214:t=79; break;
case 215:t=80; break;
case 216:t=81; break;
case 217:t=82; break;
//转换从R~Z
case 226:t=83; break;
case 227:t=84; break;
case 228:t=85; break;
case 229:t=86; break;
case 230:t=87; break;
case 231:t=88; break;
case 232:t=89; break;
case 233:t=90; break;
//转换从0~9
case 240:t=48; break;
case 241:t=49; break;
case 242:t=50; break;
case 243:t=51; break;
case 244:t=52; break;
case 245:t=53; break;
case 246:t=54; break;
case 247:t=55; break;
case 248:t=56; break;
case 249:t=57; break;
//对于ASCII码没有的数据使用空格替代
default: t=32;
}
return t;
}
//Read and Write Ascii header
void SEGY_RW::Read_AsciiHeader(string &input_segy_file)
{
//Read Ascii Header
Input_SEGY_File_Name=input_segy_file;
for (int i = 0; i < SEGY_ASCII_HDR_SIZE; i ++)
{
Input_SEGY_File.read((char *) &this->ascii_hdr.buffer[i], sizeof(uint8_t));
//translate to txt
display_ascii_hdr[i]=swapEBCDICcodeToASCIIcode(ascii_hdr.buffer[i]);
}
}
//Write Ascii header as txt file
void SEGY_RW::Write_Asciihdr2txt()
{
// char buffer[300];
//getcwd(buffer, 300);
// strcat(buffer, "EBCDIC.txt");
fstream Ascii_txt("EBCDIC.txt",ios::out);
Ascii_txt<<display_ascii_hdr;
Ascii_txt.close();
}
//==//Write Ascii header
void SEGY_RW::Write_AsciiHeader(string &output_segy_file)
{
Output_SEGY_File_Name=output_segy_file;
for (int i = 0; i < SEGY_ASCII_HDR_SIZE; i ++)
{
Output_SEGY_File.write((char *) &this->ascii_hdr.buffer[i], sizeof(uint8_t));
}
}
//Read and Write Binary volumn header
void SEGY_RW::Read_VolumnHeader(string &input_segy_file)
{
Input_SEGY_File_Name=input_segy_file;
//Read Binary Volumn Header
Input_SEGY_File.read((char *) &volumn_hdr.job_id_number, sizeof(int32_T));
Input_SEGY_File.read((char *) &volumn_hdr.line_number, sizeof(int32_T));
Input_SEGY_File.read((char *) &volumn_hdr.reel_number, sizeof(int32_T));
Input_SEGY_File.read((char *) &volumn_hdr.traces_per_record, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.aux_traces_per_record, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.sample_data_interval_ms, sizeof(int16_t));//本卷带采样间隔
Input_SEGY_File.read((char *) &volumn_hdr.original_data_interval_ms, sizeof(int16_t));//野外采样间隔
Input_SEGY_File.read((char *) &volumn_hdr.samples_per_trace, sizeof(int16_t));//本卷带每道采样个数
Input_SEGY_File.read((char *) &volumn_hdr.original_samples_per_trace, sizeof(int16_t));//野外原始每道采样个数
Input_SEGY_File.read((char *) &volumn_hdr.data_sample_format_code, sizeof(int16_t)); //数据采样格式
Input_SEGY_File.read((char *) &volumn_hdr.CDP_fold, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.trace_sorting_code, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.vertical_sum_code, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.sweep_frequency_start_hz, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.sweep_frequency_end_hz, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.sweep_length_ms, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.sweep_type_code, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.trace_number_of_sweep_channel, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.sweep_trace_taper_length_start_ms, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.sweep_trace_taper_length_end_ms, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.taper_type_code, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.correlated_data_traces_flag, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.binary_gain_recovered_flag, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.amplitude_recovery_method_code, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.measurement_system, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.impulse_signal_polarity, sizeof(int16_t));
Input_SEGY_File.read((char *) &volumn_hdr.vibratory_polarity_code, sizeof(int16_t));
//Judge the sampling format
if(SEGY_RW::volumn_hdr.data_sample_format_code<= 8)
{
m_iOSFormat = PC_FORMAT;
cout<<"Attention please: Your seismic datum are IEEE float format!"<<endl;
}
else
{
m_iOSFormat = UNIX_FORMAT;
cout<<"Attention please: Your seismic datum are IBM float format!"<<endl;
}
if(m_iOSFormat==UNIX_FORMAT){
volumn_hdr.job_id_number=swapDataToLong(volumn_hdr.job_id_number);
volumn_hdr.line_number=swapDataToLong(volumn_hdr.line_number);
volumn_hdr.reel_number=swapDataToLong(volumn_hdr.reel_number);
volumn_hdr.traces_per_record=swapDataToShort(volumn_hdr.traces_per_record);
volumn_hdr.aux_traces_per_record=swapDataToShort(volumn_hdr.aux_traces_per_record);
volumn_hdr.sample_data_interval_ms=swapDataToShort(volumn_hdr.sample_data_interval_ms);
volumn_hdr.original_data_interval_ms=swapDataToShort(volumn_hdr.original_data_interval_ms);//采样间隔
volumn_hdr.samples_per_trace=swapDataToShort(volumn_hdr.samples_per_trace);
volumn_hdr.original_samples_per_trace=swapDataToShort(volumn_hdr.original_samples_per_trace);//单道采样点数
volumn_hdr.data_sample_format_code=swapDataToShort(volumn_hdr.data_sample_fo
- 1
- 2
前往页