Ejemplo n.º 1
0
def fmt_mdif_block(dims, db):
    dimnames = [x.name for x in dims]
    fmts = [x.outputformat for x in dims]
    for coord in itertools.product(*[x.data for x in dims[1:]]):
        for iname, fmt, value in zip(dimnames[1:], fmts[1:], coord):
            #            import pdb;pdb.set_trace()
            yield [("VAR SWEEP.%s(real) = " + fmt) % (iname, value)]
        blockname = db.blockname
        if blockname is None:
            blockname = "DATABLOCK"
        yield ["BEGIN %s" % blockname]

        attribnames, attribdata = zip(*[(k, v) for (k, v) in db.vardata.items() if v.dims == dims[1:]])
        attribheader = format_complex_header(attribnames, attribdata, "%s(real)", "%s(complex)", None, unit_fmt=False)
        for name, data in zip(attribheader, attribdata):
            yield [("# %s = %s" % (name, data.outputformat)) % data[coord]]

        header, columns = zip(*[(k, v) for (k, v) in db.vardata.items() if v.dims == dims])
        header = (dims[0].name,) + header

        idx = (Ellipsis,) + coord
        columns = [col[idx] for col in columns]
        columns = [hfarray(dims[0])] + columns
        outheader = format_complex_header(header, columns, "%s(real)", "%s(complex)", None, unit_fmt=False)

        yield ["% " + " ".join(outheader)]
        fmts = [x.outputformat for x in columns]
        #        import pdb;pdb.set_trace()
        for row in zip(*columns):
            out = []
            for elem, fmt in zip(row, fmts):
                out.extend(format_elem(fmt, elem))
            yield out
        yield ["END"]
Ejemplo n.º 2
0
def fmt_mdif_block(dims, db):
    dimnames = [x.name for x in dims]
    fmts = [x.outputformat for x in dims]
    for coord in itertools.product(*[x.data for x in dims[1:]]):
        for iname, fmt, value in zip(dimnames[1:], fmts[1:], coord):
            #            import pdb;pdb.set_trace()
            yield [("VAR SWEEP.%s(real) = " + fmt) % (iname, value)]
        blockname = db.blockname
        if blockname is None:
            blockname = "DATABLOCK"
        yield ["BEGIN %s" % blockname]

        attribnames, attribdata = zip(*[(k, v)
                                        for (k, v) in db.vardata.items()
                                        if v.dims == dims[1:]])
        attribheader = format_complex_header(attribnames,
                                             attribdata,
                                             "%s(real)",
                                             "%s(complex)",
                                             None,
                                             unit_fmt=False)
        for name, data in zip(attribheader, attribdata):
            yield [("# %s = %s" % (name, data.outputformat)) % data[coord]]

        header, columns = zip(*[(k, v) for (k, v) in db.vardata.items()
                                if v.dims == dims])
        header = (dims[0].name, ) + header

        idx = (Ellipsis, ) + coord
        columns = [col[idx] for col in columns]
        columns = [hfarray(dims[0])] + columns
        outheader = format_complex_header(header,
                                          columns,
                                          "%s(real)",
                                          "%s(complex)",
                                          None,
                                          unit_fmt=False)

        yield ["% " + " ".join(outheader)]
        fmts = [x.outputformat for x in columns]
        #        import pdb;pdb.set_trace()
        for row in zip(*columns):
            out = []
            for elem, fmt in zip(row, fmts):
                out.extend(format_elem(fmt, elem))
            yield out
        yield ["END"]
Ejemplo n.º 3
0
 def test_format_complex_header_2(self):
     res = common.format_complex_header(["Z"],
                                        [hfarray([0.1 + 1j], unit=None)],
                                        "%s",
                                        "Re(%s)",
                                        "Im(%s)"
                                        )
     self.assertEqual(res, ["Re(Z)", "Im(Z)"])
Ejemplo n.º 4
0
 def test_format_complex_header_5(self):
     res = common.format_complex_header(["Z"],
                                        [hfarray([0.1 + 1j], unit=None)],
                                        "%s",
                                        "%s",
                                        None
                                        )
     self.assertEqual(res, ["Z"])
Ejemplo n.º 5
0
 def test_format_complex_header_3(self):
     res = common.format_complex_header(["Z"],
                                        [hfarray([0.1], unit="Ohm")],
                                        "%s",
                                        "Re(%s)",
                                        "Im(%s)"
                                        )
     self.assertEqual(res, ["Z [Ohm]"])
Ejemplo n.º 6
0
def format_sp_block(sweepvars, header, fmts, columns, blockname, comments):
    for comment in comments.fullcomments:
        yield ["!" + comment.lstrip("!")]
    for iname, fmt, value in sweepvars:
        yield [("!@%s=" + fmt) % (iname, value)]
    header, columns = make_col_from_matrix(header, columns, "%s%s%s")
    outheader = format_complex_header(header, columns, "%s", "Re(%s)", "Im(%s)", padheader=True)

    yield outheader
    fmts = [x.outputformat for x in columns]
    for row in zip(*columns):
        out = []
        for elem, fmt in zip(row, fmts):
            out.extend(format_elem(fmt, elem))
        yield out
Ejemplo n.º 7
0
def format_sp_block(sweepvars, header, fmts, columns, blockname, comments):
    for comment in comments.fullcomments:
        yield ["!" + comment.lstrip("!")]
    for iname, fmt, value in sweepvars:
        yield [("!@%s=" + fmt) % (iname, value)]
    header, columns = make_col_from_matrix(header, columns, "%s%s%s")
    outheader = format_complex_header(header, columns, "%s", "Re(%s)",
                                      "Im(%s)")

    yield outheader
    fmts = [x.outputformat for x in columns]
    for row in zip(*columns):
        out = []
        for elem, fmt in zip(row, fmts):
            out.extend(format_elem(fmt, elem))
        yield out
Ejemplo n.º 8
0
 def test_format_complex_header_2(self):
     res = common.format_complex_header(["Z"],
                                        [hfarray([0.1 + 1j], unit=None)],
                                        "%s", "Re(%s)", "Im(%s)")
     self.assertEqual(res, ["Re(Z)", "Im(Z)"])
Ejemplo n.º 9
0
 def test_format_complex_header_5(self):
     res = common.format_complex_header(["Z"],
                                        [hfarray([0.1 + 1j], unit=None)],
                                        "%s", "%s", None)
     self.assertEqual(res, ["Z"])
Ejemplo n.º 10
0
 def test_format_complex_header_3(self):
     res = common.format_complex_header(["Z"], [hfarray([0.1], unit="Ohm")],
                                        "%s", "Re(%s)", "Im(%s)")
     self.assertEqual(res, ["Z [Ohm]"])