예제 #1
0
    def setUp(self):
        self.temp = TempFile()

        ad.init_noxml()

        ad.allocate_buffer(ad.BUFFER_ALLOC_WHEN.NOW, 10)
        g = ad.declare_group("temperature", "", ad.FLAG.YES)
        ad.define_var(g, "NX", "", ad.DATATYPE.integer, "", "", "")
        ad.define_var(g, "size", "", ad.DATATYPE.integer, "", "", "")
        ad.define_var(g, "temperature", "", ad.DATATYPE.double, "size,NX",
                      "size,NX", "0,0")
        self.msg = "this is a test"
        self.unit = "C"
        ## attr must be <varpath> + / + something without / (line 857, common_read.c)
        ad.define_attribute(g, "temperature/desc", "", ad.DATATYPE.string,
                            self.msg, "")
        ad.define_attribute(g, "temperature/unit", "", ad.DATATYPE.string,
                            self.unit, "")
        ad.select_method(g, "POSIX1", "verbose=3", "")

        fd = ad.open("temperature", self.temp.path, "w")
        self.NX = 10
        self.size = 2
        groupsize = 4 + 4 + 8 * self.size * self.NX
        t = np.array(range(self.NX * self.size), dtype=np.float64)
        self.tt = t.reshape((self.size, self.NX))
        ad.set_group_size(fd, groupsize)
        ad.write_int(fd, "NX", self.NX)
        ad.write_int(fd, "size", self.size)
        ad.write(fd, "temperature", self.tt)
        ad.close(fd)

        ad.finalize()

        self.f = ad.file(self.temp.path)
    def setUp(self):
        self.temp = TempFile()

        ad.init_noxml()

        ad.allocate_buffer(ad.BUFFER_ALLOC_WHEN.NOW, 10)
        g = ad.declare_group("temperature", "", ad.FLAG.YES)
        ad.define_var(g, "NX", "", ad.DATATYPE.integer, "", "", "")
        ad.define_var(g, "size", "", ad.DATATYPE.integer, "", "", "")
        ad.define_var(g, "temperature", "", ad.DATATYPE.double, "size,NX",
                      "size,NX", "0,0")
        self.msg = "this is a test"
        ad.define_attribute(g, "desc", "", ad.DATATYPE.string, self.msg, "")
        ad.select_method(g, "POSIX1", "verbose=3", "")

        for i in range(5):
            mode = "a"
            if i == 0: mode = "w"
            fd = ad.open("temperature", self.temp.path, mode)
            self.NX = 10
            self.size = 2
            groupsize = 4 + 4 + 8 * self.size * self.NX
            t = np.array(range(self.NX * self.size),
                         dtype=np.float64) + 100 * i
            self.tt = t.reshape((self.size, self.NX))
            ad.set_group_size(fd, groupsize)
            ad.write_int(fd, "NX", self.NX)
            ad.write_int(fd, "size", self.size)
            ad.write(fd, "temperature", self.tt)
            ad.close(fd)

        ad.finalize()

        self.f = ad.file(self.temp.path)
예제 #3
0
    def setUp(self):
        self.temp = TempFile()

        ad.init_noxml()

        ad.allocate_buffer (ad.BUFFER_ALLOC_WHEN.NOW, 10);
        g = ad.declare_group("temperature", "", ad.FLAG.YES)
        ad.define_var(g, "NX", "", ad.DATATYPE.integer, "", "", "")
        ad.define_var(g, "size", "", ad.DATATYPE.integer, "", "", "")
        ad.define_var(g, "temperature", "", ad.DATATYPE.double, "size,NX", "size,NX", "0,0")
        ad.define_var(g, "temperature", "", ad.DATATYPE.double, "size,NX", "size,NX", "0,0")
        self.msg = "this is a test"
        ad.define_attribute(g, "desc", "", ad.DATATYPE.string, self.msg, "")
        ad.define_attribute(g, "temperature/unit", "", ad.DATATYPE.string, "C", "")
        ad.define_attribute(g, "temperature/desc", "", ad.DATATYPE.string, "description", "")
        ad.define_attribute(g, "/subgroup/subsubgroup/otherattr", "", ad.DATATYPE.string, "another", "")
        ad.define_var(g, "/subgroup/subsubgroup/othervar", "", ad.DATATYPE.integer, "", "", "")
        ad.select_method(g, "POSIX1", "verbose=3", "")

        fd = ad.open("temperature", self.temp.path, "w")
        self.NX = 10
        self.size = 2
        groupsize =  4 + 4 + 8 * self.size * self.NX + 4
        t = np.array(range(self.NX * self.size), dtype=np.float64)
        self.tt = t.reshape((self.size, self.NX))
        ad.set_group_size(fd, groupsize)
        ad.write_int(fd, "NX", self.NX)
        ad.write_int(fd, "size", self.size)
        ad.write(fd, "temperature", self.tt)
        ad.write_int(fd, "/subgroup/subsubgroup/othervar", 99)
        ad.close(fd)

        ad.finalize()

        self.f = ad.file(self.temp.path)
예제 #4
0
    def setUp(self):
        self.temp = TempFile()

        ad.init_noxml()

        ad.allocate_buffer (ad.BUFFER_ALLOC_WHEN.NOW, 10);
        g = ad.declare_group("temperature", "", ad.FLAG.YES)
        ad.define_var(g, "NX", "", ad.DATATYPE.integer, "", "", "")
        ad.define_var(g, "size", "", ad.DATATYPE.integer, "", "", "")
        ad.define_var(g, "temperature", "", ad.DATATYPE.double, "size,NX", "size,NX", "0,0")
        self.msg = "this is a test"
        self.unit = "C"
        ## attr must be <varpath> + / + something without / (line 857, common_read.c)
        ad.define_attribute(g, "temperature/desc", "", ad.DATATYPE.string, self.msg, "")
        ad.define_attribute(g, "temperature/unit", "", ad.DATATYPE.string, self.unit, "")
        ad.select_method(g, "POSIX1", "verbose=3", "")

        fd = ad.open("temperature", self.temp.path, "w")
        self.NX = 10
        self.size = 2
        groupsize =  4 + 4 + 8 * self.size * self.NX
        t = np.array(range(self.NX * self.size), dtype=np.float64)
        self.tt = t.reshape((self.size, self.NX))
        ad.set_group_size(fd, groupsize)
        ad.write_int(fd, "NX", self.NX)
        ad.write_int(fd, "size", self.size)
        ad.write(fd, "temperature", self.tt)
        ad.close(fd)

        ad.finalize()

        self.f = ad.file(self.temp.path)
예제 #5
0
    def write(self, msg):

        doid = msg['doid']
        column = msg['column']
        rows = msg['rows']
        shape = msg['shape']
        rowid = msg['row']
        datatype = msg['datatype']
        data = msg['data']
        filename = self.filepath + '/' + doid

        dimension = [rows] + copy.copy(shape)
        global_dimension = copy.copy(dimension)
        global_dimension[0] = self.maxrows
        offset = [0] * len(dimension)
        offset[0] = rowid

        ad.init_noxml()
        ad.allocate_buffer(ad.BUFFER_ALLOC_WHEN.NOW, self.buffersize)
        adios_group = ad.declare_group("shore", "", ad.FLAG.YES)
        local_dimension = str(dimension)[1:-1]
        global_dimension = str(global_dimension)[1:-1]
        offset = str(offset)[1:-1]

        ad.select_method(adios_group, "POSIX", "", "")
        ad.define_var(adios_group, column, "",
                      self.dtype_numpy2adios[datatype], local_dimension,
                      global_dimension, offset)
        adios_file = ad.open("shore", filename, 'u')
        group_size = 1000000
        if data.nbytes > group_size:
            group_size = data.nbytes
        ad.set_group_size(adios_file, group_size)
        ad.write(adios_file, column, data, datatype)
        ad.close(adios_file)
        ad.finalize()

        return True
예제 #6
0
    def write_scalar(self, adtype, val, varname='val'):
        ad.init_noxml()
        ad.allocate_buffer(ad.BUFFER_ALLOC_WHEN.NOW, 10)
        g = ad.declare_group("group", "", ad.FLAG.YES)
        ad.define_var(g, varname, "", adtype, "", "", "")
        ad.select_method(g, "POSIX1", "", "")

        if adtype == ad.DATATYPE.string:
            dtype = ad.adios2npdtype(adtype, len(str(val)))
            npval = np.array(val, dtype=dtype)
        else:
            dtype = ad.adios2npdtype(adtype)
            npval = np.array(val, dtype=dtype)

        fd = ad.open("group", self.temp.path, "w")
        ad.set_group_size(fd, npval.nbytes)
        ad.write(fd, varname, val, dtype)
        ad.close(fd)
        ad.finalize()

        f = ad.file(self.temp.path)
        v = f.vars['val']
        self.assertEqual(v.read(), npval)
예제 #7
0
    def write_scalar(self, adtype, val, varname='val'):
        ad.init_noxml()
        ad.allocate_buffer (ad.BUFFER_ALLOC_WHEN.NOW, 10);
        g = ad.declare_group("group", "", ad.FLAG.YES)
        ad.define_var(g, varname, "", adtype, "", "", "")
        ad.select_method(g, "POSIX1", "", "")

        if adtype == ad.DATATYPE.string:
            dtype = ad.adios2npdtype(adtype, len(str(val)))
            npval = np.array(val, dtype=dtype)
        else:
            dtype = ad.adios2npdtype(adtype)
            npval = np.array(val, dtype=dtype)

        fd = ad.open("group", self.temp.path, "w")
        ad.set_group_size(fd, npval.nbytes)
        ad.write(fd, varname, val, dtype)
        ad.close(fd)
        ad.finalize()

        f = ad.file(self.temp.path)
        v = f.vars['val']
        self.assertEqual(v.read(), npval)
예제 #8
0
import adios as ad
import numpy as np

## Writing
print "\n>>> Writing ...\n"

ad.init("config.xml")
fd = ad.open("temperature", "adios_test.bp", "w")

NX = 10
size = 2
groupsize =  4 + 4 + 8 * size * NX
t = np.array(range(NX*size), dtype=np.float64)
tt = t.reshape((size, NX))
ad.set_group_size(fd, groupsize)
ad.write_int(fd, "NX", NX)
ad.write_int(fd, "size", size)
ad.write(fd, "temperature", tt)
ad.close(fd)

ad.finalize()

## Reading
print "\n>>> Reading ...\n"

f = ad.file("adios_test.bp")
f.printself()

v = f.var['temperature']
v.printself()
예제 #9
0
#!/usr/bin/env python
import adios
import numpy as np

adios.init("config.xml")
fd = adios.open("temperature", "adios_test.bp", "w")

NX = 10
size = 1
rank = 0
groupsize =  4 + 4 + 4 + 8 * 1 * NX
t = np.array(range(NX), dtype=np.float64)
adios.set_group_size(fd, groupsize)
adios.write_int(fd, "NX", NX)
adios.write_int(fd, "size", size)
adios.write_int(fd, "rank", rank)
adios.write(fd, "temperature", t)
adios.close(fd)

adios.finalize()