📄 msg_header.~cpp
字号:
//-----------------------------------------------------------------------------//// File : MSG_header.cpp// Description : MSG HRIT-LRIT format interface// Project : Meteosatlib// Author : Graziano Giuliani// References : MSG/SPE/057 LRIT-HRIT Mission Specific Implementation,// V. 4.1 9 Mar 2001//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA////-----------------------------------------------------------------------------#include <cstring>#include <MSG_header.h>extern void AddHritLog(char * Type, char *Str,bool aP);stTextInfo::stTextInfo(){
Header_Type = 0;
Header_Record_Length = 0;
szText = NULL;
bValid = false;
}
stTextInfo::~stTextInfo()
{
if(szText!=NULL)delete szText;
}
bool stTextInfo::Assign(unsigned char *ptr)
{
if(szText!=NULL)
{
delete szText;
szText = NULL;
}
if(*ptr==Header_Type)
{
Header_Record_Length = UInt2(ptr+1);
szText = new char[Header_Record_Length];
if(szText!=NULL)
{
ZeroMemory(szText, Header_Record_Length);
MoveMemory(szText, ptr+3, Header_Record_Length-3);
bValid = true;
return true;
}
}
return false;
}
//===========================================================================
bool stPrimaryHeader::Assign(unsigned char *ptr)
{
Header_Type = 0;
if(*ptr==Header_Type)
{
Header_Record_Length = 0x10;
File_Type_Code = ptr[3];
Total_Header_Length = UInt4(ptr+4);
Data_Field_Length = UInt8(ptr+8);
Data_Field_Length /=8 ;
bValid = true;
return true;
}
return false;
}
//---------------------------------------------------------------------------
bool stImageStruct::Assign(unsigned char *ptr)
{
Header_Type = 1;
if(*ptr==Header_Type)
{
Header_Record_Length = 9;
NB = ptr[3];
NC = UInt2(ptr+4);
NL = UInt2(ptr+6);
Compression_Flag = ptr[8];
bValid = true;
return true;
}
return false;
}
//---------------------------------------------------------------------------
bool stImageNavigation::Assign(unsigned char *ptr)
{
Header_Type = 2;
if(*ptr==Header_Type)
{
Header_Record_Length = 0x33;
ZeroMemory(Projection_Name, 32);
MoveMemory(Projection_Name, ptr+3, 30);
CFAC = UInt4(ptr+35);
LFAC = UInt4(ptr+39);
COFF = UInt4(ptr+43);
LOFF = UInt4(ptr+47);
bValid = true;
return true;
}
return false;
}
//---------------------------------------------------------------------------
bool stTimeStamp::Assign(unsigned char *ptr)
{
Header_Type = 5;
if(*ptr==Header_Type)
{
Header_Record_Length = 10;
CDS_P_Field = ptr[3];
CDS_T_Field_day = UInt2(ptr+4);
CDS_T_Field_ms = UInt4(ptr+6);
bValid = true;
return true;
}
return false;
}
//---------------------------------------------------------------------------
bool stKeyHeader::Assign(unsigned char *ptr)
{
Header_Type = 7;
if(*ptr==Header_Type)
{
Header_Record_Length = 7;
Key_Number = UInt4(ptr+3);
bValid = true;
return true;
}
return false;
}
//---------------------------------------------------------------------------
bool stImageSegmentID::Assign(unsigned char *ptr)
{
Header_Type = 0x80;
if(*ptr==Header_Type)
{
Header_Record_Length = 7;
Image_Segm_Seq_No = ptr[3];
Total_No_Image_Segm = ptr[4];
Line_No_Image_Segm = UInt2(ptr+5);
bValid = true;
return true;
}
return false;
}
//---------------------------------------------------------------------------
bool stEncryptionKeyMsgHeader::Assign(unsigned char *ptr)
{
Header_Type = 0x81;
if(*ptr==Header_Type)
{
Header_Record_Length = 5;
Station_Number = UInt2(ptr+3);
bValid = true;
return true;
}
return false;
}
//===========================================================================
THritFile::THritFile()
{
data = NULL;
dwBufSize = 0;
}
//---------------------------------------------------------------------------
THritFile::THritFile(char* fs)
{
data = NULL;
dwBufSize = 0;
strncpy(szFileName, fs, 254);
GetHeaderInfo();
}
//---------------------------------------------------------------------------
THritFile::~THritFile()
{
if(data!=NULL) delete data;
}
//---------------------------------------------------------------------------
void THritFile::SetFileName(unsigned char *fs)
{
strncpy(szFileName, fs, 254);
}
//---------------------------------------------------------------------------
void THritFile::GetHeaderInfo(unsigned char *ptr, int n)
{
int i = 0;
if(m_PrimaryHeader.Assign(ptr+i))
{
i += m_PrimaryHeader.Header_Record_Length;
}
if(m_ImageStruct.Assign(ptr+i))
{
i += m_ImageStruct.Header_Record_Length;
}
if(i<n && m_ImageNavigation.Assign(ptr+i))
{
i += m_ImageNavigation.Header_Record_Length;
}
if(i<n && m_ImageDataFunction.Assign(ptr+i))
{
i += m_ImageDataFunction.Header_Record_Length;
}
if(i<n && m_Annotation.Assign(ptr+i))
{
i += m_Annotation.Header_Record_Length;
}
if(i<n && m_TimeStamp.Assign(ptr+i))
{
i += m_TimeStamp.Header_Record_Length;
}
if(i<n && m_AncillaryText.Assign(ptr+i))
{
i += m_AncillaryText.Header_Record_Length;
}
if(i<n && m_KeyHeader.Assign(ptr+i))
{
i += m_KeyHeader.Header_Record_Length;
}
if(i<n && m_ImageSegmentID.Assign(ptr+i))
{
i += m_ImageSegmentID.Header_Record_Length;
}
if(i<n && m_EncryptionKeyMsgHeader.Assign(ptr+i))
{
i += m_EncryptionKeyMsgHeader.Header_Record_Length;
}
if(i<n && m_ImageCompensationInfo.Assign(ptr+i))
{
i += m_ImageCompensationInfo.Header_Record_Length;
}
if(i<n && m_ImageObserveTime.Assign(ptr+i))
{
i += m_ImageObserveTime.Header_Record_Length;
}
if(i<n) m_ImageQualityInfo.Assign(ptr+i);
}//---------------------------------------------------------------------------void THritFile::GetHeaderInfo()
{
unsigned int i, k, n;
unsigned char *ptr;
unsigned char A[32];
FILE *fp = fopen(szFileName, "rb");
if(fp!=NULL)
{
n = fread(A, 1, 16, fp);
if(n==16)
{
if(m_PrimaryHeader.Assign(A))
{
ptr = new char[m_PrimaryHeader.Total_Header_Length+256];
if(ptr!=NULL)
{
fseek(fp, 0, SEEK_SET);
n = fread(ptr, 1, m_PrimaryHeader.Total_Header_Length, fp);
GetHeaderInfo(ptr, n);
delete ptr;
}
}
}
fclose(fp);
}
}
//---------------------------------------------------------------------------
unsigned char *THritFile::ReadDataField(unsigned long& nReadBytes)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -