Commit 9ed9e892 authored by Purves, Murray's avatar Purves, Murray
Browse files

Adding further sizing to variable names and checksums

parent 6d1e8ce4
Pipeline #16766 failed with stages
in 8 minutes and 47 seconds
......@@ -158,6 +158,7 @@ bool ARLDataStream::read_index_header(const ARLRecordHeader& rheader,
{
bool result = false;
// Read main part of index header
std::string headerString =
p->stream->readString(ARLDataStream::PImpl::indexHeaderLength);
expand(headerString, rheader, iheader);
......@@ -166,6 +167,28 @@ bool ARLDataStream::read_index_header(const ARLRecordHeader& rheader,
p->recordSize =
(iheader.nx * iheader.ny) + ARLDataStream::PImpl::recordHeaderLength;
// Read variable description part of index header
for (size_t level = 0; level < iheader.nz; ++level)
{
// Read levels information
std::string levelString = p->stream->readString(6);
iheader.levels.push_back(std::stof(levelString));
std::string nVarsString = p->stream->readString(2);
iheader.nVarsAtLevels.push_back(std::stoi(nVarsString));
// Read names and checksums
iheader.varNames.push_back(std::vector<std::string>());
iheader.checkSums.push_back(std::vector<int>());
for (size_t var = 0; var < iheader.nVarsAtLevels[level]; ++var)
{
std::string nameString = p->stream->readString(4);
iheader.varNames[level].push_back(nameString);
std::string sumString = p->stream->readString(3);
iheader.checkSums[level].push_back(std::stoi(sumString));
p->stream->skipBytes(1);
}
}
radix_line(" Read index header: model = " << iheader.model_id);
radix_line(" nx = " << iheader.nx);
radix_line(" ny = " << iheader.ny);
......@@ -204,17 +227,10 @@ bool ARLDataStream::write_index_header(const ARLRecordHeader& rheader,
pos += sprintf(indexHeaderVars + pos, "%2d", iheader.nVarsAtLevels[level]);
for (size_t var = 0; var < iheader.nVarsAtLevels[level]; ++var)
{
if (level == 0)
{
pos += sprintf(indexHeaderVars + pos, "%4s",
iheader.surfaceVarNames[var].c_str());
}
else
{
pos += sprintf(indexHeaderVars + pos, "%4s",
iheader.varNames[var].c_str());
}
pos += sprintf(indexHeaderVars + pos, "%3d ", iheader.checkSums[var]);
pos += sprintf(indexHeaderVars + pos, "%4s",
iheader.varNames[level][var].c_str());
pos +=
sprintf(indexHeaderVars + pos, "%3d ", iheader.checkSums[level][var]);
}
}
......
......@@ -75,12 +75,12 @@ class RADIX_PUBLIC ARLDataStream
*/
bool read_record(const ARLRecordHeader& rheader,
const ARLIndexHeader& iheader,
std::vector<std::vector<float> >& record);
std::vector<std::vector<float>>& record);
// TODO
bool write_record(const ARLRecordHeader& rheader,
const ARLIndexHeader& iheader,
const std::vector<std::vector<float> >& record);
const std::vector<std::vector<float>>& record);
void close_stream();
......@@ -111,9 +111,8 @@ struct RADIX_PUBLIC ARLIndexHeader
int lenh;
std::vector<float> levels;
std::vector<int> nVarsAtLevels;
std::vector<std::string> surfaceVarNames;
std::vector<std::string> varNames;
std::vector<int> checkSums;
std::vector<std::vector<std::string>> varNames;
std::vector<std::vector<int>> checkSums;
bool prime;
bool latlon;
......
......@@ -449,9 +449,20 @@ int main(int argc, char **argv)
thisIndexHeader.lenh = numberGridCells * numberGridCells;
thisIndexHeader.levels = inputPressures;
thisIndexHeader.nVarsAtLevels = std::vector<int>(inputPressures.size(), 5);
thisIndexHeader.surfaceVarNames = {"PRSS", "TEMP", "RELH", "UWND", "VWND"};
thisIndexHeader.varNames = {"HGTS", "TEMP", "RELH", "UWND", "VWND"};
thisIndexHeader.checkSums = std::vector<int>(5, 0);
std::vector<std::string> surfaceVarNames = {"PRSS", "TEMP", "RELH", "UWND",
"VWND"};
std::vector<std::string> varNames = {"HGTS", "TEMP", "RELH", "UWND",
"VWND"};
thisIndexHeader.varNames.push_back(surfaceVarNames);
for (size_t level = 1; level < inputPressures.size(); ++level)
{
thisIndexHeader.varNames.push_back(varNames);
}
std::vector<int> checkSums = std::vector<int>(5, 0);
for (size_t level = 0; level < inputPressures.size(); ++level)
{
thisIndexHeader.checkSums.push_back(checkSums);
}
// Write the headers
outputStream.write_record_header(thisRecordHeader);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment