File: inlineMixedLang.cpp

package info (click to toggle)
adios2 2.10.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 33,764 kB
  • sloc: cpp: 175,964; ansic: 160,510; f90: 14,630; yacc: 12,668; python: 7,275; perl: 7,126; sh: 2,825; lisp: 1,106; xml: 1,049; makefile: 579; lex: 557
file content (61 lines) | stat: -rw-r--r-- 1,567 bytes parent folder | download | duplicates (2)
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
/*
 * Distributed under the OSI-approved Apache License, Version 2.0.  See
 * accompanying file Copyright.txt for details.
 *
 * inlineMixedLang.cpp example borrowed from bpFWriteCRead example, but using
 * the inline engine. inlineMixedLang.f90 creates data and uses inline writer
 * for making that data available in C++ functions that reads the data.
 *
 *  Created on: Oct 20, 2021
 *      Author: Caitlin Ross caitlin.ross@kitware.com
 */

#include <iostream>

#include "InlineExampleFC.h"
#include <adios2.h>

adios2::IO *adiosIO;
adios2::Engine reader;

extern "C" {

void FC_GLOBAL(open_reader, OPEN_READER)(adios2::IO *io)
{
    adiosIO = io;
    reader = adiosIO->Open("reader", adios2::Mode::Read);
}

void FC_GLOBAL(analyze_data, ANALYZE_DATA)()
{
    // begin step on the reader
    reader.BeginStep();

    // grab the desired variable
    auto u = adiosIO->InquireVariable<float>("data2D");
    if (!u)
    {
        std::cerr << "variable data2D not found!" << std::endl;
        return;
    }
    auto shape = u.Shape();

    // get the data pointer and do some stuff with it
    float *data = nullptr;
    reader.Get(u, &data);
    std::cout << "c++ output: " << std::endl;
    for (size_t i = 0; i < shape[1]; i++)
    {
        for (size_t j = 0; j < shape[0]; j++)
        {
            std::cout << data[shape[0] * i + j] << "\t";
        }
        std::cout << std::endl;
    }

    // end step for the reader, signaling that we're done using the data
    reader.EndStep();
}

void FC_GLOBAL(close_reader, CLOSE_READER)() { reader.Close(); }
}