1#
2# Distributed under the OSI-approved Apache License, Version 2.0.  See
3# accompanying file Copyright.txt for details.
4#
5# Test writer to produce a test dataset for Matlab reading
6# This is serial since the Matlab reader is built with serial ADIOS
7#
8#
9#  Created on: Jan 28, 2019
10#      Author: Norbert Podhorszki, pnorbert@ornl.gov
11#
12
13import numpy
14import adios2
15
16# User data
17NRows = 5
18NCols = 6
19
20shape = [NRows, NCols]
21start = [0, 0]
22count = [NRows, NCols]
23
24temperatures = numpy.zeros(NRows * NCols, dtype=numpy.int16)
25npcols = numpy.array([NCols])
26nprows = numpy.array([NRows])
27
28value = (NRows * NCols) + 1
29for i in range(0, NRows):
30    for j in range(0, NCols):
31        temperatures[i * NCols + j] = value
32        value = value + 1
33
34# ADIOS2 low-level API for Write
35adios = adios2.ADIOS()
36io = adios.DeclareIO("writer")
37
38varStr = io.DefineVariable("note")
39varCols = io.DefineVariable("ncols", npcols)
40varRows = io.DefineVariable("nrows", nprows)
41varT = io.DefineVariable(
42    "temperature2D", temperatures, shape, start, count, adios2.ConstantDims)
43
44io.DefineAttribute("aaa", numpy.array([3.1415]))
45io.DefineAttribute("anote", "just a string")
46io.DefineAttribute("adimnames", ["rows", "columns"])
47npdims = numpy.array([NRows, NCols], dtype=numpy.int32)
48io.DefineAttribute("adims", npdims)
49
50
51fw = io.Open("test1.bp", adios2.Mode.Write)
52fw.Put(varStr, "This is an ADIOS2 output")
53fw.Put(varCols, npcols)
54fw.Put(varRows, nprows)
55fw.Put(varT, temperatures)
56fw.Close()
57