Newer
Older
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* adios2_f2c_variable.cpp
*
* Created on: Nov 12, 2017
* Author: William F Godoy godoywf@ornl.gov
*/
#include "adios2_f2c_variable.h"
#include <cstddef>
#include <stdexcept>
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
void FC_GLOBAL(adios2_variable_name_f2c,
ADIOS2_VARIABLE_NAME_F2C)(const adios2_Variable **variable,
char name[1024], int *length,
int *ierr)
{
*ierr = 0;
try
{
size_t lengthC = 0;
const char *nameC = adios2_variable_name(*variable, &lengthC);
if (nameC == nullptr)
{
throw std::runtime_error("ERROR: null pointer\n");
}
for (size_t i = 0; i < lengthC; ++i)
{
name[i] = nameC[i];
}
*length = static_cast<int>(lengthC);
}
catch (std::exception &e)
{
*ierr = 1;
}
}
void FC_GLOBAL(adios2_variable_type_f2c,
ADIOS2_VARIABLE_TYPE_F2C)(const adios2_Variable **variable,
int *type, int *ierr)
{
*ierr = 0;
try
{
*type = static_cast<int>(adios2_variable_type(*variable));
}
catch (std::exception &e)
{
*ierr = 1;
}
}
void FC_GLOBAL(adios2_set_selection_f2c,
ADIOS2_SET_SELECTION_F2C)(adios2_Variable **variable,
const int *ndims, const int *start,
const int *count, int *ierr)
{
auto lf_IntToSizeT = [](const int *dimensions, const int size,
std::vector<std::size_t> &output,
const bool offset) {
if (dimensions == nullptr)
{
return;
}
output.resize(size);
if (offset)
{
for (unsigned int d = 0; d < size; ++d)
{
output[d] = dimensions[d] - 1;
}
}
else
{
for (unsigned int d = 0; d < size; ++d)
{
output[d] = dimensions[d];
}
}
};
*ierr = 0;
if (start == nullptr || count == nullptr)
{
*ierr = 1;
return;
}
std::vector<std::size_t> startV, countV;
lf_IntToSizeT(start, *ndims, startV, true);
lf_IntToSizeT(count, *ndims, countV, false);