Skip to content
Snippets Groups Projects
Commit a0a13705 authored by William F Godoy's avatar William F Godoy
Browse files

Initial bpls2

parent 26031a9f
No related branches found
No related tags found
1 merge request!294Bp1read : Initial Reading Capabilities and latest API
...@@ -32,7 +32,7 @@ else() ...@@ -32,7 +32,7 @@ else()
endif() endif()
install( install(
TARGETS ${adios2_f} EXPORT adios2 TARGETS adios2_f EXPORT adios2
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
......
...@@ -8,6 +8,7 @@ if(ADIOS2_HAVE_DataMan) ...@@ -8,6 +8,7 @@ if(ADIOS2_HAVE_DataMan)
endif() endif()
add_subdirectory(adios2) add_subdirectory(adios2)
add_subdirectory(utils)
install( install(
FILES adios2.h FILES adios2.h
......
#------------------------------------------------------------------------------#
# Distributed under the OSI-approved Apache License, Version 2.0. See
# accompanying file Copyright.txt for details.
#------------------------------------------------------------------------------#
#BPLS2
add_executable(bpls2 ./bpls2/main.cpp ./bpls2/BPLS2.cpp Utils.cpp)
target_link_libraries(bpls2 PRIVATE adios2)
install(TARGETS bpls2
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
...@@ -2,15 +2,20 @@ ...@@ -2,15 +2,20 @@
* Distributed under the OSI-approved Apache License, Version 2.0. See * Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details. * accompanying file Copyright.txt for details.
* *
* BPLS2.cpp * Utils.cpp
* *
* Created on: Oct 5, 2017 * Created on: Oct 24, 2017
* Author: William F Godoy godoywf@ornl.gov * Author: William F Godoy godoywf@ornl.gov
*/ */
#include "Utils.h"
namespace adios2 namespace adios2
{ {
namespace utils
Utils::Utils(const std::string name, int argc, char *argv[])
: m_Name(name), m_Arguments(argv, argv + argc)
{ {
} }
} // end namespace adios2 } // end namespace adios2
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* Utils.h
*
* Created on: Oct 24, 2017
* Author: William F Godoy godoywf@ornl.gov
*/
#ifndef SOURCE_UTILS_UTILS_H_
#define SOURCE_UTILS_UTILS_H_
#include <string>
#include <vector>
#include "adios2/ADIOSTypes.h"
namespace adios2
{
class Utils
{
public:
const std::string m_Name;
Utils(const std::string name, int argc, char *argv[]);
virtual ~Utils() = default;
virtual void Run() = 0;
protected:
const std::vector<std::string> m_Arguments;
Params m_Parameters;
virtual void ParseArguments() = 0;
virtual void ProcessParameters() const = 0;
virtual void PrintUsage() const noexcept = 0;
virtual void PrintExamples() const noexcept = 0;
virtual void SetParameters(const std::string argument,
const bool isLong) = 0;
};
} /// end namespace adios2
#endif /* SOURCE_UTILS_UTILS_H_ */
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* BPLS2.cpp
*
* Created on: Oct 5, 2017
* Author: William F Godoy godoywf@ornl.gov
*/
#include "BPLS2.h"
#include <iostream>
namespace adios2
{
namespace utils
{
const std::string BPLS2::m_HelpMessage = "For usage run either:\n"
"\t bpls2 --help\n"
"\t bpls2 -h \n";
const std::map<std::string, std::string> BPLS2::m_Options = {
{"long", "l"}, {"attrs", "a"}, {"attrsonly", "A"},
{"dump", "d"}, {"verbose", "v"}, {"help", "h"}};
BPLS2::BPLS2(int argc, char *argv[]) : Utils("bpls2", argc, argv) {}
void BPLS2::Run()
{
ParseArguments();
ProcessParameters();
}
// PRIVATE
void BPLS2::ParseArguments()
{
if (m_Arguments.size() == 1)
{
throw std::invalid_argument("ERROR: Missing bpfile\n" + m_HelpMessage);
}
bool isFileSet = false;
for (auto itArg = m_Arguments.begin() + 1; itArg != m_Arguments.end();
++itArg)
{
if (itArg->find("--") == 0) // long argument
{
const std::string argument(itArg->substr(2));
if (argument.size() == 1)
{
throw std::invalid_argument(
"ERROR: unknown single character option, did you mean -" +
argument + " ?\n");
}
SetParameters(argument, true);
}
else if (itArg->find("-") == 0) // short argument
{
const std::string argument(itArg->substr(1));
SetParameters(argument, false);
if (argument == "s" || argument == "c")
{
++itArg;
// SetParameters(*itArg);
}
}
else
{
if (isFileSet)
{
throw std::invalid_argument(
"ERROR: only 1 bpfile is allowed\n" + m_HelpMessage);
}
m_FileName = *itArg;
isFileSet = true;
}
}
}
void BPLS2::ProcessParameters() const
{
if (m_Parameters.count("help") == 1)
{
PrintUsage();
if (m_Parameters.size() > 1)
{
std::cout << "\n";
std::cout << "Found --help , -h option, discarding others\n";
std::cout << "Rerun without --help , -h option\n";
}
return;
}
if (m_FileName.empty())
{
throw std::invalid_argument("ERROR: file not passed to bpls2\n" +
m_HelpMessage);
}
}
void BPLS2::PrintUsage() const noexcept
{
std::cout << "This is ADIOS2 binary pack listing (bpls2) utility. Usage:\n";
std::cout << "\t bpls2 [OPTIONS] bpfile [MASK1 MASK2 ...]\n";
std::cout << "\n";
std::cout << "[OPTIONS]:\n";
std::cout << "\n";
std::cout << "-l , --long Print variables and attributes metadata\n";
std::cout << " information, no overhead\n";
std::cout << "-a , --attributes List attributes metadata\n";
std::cout << "Example: bpls2 -lav bpfile\n";
}
void BPLS2::PrintExamples() const noexcept {}
void BPLS2::SetParameters(const std::string argument, const bool isLong)
{
if (argument == "-" || argument.empty())
{
throw std::invalid_argument("ERROR: invalid argument: -" + argument +
"\n");
}
bool isOption = false;
if (m_Options.count(argument) == 1 && isLong)
{
isOption = true;
m_Parameters[argument] = "";
}
else if (!isLong)
{
for (const auto &optionPair : m_Options)
{
if (argument == optionPair.second)
{
isOption = true;
m_Parameters[optionPair.first] = "";
break;
}
}
}
if (isOption)
{
return;
}
// look for multiple options by character
for (const char argChar : argument)
{
const std::string argCharString(1, argChar);
isOption = false;
for (const auto &optionPair : m_Options)
{
if (argCharString == optionPair.second)
{
m_Parameters[optionPair.first] = "";
isOption = true;
}
}
if (!isOption)
{
throw std::invalid_argument("ERROR: unknown option " +
argCharString + " in argument " +
argument + "\n");
}
}
}
} // end namespace utils
} // end namespace adios2
...@@ -8,15 +8,39 @@ ...@@ -8,15 +8,39 @@
* Author: William F Godoy godoywf@ornl.gov * Author: William F Godoy godoywf@ornl.gov
*/ */
#ifndef ADIOS2_UTILS_BPLS2_BPLS2_H_ #ifndef UTILS_BPLS2_BPLS2_H_
#define ADIOS2_UTILS_BPLS2_BPLS2_H_ #define UTILS_BPLS2_BPLS2_H_
#include "utils/Utils.h"
namespace adios2 namespace adios2
{ {
namespace utils namespace utils
{ {
class BPLS2 : public Utils
{
public:
BPLS2(int argc, char *argv[]);
~BPLS2() = default;
void Run() final;
private:
static const std::string m_HelpMessage;
static const std::map<std::string, std::string> m_Options;
std::string m_FileName;
void ParseArguments() final;
void ProcessParameters() const final;
void PrintUsage() const noexcept final;
void PrintExamples() const noexcept final;
void SetParameters(const std::string argument, const bool isLong) final;
};
} // end namespace utils } // end namespace utils
} // end namespace adios2 } // end namespace adios2
#endif /* ADIOS2_UTILS_BPLS2_BPLS2_H_ */ #endif /* UTILS_BPLS2_BPLS2_H_ */
...@@ -8,6 +8,21 @@ ...@@ -8,6 +8,21 @@
* Author: William F Godoy godoywf@ornl.gov * Author: William F Godoy godoywf@ornl.gov
*/ */
#include "adios2/utils/bpls2/BPLS2.h" #include <iostream>
#include <stdexcept>
int main(int argc, char *argv[]) { return 0; } #include "utils/bpls2/BPLS2.h"
int main(int argc, char *argv[])
{
try
{
adios2::utils::BPLS2 bpls2(argc, argv);
bpls2.Run();
}
catch (std::exception &e)
{
std::cout << "bpls2 Caught an Exception\n";
std::cout << e.what() << "\n";
}
}
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