Skip to content

Commit

Permalink
Merge pull request #4145 from anagainaru/bpls-derived
Browse files Browse the repository at this point in the history
Option in `bpls` to show the expression string for derived variables
  • Loading branch information
anagainaru authored Apr 18, 2024
2 parents fcbea67 + 019557b commit 0ee43a4
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions source/adios2/core/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ class Engine
return false;
}

virtual const char *VariableExprStr(const VariableBase &) { return NULL; }

/** Notify the engine when a new attribute is defined. Called from IO.tcc
*/
virtual void NotifyEngineAttribute(std::string name, DataType type) noexcept;
Expand Down
5 changes: 5 additions & 0 deletions source/adios2/engine/bp5/BP5Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,11 @@ bool BP5Reader::VariableMinMax(const VariableBase &Var, const size_t Step, MinMa
return m_BP5Deserializer->VariableMinMax(Var, Step, MinMax);
}

const char *BP5Reader::VariableExprStr(const VariableBase &Var)
{
return static_cast<const char *>(m_BP5Deserializer->VariableExprStr(Var));
}

void BP5Reader::InitTransports()
{
if (m_IO.m_TransportsParameters.empty())
Expand Down
1 change: 1 addition & 0 deletions source/adios2/engine/bp5/BP5Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class BP5Reader : public BP5Engine, public Engine
MinVarInfo *MinBlocksInfo(const VariableBase &, const size_t Step) const;
bool VarShape(const VariableBase &Var, const size_t Step, Dims &Shape) const;
bool VariableMinMax(const VariableBase &, const size_t Step, MinMaxStruct &MinMax);
const char *VariableExprStr(const VariableBase &Var);

private:
format::BP5Deserializer *m_BP5Deserializer = nullptr;
Expand Down
6 changes: 6 additions & 0 deletions source/adios2/toolkit/format/bp5/BP5Deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2443,5 +2443,11 @@ bool BP5Deserializer::VariableMinMax(const VariableBase &Var, const size_t Step,
return true;
}

char *BP5Deserializer::VariableExprStr(const VariableBase &Var)
{
BP5VarRec *VarRec = LookupVarByKey((void *)&Var);
return VarRec->ExprStr;
}

}
}
1 change: 1 addition & 0 deletions source/adios2/toolkit/format/bp5/BP5Deserializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class BP5Deserializer : virtual public BP5Base
MinVarInfo *MinBlocksInfo(const VariableBase &Var, const size_t Step);
bool VarShape(const VariableBase &, const size_t Step, Dims &Shape) const;
bool VariableMinMax(const VariableBase &var, const size_t Step, MinMaxStruct &MinMax);
char *VariableExprStr(const VariableBase &var);
void GetAbsoluteSteps(const VariableBase &variable, std::vector<size_t> &keys) const;

const bool m_WriterIsRowMajor;
Expand Down
17 changes: 17 additions & 0 deletions source/utils/bpls/bpls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "bpls.h"
#include "verinfo.h"

#include <algorithm>
#include <chrono>
#include <cinttypes>
#include <cstdio>
Expand Down Expand Up @@ -103,6 +104,7 @@ bool hidden_attrs; // show hidden attrs in BP file
int hidden_attrs_flag; // to be passed on in option struct
bool show_decomp; // show decomposition of arrays
bool show_version; // print binary version info of file before work
bool show_derived_expr; // show the expression string for derived vars
adios2::Accuracy accuracy;
bool accuracyWasSet = false;

Expand Down Expand Up @@ -176,6 +178,7 @@ void display_help()
" e.g. error=\"0.0,0.0,abs\"\n"
" L2 norm = 0.0, Linf = inf\n"

" --show-derived Show the expression string for derived vars\n"
" --transport-parameters | -T Specify File transport "
"parameters\n"
" e.g. \"Library=stdio\"\n"
Expand Down Expand Up @@ -655,6 +658,8 @@ int bplsMain(int argc, char *argv[])
arg.AddArgument("--engine-params", argT::SPACE_ARGUMENT, &engine_params,
"| -P string Specify ADIOS Engine Parameters manually");
arg.AddArgument("-P", argT::SPACE_ARGUMENT, &engine_params, "");
arg.AddBooleanArgument("--show-derived", &show_derived_expr,
"Show the expression string for derived variables");

if (!arg.Parse())
{
Expand Down Expand Up @@ -779,6 +784,7 @@ void init_globals()
printByteAsChar = false;
show_decomp = false;
show_version = false;
show_derived_expr = false;
for (i = 0; i < MAX_DIMS; i++)
{
istart[i] = 0LL;
Expand Down Expand Up @@ -1291,6 +1297,17 @@ int printVariableInfo(core::Engine *fp, core::IO *io, core::Variable<T> *variabl
}
}

if (show_derived_expr)
{
const char *ExprPtr = fp->VariableExprStr(*variable);
if (ExprPtr != NULL)
{
std::string ExprStr(ExprPtr);
std::replace(ExprStr.begin(), ExprStr.end(), '\n', ' ');
fprintf(outf, " Derived variable with expression: %s\n", ExprStr.c_str());
}
}

if (dump && !show_decomp)
{
variable->SetAccuracy(accuracy);
Expand Down
1 change: 1 addition & 0 deletions testing/utils/cwriter/TestUtilsCWriter.bplsh.expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The time dimension is the first dimension then.
--error | -X string Specify read accuracy (error,norm,rel|abs)
e.g. error="0.0,0.0,abs"
L2 norm = 0.0, Linf = inf
--show-derived Show the expression string for derived vars
--transport-parameters | -T Specify File transport parameters
e.g. "Library=stdio"
--engine | -E <name> Specify ADIOS Engine
Expand Down

0 comments on commit 0ee43a4

Please sign in to comment.