<commit_before>/*
 * Distributed under the OSI-approved Apache License, Version 2.0.  See
 * accompanying file Copyright.txt for details.
 *
 * adios2_f2c_io.cpp
 *
 *  Created on: Nov 8, 2017
 *      Author: <NAME> <EMAIL>
 */

#include "adios2_f2c_io.h"

#include <cstddef>  //std::size_t
#include <iostream> //std::cerr
#include <stdexcept>
#include <vector>

void FC_GLOBAL(adios2_set_parameter_f2c,
               ADIOS2_SET_PARAMETER_F2C)(adios2_IO **io, const char *key,
                                         const char *value, int *ierr)
{
    *ierr = 0;

    try
    {
        adios2_set_parameter(*io, key, value);
    }
    catch (std::exception &e)
    {
        std::cerr << "ADIOS2 set_parameter: " << e.what() << "\n";
        *ierr = -1;
    }
}

void FC_GLOBAL(adios2_add_transport_f2c,
               ADIOS2_ADD_TRANSPORT_F2C)(int *transport_index, adios2_IO **io,
                                         const char *transport_type, int *ierr)
{
    *ierr = 0;
    *transport_index = -1;

    try
    {
        *transport_index =
            static_cast<int>(adios2_add_transport(*io, transport_type));

        if (*transport_index == -1)
        {
            throw std::invalid_argument("ERROR: transport_index handler not "
                                        "set, in call to "
                                        "adios2_add_transport\n");
        }
    }
    catch (std::exception &e)
    {
        std::cerr << "ADIOS2 add_transport: " << e.what() << "\n";
        *ierr = -1;
    }
}

void FC_GLOBAL(adios2_set_transport_parameter_f2c,
               ADIOS2_SET_TRANSPORT_PARAMETER_F2C)(adios2_IO **io,
                                                   const int *transport_index,
                                                   const char *key,
                                                   const char *value, int *ierr)
{
    *ierr = 0;

    try
    {
        adios2_set_transport_parameter(
            *io, static_cast<unsigned int>(*transport_index), key, value);
    }
    catch (std::exception &e)
    {
        std::cerr << "ADIOS2 set_transport_parameter: " << e.what() << "\n";
        *ierr = -1;
    }
}

void FC_GLOBAL(adios2_define_global_variable_f2c,
               ADIOS2_DEFINE_GLOBAL_VARIABLE_F2C)(adios2_Variable **variable,
                                                  adios2_IO **io,
                                                  const char *name,
                                                  const int *type, void *data,
                                                  int *ierr)
{
    *ierr = 0;
    try
    {
        *variable = adios2_define_variable(
            *io, name, static_cast<adios2_type>(*type), 0, nullptr, nullptr,
            nullptr, adios2_constant_dims_false, data);
    }
    catch (std::exception &e)
    {
        std::cerr << "ADIOS2 define_variable " << name << ": " << e.what()
                  << "\n";
        *ierr = -1;
    }
}

void FC_GLOBAL(adios2_define_variable_f2c, ADIOS2_DEFINE_VARIABLE_F2C)(<commit_msg>Fortran API fix: Values have by nature constant dimensions<commit_after>/*
 * Distributed under the OSI-approved Apache License, Version 2.0.  See
 * accompanying file Copyright.txt for details.
 *
 * adios2_f2c_io.cpp
 *
 *  Created on: Nov 8, 2017
 *      Author: <NAME> <EMAIL>
 */

#include "adios2_f2c_io.h"

#include <cstddef>  //std::size_t
#include <iostream> //std::cerr
#include <stdexcept>
#include <vector>

void FC_GLOBAL(adios2_set_parameter_f2c,
               ADIOS2_SET_PARAMETER_F2C)(adios2_IO **io, const char *key,
                                         const char *value, int *ierr)
{
    *ierr = 0;

    try
    {
        adios2_set_parameter(*io, key, value);
    }
    catch (std::exception &e)
    {
        std::cerr << "ADIOS2 set_parameter: " << e.what() << "\n";
        *ierr = -1;
    }
}

void FC_GLOBAL(adios2_add_transport_f2c,
               ADIOS2_ADD_TRANSPORT_F2C)(int *transport_index, adios2_IO **io,
                                         const char *transport_type, int *ierr)
{
    *ierr = 0;
    *transport_index = -1;

    try
    {
        *transport_index =
            static_cast<int>(adios2_add_transport(*io, transport_type));

        if (*transport_index == -1)
        {
            throw std::invalid_argument("ERROR: transport_index handler not "
                                        "set, in call to "
                                        "adios2_add_transport\n");
        }
    }
    catch (std::exception &e)
    {
        std::cerr << "ADIOS2 add_transport: " << e.what() << "\n";
        *ierr = -1;
    }
}

void FC_GLOBAL(adios2_set_transport_parameter_f2c,
               ADIOS2_SET_TRANSPORT_PARAMETER_F2C)(adios2_IO **io,
                                                   const int *transport_index,
                                                   const char *key,
                                                   const char *value, int *ierr)
{
    *ierr = 0;

    try
    {
        adios2_set_transport_parameter(
            *io, static_cast<unsigned int>(*transport_index), key, value);
    }
    catch (std::exception &e)
    {
        std::cerr << "ADIOS2 set_transport_parameter: " << e.what() << "\n";
        *ierr = -1;
    }
}

void FC_GLOBAL(adios2_define_global_variable_f2c,
               ADIOS2_DEFINE_GLOBAL_VARIABLE_F2C)(adios2_Variable **variable,
                                                  adios2_IO **io,
                                                  const char *name,
                                                  const int *type, void *data,
                                                  int *ierr)
{
    *ierr = 0;
    try
    {
        *variable = adios2_define_variable(
            *io, name, static_cast<adios2_type>(*type), 0, nullptr, nullptr,
            nullptr, adios2_constant_dims_true, data);
    }
    catch (std::exception &e)
    {
        std::cerr << "ADIOS2 define_variable " << name << ": " << e.what()
                  << "\n";
        *ierr = -1;
    }
}

void FC_GLOBAL(adios2_define_variable_f2c, ADIOS2_DEFINE_VARIABLE_F2C)(
{'fraction_non_alphanumeric': 0.11120209629872257, 'fraction_numerical': 0.01899770717327219, 'mean_word_length': 1.5456440183409754, 'pattern_counts': {'":': 2, '<': 77, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4905741', 'n_tokens_mistral': 1929, 'n_tokens_neox': 1910, 'n_words': 375}