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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* ExampleReadPlugin.tcc
*
* Created on: Jul 5, 2021
* Author: Caitlin Ross <caitlin.ross@kitware.com>
*/
#ifndef EXAMPLEREADPLUGIN_TCC_
#define EXAMPLEREADPLUGIN_TCC_
#include "ExampleReadPlugin.h"
namespace adios2
{
namespace plugin
{
template <typename T>
void ExampleReadPlugin::AddVariable(const std::string &name, Dims shape, Dims start, Dims count)
{
core::Variable<T> *v = m_IO.InquireVariable<T>(name);
if (!v)
{
m_IO.DefineVariable<T>(name, shape, start, count);
}
}
template <class T>
inline void ExampleReadPlugin::ReadVariable(core::Variable<T> &variable, T *values)
{
while (m_DataFile.good())
{
std::string line;
std::getline(m_DataFile, line);
auto delimPos = line.find(",");
auto name = line.substr(0, delimPos);
size_t step = std::stoul(line.substr(delimPos + 1));
if (name == variable.m_Name && m_CurrentStep == step)
{
std::string vals;
std::getline(m_DataFile, vals);
if (vals.find(",") == vals.npos)
{
values[0] = helper::StringTo<T>(vals, "");
}
else
{
std::istringstream ss(vals);
std::string val;
int i = 0;
while (std::getline(ss, val, ','))
{
values[i] = helper::StringTo<T>(val, "");
i++;
}
}
break;
}
}
}
template <>
inline void ExampleReadPlugin::ReadVariable(core::Variable<std::string> &variable,
std::string *values)
{
while (m_DataFile.good())
{
std::string line;
std::getline(m_DataFile, line);
if (line == variable.m_Name)
{
std::getline(m_DataFile, values[0]);
break;
}
}
}
template <>
inline void ExampleReadPlugin::ReadVariable(core::Variable<char> &variable, char *values)
{
while (m_DataFile.good())
{
std::string line;
std::getline(m_DataFile, line);
if (line == variable.m_Name)
{
for (size_t i = 0; i < variable.SelectionSize(); ++i)
{
m_DataFile.get(&values[i], 1, ',');
}
break;
}
}
}
template <>
inline void ExampleReadPlugin::ReadVariable(core::Variable<unsigned char> &variable,
unsigned char *values)
{
while (m_DataFile.good())
{
std::string line;
std::getline(m_DataFile, line);
if (line == variable.m_Name)
{
for (size_t i = 0; i < variable.SelectionSize(); ++i)
{
char val;
m_DataFile.get(&val, 1, ',');
values[i] = static_cast<unsigned char>(val);
}
break;
}
}
}
template <>
inline void ExampleReadPlugin::ReadVariable(core::Variable<signed char> &variable,
signed char *values)
{
while (m_DataFile.good())
{
std::string line;
std::getline(m_DataFile, line);
if (line == variable.m_Name)
{
for (size_t i = 0; i < variable.SelectionSize(); ++i)
{
char val;
m_DataFile.get(&val, 1, ',');
values[i] = static_cast<signed char>(val);
}
break;
}
}
}
template <>
inline void ExampleReadPlugin::ReadVariable(core::Variable<short> &variable, short *values)
{
while (m_DataFile.good())
{
std::string line;
std::getline(m_DataFile, line);
if (line == variable.m_Name)
{
for (size_t i = 0; i < variable.SelectionSize(); ++i)
{
std::string val;
std::getline(m_DataFile, val, ',');
values[i] = static_cast<short>(std::stoi(val));
}
break;
}
}
}
template <>
inline void ExampleReadPlugin::ReadVariable(core::Variable<unsigned short> &variable,
unsigned short *values)
{
while (m_DataFile.good())
{
std::string line;
std::getline(m_DataFile, line);
if (line == variable.m_Name)
{
for (size_t i = 0; i < variable.SelectionSize(); ++i)
{
std::string val;
std::getline(m_DataFile, val, ',');
values[i] = static_cast<unsigned short>(std::stoi(val));
}
break;
}
}
}
template <>
inline void ExampleReadPlugin::ReadVariable(core::Variable<long double> &variable,
long double *values)
{
while (m_DataFile.good())
{
std::string line;
std::getline(m_DataFile, line);
if (line == variable.m_Name)
{
for (size_t i = 0; i < variable.SelectionSize(); ++i)
{
std::string val;
std::getline(m_DataFile, val, ',');
try
{
values[i] = std::strtold(val.c_str(), nullptr);
}
catch (...)
{
std::throw_with_nested(
std::invalid_argument("ERROR: could not cast " + val + " to long double "));
}
}
break;
}
}
}
template <>
inline void ExampleReadPlugin::ReadVariable(core::Variable<std::complex<float>> &variable,
std::complex<float> *values)
{
throw std::invalid_argument("ERROR: std::complex<float> not supported in this engine");
}
template <>
inline void ExampleReadPlugin::ReadVariable(core::Variable<std::complex<double>> &variable,
std::complex<double> *values)
{
throw std::invalid_argument("ERROR: std::complex<double> not supported in this engine");
}
} // end namespace plugin
} // end namespace adios2
#endif /* EXAMPLEREADPLUGIN_TCC_ */
|