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

📄 wrseg2.cpp

📁 《面向对象程序设计实用教程》一书的源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// WrSeg21.cpp: implementation of the WrSeg2 class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "cge.h"
#include "WrSeg2.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
	static char szFilter[] = "Accounting Files (*.dat)|*.dat|All Files (*.*)|*.*||";
    static char lpstrCustomFilter[255]={"Previous Filter\0*.dat\0"};
    #define MAX_PATH          260

WrSeg2::WrSeg2() 
{


}

WrSeg2::~WrSeg2()
{

}


void WrSeg2::Write_Seg2(const CString s[12], const CObList& m_CMyLineList, const CString m_path[10])
{
	  WORD FileFlag = 0x3a55;  //0-1
	  WORD  ModifyNo = 0x00;  //2-3
	  CString temp_s;
	  float temp_f;
	  temp_s = s[8];
	  temp_s = temp_s.Mid(0, s[8].GetLength()-2 ) ;
	  WORD  N = atoi(temp_s) ;
	  WORD  M_Size = 4 * N ; //4-5
	  WORD  N_Count = N ;      //6-7 
	  BYTE StringEndLength = 0x01; //8	
	  BYTE String_1End = 0x00; //9_1	
      BYTE String_2End = 0x00; //9_2 ,10	
      BYTE RowEndLength = 0x01; //11
	  BYTE Row_1End = 0x0a;     //12_1
	  BYTE Row_2End = 0x00;     //12_2 ,13
	  BYTE ReadyBytes[18];  //14-31
	  int Nb0;

      for(int i=0;i<18;i++)//描述文件块是18个字节的预留区
	  {
		ReadyBytes[i] = 0x00;
	  }
	  DWORD BlockPoint[24] ; //32-N*4 ,64_bit
	  //DWORD BlockPoint = 0x00000000; //32-35 ,64_bit
	  //BlockPoint[0]  = 0x4422; //32-35 
	  DWORD pot, got, pot1, potN; 
	  for(i=0;i<N;i++)
	  {
		BlockPoint[i]  = 0x88772211; //32-35 自动添0
	  }	
	  
	  CString L_date = "ACQUISITION_DATE " ;      //32+M ,2    
	  //CTime tNow;
	  CString tdate, ttime;
	  //tNow = CTime::GetCurrentTime();      
	  //tdate = tNow.Format("%Y/%m/%d");
	  tdate = m_path[6];
	  //ttime = tNow.Format("%H:%M");
	  ttime = m_path[7];
	  L_date = L_date + tdate ;	
 	  CString L_time = "ACQUISITION_TIME " ;
	  L_time = L_time + ttime ;

	  CString L_instrument = "INSTRUMENT CGE DZQ24" ;
	  CString L_units = "UNITS METER";
	  CString L_trace = "TRACE_SORT COMMON SOURCE";
	  m_base = m_path[1];
	  m_shoot = m_path[3];
	  CString temp1 = "NOTE \nBASE_INTERVAL " + m_base; //检波器间距
	  CString temp2 = "\nSHOT_INTERVAL " + m_shoot; //炮点间距	  
	  //改数
      Nb0 = s[0].Find ("-");
	  Nb0 = atoi(s[0].Left (Nb0));
	  temp_s.Format("%d",Nb0);
	  CString L_note = temp1 + temp2 +  _T("\n") ;
	  //CString L_note = temp1 + temp2 + "\nINSTRUMENT_NUMBER " + temp_s + _T("\n") ;
	  BYTE L_temp[3]  = {0x00, 0X00, 0X00};  //只写3个空字节{结束符,长度,空串本身}

	CFile Sg2_wr(m_path[0],CFile::modeCreate | CFile::modeWrite);
	
	Sg2_wr.WriteHuge(&FileFlag,2);
	Sg2_wr.WriteHuge(&ModifyNo,2);
	Sg2_wr.WriteHuge(&M_Size,2);
    Sg2_wr.WriteHuge(&N_Count,2);
    Sg2_wr.WriteHuge(&StringEndLength,1);
    Sg2_wr.WriteHuge(&String_1End,1);
	//if(StringEndLength==0x02) Sg2_wr.WriteHuge(&String_2End,1);
	Sg2_wr.WriteHuge(&String_2End,1);
	Sg2_wr.WriteHuge(&RowEndLength,1);
	Sg2_wr.WriteHuge(&Row_1End,1);
	//if(RowEndLength==0x02) Sg2_wr.WriteHuge(&Row_2End,1);
	Sg2_wr.WriteHuge(&Row_2End,1);
    Sg2_wr.WriteHuge(ReadyBytes,18);//14-31
	potN = got = Sg2_wr.GetPosition ();            //N1
    //Sg2_wr.WriteHuge(&BlockPoint,4);//32-4*N
    Sg2_wr.WriteHuge(&BlockPoint,4*N);//32-4*N
	
	pot = L_date.GetLength() + 3;
	Sg2_wr.WriteHuge(&pot, 2) ;
	Sg2_wr.WriteHuge(L_date,L_date.GetLength() ) ;
	Sg2_wr.WriteHuge(&Row_2End,1 ) ;

	pot = L_time.GetLength() + 3;
	Sg2_wr.WriteHuge(&pot, 2) ;	
	Sg2_wr.WriteHuge(L_time,L_time.GetLength() ) ;
	Sg2_wr.WriteHuge(&Row_2End,1 ) ;
	//m
	pot = L_instrument.GetLength() + 3;
	Sg2_wr.WriteHuge(&pot, 2) ;
	Sg2_wr.WriteHuge(L_instrument,L_instrument.GetLength() ) ;
	Sg2_wr.WriteHuge(&Row_2End,1 ) ;

	pot = L_units.GetLength() + 3;
	Sg2_wr.WriteHuge(&pot, 2) ;
	Sg2_wr.WriteHuge(L_units,L_units.GetLength() ) ;
	Sg2_wr.WriteHuge(&Row_2End,1 ) ;

	pot = L_trace.GetLength() + 3;
	Sg2_wr.WriteHuge(&pot, 2) ;
	Sg2_wr.WriteHuge(L_trace,L_trace.GetLength() ) ;
	Sg2_wr.WriteHuge(&Row_2End,1 ) ;

	pot = L_note.GetLength() + 4;
	Sg2_wr.WriteHuge(&pot, 2) ;
	Sg2_wr.WriteHuge(L_note, L_note.GetLength() ) ;
	Sg2_wr.WriteHuge(&Row_2End,1 ) ;		
	Sg2_wr.WriteHuge(L_temp, 3);	

	while(Sg2_wr.GetPosition ()%4 != 0 )
	{
		Sg2_wr.WriteHuge(&Row_2End,1 ) ; 
	}
	
    //dk
	int Ni,j,yp,Nb;
	WORD RecordFlag = 0x4422;          //0-1	  
	WORD RecordBlock_Size = 0x3322;    //2-3 本描述块大小
	DWORD RecordDataBlock_Size = 4 * atoi(s[5]) ; //4-7
	DWORD Ns_Count = atoi(s[5]);               //8-11
	BYTE Data_Form=0x02;                //12
	BYTE Pre_Bytes[19];   //13-31
	//int i_d;

    POSITION m_position;
    CMyLine* pMyLine;  
	potN = potN - 4 ;  //N_i
	i = s[0].Find("-");
	Nb = atoi(s[0].Mid(0,i));

	CString Rec_1AscKey;// ="CHANNEL_NUMBER " + temp_s ; //32
	CString Rec_2AscKey;// ="DELAY " + s[6];
	CString Rec_3AscKey;// ="HIGH_CUT_FILTER " + s[1] ;
	m_lineno = m_path[5];
	CString Rec_4AscKey;// ="LINE_ID " + m_lineno;   //侧线号
	CString Rec_5AscKey;// ="LOW_CUT_FILTER " + s[2] ;  
	CString Rec_6AscKey;

	CString Rec_7AscKey;// ="RAW_RECORD " + m_path[0];     //m_file_name;
    m_place = m_path[4];
	CString Rec_8AscKey;// ="RECEIVER_LOCATION " + m_place;//偏移距
    CString Rec_9AscKey;// ="SAMPLE_INTERVAL " + temp_s;	  

	CString Rec_10AscKey;// ="SOURCE_LOCATION " + m_sour;//震源位置 
	CString Rec_11AscKey;// ="STACK " + s[9];
	CString Rec_12AscKey;// ="NOTE \nDISPLAY_SCALE " + s[10] + _T("\n") ;
	//BYTE Rec_EndAscKey[3];// = {0x00,0x00,0x00};             //32+M ,4

    if(!m_CMyLineList.IsEmpty())
	{
	 m_position = m_CMyLineList.GetHeadPosition();
 	 for(Ni=0;Ni<N;Ni++)	
	 { 
	  potN = potN + 4 ;  //N_i
	  pot = Sg2_wr.GetPosition ();
	  Sg2_wr.Seek(potN,CFile::begin);	  
	  Sg2_wr.WriteHuge(&pot, 4);	//N
	  Sg2_wr.Seek(pot,CFile::begin); 
	  //WORD RecordFlag = 0x4422;          //0-1	  
	  //WORD RecordBlock_Size = 0x3322;    //2-3 本描述块大小
	  //DWORD RecordDataBlock_Size = 4 * atoi(s[5]) ; //4-7
	  //WORD Ns_Count = atoi(s[5]);               //8-11
	  //BYTE Data_Form=0x02;                //12
	  //BYTE Pre_Bytes[19];   //13-31
	  for(i=0;i<19;i++) //描述道块是19个字节的预留区
	  {
			Pre_Bytes[i] = 0x00;
	  }
	
	  temp_s.Format("%d", Nb+Ni); //从最小的记录道号开始
	  //改数
	  //temp_s.Format("%d", Ni+1); // 1开始
	  Rec_1AscKey ="CHANNEL_NUMBER " + temp_s ; //32
	  Rec_2AscKey ="DELAY " + s[6];
	  temp_f = atof(s[1]);
	  temp_s.Format("%.1f",temp_f);	  
	  Rec_3AscKey ="HIGH_CUT_FILTER " + temp_s; //s[1] ;
	  //改数
	  //Rec_3AscKey ="HIGH_CUT_FILTER " + "350.0" ;
	  m_lineno = m_path[5];
	  Rec_4AscKey ="LINE_ID " + m_lineno;   //侧线号
	  temp_f = atof(s[2]);
	  temp_s.Format("%.1f",temp_f);
	  
	  Rec_5AscKey ="LOW_CUT_FILTER " + temp_s; //s[2] ;  
	  //改数
	  //Rec_5AscKey ="LOW_CUT_FILTER " + "0.1";  

	  //CString Rec_6AscKey;
	  if(s[3] == "关" )
	  {
		Rec_6AscKey = "NOTCH_FREQUENCY 0" ;
	  }else
	  {
	  	Rec_6AscKey = "NOTCH_FREQUENCY 50" ; // !!! or 50Hz ?
	  }	  
	  //Rec_7AscKey ="RAW_RECORD " + m_path[0];     //m_file_name;
	  Rec_7AscKey ="RAW_RECORD " + m_path[8];     //m_file_name、old filename;//m46
	  m_place = m_path[4]; //m_place;//偏移距
	  m_sour = m_path[2];
	  //or 检波器位置的值 = atof(m_sour)+atof(m_place)+atof(m_base)*(Nb+Ni)
	  temp_f = atof(m_sour)+atof(m_place)+atof(m_base)* Ni;//(Nb+Ni);//从1开始	  
	  //temp_f = atof(m_place);
	  temp_s.Format("%.2f",temp_f);
	  Rec_8AscKey ="RECEIVER_LOCATION " + temp_s; //m_place;//偏移距
	  temp_s = s[4]; temp_s = temp_s.Mid(0, s[4].GetLength() - 2 );
	  if(s[4].Right(2) == "us")
	  {
		temp_s.Format("%.6f", atoi(temp_s) / 1000000.0 ) ;
	  }/*else
	  {
		temp_s.Format("%.6f", atoi(temp_s) / 1000.0 ) ;
	  }*/
	  if(s[4].Right(2) == "ms")
	  {
		temp_s.Format("%.6f", atoi(temp_s) / 1000.0 ) ;
	  }

	  Rec_9AscKey ="SAMPLE_INTERVAL " + temp_s;	  
	  //改数
	  //Rec_9AscKey ="SAMPLE_INTERVAL " + "0.0001";	  
	  m_sour = m_path[2]; 	 
	  temp_f = atof(m_sour);
	  temp_s.Format("%.2f",temp_f);
	  Rec_10AscKey ="SOURCE_LOCATION " + temp_s; //m_sour;//震源位置 
	  Rec_11AscKey ="STACK " + s[9];
	  Rec_12AscKey ="NOTE \nDISPLAY_SCALE " + s[10] + _T("\n") ;
	  //改数
	  //Rec_11AscKey ="STACK " + "1";
	  //Rec_12AscKey ="NOTE \nDISPLAY_SCALE " + s[10] + _T("\n") ;
	  
	  BYTE Rec_EndAscKey[3] = {0x00,0x00,0x00};             //32+M ,4
      //The 32+M ,END

	got = Sg2_wr.GetPosition ();
	Sg2_wr.WriteHuge(&RecordFlag,2);
	Sg2_wr.WriteHuge(&RecordBlock_Size ,2);    //X
    Sg2_wr.WriteHuge(&RecordDataBlock_Size,4);
    Sg2_wr.WriteHuge(&Ns_Count,4);
    Sg2_wr.WriteHuge(&Data_Form,1);
    Sg2_wr.WriteHuge(Pre_Bytes,19);
    
	pot = Rec_1AscKey.GetLength() + 3;
	Sg2_wr.WriteHuge(&pot, 2) ;
	Sg2_wr.WriteHuge(Rec_1AscKey,Rec_1AscKey.GetLength() );	
    Sg2_wr.WriteHuge(&Row_2End,1 ) ;

    pot = Rec_2AscKey.GetLength() + 3;
	Sg2_wr.WriteHuge(&pot, 2) ;
	Sg2_wr.WriteHuge(Rec_2AscKey,Rec_2AscKey.GetLength() );	
    Sg2_wr.WriteHuge(&Row_2End,1 ) ;
	
	pot = Rec_3AscKey.GetLength() + 3;
	Sg2_wr.WriteHuge(&pot, 2) ;
	Sg2_wr.WriteHuge(Rec_3AscKey,Rec_3AscKey.GetLength() );	
    Sg2_wr.WriteHuge(&Row_2End,1 ) ;

	pot = Rec_4AscKey.GetLength() + 3;
	Sg2_wr.WriteHuge(&pot, 2) ;
	Sg2_wr.WriteHuge(Rec_4AscKey,Rec_4AscKey.GetLength() );	
    Sg2_wr.WriteHuge(&Row_2End,1 ) ;

	pot = Rec_5AscKey.GetLength() + 3;
	Sg2_wr.WriteHuge(&pot, 2) ;
	Sg2_wr.WriteHuge(Rec_5AscKey,Rec_5AscKey.GetLength() );	
    Sg2_wr.WriteHuge(&Row_2End,1 ) ;

	pot = Rec_6AscKey.GetLength() + 3;
	Sg2_wr.WriteHuge(&pot, 2) ;
	Sg2_wr.WriteHuge(Rec_6AscKey,Rec_6AscKey.GetLength() );	
    Sg2_wr.WriteHuge(&Row_2End,1 ) ;

	pot = Rec_7AscKey.GetLength() + 3;
	Sg2_wr.WriteHuge(&pot, 2) ;
	Sg2_wr.WriteHuge(Rec_7AscKey,Rec_7AscKey.GetLength() );	
    Sg2_wr.WriteHuge(&Row_2End,1 ) ;

	pot = Rec_8AscKey.GetLength() + 3;
	Sg2_wr.WriteHuge(&pot, 2) ;
	Sg2_wr.WriteHuge(Rec_8AscKey,Rec_8AscKey.GetLength() );	
    Sg2_wr.WriteHuge(&Row_2End,1 ) ;

	pot = Rec_9AscKey.GetLength() + 3;
	Sg2_wr.WriteHuge(&pot, 2) ;
	Sg2_wr.WriteHuge(Rec_9AscKey,Rec_9AscKey.GetLength() );	
    Sg2_wr.WriteHuge(&Row_2End,1 ) ;

	pot = Rec_10AscKey.GetLength() + 3;

⌨️ 快捷键说明

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