Unverified Commit 340ed86d authored by William F Godoy's avatar William F Godoy Committed by GitHub
Browse files

Merge pull request #1041 from williamfgc/set_shape

Reinstate set shape function
parents d93dd5c1 3c2a5141
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -79,6 +79,31 @@ adios2_shapeid adios2_ToShapeID(const adios2::ShapeID shapeIDCpp,
extern "C" {
#endif

adios2_error adios2_set_shape(adios2_variable *variable, const size_t ndims,
                              const size_t *shape)
{
    try
    {
        adios2::helper::CheckForNullptr(variable,
                                        "for adios2_variable, in call to "
                                        "adios2_set_shape");
        adios2::helper::CheckForNullptr(shape, "for start, in call to "
                                               "adios2_set_shape");

        adios2::core::VariableBase *variableBase =
            reinterpret_cast<adios2::core::VariableBase *>(variable);

        const adios2::Dims shapeV(shape, shape + ndims);
        variableBase->SetShape(shapeV);
        return adios2_error_none;
    }
    catch (...)
    {
        return static_cast<adios2_error>(
            adios2::helper::ExceptionToError("adios2_set_shape"));
    }
}

adios2_error adios2_set_selection(adios2_variable *variable, const size_t ndims,
                                  const size_t *start, const size_t *count)
{
+11 −0
Original line number Diff line number Diff line
@@ -19,6 +19,17 @@
extern "C" {
#endif

/**
 * Set new shape, care must be taken when reading back the variable for
 * different steps. Only applies to Global arrays.
 * @param variable handler for which new selection will be applied to
 * @param ndims number of dimensions for start and count
 * @param shape new shape dimensions array
 * @return adios2_error 0: success, see enum adios2_error for errors
 */
adios2_error adios2_set_shape(adios2_variable *variable, const size_t ndims,
                              const size_t *shape);

/**
 * Set new start and count dimensions
 * @param variable handler for which new selection will be applied to
+8 −0
Original line number Diff line number Diff line
@@ -30,6 +30,14 @@ namespace adios2
    }                                                                          \
                                                                               \
    template <>                                                                \
    void Variable<T>::SetShape(const Dims &shape)                              \
    {                                                                          \
        helper::CheckForNullptr(m_Variable,                                    \
                                "in call to Variable<T>::SetShape");           \
        m_Variable->SetShape(shape);                                           \
    }                                                                          \
                                                                               \
    template <>                                                                \
    void Variable<T>::SetSelection(const Box<Dims> &selection)                 \
    {                                                                          \
        helper::CheckForNullptr(m_Variable,                                    \
+7 −0
Original line number Diff line number Diff line
@@ -52,6 +52,13 @@ public:
    /** Checks if object is valid, e.g. if( variable ) { //..valid } */
    explicit operator bool() const noexcept;

    /**
     * Set new shape, care must be taken when reading back the variable for
     * different steps. Only applies to Global arrays.
     * @param shape new shape dimensions array
     */
    void SetShape(const adios2::Dims &shape);

    /**
     * Sets a variable selection modifying current {start, count}
     * Count is the dimension from Start point
+37 −0
Original line number Diff line number Diff line
@@ -97,6 +97,43 @@ void FC_GLOBAL(adios2_variable_steps_f2c,
    }
}

void FC_GLOBAL(adios2_set_shape_f2c,
               ADIOS2_SET_SHAPE_F2C)(adios2_variable **variable,
                                     const int *ndims, const int64_t *shape,
                                     int *ierr)
{
    auto lf_IntToSizeT = [](const int64_t *dimensions, const int size,
                            std::vector<std::size_t> &output) {

        output.resize(size);

        for (auto d = 0; d < size; ++d)
        {
            output[d] = dimensions[d];
        }

    };

    try
    {
        if (shape == nullptr || ndims == nullptr)
        {
            throw std::invalid_argument(
                "ERROR: either shape_dims, or ndims is a null pointer, in call "
                "to adios2_set_shape\n");
        }
        std::vector<std::size_t> shapeV;
        lf_IntToSizeT(shape, *ndims, shapeV);
        *ierr = static_cast<int>(
            adios2_set_shape(*variable, *ndims, shapeV.data()));
    }
    catch (...)
    {
        *ierr = static_cast<int>(
            adios2::helper::ExceptionToError("adios2_set_shape"));
    }
}

void FC_GLOBAL(adios2_set_selection_f2c,
               ADIOS2_SET_SELECTION_F2C)(adios2_variable **variable,
                                         const int *ndims, const int64_t *start,
Loading