1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
/******************************************************************************
*
* Purpose: Implementation of Prologue class. Parse the prologue of one
* repeat cycle and keep the interesting info.
* Author: Bas Retsios, retsios@itc.nl
*
******************************************************************************
* Copyright (c) 2004, ITC
*
* SPDX-License-Identifier: MIT
******************************************************************************/
#include "cpl_port.h" // Must be first.
#include "prologue.h"
static int size_SatelliteStatus()
{
int iSizePrimary = 1 + 4 + 1 + 1 + 4 + 4 + 1 + 1 + 4 + 4 + 1;
int iSizeOrbitCoef = 4 + 4 + 8 * 8 + 8 * 8 + 8 * 8 + 8 * 8 + 8 * 8 + 8 * 8;
int iSizeOrbit = 4 + 4 + 100 * iSizeOrbitCoef;
int iSizeAttitudeCoef = 4 + 4 + 8 * 8 + 8 * 8 + 8 * 8;
int iSizeAttitude = 4 + 4 + 8 + 100 * iSizeAttitudeCoef;
int iSizeSpinRateatRCStart = 8;
int iSizeUTCCorrelation = 4 + 4 + 4 * 4 * 3 + 8 + 8 + 8 + 8 + 8;
int iTotalSize = iSizePrimary + iSizeOrbit + iSizeAttitude +
iSizeSpinRateatRCStart + iSizeUTCCorrelation;
return iTotalSize;
}
static int size_ImageAcquisition()
{
// up to DHSSSynchSelection
int iSize1 = 8 + 8 + 8 + 12 + 42 + 42 * 2 + 2 + 2 + 2 + 2 + 1;
// up to RefocusingDirection
int iSize2 = 42 * 2 + 42 + 42 * 2 + 42 * 2 + 42 * 2 + 27 * 2 + 15 * 2 +
6 * 2 + 1 + 2 + 1;
// to end
int iSize3 =
2 + 1 + 2 + 4 + 2 + 2 + 2 + 1 + 4 + 1 + 4 + 4 + 1 + 1 + 2 + 2 + 2 + 2;
int iTotalSize = iSize1 + iSize2 + iSize3;
return iTotalSize;
}
static int size_CelestialEvents()
{
int iSizeCelestialBodies = 2 + 2 + 4 + 4 +
3 * 100 * (2 + 2 + 8 * 8 + 8 * 8) +
100 * (20 * (2 + 2 + 2 + 8 * 8 + 8 * 8));
int iSizeRelationToImage = 1 + 2 + 2 + 1 + 1 + 1;
int iTotalSize = iSizeCelestialBodies + iSizeRelationToImage;
return iTotalSize;
}
static int size_Correction()
{
return 19229;
}
static double iReadDouble(std::ifstream &ifile)
{
double rVal;
ifile.read(reinterpret_cast<char *>(&rVal), 8);
CPL_MSBPTR64(&rVal);
return rVal;
}
static double iReadReal(std::ifstream &ifile)
{
float fVal;
ifile.read(reinterpret_cast<char *>(&fVal), 4);
CPL_MSBPTR32(&fVal);
return fVal;
}
static int iReadInt(std::ifstream &ifile)
{
int iResult;
ifile.read(reinterpret_cast<char *>(&iResult), 4);
CPL_MSBPTR32(&iResult);
return iResult;
}
static unsigned char iReadByte(std::ifstream &ifile)
{
// will read 1 byte from the file
char b;
ifile.read(&b, 1);
return b;
}
ReferenceGridRecord::ReferenceGridRecord(std::ifstream &ifile)
{
NumberOfLines = iReadInt(ifile);
NumberOfColumns = iReadInt(ifile);
LineDirGridStep = iReadReal(ifile);
ColumnDirGridStep = iReadReal(ifile);
GridOrigin = iReadByte(ifile);
}
PlannedCoverageVIS_IRRecord::PlannedCoverageVIS_IRRecord(std::ifstream &ifile)
{
SouthernLinePlanned = iReadInt(ifile);
NorthernLinePlanned = iReadInt(ifile);
EasternColumnPlanned = iReadInt(ifile);
WesternColumnPlanned = iReadInt(ifile);
}
PlannedCoverageHRVRecord::PlannedCoverageHRVRecord(std::ifstream &ifile)
{
LowerSouthLinePlanned = iReadInt(ifile);
LowerNorthLinePlanned = iReadInt(ifile);
LowerEastColumnPlanned = iReadInt(ifile);
LowerWestColumnPlanned = iReadInt(ifile);
UpperSouthLinePlanned = iReadInt(ifile);
UpperNorthLinePlanned = iReadInt(ifile);
UpperEastColumnPlanned = iReadInt(ifile);
UpperWestColumnPlanned = iReadInt(ifile);
}
ImageDescriptionRecord::ImageDescriptionRecord(std::ifstream &ifile)
{
TypeOfProjection = iReadByte(ifile);
LongitudeOfSSP = iReadReal(ifile);
ReferenceGridVIS_IR = new ReferenceGridRecord(ifile);
ReferenceGridHRV = new ReferenceGridRecord(ifile);
PlannedCoverageVIS_IR = new PlannedCoverageVIS_IRRecord(ifile);
PlannedCoverageHRV = new PlannedCoverageHRVRecord(ifile);
ImageProcDirection = iReadByte(ifile);
PixelGenDirection = iReadByte(ifile);
for (int i = 0; i < 12; ++i)
PlannedChannelProcessing[i] = iReadByte(ifile);
}
ImageDescriptionRecord::~ImageDescriptionRecord()
{
delete ReferenceGridVIS_IR;
delete ReferenceGridHRV;
delete PlannedCoverageVIS_IR;
delete PlannedCoverageHRV;
}
RadiometricProcessingRecord::RadiometricProcessingRecord(std::ifstream &ifile)
{
// skip a part that doesn't interest us
unsigned char dummy[12];
int i;
for (i = 0; i < 6; ++i)
ifile.read((char *)dummy, 12);
for (i = 0; i < 12; ++i)
{
Cal_Slope[i] = iReadDouble(ifile);
Cal_Offset[i] = iReadDouble(ifile);
}
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Prologue::Prologue() : m_idr(nullptr), m_rpr(nullptr)
{
}
Prologue::~Prologue()
{
if (m_idr)
delete m_idr;
if (m_rpr)
delete m_rpr;
}
void Prologue::read(std::ifstream &ifile)
{
/*unsigned char version = */ iReadByte(ifile);
int iSkipHeadersSize = size_SatelliteStatus() + size_ImageAcquisition() +
size_CelestialEvents() + size_Correction();
ifile.seekg(iSkipHeadersSize, std::ios_base::cur);
m_idr = new ImageDescriptionRecord(ifile);
m_rpr = new RadiometricProcessingRecord(ifile);
// TODO: file is not left at the end of the Radiometric Processing Record
}
|