Skip to content
Snippets Groups Projects
Commit 6c8f9672 authored by williamfgc's avatar williamfgc Committed by GitHub
Browse files

Merge pull request #125 from williamfgc/bpdumpfix

BP file output now compatible with bpdump
parents 7a16fa23 2b91f85a
No related branches found
No related tags found
No related merge requests found
......@@ -248,14 +248,19 @@ void BP1Writer::WriteDimensionsRecord(const Dims localDimensions,
void BP1Writer::WriteDimensionsRecord(const Dims localDimensions,
const Dims globalDimensions,
const Dims offsets,
const unsigned int skip,
std::vector<char> &buffer,
size_t &position) noexcept
size_t &position,
const bool isCharacteristic) noexcept
{
auto lf_WriteFlaggedDim = [](std::vector<char> &buffer, size_t &position,
const size_t dimension) {
constexpr char no = 'n';
CopyToBuffer(buffer, position, &no);
auto lf_CopyDimension = [](std::vector<char> &buffer, size_t &position,
const size_t dimension,
const bool isCharacteristic) {
if (!isCharacteristic)
{
constexpr char no = 'n';
CopyToBuffer(buffer, position, &no);
}
CopyToBuffer(buffer, position,
reinterpret_cast<const uint64_t *>(&dimension));
};
......@@ -263,19 +268,28 @@ void BP1Writer::WriteDimensionsRecord(const Dims localDimensions,
// BODY Starts here
if (offsets.empty())
{
unsigned int globalBoundsSkip = 18;
if (isCharacteristic)
{
globalBoundsSkip = 16;
}
for (const auto &localDimension : localDimensions)
{
lf_WriteFlaggedDim(buffer, position, localDimension);
position += skip;
lf_CopyDimension(buffer, position, localDimension,
isCharacteristic);
position += globalBoundsSkip;
}
}
else
{
for (unsigned int d = 0; d < localDimensions.size(); ++d)
{
lf_WriteFlaggedDim(buffer, position, localDimensions[d]);
lf_WriteFlaggedDim(buffer, position, globalDimensions[d]);
lf_WriteFlaggedDim(buffer, position, offsets[d]);
lf_CopyDimension(buffer, position, localDimensions[d],
isCharacteristic);
lf_CopyDimension(buffer, position, globalDimensions[d],
isCharacteristic);
lf_CopyDimension(buffer, position, offsets[d], isCharacteristic);
}
}
}
......
......@@ -186,9 +186,8 @@ private:
/** Overloaded version for data buffer */
void WriteDimensionsRecord(const Dims localDimensions,
const Dims globalDimensions, const Dims offsets,
const unsigned int skip,
std::vector<char> &buffer,
size_t &position) noexcept;
std::vector<char> &buffer, size_t &position,
const bool isCharacteristic = false) noexcept;
/** Writes min max */
template <class T>
......
......@@ -175,16 +175,15 @@ void BP1Writer::WriteVariableMetadataInData(
CopyToBuffer(buffer, position, &dimensionsLength); // length
WriteDimensionsRecord(variable.m_Count, variable.m_Shape, variable.m_Start,
18, buffer, position);
buffer, position);
// CHARACTERISTICS
// FIX
WriteVariableCharacteristics(variable, stats, buffer, position);
// Back to varLength including payload size
// remove its own size (8) from length
// not need to remove its own size (8) from length from bpdump
const uint64_t varLength =
position - varLengthPosition + variable.PayLoadSize() - 8;
position - varLengthPosition + variable.PayLoadSize();
size_t backPosition = varLengthPosition;
CopyToBuffer(buffer, backPosition, &varLength);
......@@ -301,10 +300,6 @@ void BP1Writer::WriteCharacteristicRecord(const uint8_t characteristicID,
{
const std::uint8_t id = characteristicID;
CopyToBuffer(buffer, position, &id);
const std::uint16_t lengthOfCharacteristic = sizeof(T);
CopyToBuffer(buffer, position, &lengthOfCharacteristic);
CopyToBuffer(buffer, position, &value);
++characteristicsCounter;
}
......@@ -372,25 +367,18 @@ void BP1Writer::WriteVariableCharacteristics(
// DIMENSIONS
uint8_t characteristicID = characteristic_dimensions;
CopyToBuffer(buffer, position, &characteristicID);
const uint8_t dimensions = variable.m_Count.size();
// 24 = 3 local, global, offset x 8 bytes/each
const int16_t lengthOfDimensionsCharacteristic = 24 * dimensions + 3;
CopyToBuffer(buffer, position, &lengthOfDimensionsCharacteristic);
const uint8_t dimensions = variable.m_Count.size();
CopyToBuffer(buffer, position, &dimensions); // count
const uint16_t dimensionsLength = 24 * dimensions;
CopyToBuffer(buffer, position, &dimensionsLength); // length
WriteDimensionsRecord(variable.m_Count, variable.m_Shape, variable.m_Start,
16, buffer, position);
buffer, position, true); // isCharacteristic = true
++characteristicsCounter;
// VALUE for SCALAR or STAT min, max for ARRAY
WriteBoundsRecord(variable.m_SingleValue, stats, characteristicsCounter,
buffer, position);
// TIME INDEX
WriteCharacteristicRecord(characteristic_time_index, characteristicsCounter,
stats.TimeIndex, buffer, position);
// END OF CHARACTERISTICS
// Back to characteristics count and length
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment