基本信息
源码名称:seg-y地震数据操作(全部源码 qt)
源码大小:0.35M
文件格式:.rar
开发语言:C/C++
更新时间:2014-05-31
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 4 元×
微信扫码支付:4 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
本例支持qt4.8以上版本,实现了对地震格式seg-y数据的读取,显示,初级FK变换,二维线性插值的内容。
seg-y 文件读写类
//segy.cpp
#include<stdio.h>
#include <iostream>
#include <string.h>
#include<math.h>
#include<errno.h>
#include"segy.h"
#include<qstring.h>
#include<qdatastream.h>
using namespace std;
//#pragma warning(disable:4996)
//*********Public Functions************
//=========
void SEGY_RW::get_trace_num()
{
Input_SEGY_File.seekg(0.0, ios::end);
Q_INT64 pos = Input_SEGY_File.tellg();
address_file_end=pos;//for judging whether the trace number which is input by users exceeds the up limitation.
//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) ) ;
TraceNumber = volumn_hdr.traces_per_record;
//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;
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;
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;
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;
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;
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;
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;
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;
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(Q_INT8));
//translate to txt
if(m_iOSFormat==UNIX_FORMAT)
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(Q_INT8));
}
}
//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(Q_INT32));
Input_SEGY_File.read((char *) &volumn_hdr.line_number, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &volumn_hdr.reel_number, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &volumn_hdr.traces_per_record, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.aux_traces_per_record, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.sample_data_interval_ms, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.original_data_interval_ms, sizeof(Q_INT16));//
Input_SEGY_File.read((char *) &volumn_hdr.samples_per_trace, sizeof(Q_INT16));//
Input_SEGY_File.read((char *) &volumn_hdr.original_samples_per_trace, sizeof(Q_INT16));//
Input_SEGY_File.read((char *) &volumn_hdr.data_sample_format_code, sizeof(Q_INT16)); //
Input_SEGY_File.read((char *) &volumn_hdr.CDP_fold, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.trace_sorting_code, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.vertical_sum_code, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.sweep_frequency_start_hz, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.sweep_frequency_end_hz, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.sweep_length_ms, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.sweep_type_code, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.trace_number_of_sweep_channel, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.sweep_trace_taper_length_start_ms, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.sweep_trace_taper_length_end_ms, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.taper_type_code, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.correlated_data_traces_flag, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.binary_gain_recovered_flag, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.amplitude_recovery_method_code, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.measurement_system, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.impulse_signal_polarity, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &volumn_hdr.vibratory_polarity_code, sizeof(Q_INT16));
//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_format_code); //
volumn_hdr.CDP_fold=swapDataToShort(volumn_hdr.CDP_fold);
volumn_hdr.trace_sorting_code=swapDataToShort(volumn_hdr.trace_sorting_code);
volumn_hdr.vertical_sum_code=swapDataToShort(volumn_hdr.vertical_sum_code);
volumn_hdr.sweep_frequency_start_hz=swapDataToShort(volumn_hdr.sweep_frequency_start_hz);
volumn_hdr.sweep_frequency_end_hz=swapDataToShort(volumn_hdr.sweep_frequency_end_hz);
volumn_hdr.sweep_length_ms=swapDataToShort(volumn_hdr.sweep_length_ms);
volumn_hdr.sweep_type_code=swapDataToShort(volumn_hdr.sweep_type_code);
volumn_hdr.trace_number_of_sweep_channel=swapDataToShort(volumn_hdr.trace_number_of_sweep_channel);
volumn_hdr.sweep_trace_taper_length_start_ms=swapDataToShort(volumn_hdr.sweep_trace_taper_length_start_ms);
volumn_hdr.sweep_trace_taper_length_end_ms=swapDataToShort(volumn_hdr.sweep_trace_taper_length_end_ms);
volumn_hdr.taper_type_code=swapDataToShort(volumn_hdr.taper_type_code);
volumn_hdr.correlated_data_traces_flag=swapDataToShort(volumn_hdr.correlated_data_traces_flag);
volumn_hdr.binary_gain_recovered_flag=swapDataToShort(volumn_hdr.binary_gain_recovered_flag);
volumn_hdr.amplitude_recovery_method_code=swapDataToShort(volumn_hdr.amplitude_recovery_method_code);
volumn_hdr.measurement_system=swapDataToShort(volumn_hdr.measurement_system);
volumn_hdr.impulse_signal_polarity=swapDataToShort(volumn_hdr.impulse_signal_polarity);
volumn_hdr.vibratory_polarity_code=swapDataToShort(volumn_hdr.vibratory_polarity_code);
}
for( int i = 0; i < 340; i )
{
Input_SEGY_File.read((char *) &volumn_hdr.buffer[i], sizeof(Q_INT8));
}
}
void SEGY_RW::Write_VolumnHeader(string &output_segy_file)
{
Output_SEGY_File_Name=output_segy_file;
//Write Binary Volumn Header
Output_SEGY_File.write((char *) &volumn_hdr.job_id_number, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &volumn_hdr.line_number, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &volumn_hdr.reel_number, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &volumn_hdr.traces_per_record, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.aux_traces_per_record, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.sample_data_interval_ms, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.original_data_interval_ms, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.samples_per_trace, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.original_samples_per_trace, sizeof(Q_INT16));
volumn_hdr.data_sample_format_code=5;
Output_SEGY_File.write((char *) &volumn_hdr.data_sample_format_code, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.CDP_fold, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.trace_sorting_code, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.vertical_sum_code, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.sweep_frequency_start_hz, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.sweep_frequency_end_hz, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.sweep_length_ms, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.sweep_type_code, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.trace_number_of_sweep_channel, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.sweep_trace_taper_length_start_ms, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.sweep_trace_taper_length_end_ms, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.taper_type_code, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.correlated_data_traces_flag, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.binary_gain_recovered_flag, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.amplitude_recovery_method_code, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.measurement_system, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.impulse_signal_polarity, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &volumn_hdr.vibratory_polarity_code, sizeof(Q_INT16));
//
for( int i = 0; i < 340; i )
{
Output_SEGY_File.write((char *) &volumn_hdr.buffer[i], sizeof(Q_INT8));
}
}
//Initial trace header and trace datum
void SEGY_RW::Initialize_Trace()
{
//Initialize Trace Header
trace_hdr.trace_sequence_number_within_line=0;
trace_hdr.trace_sequence_number_within_reel=0;
trace_hdr.original_field_record_number=0;
trace_hdr.trace_sequence_number_within_original_field_record=0;
trace_hdr.energy_source_point_number=0;
trace_hdr.cdp_ensemble_number=0;
trace_hdr.trace_sequence_number_within_cdp_ensemble=0;
trace_hdr.trace_identification_code=0;
trace_hdr.number_of_vertically_summed_traces_yielding_this_trace=0;
trace_hdr.number_of_horizontally_stacked_traced_yielding_this_trace=0;
trace_hdr.data_use=0;
trace_hdr.distance_from_source_point_to_receiver_group=0;
trace_hdr.receiver_group_elevation=0;
trace_hdr.surface_elevation_at_source=0;
trace_hdr.source_depth_below_surface=0;
trace_hdr.datum_elevation_at_receiver_group=0;
trace_hdr.datum_elevation_at_source=0;
trace_hdr.water_depth_at_source=0;
trace_hdr.water_depth_at_receiver_group=0;
trace_hdr.scalar_for_elevations_and_depths=0;
trace_hdr.scalar_for_coordinates=0;
trace_hdr.x_source_coordinate=0;
trace_hdr.y_source_coordinate=0;
trace_hdr.x_receiver_group_coordinate=0;
trace_hdr.y_receiver_group_coordinate=0;
trace_hdr.coordinate_units=0;
trace_hdr.weathering_velocity=0;
trace_hdr.subweathering_velocity=0;
trace_hdr.uphole_time_at_source=0;
trace_hdr.uphole_time_at_group=0;
trace_hdr.source_static_correction=0;
trace_hdr.group_static_correction=0;
trace_hdr.total_static_applied=0;
trace_hdr.lag_time_a=0;
trace_hdr.lag_time_b=0;
trace_hdr.delay_according_time=0;
trace_hdr.mute_time_start=0;
trace_hdr.mute_time_end=0;
trace_hdr.samples_in_this_trace=0;
trace_hdr.sample_intervall=0;
trace_hdr.gain_type_instruments=0;
trace_hdr.igc=0;
trace_hdr.igi=0;
trace_hdr.corr=0;
trace_hdr.sfs=0;
trace_hdr.sfe=0;
trace_hdr.slen=0;
trace_hdr.styp=0;
trace_hdr.stas=0;
trace_hdr.stae=0;
trace_hdr.tatyp=0;
trace_hdr.afilf=0;
trace_hdr.afils=0;
trace_hdr.nofilf=0;
trace_hdr.nofils=0;
trace_hdr.lcf=0;
trace_hdr.hcf=0;
trace_hdr.lcs=0;
trace_hdr.hcs=0;
trace_hdr.year=0;
trace_hdr.day=0;
trace_hdr.hour=0;
trace_hdr.minute=0;
trace_hdr.sec=0;
trace_hdr.timbas=0;
trace_hdr.trwf=0;
trace_hdr.grnors=0;
trace_hdr.grnofr=0;
trace_hdr.grnlof=0;
trace_hdr.gaps=0;
trace_hdr.otrav=0;
for (int i = 0; i < 15; i )
trace_hdr.user_define[i]=0;
//Initialize Trace Data
trace_data=new float [Sample_Number];
for(int i=0;i<Sample_Number;i )
trace_data[i]=0;
}
//======
SEGY_RW::SEGY_RW( string &input_segy_file,string &output_segy_file)
{
trace_data = NULL;
pFileName = NULL;
Input_SEGY_File_Name=input_segy_file;
Output_SEGY_File_Name=output_segy_file;
//Open Input Seismic Data File
Input_SEGY_File.open(Input_SEGY_File_Name.c_str(), ios::in | ios::binary );
if(!Input_SEGY_File.is_open())
{
cout<<"ERROR: Can't Open Input Seismic Data File";
exit(1);
}
//Open Output Seismic Data File
Output_SEGY_File.open(Output_SEGY_File_Name.c_str(), ios::out | ios::binary|ios::trunc );
if(!Output_SEGY_File.is_open())
{
cout<<"ERROR: Can't Open Output Seismic Data File";
exit(1);
}
//
//pFileName=fopen("E:\\PROJECT\\Datum\\Seismic_Data\\Yraw_testline.sgy","rb");
//if(pFileName==NULL){cout<<"erro input!";};
char ch[1000];
strcpy(ch,input_segy_file.c_str());
//cout<<ch<<endl;
//errno_t err;
//int err;
// err = fopen_s( &pFileName, ch,"rb"); //assign the value of the pFileName
// err = fopen( &pFileName, ch,"rb");
// if ( errno!=0)
// {
// printf( "打开文件失败,错误代码=%d\n",err);
// }
m_iOSFormat = PC_FORMAT;//
//Read Ascii Header
Read_AsciiHeader(input_segy_file);
//Read Binary Volumn Header
Read_VolumnHeader(input_segy_file);
//Write Ascii Header
Write_AsciiHeader(output_segy_file);
// Write_Asciihdr2txt();
//Write Binary Volumn Header
Write_VolumnHeader(output_segy_file);
//Seismic Data Parameters
this->get_trace_num();
SampleInterval=volumn_hdr.sample_data_interval_ms;
Sample_Number=volumn_hdr.samples_per_trace;
//Initialize Trace Header and Trace data
Initialize_Trace();
//Close Seismic Data File
Input_SEGY_File.close( );
Output_SEGY_File.close( );
}
//========
SEGY_RW::~SEGY_RW()
{
//Seismic_Stratify_File_Input.close();
if(trace_data!=NULL)
delete [] trace_data;
if(pFileName!=NULL)
fclose(pFileName);
}
//========
void SEGY_RW::Read_TraceHeader(int trace_id)
{
if(trace_id<1||trace_id>TraceNumber) {cout<<"Your trace number is too small or large!"<<endl; exit(1);}
//here we must use Q_INT64 instead of int ,because of the support to large file .
Q_INT64 pos = (Q_INT64)3600 ( (Q_INT64)trace_id - (Q_INT64)1) * ( (Q_INT64)240 (Q_INT64)Sample_Number * sizeof(float));//
Input_SEGY_File.open(Input_SEGY_File_Name.c_str(),ios_base::in| ios::binary);
Input_SEGY_File.seekg(pos);//
// fseek( pFileName,pos, SEEK_SET );
// if(ftell(pFileName)>=address_file_end){cout<<"exceed the trace range: TraceHeader!"<<endl;};
//cout<<"telltracehdrdata: "<<_ftelli64(pFileName)<<endl<<"address "<<address_file_end<<endl<<"Tracehdrpos: "<<pos<<endl;
//Read Trace Header
Input_SEGY_File.read((char *) &trace_hdr.trace_sequence_number_within_line, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.trace_sequence_number_within_reel, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.original_field_record_number, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.trace_sequence_number_within_original_field_record, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.energy_source_point_number, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.cdp_ensemble_number, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.trace_sequence_number_within_cdp_ensemble, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.trace_identification_code, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.number_of_vertically_summed_traces_yielding_this_trace, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.number_of_horizontally_stacked_traced_yielding_this_trace, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.data_use, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.distance_from_source_point_to_receiver_group, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.receiver_group_elevation, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.surface_elevation_at_source, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.source_depth_below_surface, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.datum_elevation_at_receiver_group, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.datum_elevation_at_source, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.water_depth_at_source, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.water_depth_at_receiver_group, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.scalar_for_elevations_and_depths, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.scalar_for_coordinates, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.x_source_coordinate, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.y_source_coordinate, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.x_receiver_group_coordinate, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.y_receiver_group_coordinate, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.coordinate_units, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.weathering_velocity, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.subweathering_velocity, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.uphole_time_at_source, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.uphole_time_at_group, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.source_static_correction, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.group_static_correction, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.total_static_applied, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.lag_time_a, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.lag_time_b, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.delay_according_time, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.mute_time_start, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.mute_time_end, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.samples_in_this_trace, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.sample_intervall, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.gain_type_instruments, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.igc, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.igi, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.corr, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.sfs, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.sfe, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.slen, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.styp, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.stas, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.stae, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.tatyp, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.afilf, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.afils, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.nofilf, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.nofils, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.lcf, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.hcf, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.lcs, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.hcs, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.year, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.day, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.hour, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.minute, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.sec, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.timbas, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.trwf, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.grnors, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.grnofr, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.grnlof, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.gaps, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.otrav, sizeof(Q_INT16));
for (int i = 0; i < 15; i )
{
Input_SEGY_File.read((char *) & trace_hdr.user_define[i], sizeof(Q_INT32));
}
if(m_iOSFormat==UNIX_FORMAT){ //cout<<"IBM"<<endl;
trace_hdr.trace_sequence_number_within_line = swapDataToLong ( trace_hdr.trace_sequence_number_within_line ) ;
trace_hdr.trace_sequence_number_within_reel = swapDataToLong ( trace_hdr.trace_sequence_number_within_reel ) ;
trace_hdr.original_field_record_number = swapDataToLong ( trace_hdr.original_field_record_number ) ;
trace_hdr.trace_sequence_number_within_original_field_record = swapDataToLong ( trace_hdr.trace_sequence_number_within_original_field_record ) ;
trace_hdr.energy_source_point_number = swapDataToLong ( trace_hdr.energy_source_point_number ) ;
trace_hdr.cdp_ensemble_number = swapDataToLong ( trace_hdr.cdp_ensemble_number ) ;
trace_hdr.trace_sequence_number_within_cdp_ensemble = swapDataToLong ( trace_hdr.trace_sequence_number_within_cdp_ensemble ) ;
trace_hdr.trace_identification_code = swapDataToShort ( trace_hdr.trace_identification_code ) ;
trace_hdr.number_of_vertically_summed_traces_yielding_this_trace = swapDataToShort ( trace_hdr.number_of_vertically_summed_traces_yielding_this_trace ) ;
trace_hdr.number_of_horizontally_stacked_traced_yielding_this_trace = swapDataToShort ( trace_hdr.number_of_horizontally_stacked_traced_yielding_this_trace ) ;
trace_hdr.data_use = swapDataToShort ( trace_hdr.data_use ) ;
trace_hdr.distance_from_source_point_to_receiver_group = swapDataToLong ( trace_hdr.distance_from_source_point_to_receiver_group ) ;
trace_hdr.receiver_group_elevation = swapDataToLong ( trace_hdr.receiver_group_elevation ) ;
trace_hdr.surface_elevation_at_source = swapDataToLong ( trace_hdr.surface_elevation_at_source ) ;
trace_hdr.source_depth_below_surface = swapDataToLong ( trace_hdr.source_depth_below_surface ) ;
trace_hdr.datum_elevation_at_receiver_group = swapDataToLong ( trace_hdr.datum_elevation_at_receiver_group ) ;
trace_hdr.datum_elevation_at_source = swapDataToLong ( trace_hdr.datum_elevation_at_source ) ;
trace_hdr.water_depth_at_source = swapDataToLong ( trace_hdr.water_depth_at_source ) ;
trace_hdr.water_depth_at_receiver_group = swapDataToLong ( trace_hdr.water_depth_at_receiver_group ) ;
trace_hdr.scalar_for_elevations_and_depths = swapDataToShort ( trace_hdr.scalar_for_elevations_and_depths ) ;
trace_hdr.scalar_for_coordinates = swapDataToShort ( trace_hdr.scalar_for_coordinates ) ;
trace_hdr.x_source_coordinate = swapDataToLong ( trace_hdr.x_source_coordinate ) ;
trace_hdr.y_source_coordinate = swapDataToLong ( trace_hdr.y_source_coordinate ) ;
trace_hdr.x_receiver_group_coordinate = swapDataToLong ( trace_hdr.x_receiver_group_coordinate ) ;
trace_hdr.y_receiver_group_coordinate = swapDataToLong ( trace_hdr.y_receiver_group_coordinate ) ;
trace_hdr.coordinate_units = swapDataToShort ( trace_hdr.coordinate_units ) ;
trace_hdr.weathering_velocity = swapDataToShort ( trace_hdr.weathering_velocity ) ;
trace_hdr.subweathering_velocity = swapDataToShort ( trace_hdr.subweathering_velocity ) ;
trace_hdr.uphole_time_at_source = swapDataToShort ( trace_hdr.uphole_time_at_source ) ;
trace_hdr.uphole_time_at_group = swapDataToShort ( trace_hdr.uphole_time_at_group ) ;
trace_hdr.source_static_correction = swapDataToShort ( trace_hdr.source_static_correction ) ;
trace_hdr.group_static_correction = swapDataToShort ( trace_hdr.group_static_correction ) ;
trace_hdr.total_static_applied = swapDataToShort ( trace_hdr.total_static_applied ) ;
trace_hdr.lag_time_a = swapDataToShort ( trace_hdr.lag_time_a ) ;
trace_hdr.lag_time_b = swapDataToShort ( trace_hdr.lag_time_b ) ;
trace_hdr.delay_according_time = swapDataToShort ( trace_hdr.delay_according_time ) ;
trace_hdr.mute_time_start = swapDataToShort ( trace_hdr.mute_time_start ) ;
trace_hdr.mute_time_end = swapDataToShort ( trace_hdr.mute_time_end ) ;
trace_hdr.samples_in_this_trace = swapDataToShort ( trace_hdr.samples_in_this_trace ) ;
trace_hdr.sample_intervall = swapDataToShort ( trace_hdr.sample_intervall ) ;
trace_hdr.gain_type_instruments = swapDataToShort ( trace_hdr.gain_type_instruments ) ;
trace_hdr.igc = swapDataToShort ( trace_hdr.igc ) ;
trace_hdr.igi = swapDataToShort ( trace_hdr.igi ) ;
trace_hdr.corr = swapDataToShort ( trace_hdr.corr ) ;
trace_hdr.sfs = swapDataToShort ( trace_hdr.sfs ) ;
trace_hdr.sfe = swapDataToShort ( trace_hdr.sfe ) ;
trace_hdr.slen = swapDataToShort ( trace_hdr.slen ) ;
trace_hdr.styp = swapDataToShort ( trace_hdr.styp ) ;
trace_hdr.stas = swapDataToShort ( trace_hdr.stas ) ;
trace_hdr.stae = swapDataToShort ( trace_hdr.stae ) ;
trace_hdr.tatyp = swapDataToShort ( trace_hdr.tatyp ) ;
trace_hdr.afilf = swapDataToShort ( trace_hdr.afilf ) ;
trace_hdr.afils = swapDataToShort ( trace_hdr.afils ) ;
trace_hdr.nofilf = swapDataToShort ( trace_hdr.nofilf ) ;
trace_hdr.nofils = swapDataToShort ( trace_hdr.nofils ) ;
trace_hdr.lcf = swapDataToShort ( trace_hdr.lcf ) ;
trace_hdr.hcf = swapDataToShort ( trace_hdr.hcf ) ;
trace_hdr.lcs = swapDataToShort ( trace_hdr.lcs ) ;
trace_hdr.hcs = swapDataToShort ( trace_hdr.hcs ) ;
trace_hdr.year = swapDataToShort ( trace_hdr.year ) ;
trace_hdr.day = swapDataToShort ( trace_hdr.day ) ;
trace_hdr.hour = swapDataToShort ( trace_hdr.hour ) ;
trace_hdr.minute = swapDataToShort ( trace_hdr.minute ) ;
trace_hdr.sec = swapDataToShort ( trace_hdr.sec ) ;
trace_hdr.timbas = swapDataToShort ( trace_hdr.timbas ) ;
trace_hdr.trwf = swapDataToShort ( trace_hdr.trwf ) ;
trace_hdr.grnors = swapDataToShort ( trace_hdr.grnors ) ;
trace_hdr.grnofr = swapDataToShort ( trace_hdr.grnofr ) ;
trace_hdr.grnlof = swapDataToShort ( trace_hdr.grnlof ) ;
trace_hdr.gaps = swapDataToShort ( trace_hdr.gaps ) ;
trace_hdr.otrav = swapDataToShort ( trace_hdr.otrav ) ;
for (int i = 0; i < 15; i )
{
trace_hdr.user_define[i]=swapDataToLong(trace_hdr.user_define[i]);
}
}
if(Input_SEGY_File.is_open())
Input_SEGY_File.close();
}
//=========
void SEGY_RW::Read_TraceData(float * one_trace_data,int trace_id)
{
if(trace_id<1||trace_id>TraceNumber) {cout<<"Your trace number is too small or large!"<<endl; exit(1);}
//Calculate the position of current trace in the SEGY file
Q_INT64 pos = (Q_INT64)3840 ((Q_INT64)trace_id - (Q_INT64)1) * ((Q_INT64)240 (Q_INT64)Sample_Number * sizeof(float));
Input_SEGY_File.open(Input_SEGY_File_Name.c_str(),ios_base::in| ios::binary);
Input_SEGY_File.seekg(pos);
//fseek( pFileName,pos, SEEK_SET );
//if(ftell(pFileName)>=address_file_end){cout<<"exceed the trace range: TraceData!"<<endl;};
//cout<<"telltracedata: "<<pos<<endl;
//Read Trace Data
for (int i = 0; i <Sample_Number; i )
{
//fread((char *) &trace_data[i], sizeof(float),1,pFileName);
Input_SEGY_File.read((char *) &trace_data[i], sizeof(float));
one_trace_data[i]=trace_data[i];
if(m_iOSFormat==UNIX_FORMAT){
IBM2IEEE(&one_trace_data[i],1);};
}
Input_SEGY_File.close();
}
void SEGY_RW::Read_TraceData(VVD &data)
{
data.resize(TraceNumber);//
Input_SEGY_File.open(Input_SEGY_File_Name.c_str(),ios_base::in| ios::binary);
for(int trace_id=0;trace_id<TraceNumber; trace_id){
data[trace_id].resize(Sample_Number);
//Calculate the position of current trace in the SEGY file
Q_INT64 pos = (Q_INT64)3840 ((Q_INT64)trace_id /*- (Q_INT64)1*/) * ((Q_INT64)240 (Q_INT64)Sample_Number * sizeof(float));
Input_SEGY_File.seekg(pos);
//Read Trace Data
for (int i = 0; i <Sample_Number; i )
{
Input_SEGY_File.read((char *) &trace_data[i], sizeof(float));
if(m_iOSFormat==UNIX_FORMAT)
IBM2IEEE(&trace_data[i],1);
data[trace_id][i]=static_cast<double>(trace_data[i]);
//if(m_iOSFormat==UNIX_FORMAT){
//IBM2IEEE(&one_trace_data[i],1);};
}
}
Input_SEGY_File.close();
}
//=========
void SEGY_RW::Write_TraceHeader()
{
Output_SEGY_File.open(Output_SEGY_File_Name.c_str(), ios::out |ios::binary|ios::app);
//Write the trace header value of every trace
Output_SEGY_File.write((char *) &trace_hdr.trace_sequence_number_within_line, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.trace_sequence_number_within_reel, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.original_field_record_number, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.trace_sequence_number_within_original_field_record, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.energy_source_point_number, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.cdp_ensemble_number, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.trace_sequence_number_within_cdp_ensemble, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.trace_identification_code, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.number_of_vertically_summed_traces_yielding_this_trace, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.number_of_horizontally_stacked_traced_yielding_this_trace, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.data_use, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.distance_from_source_point_to_receiver_group, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.receiver_group_elevation, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.surface_elevation_at_source, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.source_depth_below_surface, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.datum_elevation_at_receiver_group, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.datum_elevation_at_source, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.water_depth_at_source, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.water_depth_at_receiver_group, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.scalar_for_elevations_and_depths, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.scalar_for_coordinates, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.x_source_coordinate, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.y_source_coordinate, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.x_receiver_group_coordinate, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.y_receiver_group_coordinate, sizeof(Q_INT32));
Output_SEGY_File.write((char *) &trace_hdr.coordinate_units, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.weathering_velocity, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.subweathering_velocity, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.uphole_time_at_source, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.uphole_time_at_group, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.source_static_correction, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.group_static_correction, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.total_static_applied, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.lag_time_a, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.lag_time_b, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.delay_according_time, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.mute_time_start, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.mute_time_end, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.samples_in_this_trace, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.sample_intervall, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.gain_type_instruments, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.igc, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.igi, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.corr, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.sfs, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.sfe, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.slen, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.styp, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.stas, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.stae, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.tatyp, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.afilf, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.afils, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.nofilf, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.nofils, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.lcf, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.hcf, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.lcs, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.hcs, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.year, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.day, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.hour, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.minute, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.sec, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.timbas, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.trwf, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.grnors, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.grnofr, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.grnlof, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.gaps, sizeof(Q_INT16));
Output_SEGY_File.write((char *) &trace_hdr.otrav, sizeof(Q_INT16));
for (int i = 0; i < 15; i )
{
Output_SEGY_File.write((char *) & trace_hdr.user_define[i], sizeof(Q_INT32));
}
//
Output_SEGY_File.close();
}
//=========
void SEGY_RW::Write_TraceData(const float * one_trace_data)
{
Output_SEGY_File.open(Output_SEGY_File_Name.c_str(), ios::out|ios::binary|ios::app);
for (int i = 0; i <Sample_Number; i )
{
Output_SEGY_File.write((char *) & one_trace_data[i], sizeof(float));
}
Output_SEGY_File.close();
}
//=========
short SEGY_RW::Return_SampleNumber()
{
return volumn_hdr.samples_per_trace;
}
//=========
short SEGY_RW::Return_SampleInterval()
{
return volumn_hdr.sample_data_interval_ms;
}
//=========
int SEGY_RW::Return_TraceNumber()
{
return TraceNumber;
}
//=========
int SEGY_RW::Return_CMP()
{
return trace_hdr.cdp_ensemble_number;
}
//=========
int SEGY_RW::Return_Trace_Id_Of_CMP()
{
return trace_hdr.trace_sequence_number_within_cdp_ensemble;
}
int SEGY_RW::Return_Trace()
{
return trace_hdr. trace_sequence_number_within_reel;
}
int SEGY_RW::Return_ShotNum()
{
return trace_hdr.energy_source_point_number;
}
int SEGY_RW::Return_Trace_Id_Of_Shot()
{
return trace_hdr.trace_sequence_number_within_original_field_record;
}
int SEGY_RW::Return_Sampling_Format_Code()
{
return volumn_hdr.data_sample_format_code;
}
//IBM VS. IEEE
long SEGY_RW::swapDataToLong(long x)
{
Q_INT8* cbuf;
Q_INT8 tem;
cbuf = (Q_INT8*)&x;
tem = cbuf[0]; cbuf[0] = cbuf[3]; cbuf[3] = tem;
tem = cbuf[2]; cbuf[2] = cbuf[1]; cbuf[1] = tem;
return x;
}
short SEGY_RW::swapDataToShort(short x)
{
Q_INT8* cbuf;
Q_INT8 tem;
cbuf=(Q_INT8*)&x;
tem = cbuf[0]; cbuf[0] = cbuf[1]; cbuf[1] = tem;
return x;
}
void SEGY_RW::IBM2IEEE(float* data, bool swap)
{
unsigned char *cbuf,expp,tem,sign;
unsigned long *umantis,expll;
long *mantis;
int shift;
cbuf = (unsigned char*)&data[0]; //
umantis = (unsigned long*)&data[0]; //
mantis = (long*)&data[0];
if(swap)
{
tem = cbuf[0]; cbuf[0] = cbuf[3]; cbuf[3] = tem;
tem = cbuf[2]; cbuf[2] = cbuf[1]; cbuf[1] = tem;
}
expp = (unsigned char)(*mantis >> 24);
*mantis = (*mantis) << 8;
shift = 1;
while(*mantis > 0 && shift < 23)
{
*mantis = *mantis << 1;
shift ;
}
*mantis = *mantis<<1;
sign = expp & 0x80;
expp = expp & 0x7F;
if(expp != 0)
{
expp = expp-64;
*umantis = *umantis>>9;
expll = 0x7F (expp*4 - shift);
expll = expll << 23;
if(sign) *umantis = expll | *mantis | 0x80000000;
else *umantis = expll | *mantis;
}
}
/*
1 = 32-bit IBM floating point
2 = 32-bit fixed-point (integer)
3 = 16-bit fixed-point (integer)
4 = 32-bit fixed-point with gain code (integer)
5 = 32-bit IEEE floating point
6 = NOT CURRENTLY USERD
7 = NOT CURRENTLY USERD
8 = 8-bit(integer)
*/
//=========
//////////////////////////////////////////////////////////////////////////
void SEGY_RW::Read_TraceHeader_IBM(int trace_id)
{
if(trace_id<1||trace_id>TraceNumber) {cout<<"Your trace number is too small or large!"<<endl; exit(1);}
//here we must use Q_INT64 instead of int ,because of the support to large file .
Q_INT64 pos = (Q_INT64)3600 ( (Q_INT64)trace_id - (Q_INT64)1) * ( (Q_INT64)240 (Q_INT64)Sample_Number * sizeof(float));//
Input_SEGY_File.open(Input_SEGY_File_Name.c_str(),ios_base::in| ios::binary);
Input_SEGY_File.seekg(pos);//
// fseek( pFileName,pos, SEEK_SET );
// if(ftell(pFileName)>=address_file_end){cout<<"exceed the trace range: TraceHeader!"<<endl;};
//cout<<"telltracehdrdata: "<<_ftelli64(pFileName)<<endl<<"address "<<address_file_end<<endl<<"Tracehdrpos: "<<pos<<endl;
//Read Trace Header
Input_SEGY_File.read((char *) &trace_hdr.trace_sequence_number_within_line, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.trace_sequence_number_within_reel, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.original_field_record_number, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.trace_sequence_number_within_original_field_record, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.energy_source_point_number, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.cdp_ensemble_number, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.trace_sequence_number_within_cdp_ensemble, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.trace_identification_code, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.number_of_vertically_summed_traces_yielding_this_trace, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.number_of_horizontally_stacked_traced_yielding_this_trace, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.data_use, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.distance_from_source_point_to_receiver_group, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.receiver_group_elevation, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.surface_elevation_at_source, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.source_depth_below_surface, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.datum_elevation_at_receiver_group, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.datum_elevation_at_source, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.water_depth_at_source, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.water_depth_at_receiver_group, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.scalar_for_elevations_and_depths, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.scalar_for_coordinates, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.x_source_coordinate, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.y_source_coordinate, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.x_receiver_group_coordinate, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.y_receiver_group_coordinate, sizeof(Q_INT32));
Input_SEGY_File.read((char *) &trace_hdr.coordinate_units, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.weathering_velocity, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.subweathering_velocity, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.uphole_time_at_source, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.uphole_time_at_group, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.source_static_correction, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.group_static_correction, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.total_static_applied, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.lag_time_a, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.lag_time_b, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.delay_according_time, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.mute_time_start, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.mute_time_end, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.samples_in_this_trace, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.sample_intervall, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.gain_type_instruments, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.igc, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.igi, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.corr, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.sfs, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.sfe, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.slen, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.styp, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.stas, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.stae, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.tatyp, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.afilf, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.afils, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.nofilf, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.nofils, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.lcf, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.hcf, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.lcs, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.hcs, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.year, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.day, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.hour, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.minute, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.sec, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.timbas, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.trwf, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.grnors, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.grnofr, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.grnlof, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.gaps, sizeof(Q_INT16));
Input_SEGY_File.read((char *) &trace_hdr.otrav, sizeof(Q_INT16));
for (int i = 0; i < 15; i )
{
Input_SEGY_File.read((char *) & trace_hdr.user_define[i], sizeof(Q_INT32));
}
if(Input_SEGY_File.is_open())
Input_SEGY_File.close();
}
void SEGY_RW::Write_TraceData_IBM(float *one_trace_data)
{
for(int i = 0; i <Sample_Number; i )
{
IEEE2IBM(&one_trace_data[i]);
}
Output_SEGY_File.open(Output_SEGY_File_Name.c_str(), ios::out|ios::binary|ios::app);
for (int i = 0; i <Sample_Number; i )
{
Output_SEGY_File.write((char *) & one_trace_data[i], sizeof(float));
}
Output_SEGY_File.close();
}
void SEGY_RW::IEEE2IBM(float *data)
{
char *from;
char *to;
unsigned fconv, fsign, fexpn;
register unsigned fmant;
register int t;
register char *bp = (char *) &fconv;
from=(char*)&data[0];
to=(char*)&data[0];
bp[0] = from[0];
bp[1] = from[1];
bp[2] = from[2];
bp[3] = from[3];
from = 4;
fsign = (unsigned) 0x80000000 & fconv;
fexpn = (unsigned) 0x7f800000 & fconv;
fmant = ((unsigned) 0x007fffff & fconv) |
(unsigned) 0x00800000; /* add 1 at 9-th bit */
if (!fexpn) fconv = 0;
else {
t = (int) (fexpn >> 23) - 127 1;
while (t & 0x7) {
t;
fmant >>= 1;
}
fexpn = (unsigned) ((t>>2) 64) << 24;
fconv = fsign | fexpn | fmant;
}
*to = bp[0];
*to = bp[1];
*to = bp[2];
*to = bp[3];
}