testing for lookup w/ rescope list

testing for lookup w/ rescope list

:- add_to_path('../lib').
:- use_module(classad).

:- use_module(library(debug)).
:- use_module(library(plunit)).

:- use_module(library(lists)).
:- use_module(library(assoc)).
:- use_module(library(date)).

:- begin_tests(classad).

test('new_classad-1') :-
    new_classad('[classad]'(M)),
    is_assoc(M),
    assoc_to_list(M, []).

test('is_classad-1') :-
    new_classad(CA),
    is_classad(CA).

test('is_classad-2') :-
    \+is_classad(a),
    \+is_classad('[classad]'(foo)).

test('classad_assign_native-1') :-
    new_classad(CA0),
    classad_assign_native(vV, "4+2", CA0, '[classad]'(M)),
    assoc_to_list(M, [vv-'+'(4,2)]).

test('classad_assign/4-1') :-
    new_classad(CA0),
    classad_assign(xX, 0, CA0, '[classad]'(M)),
    assoc_to_list(M, [xx-0]).

test('classad_assign/4-context') :-
    new_classad(CA0),
    classad_assign(xX, 0, [CA0], ['[classad]'(M)]),
    assoc_to_list(M, [xx-0]).

test('classad_assign/3-1') :-
    classad_eval_native("[z=1]", [], CAZ),
    new_classad(CA0),
    classad_assign([x1 = error,
                    x2 = undefined,
                    x3 = 42,
                    x4 = 3.14,
                    x5 = 'A String',
                    x6 = ['a', ['list']],
                    x7 = true,
                    x8 = CAZ
                    ],
                   CA0, '[classad]'(M)),
    assoc_to_list(M,
                  [x1-error,
                   x2-undefined,
                   x3-42,
                   x4-3.14,
                   x5-'[str]'('A String'),
                   x6-['[str]'(a),['[str]'(list)]],
                   x7-true,
                   x8-'[classad]'(MZ)]),
    assoc_to_list(MZ, [z-1]).

test('classad_assign/3-time') :-
    new_classad(CA0),
    classad_assign(['AT1' = date(2012,2,24,6,12,31.0,25200,'MST',false),
                    'AT2' = abstime(1330089151.0, 25200),
                    'AT3' = reltime(60)
                    ],
                   CA0, '[classad]'(M)),
    assoc_to_list(M,
                  [at1-'[abstime]'(1330089151.0, 25200),
                   at2-'[abstime]'(1330089151.0, 25200),
                   at3-'[reltime]'(60)]).

test('classad_assign/3-mixed') :-
    new_classad(CA0),
    classad_assign([x1 = 42,
                    [x2, 3.14],
                    [x3, true, T3],
                    [x4, false, boolean],
                    [x5, "String", as(string)]],
                    CA0, '[classad]'(M)),
    T3 == boolean,
    assoc_to_list(M,
                  [x1-42,
                   x2-3.14,
                   x3-true,
                   x4-false,
                   x5-'[str]'('String')]).

test('classad_assign/3-qtype') :-
    classad_eval_native("[z=1]", [], CAZ),
    new_classad(CA0),
    classad_assign([[x1, error, T1],
                    [x2, undefined, T2],
                    [x3, 42, T3],
                    [x4, 3.14, T4],
                    [x5, 'A String', T5],
                    [x6, ['a', ['list']], T6],
                    [x7, true, T7],
                    [x8, CAZ, T8],
                    [x9, abstime(0,0), T9],
                    [x10, reltime(0), T10]
                    ],
                   CA0, _CA),
    T1 == error,
    T2 == undefined,
    T3 == integer,
    T4 == real,
    T5 == string,
    T6 == list,
    T7 == boolean,
    T8 == classad,
    T9 == abstime,
    T10 == reltime.

test('classad_assign/3-ftype') :-
    classad_eval_native("[z=1]", [], CAZ),
    new_classad(CA0),
    classad_assign([[x1, error, error],
                    [x2, undefined, undefined],
                    [x3, 42, integer],
                    [x4, 3.14, real],
                    [x5, 'A String', string],
                    [x6, ['a', ['list']], list],
                    [x7, true, boolean],
                    [x8, CAZ, classad],
                    [x9, abstime(0,0), abstime],
                    [x10, reltime(0), reltime]
                    ],
                   CA0, _CA).

test('classad_assign/3-ftype-fail') :-
    new_classad(CA0),
    \+classad_assign([[x1, 42, list]], CA0, _CA).

test('classad_assign/3-promotions') :-
    classad_eval:local_tzo(Z),
    new_classad(CA0),
    classad_assign([[x1, "a string", as(string)],
                    [x2, 60, as(reltime)],
                    [x3, 1.5, as(reltime)],
                    [x4, 1330089151, as(abstime)],
                    [x5, 1330089151.5, as(abstime)],
                    [x6, 1, as(real)],
                    [x7, 1, as(number)],
                    [x8, 1, as(integer)],
                    [x9, 1.0, as(real)],
                    [x91, 1.0, as(integer)],
                    [x92, 1.0, as(number)]
                   ], CA0, '[classad]'(M)),
    assoc_to_list(M, [x1-'[str]'('a string'),
                      x2-'[reltime]'(60),
                      x3-'[reltime]'(1.5),
                      x4-'[abstime]'(1330089151, Z),
                      x5-'[abstime]'(1330089151.5, Z),
                      x6-1.0,
                      x7-1,
                      x8-1,
                      x9-1.0,
                      x91-1,
                      x92-1.0
                    ]).

test('classad_lookup/3-1') :-
    new_classad(CA0),
    classad_assign(x, 'fred', CA0, CA),
    classad_lookup(x, CA, 'fred').

test('classad_lookup/4-qtype') :-
    new_classad(CA0),
    classad_assign(v, false, CA0, CA),
    classad_lookup(v, CA, false, T),
    T == boolean.

test('classad_lookup/4-qtype-novar') :-
    new_classad(CA0),
    classad_assign(v, false, CA0, CA),
    classad_lookup(x, CA, undefined, T),
    T == novar.

test('classad_lookup/4-ftype') :-
    new_classad(CA0),
    classad_assign(v, false, CA0, CA),
    classad_lookup(v, CA, false, boolean),
    \+classad_lookup(v, CA, false, list).

test('classad_lookup/3-context') :-
    classad_eval_native("[pi=3.14]", [], C),
    classad_eval_native("[r=2; a=pi*r*r]", [], CA),
    classad_lookup(a, [CA, C], 12.56).

test('classad_lookup/4-rescope') :-
    classad_eval_native("[x = 5]", [], O),
    classad_eval_native("[x = 4; b = x < other.x]", [], CA),
    classad_lookup(b, CA, [other=O], true).

test('classad_lookup/5-qtype') :-
    classad_eval_native("[x = 5]", [], O),
    classad_eval_native("[x = 4; b = x < other.x]", [], CA),
    classad_lookup(b, CA, [other=O], Val, Type),
    Val == true, Type == boolean.

test('classad_lookup/5-ftype') :-
    classad_eval_native("[x = 5]", [], O),
    classad_eval_native("[x = 4; b = x < other.x]", [], CA),
    classad_lookup(b, CA, [other=O], true, boolean),
    \+classad_lookup(b, CA, [other=O], true, string).

test('classad_lookup/2-1') :-
    classad_eval_native("[z=1]", [], CAZ),
    new_classad(CA0),
    classad_assign([[x1, error],
                    [x2, undefined],
                    [x3, 42],
                    [x4, 3.14],
                    [x5, 'A String'],
                    [x6, ['a', ['list']]],
                    [x7, true],
                    [x8, CAZ],
                    [x9, abstime(0,0)],
                    [x10, reltime(0)]
                    ],
                   CA0, CA),
    classad_lookup(CA,
                   [[x1, error],
                    [x2, undefined],
                    [x3, 42],
                    [x4, 3.14],
                    [x5, 'A String'],
                    [x6, ['a', ['list']]],
                    [x7, true],
                    [x8, CAZ],
                    [x9, abstime(0,0)],
                    [x10, reltime(0)]
                    ]).

test('classad_lookup/2-qtype') :-
    classad_eval_native("[z=1]", [], CAZ),
    new_classad(CA0),
    classad_assign([x1 = error,
                    x2 = undefined,
                    x3 = 42,
                    x4 = 3.14,
                    x5 = 'A String',
                    x6 = ['a', ['list']],
                    x7 = true,
                    x8 = CAZ,
                    x9 = abstime(0,0),
                    x10 = reltime(0)
                    ],
                   CA0, CA),
    classad_lookup(CA,
                   [[x1, error, T1],
                    [x2, undefined, T2],
                    [x3, 42, T3],
                    [x4, 3.14, T4],
                    [x5, 'A String', T5],
                    [x6, ['a', ['list']], T6],
                    [x7, true, T7],
                    [x8, CAZ, T8],
                    [x9, abstime(0,0), T9],
                    [x10, reltime(0), T10]
                    ]),
    T1 == error,
    T2 == undefined,
    T3 == integer,
    T4 == real,
    T5 == string,
    T6 == list,
    T7 == boolean,
    T8 == classad,
    T9 == abstime,
    T10 == reltime.

test('classad_lookup/2-ftype') :-
    classad_eval_native("[z=1]", [], CAZ),
    new_classad(CA0),
    classad_assign([x1 = error,
                    x2 = undefined,
                    x3 = 42,
                    x4 = 3.14,
                    x5 = 'A String',
                    x6 = ['a', ['list']],
                    x7 = true,
                    x8 = CAZ,
                    x9 = abstime(0,0),
                    x10 = reltime(0)
                    ],
                   CA0, CA),
    classad_lookup(CA,
                   [[x1, error, error],
                    [x2, undefined, undefined],
                    [x3, 42, integer],
                    [x4, 3.14, real],
                    [x5, 'A String', string],
                    [x6, ['a', ['list']], list],
                    [x7, true, boolean],
                    [x8, CAZ, classad],
                    [x9, abstime(0,0), abstime],
                    [x10, reltime(0), reltime]
                    ]).

test('classad_lookup/2-mixed') :-
    new_classad(CA0),
    classad_assign([x3 = 42,
                    x4 = 3.14],
                   CA0, CA),
    classad_lookup(CA,
                   [x3 = V3,
                    [x3, 42],
                    [x3, V3b],
                    [x3, 42, integer],
                    [x3, V3a, number],
                    [x4, 3.14, T4],
                    [x4, V4, T4b],
                    [x4, 3.14, number],
                    x5 = V5,
                    x5 = undefined,
                    [x5, undefined, T5],
                    [x5, undefined, novar]
                    ]),
    V3 == 42,
    V3a == 42,
    V3b == 42,
    T4 == real,
    V4 == 3.14,
    T4b == real,
    V5 == undefined,
    T5 == novar.

test('classad_lookup/2-context') :-
    new_classad(CA0),
    classad_assign([x3 = 42,
                    x4 = 3.14],
                   CA0, CA),
    classad_lookup([CA],
                   [x3 = V3,
                    [x3, 42],
                    [x3, V3b],
                    [x3, 42, integer],
                    [x3, V3a, number],
                    [x4, 3.14, T4],
                    [x4, V4, T4b],
                    [x4, 3.14, number],
                    x5 = V5,
                    x5 = undefined,
                    [x5, undefined, T5],
                    [x5, undefined, novar]
                    ]),
    V3 == 42,
    V3a == 42,
    V3b == 42,
    T4 == real,
    V4 == 3.14,
    T4b == real,
    V5 == undefined,
    T5 == novar.

test('classad_lookup/2-promotions') :-
    classad_eval:local_tzo(Z),
    new_classad(CA0),
    classad_assign([x1 = 42,
                    x2 = 3.14,
                    xri = 60,
                    xrr = 60.0,
                    xai = 1330089151,
                    xar = 1330089151.0,
                    at = abstime(1330089151, 25200),
                    rt = reltime(3600),
                    bt = true,
                    bf = false,
                    s = 'pebbles'],
                    CA0, CA),
    classad_lookup(CA,
                   [[x1, V1, as(real)],
                    [x1, V1b, as(number)],
                    [x2, V2, as(integer)],
                    [x2, V2b, as(number)],
                    [xri, VRI, as(reltime)],
                    [xrr, VRR, as(reltime)],
                    [xai, VAI, as(abstime)],
                    [xar, VAR, as(abstime)],
                    [xai, VDI, as(date)],
                    [xar, VDR, as(date)],
                    [at, VDA, as(date)],
                    [at, VIA, as(integer)],
                    [at, VRA, as(real)],
                    [at, VNA, as(number)],
                    [rt, VIRb, as(integer)],
                    [rt, VRRb, as(real)],
                    [rt, VNRb, as(number)],
                    [bt, VBTI, as(integer)],
                    [bt, VBTR, as(real)],
                    [bt, VBTN, as(number)],
                    [bf, VBFI, as(integer)],
                    [bf, VBFR, as(real)],
                    [bf, VBFN, as(number)],
                    [s, VSC, as(codelist)]
                   ]),
    V1 == 42.0,
    V1b == 42,
    V2 == 3,
    V2b == 3.14,
    VRI == reltime(60),
    VRR == reltime(60.0),
    VAI == abstime(1330089151, Z),
    VAR == abstime(1330089151.0, Z),
    VDI == date(2012,2,24,6,12,31.0,Z,-,-),
    VDR == date(2012,2,24,6,12,31.0,Z,-,-),
    VDA == date(2012,2,24,6,12,31.0,25200,-,-),
    VIA == 1330089151,
    VRA == 1330089151.0,
    VNA == 1330089151,
    VIRb == 3600,
    VRRb == 3600.0,
    VNRb == 3600,
    VBTI == 1,
    VBTR == 1.0,
    VBTN == 1,
    VBFI == 0,
    VBFR == 0.0,
    VBFN == 0,
    VSC == "pebbles".

test('classad_lookup/3-rescope') :-
    classad_eval_native("[pi=3.14; e=2.72]", [], Math),
    classad_eval_native("[r = 2;  area = math.pi*r*r;  base = math.e]", [], CA),
    classad_lookup(CA, [math=Math],
                   [area = Area,
                    base = Base,
                    [base, 2.72],
                    [area, 12.56, real],
                    [base, 2, as(integer)]
                   ]),
    Area == 12.56,
    Base = 2.72.

:- end_tests(classad).

:- add_to_path('../lib').
:- use_module(classad).

:- use_module(library(debug)).
:- use_module(library(plunit)).

:- use_module(library(lists)).
:- use_module(library(assoc)).
:- use_module(library(date)).

:- begin_tests(classad).

test('new_classad-1') :-
    new_classad('[classad]'(M)),
    is_assoc(M),
    assoc_to_list(M, []).

test('is_classad-1') :-
    new_classad(CA),
    is_classad(CA).

test('is_classad-2') :-
    \+is_classad(a),
    \+is_classad('[classad]'(foo)).

test('classad_assign_native-1') :-
    new_classad(CA0),
    classad_assign_native(vV, "4+2", CA0, '[classad]'(M)),
    assoc_to_list(M, [vv-'+'(4,2)]).

test('classad_assign/4-1') :-
    new_classad(CA0),
    classad_assign(xX, 0, CA0, '[classad]'(M)),
    assoc_to_list(M, [xx-0]).

test('classad_assign/4-context') :-
    new_classad(CA0),
    classad_assign(xX, 0, [CA0], ['[classad]'(M)]),
    assoc_to_list(M, [xx-0]).

test('classad_assign/3-1') :-
    classad_eval_native("[z=1]", [], CAZ),
    new_classad(CA0),
    classad_assign([x1 = error,
                    x2 = undefined,
                    x3 = 42,
                    x4 = 3.14,
                    x5 = 'A String',
                    x6 = ['a', ['list']],
                    x7 = true,
                    x8 = CAZ
                    ],
                   CA0, '[classad]'(M)),
    assoc_to_list(M,
                  [x1-error,
                   x2-undefined,
                   x3-42,
                   x4-3.14,
                   x5-'[str]'('A String'),
                   x6-['[str]'(a),['[str]'(list)]],
                   x7-true,
                   x8-'[classad]'(MZ)]),
    assoc_to_list(MZ, [z-1]).

test('classad_assign/3-time') :-
    new_classad(CA0),
    classad_assign(['AT1' = date(2012,2,24,6,12,31.0,25200,'MST',false),
                    'AT2' = abstime(1330089151.0, 25200),
                    'AT3' = reltime(60)
                    ],
                   CA0, '[classad]'(M)),
    assoc_to_list(M,
                  [at1-'[abstime]'(1330089151.0, 25200),
                   at2-'[abstime]'(1330089151.0, 25200),
                   at3-'[reltime]'(60)]).

test('classad_assign/3-mixed') :-
    new_classad(CA0),
    classad_assign([x1 = 42,
                    [x2, 3.14],
                    [x3, true, T3],
                    [x4, false, boolean],
                    [x5, "String", as(string)]],
                    CA0, '[classad]'(M)),
    T3 == boolean,
    assoc_to_list(M,
                  [x1-42,
                   x2-3.14,
                   x3-true,
                   x4-false,
                   x5-'[str]'('String')]).

test('classad_assign/3-qtype') :-
    classad_eval_native("[z=1]", [], CAZ),
    new_classad(CA0),
    classad_assign([[x1, error, T1],
                    [x2, undefined, T2],
                    [x3, 42, T3],
                    [x4, 3.14, T4],
                    [x5, 'A String', T5],
                    [x6, ['a', ['list']], T6],
                    [x7, true, T7],
                    [x8, CAZ, T8],
                    [x9, abstime(0,0), T9],
                    [x10, reltime(0), T10]
                    ],
                   CA0, _CA),
    T1 == error,
    T2 == undefined,
    T3 == integer,
    T4 == real,
    T5 == string,
    T6 == list,
    T7 == boolean,
    T8 == classad,
    T9 == abstime,
    T10 == reltime.

test('classad_assign/3-ftype') :-
    classad_eval_native("[z=1]", [], CAZ),
    new_classad(CA0),
    classad_assign([[x1, error, error],
                    [x2, undefined, undefined],
                    [x3, 42, integer],
                    [x4, 3.14, real],
                    [x5, 'A String', string],
                    [x6, ['a', ['list']], list],
                    [x7, true, boolean],
                    [x8, CAZ, classad],
                    [x9, abstime(0,0), abstime],
                    [x10, reltime(0), reltime]
                    ],
                   CA0, _CA).

test('classad_assign/3-ftype-fail') :-
    new_classad(CA0),
    \+classad_assign([[x1, 42, list]], CA0, _CA).

test('classad_assign/3-promotions') :-
    classad_eval:local_tzo(Z),
    new_classad(CA0),
    classad_assign([[x1, "a string", as(string)],
                    [x2, 60, as(reltime)],
                    [x3, 1.5, as(reltime)],
                    [x4, 1330089151, as(abstime)],
                    [x5, 1330089151.5, as(abstime)],
                    [x6, 1, as(real)],
                    [x7, 1, as(number)],
                    [x8, 1, as(integer)],
                    [x9, 1.0, as(real)],
                    [x91, 1.0, as(integer)],
                    [x92, 1.0, as(number)]
                   ], CA0, '[classad]'(M)),
    assoc_to_list(M, [x1-'[str]'('a string'),
                      x2-'[reltime]'(60),
                      x3-'[reltime]'(1.5),
                      x4-'[abstime]'(1330089151, Z),
                      x5-'[abstime]'(1330089151.5, Z),
                      x6-1.0,
                      x7-1,
                      x8-1,
                      x9-1.0,
                      x91-1,
                      x92-1.0
                    ]).

test('classad_lookup/3-1') :-
    new_classad(CA0),
    classad_assign(x, 'fred', CA0, CA),
    classad_lookup(x, CA, 'fred').

test('classad_lookup/4-qtype') :-
    new_classad(CA0),
    classad_assign(v, false, CA0, CA),
    classad_lookup(v, CA, false, T),
    T == boolean.

test('classad_lookup/4-qtype-novar') :-
    new_classad(CA0),
    classad_assign(v, false, CA0, CA),
    classad_lookup(x, CA, undefined, T),
    T == novar.

test('classad_lookup/4-ftype') :-
    new_classad(CA0),
    classad_assign(v, false, CA0, CA),
    classad_lookup(v, CA, false, boolean),
    \+classad_lookup(v, CA, false, list).

test('classad_lookup/3-context') :-
    classad_eval_native("[pi=3.14]", [], C),
    classad_eval_native("[r=2; a=pi*r*r]", [], CA),
    classad_lookup(a, [CA, C], 12.56).

test('classad_lookup/4-rescope') :-
    classad_eval_native("[x = 5]", [], O),
    classad_eval_native("[x = 4; b = x < other.x]", [], CA),
    classad_lookup(b, CA, [other=O], true).

test('classad_lookup/5-qtype') :-
    classad_eval_native("[x = 5]", [], O),
    classad_eval_native("[x = 4; b = x < other.x]", [], CA),
    classad_lookup(b, CA, [other=O], Val, Type),
    Val == true, Type == boolean.

test('classad_lookup/5-ftype') :-
    classad_eval_native("[x = 5]", [], O),
    classad_eval_native("[x = 4; b = x < other.x]", [], CA),
    classad_lookup(b, CA, [other=O], true, boolean),
    \+classad_lookup(b, CA, [other=O], true, string).

test('classad_lookup/2-1') :-
    classad_eval_native("[z=1]", [], CAZ),
    new_classad(CA0),
    classad_assign([[x1, error],
                    [x2, undefined],
                    [x3, 42],
                    [x4, 3.14],
                    [x5, 'A String'],
                    [x6, ['a', ['list']]],
                    [x7, true],
                    [x8, CAZ],
                    [x9, abstime(0,0)],
                    [x10, reltime(0)]
                    ],
                   CA0, CA),
    classad_lookup(CA,
                   [[x1, error],
                    [x2, undefined],
                    [x3, 42],
                    [x4, 3.14],
                    [x5, 'A String'],
                    [x6, ['a', ['list']]],
                    [x7, true],
                    [x8, CAZ],
                    [x9, abstime(0,0)],
                    [x10, reltime(0)]
                    ]).

test('classad_lookup/2-qtype') :-
    classad_eval_native("[z=1]", [], CAZ),
    new_classad(CA0),
    classad_assign([x1 = error,
                    x2 = undefined,
                    x3 = 42,
                    x4 = 3.14,
                    x5 = 'A String',
                    x6 = ['a', ['list']],
                    x7 = true,
                    x8 = CAZ,
                    x9 = abstime(0,0),
                    x10 = reltime(0)
                    ],
                   CA0, CA),
    classad_lookup(CA,
                   [[x1, error, T1],
                    [x2, undefined, T2],
                    [x3, 42, T3],
                    [x4, 3.14, T4],
                    [x5, 'A String', T5],
                    [x6, ['a', ['list']], T6],
                    [x7, true, T7],
                    [x8, CAZ, T8],
                    [x9, abstime(0,0), T9],
                    [x10, reltime(0), T10]
                    ]),
    T1 == error,
    T2 == undefined,
    T3 == integer,
    T4 == real,
    T5 == string,
    T6 == list,
    T7 == boolean,
    T8 == classad,
    T9 == abstime,
    T10 == reltime.

test('classad_lookup/2-ftype') :-
    classad_eval_native("[z=1]", [], CAZ),
    new_classad(CA0),
    classad_assign([x1 = error,
                    x2 = undefined,
                    x3 = 42,
                    x4 = 3.14,
                    x5 = 'A String',
                    x6 = ['a', ['list']],
                    x7 = true,
                    x8 = CAZ,
                    x9 = abstime(0,0),
                    x10 = reltime(0)
                    ],
                   CA0, CA),
    classad_lookup(CA,
                   [[x1, error, error],
                    [x2, undefined, undefined],
                    [x3, 42, integer],
                    [x4, 3.14, real],
                    [x5, 'A String', string],
                    [x6, ['a', ['list']], list],
                    [x7, true, boolean],
                    [x8, CAZ, classad],
                    [x9, abstime(0,0), abstime],
                    [x10, reltime(0), reltime]
                    ]).

test('classad_lookup/2-mixed') :-
    new_classad(CA0),
    classad_assign([x3 = 42,
                    x4 = 3.14],
                   CA0, CA),
    classad_lookup(CA,
                   [x3 = V3,
                    [x3, 42],
                    [x3, V3b],
                    [x3, 42, integer],
                    [x3, V3a, number],
                    [x4, 3.14, T4],
                    [x4, V4, T4b],
                    [x4, 3.14, number],
                    x5 = V5,
                    x5 = undefined,
                    [x5, undefined, T5],
                    [x5, undefined, novar]
                    ]),
    V3 == 42,
    V3a == 42,
    V3b == 42,
    T4 == real,
    V4 == 3.14,
    T4b == real,
    V5 == undefined,
    T5 == novar.

test('classad_lookup/2-context') :-
    new_classad(CA0),
    classad_assign([x3 = 42,
                    x4 = 3.14],
                   CA0, CA),
    classad_lookup([CA],
                   [x3 = V3,
                    [x3, 42],
                    [x3, V3b],
                    [x3, 42, integer],
                    [x3, V3a, number],
                    [x4, 3.14, T4],
                    [x4, V4, T4b],
                    [x4, 3.14, number],
                    x5 = V5,
                    x5 = undefined,
                    [x5, undefined, T5],
                    [x5, undefined, novar]
                    ]),
    V3 == 42,
    V3a == 42,
    V3b == 42,
    T4 == real,
    V4 == 3.14,
    T4b == real,
    V5 == undefined,
    T5 == novar.

test('classad_lookup/2-promotions') :-
    classad_eval:local_tzo(Z),
    new_classad(CA0),
    classad_assign([x1 = 42,
                    x2 = 3.14,
                    xri = 60,
                    xrr = 60.0,
                    xai = 1330089151,
                    xar = 1330089151.0,
                    at = abstime(1330089151, 25200),
                    rt = reltime(3600),
                    bt = true,
                    bf = false,
                    s = 'pebbles'],
                    CA0, CA),
    classad_lookup(CA,
                   [[x1, V1, as(real)],
                    [x1, V1b, as(number)],
                    [x2, V2, as(integer)],
                    [x2, V2b, as(number)],
                    [xri, VRI, as(reltime)],
                    [xrr, VRR, as(reltime)],
                    [xai, VAI, as(abstime)],
                    [xar, VAR, as(abstime)],
                    [xai, VDI, as(date)],
                    [xar, VDR, as(date)],
                    [at, VDA, as(date)],
                    [at, VIA, as(integer)],
                    [at, VRA, as(real)],
                    [at, VNA, as(number)],
                    [rt, VIRb, as(integer)],
                    [rt, VRRb, as(real)],
                    [rt, VNRb, as(number)],
                    [bt, VBTI, as(integer)],
                    [bt, VBTR, as(real)],
                    [bt, VBTN, as(number)],
                    [bf, VBFI, as(integer)],
                    [bf, VBFR, as(real)],
                    [bf, VBFN, as(number)],
                    [s, VSC, as(codelist)]
                   ]),
    V1 == 42.0,
    V1b == 42,
    V2 == 3,
    V2b == 3.14,
    VRI == reltime(60),
    VRR == reltime(60.0),
    VAI == abstime(1330089151, Z),
    VAR == abstime(1330089151.0, Z),
    VDI == date(2012,2,24,6,12,31.0,Z,-,-),
    VDR == date(2012,2,24,6,12,31.0,Z,-,-),
    VDA == date(2012,2,24,6,12,31.0,25200,-,-),
    VIA == 1330089151,
    VRA == 1330089151.0,
    VNA == 1330089151,
    VIRb == 3600,
    VRRb == 3600.0,
    VNRb == 3600,
    VBTI == 1,
    VBTR == 1.0,
    VBTN == 1,
    VBFI == 0,
    VBFR == 0.0,
    VBFN == 0,
    VSC == "pebbles".

:- end_tests(classad).


rrepair, plots: improve the data_inc plots and extend the script to accept 5 source files

#! /usr/bin/gnuplot
# USED PARAMS
#	colDefFile -> file with column definitions
#	srcFile1 -> source file 1 path
#	srcFile1_title -> prepend this to titles of lines from srcFile1
#	srcFile2 -> source file 2 path (optional)
#	srcFile2_title -> prepend this to titles of lines from srcFile2 (optional unless srcFile2 given)
#	srcFile3 -> source file 3 path (optional)
#	srcFile3_title -> prepend this to titles of lines from srcFile3 (optional unless srcFile3 given)
#	srcFile4 -> source file 4 path (optional)
#	srcFile4_title -> prepend this to titles of lines from srcFile4 (optional unless srcFile4 given)
#	srcFile5 -> source file 5 path (optional)
#	srcFile5_title -> prepend this to titles of lines from srcFile5 (optional unless srcFile5 given)
#	destDir -> destination path for pdfs
#	regenAccInPercent -> whether to show the regen accuracy in percent instead of absolute values (useful for bloom)
#	absoluteRedundancy -> whether to show the absolute redundancy or a relative one

set macro

load colDefFile

plotCount = exists("srcFile5") ? 5 : exists("srcFile4") ? 4 : exists("srcFile3") ? 3 : exists("srcFile2") ? 2 : 1
files = srcFile1 . (plotCount >= 2 ? " " . srcFile2 : "") . (plotCount >= 3 ? " " . srcFile3 : "") . (plotCount >= 4 ? " " . srcFile4 : "") . (plotCount >= 5 ? " " . srcFile5 : "")
get_file(i) = (i == 5) ? srcFile5 : (i == 4) ? srcFile4 : (i == 3) ? srcFile3 : (i == 2) ? srcFile2 : srcFile1
get_title(i) = (i == 5) ? srcFile5_title : (i == 4) ? srcFile4_title : (i == 3) ? srcFile3_title : (i == 2) ? srcFile2_title : srcFile1_title

# http://colorbrewer2.org/?type=qualitative&scheme=Set1&n=5
# (#e41a1c, #377eb8, #4daf4a, #984ea3, #ff7f00)
# -> a little brighter version:
set style line 1 lw 2 lt 1 lc rgb '#ff191b' pt 5 # dark red
set style line 2 lw 2 lt 1 lc rgb '#2d8ede' pt 9 # dark blue
set style line 3 lw 2 lt 1 lc rgb '#59c955' pt 7 # dark green
set style line 4 lw 2 lt 1 lc rgb '#b05abd' pt 4 # dark purple
set style line 5 lw 2 lt 1 lc rgb '#ff7f00' pt 10 # dark orange
set style line 6 lw 3 lc rgb "#777777" pt 8 lt 3 # gray (for the naive line)

set style line 101 lw 3 lt 1 lc rgb '#ff191b' pt 0 # dark red
set style line 102 lw 3 lt 1 lc rgb '#2d8ede' pt 0 # dark blue
set style line 103 lw 3 lt 1 lc rgb '#59c955' pt 0 # dark green
set style line 104 lw 3 lt 1 lc rgb '#b05abd' pt 0 # dark purple
set style line 105 lw 3 lt 1 lc rgb '#ff7f00' pt 0 # dark orange

if (plotCount == 5) {
  plotShift(x, i) = (i == 5) ? (x + (x / 1.6)) : (i == 4) ? (x + (x / 3.7)) : (i == 3) ? (x) : (i == 2) ? (x - (x / 4.6)) : (x - (x / 2.6))
} else {
  if (plotCount == 4) {
    plotShift(x, i) = (i == 4) ? (x + (x / 1.9)) : (i == 3) ? (x + (x / 6.5)) : (i == 2) ? (x - (x / 7.9)) : (x - (x / 2.95))
  } else {
    if (plotCount == 3) {
      plotShift(x, i) = (i == 3) ? (x + (x / 2.3)) : (i == 2) ? (x) : (x - (x / 3.2))
    } else {
      if (plotCount == 2) {
        plotShift(x, i) = (i == 2) ? (x + (x / 3)) : (x - (x / 4))
      } else {
        plotShift(x, i) = x
      }
    }
  }
}
if (exists("regenAccInPercent") && regenAccInPercent == 1) {
  regenAcc(found, existing) = 100 - 100 * found / existing
  regenAccErr(found1, found2, existingSum) = stderrSum(found1, found2) * (100 / existingSum)
} else {
  regenAccInPercent = 0
  regenAcc(found, existing) = existing - found
  regenAccErr(found1, found2, existingSum) = stderrSum(found1, found2)
}
if (exists("absoluteRedundancy") && absoluteRedundancy == 1) {
  redundancy(transferred, updated, regen) = transferred - (updated + regen)
  redundancyStderr(transferred, updated, regen) = sqrt(transferred**2 - updated**2 - regen**2)
} else {
  absoluteRedundancy = 0
  redundancy(transferred, updated, regen) = transferred / (updated + regen)
  redundancyStderr(transferred, updated, regen) = "-"
}
plot_boxwidth = (0.8 / plotCount)

# OUTPUT
set terminal pdfcairo dashed enhanced font ",15" fontscale 0.5 size 6,4.5
fileEx = "pdf"

system "echo 'PLOT " . files . "'"
system "mkdir -p " .destDir

filename = "file"

# --OPTION
kvvSize0 = 16+4 # key+version size in bytes
kvvSize1 = kvvSize0+10 # key+version+value size in byte

# Helper
stderrSum(x,y) = sqrt(x**2 + y**2)	# sum of std. errors is root of sum of square errors
kB(x) = x / 1024
min(x,y) = (x < y) ? x : y
min3(x,y,z) = min(min(x,y),z)
max(x,y) = (x > y) ? x : y
max3(x,y,z) = max(max(x,y),z)

acc_upd_max=0.5
if (regenAccInPercent == 1) {
  do for [i=1:plotCount] {
    stats "<awk '$" . col_ftype . " == \"update\"' " . get_file(i) u (column(col_missing)+column(col_outdated) - column(col_regen)-column(col_updated)+stderrSum(column(col_sd_regen),column(col_sd_updated))) nooutput
    if (STATS_max > acc_upd_max) {acc_upd_max = STATS_max}
  }
  acc_reg_max=50.5
  acc_reg_min=49.5
  do for [i=1:plotCount] {
    stats "<awk '$" . col_ftype . " == \"regen\"' " . get_file(i) u (regenAcc(column(col_regen)+column(col_updated), column(col_missing)+column(col_outdated))+regenAccErr(column(col_sd_regen),column(col_sd_updated),(column(col_missing)+column(col_outdated)))):(regenAcc(column(col_regen)+column(col_updated), column(col_missing)+column(col_outdated))-regenAccErr(column(col_sd_regen),column(col_sd_updated),(column(col_missing)+column(col_outdated)))) nooutput
    if (STATS_min_y < acc_reg_min) {acc_reg_min = STATS_min_y}
    if (STATS_max_x > acc_reg_max) {acc_reg_max = STATS_max_x}
  }
  acc_reg_avg=(acc_reg_max+acc_reg_min)/2.0
  acc_reg_max=max(abs(acc_reg_avg-acc_reg_min), abs(acc_reg_max-acc_reg_avg))
} else {
  do for [i=1:plotCount] {
    stats "<awk '$" . col_ftype . " == \"update\" || $" . col_ftype . " == \"regen\"' " . get_file(i) u (column(col_missing)+column(col_outdated) - column(col_regen)-column(col_updated)+stderrSum(column(col_sd_regen),column(col_sd_updated))) nooutput
    if (STATS_max > acc_upd_max) {acc_upd_max = STATS_max}
  }
  acc_reg_max = acc_upd_max
}
if (acc_upd_max > 0.5) {acc_upd_max=acc_upd_max*1.05}
if (acc_reg_max > 0.5) {acc_reg_max=acc_reg_max*1.05}

red_max=0.5
do for [i=1:plotCount] {
  stats get_file(i) using (redundancy(column(col_bw_rs_kvv), column(col_updated), column(col_regen))+redundancyStderr(column(col_sd_bw_rs_kvv), column(col_sd_updated), column(col_sd_regen))) nooutput
  if (STATS_max > red_max) {red_max = STATS_max}
}
if (red_max > 0.5) {red_max=red_max*1.05}
if (red_max >= 1.5 && red_max < 2) {red_max=2}

bw_max=1
do for [i=1:plotCount] {
  stats get_file(i) using (kB(column(col_bw_rc_size)+column(col_bw_rc2_size)+stderrSum(column(col_sd_bw_rc_size), column(col_sd_bw_rc2_size)))) nooutput
  if (STATS_max > bw_max) {bw_max = STATS_max}
}
# is naive solution more expensive?
stats get_file(1) using (kB(column(col_dbsize)/4*(128+32)/8)) nooutput
if (STATS_max > bw_max) {bw_max = STATS_max}

key_width_fun(i) = min(-0.5, (6-strstrt(get_title(i), "_")) - (strlen(get_title(i)) - strstrt(get_title(i), "_")) * 0.15)
key_width = min(key_width_fun(1),key_width_fun(plotCount))
#print "key_width: ",key_width

# Solid Background
# set object 1 rect from screen 0, 0, 0 to screen 1, 1, 0 behind
# set object 1 rect fc  rgb "white"  fillstyle solid 1.0

# Style
if (plotCount == 1) {
  set style data yerrorlines
} else {
  set style data yerrorbars
}
set logscale x 2
set xrange [2:8192] # TODO: adapt if number of data points changes!
set grid layerdefault linetype 0 linewidth 1.000,  linetype 0 linewidth 1.000
set pointsize (plotCount >= 4) ? 0.7 : (plotCount == 3) ? 0.8 : 1
arrow_dx=.166666666667 # grid spacing in x
arrow_di=0 # added to each i in loop - arrows drawn at (i+arrow_di)*arrow_dx
arrow_xpoints=6 # TODO: adapt if number of data points changes!

set style line 100 lw 2 lc -1 pt 0 lt 1

#--------------------------------- ALL
set boxwidth plot_boxwidth relative
set style fill solid 1 border -1
set xtics scale 0.1
set ytics scale 0.8
set grid noxtics nomxtics layerdefault linetype 0 linewidth 1.000,  linetype 0 linewidth 1.000
set for [i=1:arrow_xpoints] arrow from graph (i+arrow_di)*arrow_dx,graph 0 to graph (i+arrow_di)*arrow_dx,graph 1 nohead back linetype 0 linewidth 1.000

set o destDir. "all_" .filename. "." .fileEx
set multiplot

all_width_r = 0.545
all_width_l = all_width_r
bw_height_full = 0.700
bw_height = 0.023 + ((plotCount > 1) ? (bw_height_full - 0.018) : bw_height_full)
red_height = (plotCount > 1) ? 0.170 : 0.174
red_pos_y = (plotCount > 1) ? bw_height_full - 0.033 : bw_height_full - 0.035
acc_height_full = (plotCount > 1) ? 0.200 : 0.204
acc_height = (plotCount > 1) ? (acc_height_full - 0.012) : acc_height_full
acc_pos_y = (plotCount > 1) ? (red_pos_y + red_height - 0.007) : (red_pos_y + red_height - 0.025)

# accuracy

set size all_width_l,acc_height
set origin -0.002,acc_pos_y
unset xlabel
set format x ""
set ylabel "|Δ| missed " font ",16"
set yrange [0:acc_upd_max]
set format y " %4.1f"
if (plotCount > 1) {
  set key at screen 0.512,(acc_pos_y + 0.001) center center vertical Left reverse opaque enhanced autotitles nobox maxrows 1 width (plotCount >= 5 ? (key_width-2.2) : plotCount >= 4 ? (key_width+1) : (key_width+3)) samplen 1.75 font ",14" spacing 1.3
} else {
  set key top left horizontal Left reverse opaque enhanced autotitles box maxcols 1 width key_width samplen 1.5 font ",13"
}

plot for [i=1:plotCount] "<awk '$" . col_ftype . " == \"update\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(column(col_missing)+column(col_outdated) - column(col_regen)-column(col_updated)):(stderrSum(column(col_sd_regen),column(col_sd_updated))) t get_title(i) ls i

set origin 0.49,acc_pos_y
unset key
unset ylabel
unset ytics
set grid y2tics
set size all_width_r,acc_height
if (regenAccInPercent == 1) {
  set y2tics mirror format "%-3.0f_{ }%%" offset 0 scale 0.8
  set y2range [(acc_reg_avg-acc_reg_max):(acc_reg_avg+acc_reg_max)]
} else {
  set y2tics mirror format "%-4.1f " scale 0.8
  set y2range [0:acc_reg_max]
}

plot for [i=1:plotCount] "<awk '$" . col_ftype . " == \"regen\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(regenAcc(column(col_regen)+column(col_updated), column(col_missing)+column(col_outdated))):(regenAccErr(column(col_sd_regen),column(col_sd_updated),(column(col_missing)+column(col_outdated)))) axes x1y2 t get_title(i) ls (plotCount > 1 ? i : 2)

set ytics scale 0.8
unset y2tics
set grid noy2tics

# redundancy

set ytics autofreq
set size all_width_l,red_height
set origin -0.002,red_pos_y
if (absoluteRedundancy == 1) {
set ylabel "Red." font ",16" # transferred / updated
} else {
set ylabel "rel. Red." font ",16" # transferred / updated
}
set yrange [0:red_max]
set y2range [0:red_max]
if (red_max > 10) {
  set format y "  %3.0f"
  set format y2 "%-3.0f "
} else {
  set format y " %4.1f"
  set format y2 "%-4.1f "
}
unset key

plot for [i=1:plotCount] "<awk '$" . col_ftype . " == \"update\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(redundancy(column(col_bw_rs_kvv), column(col_updated), column(col_regen))) with boxes t get_title(i) ls i, \
     for [i=1:plotCount] "<awk '$" . col_ftype . " == \"update\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(redundancy(column(col_bw_rs_kvv), column(col_updated), column(col_regen))):(redundancyStderr(column(col_sd_bw_rs_kvv), column(col_sd_updated), column(col_sd_regen))) with yerrorbars notitle ls (plotCount > 1 ? (100+i) : 100)

set size all_width_r,red_height
set origin 0.49,red_pos_y
if (plotCount == 1) {
  set key bottom right horizontal Right noreverse opaque enhanced autotitles box maxcols 1 width key_width samplen 1.5 font ",13"
}
unset ylabel
unset ytics
set grid y2tics
set y2tics mirror scale 0.8

plot for [i=1:plotCount] "<awk '$" . col_ftype . " == \"regen\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(redundancy(column(col_bw_rs_kvv), column(col_updated), column(col_regen))) axes x1y2 with boxes t get_title(i) ls (plotCount > 1 ? i : 2), \
     for [i=1:plotCount] "<awk '$" . col_ftype . " == \"regen\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(redundancy(column(col_bw_rs_kvv), column(col_updated), column(col_regen))):(redundancyStderr(column(col_sd_bw_rs_kvv), column(col_sd_updated), column(col_sd_regen))) with yerrorbars notitle ls (plotCount > 1 ? (100+i) : 100)

set ytics scale 0.8
unset y2tics
set grid noy2tics

# bandwidth

set size all_width_l,bw_height
set origin -0.002,-0.025
set xlabel "n in 10^3, update" font ",16"
set ylabel "RC costs (phase 1+2) in KiB" font ",16"
set yrange [1:bw_max*1.2]
set y2range [1:bw_max*1.2]
set logscale y 2
set logscale y2 2
set format y "%5.0f"
set format x
if (plotCount > 1) {
  set key at screen 0.512,(red_pos_y + 0.0065) center center vertical Left reverse opaque enhanced autotitles nobox maxrows 1 width (plotCount >= 5 ? (key_width-2.2) : plotCount >= 4 ? (key_width+1) : (key_width+3)) samplen 1.75 font ",14" spacing 1.3
} else {
  set key top left horizontal Left reverse opaque enhanced autotitles box maxcols 1 width key_width samplen 1.5 font ",13"
}

LABEL = "n × (128+32) bits\n_{(≥ naïve approach)}"
set label 10 at 6,264000*(128+32)/8/1024 LABEL front left font ",12" textcolor rgb "#777777"

plot for [i=1:plotCount] "<awk '$" . col_ftype . " == \"update\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(kB(column(col_bw_rc_size)+column(col_bw_rc2_size))) with boxes notitle ls i fs solid 0.4, \
     for [i=1:plotCount] "<awk '$" . col_ftype . " == \"update\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(kB(column(col_bw_rc_size))) with boxes t get_title(i) ls i, \
     for [i=1:plotCount] "<awk '$" . col_ftype . " == \"update\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(kB(column(col_bw_rc_size)+column(col_bw_rc2_size))):(kB(stderrSum(column(col_sd_bw_rc_size),column(col_sd_bw_rc2_size)))) with lines notitle ls (plotCount > 1 ? (100+i) : 100), \
     for [i=1:plotCount] "<awk '$" . col_ftype . " == \"update\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(kB(column(col_bw_rc_size)+column(col_bw_rc2_size))):(kB(stderrSum(column(col_sd_bw_rc_size),column(col_sd_bw_rc2_size)))) with yerrorbars notitle ls 100, \
     "<awk '$" . col_ftype . " == \"update\"' " . get_file(1) \
 u (plotShift(column(col_dbsize)/4/1000, 1)):(kB(column(col_dbsize)/4*(128+32)/8)) with linespoints notitle ls 6

set size all_width_r,bw_height
set origin 0.49,-0.025
set xlabel "n in 10^3, regen" font ",16"
unset key
unset ylabel
unset ytics
set grid y2tics
set y2tics mirror format "%-5.0f" scale 0.8

plot for [i=1:plotCount] "<awk '$" . col_ftype . " == \"regen\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(kB(column(col_bw_rc_size)+column(col_bw_rc2_size))) axes x1y2 with boxes notitle ls (plotCount > 1 ? i : 2) fs solid 0.4, \
     for [i=1:plotCount] "<awk '$" . col_ftype . " == \"regen\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(kB(column(col_bw_rc_size))) axes x1y2 with boxes t get_title(i) ls (plotCount > 1 ? i : 2), \
     for [i=1:plotCount] "<awk '$" . col_ftype . " == \"regen\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(kB(column(col_bw_rc_size)+column(col_bw_rc2_size))):(kB(stderrSum(column(col_sd_bw_rc_size),column(col_sd_bw_rc2_size)))) axes x1y2 with lines notitle ls (plotCount > 1 ? (100+i) : 100), \
     for [i=1:plotCount] "<awk '$" . col_ftype . " == \"regen\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(kB(column(col_bw_rc_size)+column(col_bw_rc2_size))):(kB(stderrSum(column(col_sd_bw_rc_size),column(col_sd_bw_rc2_size)))) axes x1y2 with yerrorbars notitle ls 100, \
     "<awk '$" . col_ftype . " == \"update\"' " . get_file(1) \
 u (plotShift(column(col_dbsize)/4/1000, 1)):(kB(column(col_dbsize)/4*(128+32)/8)) with linespoints notitle ls 6

#! /usr/bin/gnuplot
# USED PARAMS
#	colDefFile -> file with column definitions
#	srcFile1 -> source file 1 path
#	srcFile1_title -> prepend this to titles of lines from srcFile1
#	srcFile2 -> source file 2 path (optional)
#	srcFile2_title -> prepend this to titles of lines from srcFile2 (optional unless srcFile2 given)
#	srcFile3 -> source file 3 path (optional)
#	srcFile3_title -> prepend this to titles of lines from srcFile3 (optional unless srcFile3 given)
#	srcFile4 -> source file 4 path (optional)
#	srcFile4_title -> prepend this to titles of lines from srcFile4 (optional unless srcFile4 given)
#	destDir -> destination path for pdfs
#	regenAccInPercent -> whether to show the regen accuracy in percent instead of absolute values (useful for bloom)
#	absoluteRedundancy -> whether to show the absolute redundancy or a relative one

set macro

load colDefFile

plotCount = exists("srcFile4") ? 4 : exists("srcFile3") ? 3 : exists("srcFile2") ? 2 : 1
files = srcFile1 . (plotCount >= 2 ? " " . srcFile2 : "") . (plotCount >= 3 ? " " . srcFile3 : "") . (plotCount >= 4 ? " " . srcFile4 : "")
get_file(i) = (i == 4) ? srcFile4 : (i == 3) ? srcFile3 : (i == 2) ? srcFile2 : srcFile1
get_title(i) = (i == 4) ? srcFile4_title : (i == 3) ? srcFile3_title : (i == 2) ? srcFile2_title : srcFile1_title

# http://colorbrewer2.org/?type=qualitative&scheme=Set1&n=5
# (#e41a1c, #377eb8, #4daf4a, #984ea3, #ff7f00)
# -> a little brighter version:
set style line 1 lw 2 lt 1 lc rgb '#ff191b' pt 5 # dark red
set style line 2 lw 2 lt 1 lc rgb '#2d8ede' pt 9 # dark blue
set style line 3 lw 2 lt 1 lc rgb '#59c955' pt 7 # dark green
set style line 4 lw 2 lt 1 lc rgb '#b05abd' pt 4 # dark purple
set style line 5 lw 2 lt 1 lc rgb '#ff7f00' pt 10 # dark orange

set style line 101 lw 3 lt 1 lc rgb '#ff191b' pt 0 # dark red
set style line 102 lw 3 lt 1 lc rgb '#2d8ede' pt 0 # dark blue
set style line 103 lw 3 lt 1 lc rgb '#59c955' pt 0 # dark green
set style line 104 lw 3 lt 1 lc rgb '#b05abd' pt 0 # dark purple
set style line 105 lw 3 lt 1 lc rgb '#ff7f00' pt 0 # dark orange

if (plotCount == 4) {
  plotShift(x, i) = (i == 4) ? (x + (x / 1.9)) : (i == 3) ? (x + (x / 6.5)) : (i == 2) ? (x - (x / 7.9)) : (x - (x / 2.95))
} else {
  if (plotCount == 3) {
    plotShift(x, i) = (i == 3) ? (x + (x / 2.3)) : (i == 2) ? (x) : (x - (x / 3.2))
  } else {
    if (plotCount == 2) {
      plotShift(x, i) = (i == 2) ? (x + (x / 3)) : (x - (x / 4))
    } else {
      plotShift(x, i) = x
    }
  }
}
set style line 5 lw 3 lc rgb "#777777" pt 8 lt 3
if (exists("regenAccInPercent") && regenAccInPercent == 1) {
  regenAcc(found, existing) = 100 - 100 * found / existing
  regenAccErr(found1, found2, existingSum) = stderrSum(found1, found2) * (100 / existingSum)
} else {
  regenAccInPercent = 0
  regenAcc(found, existing) = existing - found
  regenAccErr(found1, found2, existingSum) = stderrSum(found1, found2)
}
if (exists("absoluteRedundancy") && absoluteRedundancy == 1) {
  redundancy(transferred, updated, regen) = transferred - (updated + regen)
  redundancyStderr(transferred, updated, regen) = sqrt(transferred**2 - updated**2 - regen**2)
} else {
  absoluteRedundancy = 0
  redundancy(transferred, updated, regen) = transferred / (updated + regen)
  redundancyStderr(transferred, updated, regen) = "-"
}
plot_boxwidth = (0.8 / plotCount)

# OUTPUT
set terminal pdfcairo dashed enhanced font ",15" fontscale 0.5 size 6,4.5
fileEx = "pdf"

system "echo 'PLOT " . files . "'"
system "mkdir -p " .destDir

filename = "file"

# --OPTION
kvvSize0 = 16+4 # key+version size in bytes
kvvSize1 = kvvSize0+10 # key+version+value size in byte

# Helper
stderrSum(x,y) = sqrt(x**2 + y**2)	# sum of std. errors is root of sum of square errors
kB(x) = x / 1024
min(x,y) = (x < y) ? x : y
min3(x,y,z) = min(min(x,y),z)
max(x,y) = (x > y) ? x : y
max3(x,y,z) = max(max(x,y),z)

acc_upd_max=0.5
if (regenAccInPercent == 1) {
  do for [i=1:plotCount] {
    stats "<awk '$" . col_ftype . " == \"update\"' " . get_file(i) u (column(col_missing)+column(col_outdated) - column(col_regen)-column(col_updated)+stderrSum(column(col_sd_regen),column(col_sd_updated))) nooutput
    if (STATS_max > acc_upd_max) {acc_upd_max = STATS_max}
  }
  acc_reg_max=50.5
  acc_reg_min=49.5
  do for [i=1:plotCount] {
    stats "<awk '$" . col_ftype . " == \"regen\"' " . get_file(i) u (regenAcc(column(col_regen)+column(col_updated), column(col_missing)+column(col_outdated))+regenAccErr(column(col_sd_regen),column(col_sd_updated),(column(col_missing)+column(col_outdated)))):(regenAcc(column(col_regen)+column(col_updated), column(col_missing)+column(col_outdated))-regenAccErr(column(col_sd_regen),column(col_sd_updated),(column(col_missing)+column(col_outdated)))) nooutput
    if (STATS_min_y < acc_reg_min) {acc_reg_min = STATS_min_y}
    if (STATS_max_x > acc_reg_max) {acc_reg_max = STATS_max_x}
  }
  acc_reg_avg=(acc_reg_max+acc_reg_min)/2.0
  acc_reg_max=max(abs(acc_reg_avg-acc_reg_min), abs(acc_reg_max-acc_reg_avg))
} else {
  do for [i=1:plotCount] {
    stats "<awk '$" . col_ftype . " == \"update\" || $" . col_ftype . " == \"regen\"' " . get_file(i) u (column(col_missing)+column(col_outdated) - column(col_regen)-column(col_updated)+stderrSum(column(col_sd_regen),column(col_sd_updated))) nooutput
    if (STATS_max > acc_upd_max) {acc_upd_max = STATS_max}
  }
  acc_reg_max = acc_upd_max
}
if (acc_upd_max > 0.5) {acc_upd_max=acc_upd_max*1.05}
if (acc_reg_max > 0.5) {acc_reg_max=acc_reg_max*1.05}

red_max=0.5
do for [i=1:plotCount] {
  stats get_file(i) using (redundancy(column(col_bw_rs_kvv), column(col_updated), column(col_regen))+redundancyStderr(column(col_sd_bw_rs_kvv), column(col_sd_updated), column(col_sd_regen))) nooutput
  if (STATS_max > red_max) {red_max = STATS_max}
}
if (red_max > 0.5) {red_max=red_max*1.05}
if (red_max >= 1.5 && red_max < 2) {red_max=2}

bw_max=1
do for [i=1:plotCount] {
  stats get_file(i) using (kB(column(col_bw_rc_size)+column(col_bw_rc2_size)+stderrSum(column(col_sd_bw_rc_size), column(col_sd_bw_rc2_size)))) nooutput
  if (STATS_max > bw_max) {bw_max = STATS_max}
}
# is naive solution more expensive?
stats get_file(1) using (kB(column(col_dbsize)/4*(128+32)/8)) nooutput
if (STATS_max > bw_max) {bw_max = STATS_max}

key_width_fun(i) = min(-0.5, (6-strstrt(get_title(i), "_")) - (strlen(get_title(i)) - strstrt(get_title(i), "_")) * 0.15)
key_width = min(key_width_fun(1),key_width_fun(plotCount))
#print "key_width: ",key_width

# Solid Background
# set object 1 rect from screen 0, 0, 0 to screen 1, 1, 0 behind
# set object 1 rect fc  rgb "white"  fillstyle solid 1.0

# Style
if (plotCount == 1) {
  set style data yerrorlines
} else {
  set style data yerrorbars
}
set logscale x 2
set xrange [2:8192] # TODO: adapt if number of data points changes!
set grid layerdefault linetype 0 linewidth 1.000,  linetype 0 linewidth 1.000
set pointsize (plotCount == 4) ? 0.7 : (plotCount == 3) ? 0.8 : 1
arrow_dx=.166666666667 # grid spacing in x
arrow_di=0 # added to each i in loop - arrows drawn at (i+arrow_di)*arrow_dx
arrow_xpoints=6 # TODO: adapt if number of data points changes!

set style line 100 lw 2 lc -1 pt 0 lt 1

#--------------------------------- ALL
set boxwidth plot_boxwidth relative
set style fill solid 1 border -1
set xtics scale 0.1
set ytics scale 0.8
set grid noxtics nomxtics layerdefault linetype 0 linewidth 1.000,  linetype 0 linewidth 1.000
set for [i=1:arrow_xpoints] arrow from graph (i+arrow_di)*arrow_dx,graph 0 to graph (i+arrow_di)*arrow_dx,graph 1 nohead back linetype 0 linewidth 1.000

set o destDir. "all_" .filename. "." .fileEx
set multiplot

all_width_r = 0.545
all_width_l = all_width_r
bw_height_full = 0.700
bw_height = 0.023 + ((plotCount > 1) ? (bw_height_full - 0.018) : bw_height_full)
red_height = (plotCount > 1) ? 0.170 : 0.174
red_pos_y = (plotCount > 1) ? bw_height_full - 0.033 : bw_height_full - 0.035
acc_height_full = (plotCount > 1) ? 0.200 : 0.204
acc_height = (plotCount > 1) ? (acc_height_full - 0.012) : acc_height_full
acc_pos_y = (plotCount > 1) ? (red_pos_y + red_height - 0.007) : (red_pos_y + red_height - 0.025)

# accuracy

set size all_width_l,acc_height
set origin -0.002,acc_pos_y
unset xlabel
set format x ""
set ylabel "|Δ| missed " font ",16"
set yrange [0:acc_upd_max]
set format y " %2.1f"
if (plotCount > 1) {
  set key at screen 0.512,(acc_pos_y + 0.001) center center vertical Left reverse opaque enhanced autotitles nobox maxrows 1 width (key_width+1) samplen 1.75 font ",14" spacing 1.3
} else {
  set key top left horizontal Left reverse opaque enhanced autotitles box maxcols 1 width key_width samplen 1.5 font ",13"
}

plot for [i=1:plotCount] "<awk '$" . col_ftype . " == \"update\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(column(col_missing)+column(col_outdated) - column(col_regen)-column(col_updated)):(stderrSum(column(col_sd_regen),column(col_sd_updated))) t get_title(i) ls i

set origin 0.49,acc_pos_y
unset key
unset ylabel
unset ytics
set grid y2tics
set size all_width_r,acc_height
if (regenAccInPercent == 1) {
  set y2tics mirror format "%-2.0f_{ }%%" offset 0 scale 0.8
  set y2range [(acc_reg_avg-acc_reg_max):(acc_reg_avg+acc_reg_max)]
} else {
  set y2tics mirror format "%-1.1f " scale 0.8
  set y2range [0:acc_reg_max]
}

plot for [i=1:plotCount] "<awk '$" . col_ftype . " == \"regen\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(regenAcc(column(col_regen)+column(col_updated), column(col_missing)+column(col_outdated))):(regenAccErr(column(col_sd_regen),column(col_sd_updated),(column(col_missing)+column(col_outdated)))) axes x1y2 t get_title(i) ls (plotCount > 1 ? i : 2)

set ytics scale 0.8
unset y2tics
set grid noy2tics

# redundancy

set ytics autofreq
set size all_width_l,red_height
set origin -0.002,red_pos_y
if (absoluteRedundancy == 1) {
set ylabel "Red." font ",16" # transferred / updated
} else {
set ylabel "rel. Red." font ",16" # transferred / updated
}
set yrange [0:red_max]
set y2range [0:red_max]
if (red_max > 10) {
  set format y "  %1.0f"
  set format y2 "%-1.0f "
} else {
  set format y " %1.1f"
  set format y2 "%-1.1f "
}
unset key

plot for [i=1:plotCount] "<awk '$" . col_ftype . " == \"update\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(redundancy(column(col_bw_rs_kvv), column(col_updated), column(col_regen))) with boxes t get_title(i) ls i, \
     for [i=1:plotCount] "<awk '$" . col_ftype . " == \"update\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(redundancy(column(col_bw_rs_kvv), column(col_updated), column(col_regen))):(redundancyStderr(column(col_sd_bw_rs_kvv), column(col_sd_updated), column(col_sd_regen))) with yerrorbars notitle ls (plotCount > 1 ? (100+i) : 100)

set size all_width_r,red_height
set origin 0.49,red_pos_y
if (plotCount == 1) {
  set key bottom right horizontal Right noreverse opaque enhanced autotitles box maxcols 1 width key_width samplen 1.5 font ",13"
}
unset ylabel
unset ytics
set grid y2tics
set y2tics mirror scale 0.8

plot for [i=1:plotCount] "<awk '$" . col_ftype . " == \"regen\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(redundancy(column(col_bw_rs_kvv), column(col_updated), column(col_regen))) axes x1y2 with boxes t get_title(i) ls (plotCount > 1 ? i : 2), \
     for [i=1:plotCount] "<awk '$" . col_ftype . " == \"regen\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(redundancy(column(col_bw_rs_kvv), column(col_updated), column(col_regen))):(redundancyStderr(column(col_sd_bw_rs_kvv), column(col_sd_updated), column(col_sd_regen))) with yerrorbars notitle ls (plotCount > 1 ? (100+i) : 100)

set ytics scale 0.8
unset y2tics
set grid noy2tics

# bandwidth

set size all_width_l,bw_height
set origin -0.002,-0.025
set xlabel "n in 10^3, update" font ",16"
set ylabel "RC costs (phase 1+2) in KiB" font ",16"
set yrange [1:bw_max*1.2]
set y2range [1:bw_max*1.2]
set logscale y 2
set logscale y2 2
set format y "%4.0f"
set format x
if (plotCount > 1) {
  set key at screen 0.512,(red_pos_y + 0.0065) center center vertical Left reverse opaque enhanced autotitles nobox maxrows 1 width (key_width+1) samplen 1.75 font ",14" spacing 1.3
} else {
  set key top left horizontal Left reverse opaque enhanced autotitles box maxcols 1 width key_width samplen 1.5 font ",13"
}

LABEL = "naïve approach"
set label 10 at 22,112000*(128+32)/8/1024 LABEL front center font ",12" textcolor rgb "#777777"

plot for [i=1:plotCount] "<awk '$" . col_ftype . " == \"update\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(kB(column(col_bw_rc_size)+column(col_bw_rc2_size))) with boxes notitle ls i fs solid 0.4, \
     for [i=1:plotCount] "<awk '$" . col_ftype . " == \"update\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(kB(column(col_bw_rc_size))) with boxes t get_title(i) ls i, \
     for [i=1:plotCount] "<awk '$" . col_ftype . " == \"update\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(kB(column(col_bw_rc_size)+column(col_bw_rc2_size))):(kB(stderrSum(column(col_sd_bw_rc_size),column(col_sd_bw_rc2_size)))) with lines notitle ls (plotCount > 1 ? (100+i) : 100), \
     for [i=1:plotCount] "<awk '$" . col_ftype . " == \"update\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(kB(column(col_bw_rc_size)+column(col_bw_rc2_size))):(kB(stderrSum(column(col_sd_bw_rc_size),column(col_sd_bw_rc2_size)))) with yerrorbars notitle ls 100, \
     "<awk '$" . col_ftype . " == \"update\"' " . get_file(1) \
 u (plotShift(column(col_dbsize)/4/1000, 2)):(kB(column(col_dbsize)/4*(128+32)/8)) with linespoints notitle ls 5

set size all_width_r,bw_height
set origin 0.49,-0.025
set xlabel "n in 10^3, regen" font ",16"
unset key
unset ylabel
unset ytics
set grid y2tics
set y2tics mirror format "%-4.0f" scale 0.8

plot for [i=1:plotCount] "<awk '$" . col_ftype . " == \"regen\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(kB(column(col_bw_rc_size)+column(col_bw_rc2_size))) axes x1y2 with boxes notitle ls (plotCount > 1 ? i : 2) fs solid 0.4, \
     for [i=1:plotCount] "<awk '$" . col_ftype . " == \"regen\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(kB(column(col_bw_rc_size))) axes x1y2 with boxes t get_title(i) ls (plotCount > 1 ? i : 2), \
     for [i=1:plotCount] "<awk '$" . col_ftype . " == \"regen\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(kB(column(col_bw_rc_size)+column(col_bw_rc2_size))):(kB(stderrSum(column(col_sd_bw_rc_size),column(col_sd_bw_rc2_size)))) axes x1y2 with lines notitle ls (plotCount > 1 ? (100+i) : 100), \
     for [i=1:plotCount] "<awk '$" . col_ftype . " == \"regen\"' " . get_file(i) \
 u (plotShift(column(col_dbsize)/4/1000, i)):(kB(column(col_bw_rc_size)+column(col_bw_rc2_size))):(kB(stderrSum(column(col_sd_bw_rc_size),column(col_sd_bw_rc2_size)))) axes x1y2 with yerrorbars notitle ls 100, \
     "<awk '$" . col_ftype . " == \"update\"' " . get_file(1) \
 u (plotShift(column(col_dbsize)/4/1000, 2)):(kB(column(col_dbsize)/4*(128+32)/8)) with linespoints notitle ls 5


wrong plot was checked in

wrong plot was checked in

git-svn-id: 0ef30dc7da0b07cedfa074587325a6c153c0ae55@11541 fdbf22ae-c210-0410-be80-ca943da6b8f8


plotting changes

plotting changes

if (!exists("datafile")) datafile='tripDistances.data'
set terminal pdf
set output 'out.pdf'
set key off
set boxwidth 0.8 absolute
set xrange [-0.5:35]
set style fill solid 0.5
set xlabel "Distance in kilometers"
set ylabel "Number of trips"
bin(x) = floor(x+0.5)
set table 'foobar.table'
plot datafile using (bin($1)):(1) smooth frequency with boxes

if (!exists("datafile")) datafile='tripDistances.data'
set key off
set boxwidth 0.9 absolute
set yrange [1:20]
#set logscale y
set style fill solid 0.25 noborder
set xlabel "Distance in kilometers"
set ylabel "Number of trips"
bin(x) = floor((x/100)+0.5)
plot datafile using (bin($1)):(1) smooth frequency with boxes


slight difference in label at lower left, flowline plot

git-svn-id: 0ef30dc7da0b07cedfa074587325a6c153c0ae55@12934 fdbf22ae-c210-0410-be80-ca943da6b8f8


[kernel] improve gnuplot file

[kernel] improve gnuplot file

#set  term X11
resultfile_ref = 'resultNETS.ref'
resultfile = 'resultNETS-WITHPROJ.ref'
resultfile = 'result.dat'
plot \
resultfile every ::2 u 1:2 t "Ball position" w l,\
resultfile every ::2 u 1:3 t "Ball Velocity" w l,\
resultfile every ::2 u 1:4 t "Reaction force" w l,\
resultfile_ref every ::2 u 1:2 t "Ball position" w l,\
resultfile_ref every ::2 u 1:3 t "Ball Velocity" w l,\
resultfile_ref every ::2 u 1:4 t "Reaction force" w l

#set  term X11
resultfile = 'resultNETS.ref'
resultfile = 'resultNETS-WITHPROJ.ref'
resultfile = 'result.dat'
plot \
resultfile every ::2 u 1:2 t "Ball position" w l,\
resultfile every ::2 u 1:3 t "Ball Velocity" w l,\
resultfile every ::2 u 1:4 t "Reaction force" w l


only add the -Wno-invalid-offsetof for gcc 3.4

git-svn-id: 88467cb1fb04b8a755be7e1ee1026be4190196ef@350 3a8e244f-b0f2-452b-bcba-4c88e055c3ca

#
# settings for gnu-compatible platforms
#

#
# Tools
#
CC = g++

#
# Flags
#

CFLAGS += -Wall

GNU_GCC_MAJOR_VERSION = $(shell $(CC) -dumpversion | awk '{split($$1,a,"."); printf("%s", a[1]);}')
GNU_GCC_MINOR_VERSION = $(shell $(CC) -dumpversion | awk '{split($$1,a,"."); printf("%s", a[2]);}')

ifeq ($(GNU_GCC_MAJOR_VERSION),3)
ifeq ($(GNU_GCC_MINOR_VERSION),4)
CFLAGS += -Wno-invalid-offsetof
endif
endif

ifdef DEBUG
CFLAGS += -g -DDEBUG=1
else
CFLAGS += -DNDEBUG=1
endif

ifdef OPTIMIZE
CFLAGS += -O2
endif

ifdef PROFILE
CFLAGS += -pg
LDFLAGS += -pg
endif

#
# settings for gnu-compatible platforms
#

#
# Tools
#
CC = g++

#
# Flags
#

CFLAGS += -Wall -Wno-invalid-offsetof

ifdef DEBUG
CFLAGS += -g -DDEBUG=1
else
CFLAGS += -DNDEBUG=1
endif

ifdef OPTIMIZE
CFLAGS += -O2
endif

ifdef PROFILE
CFLAGS += -pg
LDFLAGS += -pg
endif


Reset ranges to automatic mode:

Reset ranges to automatic mode:

The scripts sets the ranges from 0 to 4096. Resetting this values will
avoid confusion at subsequent plotting.

# File:		sreels_fit.plt
# Author:	Michael Entrup
# Version:	1.0.1
# Date:		28.07.2014

# Info:		This script is part of the Gnuplot_sreels package. The package is used to process the data that has been created by https://github.com/EFTEMj/EFTEMj/blob/master/Scripts%2BMacros/SR-EELS_char2acterisation.ijm.

#########################
#	Setup				#
#########################

if (!exists('path')) {
	print ''
	Print 'Please run "sreels_init" first.'
	print ''
}

# Order of the polynomial of the pseudo3D fit:
m = 2	# polynomial along the energy axis
n = 2	# polynomial that describes the variation of the parameters of the polynomial

# Order of the polynomial of the 3D fit:
k = 2	# polynomial along the energy axis
l = 2	# polynomial along the lateral axis

if (strstrt(GPVAL_PWD, "/")) {
	# Unix
	system 'mkdir '.path.'parameters'
} else {
	# Windows
	system 'md '.path_win.'parameters'
}

set xrange[0:4096]
set yrange[0:4096]
set zrange[0:4096]

#########################
#	Fit - 2D			#
#########################

# ToDo: Change the implementation of the 2D-Fit to use polynomials of arbitrary order.

# We can create a function that can be used to create an arbitrary number of functions. In this case the first line will create one function per input file and per position (top, center, bottom). The command eval() is essential for this approach. A function creates a string that depends on indexes and eval will run the command that is represented by the string.
f_str(N, S1, S2) = sprintf('%s%d(x) = %s', S1, N, S2)
fit_str(N, S1, S2) = sprintf('fit %s%d(x) filename_%s(%d) via %s', S1, N, S1, N, S2)

do for [i=index_start:index_stop:index_inc] {
	do for [str in "T C B"] {
		str_f_it = ''
		str_via = ''
		do for [j=0:m] {
			str_f_it = str_f_it.sprintf(' + a%d%s%d*x**%d', j, str, i, j)
			str_via = str_via.sprintf(',a%d%s%d', j, str, i)
		}
		str_f_it = substr(str_f_it, 4, strlen(str_f_it))
		str_via = substr(str_via, 2, strlen(str_via))
		eval(f_str(i, str, str_f_it))
		eval(fit_str(i, str, str_via))
	}
}

do for [i=index_start:index_stop:index_inc] {
	do for [str in "T C B"] {
		# We want to overwrite the old file, that is why we don't use the option 'append' for the first line.
		set print path.'parameters/'.str.i.'.txt'
		print '# This file contains the parameters for a polynomial "y(x) = a0*x**0 + a1*x**1 + .. + am*x**m". with m='.m
		set print path.'parameters/'.str.i.'.txt' append
		do for [j=0:m] {
			# "parameter = value('parameter')"
			print sprintf('a%d%s%d = %e', j, str, i, value('a'.j.str.i))
		}
	}
}
unset print

#########################
#	Fit - pseudo3D			#
#########################

# We don't want to show a plot or write to a file until the last call of 'replot'.
set terminal unknown

# As we only use 'replot' at a FOR-loop, we have to create an empty graph first.
splot NaN

plot_str_pseudo3D(N, S) = sprintf('replot filename_%s(%d) using ($1):(%s%d(2048)):($2) with points', S, N, S, N)
do for [i=index_start:index_stop:index_inc] {
	do for [str in "T C B"] {
		eval(plot_str_pseudo3D(i, str))
	}
}

# Now we set the table, we want to write to.
set table filename_pseudo3D
replot
unset table
set terminal wxt

str_f_it = ''
str_via =''
do for  [i=0:m] {
	do for [j=0:n] {
		str_f_it = str_f_it.sprintf(' + a%d%d*x**%d*y**%d', i, j, i, j)
		str_via = str_via.sprintf(',a%d%d',i,j)
		eval(sprintf('a%d%d = %e', i, j, 100.0**(-i-j)))
	}
}
str_f_it = substr(str_f_it, 4, strlen(str_f_it))
str_via = substr(str_via, 2, strlen(str_via))
eval('f(x,y)='.str_f_it)
# Using a fourth column for the weight is necessary. Even a constant value of 1 will do.
eval('fit f(x,y) filename_pseudo3D using 1:2:(strcol(4) eq "u"?1/0:$3):(1) via '.str_via)

set print path.'parameters/pseudo3D.txt'
print '# This file contains the parameters for "z(x,y) = "'.str_f_it.'.'
set print path.'parameters/pseudo3D.txt' append
do for  [i=0:m] {
	do for [j=0:n] {
		# "parameter = value('parameter')"
		print sprintf('a%d%d = %e', i, j ,value(sprintf('a%d%d', i, j)))
	}
}
# We will print the same values to a file that is used as input for EFTEMj. We will append more values at the section "Fit - 3D".
set print path.'parameters/EFTEMj_input.txt'
print '# This file is used as input for the SR-EELS correction of EFTEMj.'
set print path.'parameters/EFTEMj_input.txt' append
do for  [i=0:m] {
	do for [j=0:n] {
		# "parameter = value('parameter')"
		print sprintf('a%d%d = %e', i, j ,value(sprintf('a%d%d', i, j)))
	}
}
unset print

#########################
#	Fit	- 3D			#
#########################

str_f2_it = ''
str_via2 =''
do for  [i=0:k] {
	do for [j=0:l] {
		str_f2_it = str_f2_it.sprintf(' + b%d%d*x**%d*y**%d', i, j, i, j)
		str_via2 = str_via2.sprintf(',b%d%d',i,j)
		eval(sprintf('b%d%d = %e', i, j, 100.0**(-i-j)))
	}
}
str_f2_it = substr(str_f2_it, 4, strlen(str_f2_it))
str_via2 = substr(str_via2, 2, strlen(str_via2))
eval('f2(x,y)='.str_f2_it)
# Using a fourth column for the weight is necessary. Even a constant value of 1 will do.
eval('fit f2(x,y) filename_3D using 1:2:3:(1) via '.str_via2)

set print path.'parameters/3D.txt'
print '# This file contains the parameters for "z(x,y) = "'.str_f2_it.'.'
set print path.'parameters/3D.txt' append
do for  [i=0:k] {
	do for [j=0:l] {
		# "parameter = value('parameter')"
		print sprintf('b%d%d = %e', i, j ,value(sprintf('b%d%d', i, j)))
	}
}
set print path.'parameters/EFTEMj_input.txt' append
do for  [i=0:k] {
	do for [j=0:l] {
		# "parameter = value('parameter')"
		print sprintf('b%d%d = %e', i, j ,value(sprintf('b%d%d', i, j)))
	}
}
unset print
set xrange[*:*]
set yrange[*:*]
set zrange[*:*]


Fix aducrf101 builds with GCC 4.9+

Fix aducrf101 builds with GCC 4.9+

Mixing LTO and libraries requires the use of gcc-ar instead of ar.
See https://gcc.gnu.org/wiki/LinkTimeOptimizationFAQ?action=recall&rev=5#ar.2C_nm_and_ranlib

# -*- makefile -*-

# Copyright (c) 2014, Analog Devices, Inc.  All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted (subject to the limitations in the
# disclaimer below) provided that the following conditions are met:
#
# - Redistributions of source code must retain the above copyright
#   notice, this list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright
#   notice, this list of conditions and the following disclaimer in the
#   documentation and/or other materials provided with the
#   distribution.
#
# - Neither the name of Analog Devices, Inc. nor the names of its
#   contributors may be used to endorse or promote products derived
#   from this software without specific prior written permission.
#
# NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
# GRANTED BY THIS LICENSE.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
# HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Author: Jim Paris <jim.paris@rigado.com>

CROSS_COMPILE = arm-none-eabi-

CC      = $(CROSS_COMPILE)gcc
LD      = $(CROSS_COMPILE)gcc
AS      = $(CROSS_COMPILE)gcc
AR      = $(CROSS_COMPILE)gcc-ar
NM      = $(CROSS_COMPILE)gcc-nm
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
STRIP   = $(CROSS_COMPILE)strip

CFLAGS_OPT ?= -Os
CFLAGS_DEBUG ?= -ggdb3 -fomit-frame-pointer
CFLAGS += $(CFLAGS_OPT) $(CFLAGS_DEBUG)
CFLAGS += -std=gnu99
CFLAGS += -ffreestanding -mcpu=cortex-m3 -mthumb -mno-thumb-interwork
CFLAGS += -ffunction-sections -fdata-sections -fno-common -fno-builtin
CFLAGS += -flto

ifdef WERROR
  CFLAGS += -Wall -Werror
  # These warnings are triggered by existing Contiki code
  CFLAGS += -Wno-error=pointer-sign
  CFLAGS += -Wno-error=char-subscripts
  CFLAGS += -Wno-error=unused-variable
  CFLAGS += -Wno-error=unused-but-set-variable
endif

# UIP code does not follow C aliasing rules
CFLAGS += -fno-strict-aliasing

LDFLAGS  = $(CFLAGS)
LDFLAGS += -specs=nosys.specs -nostartfiles

# TODO: When it becomes more commonly available, switch to newlib-nano
# for significant size reduction, by uncommenting this:
# LDFLAGS += -specs=nano.specs

LDFLAGS += -Wl,--gc-sections
LDFLAGS += -Wl,-T$(CONTIKI_CPU)/Common/GCC/ADuCRF101.ld

ASFLAGS += -c $(CFLAGS)

# Compiler-specific startup code
CONTIKI_CPU_DIRS += Common/GCC
CONTIKI_SOURCEFILES += crt0.S

# Rules
%.hex: %
	$(OBJCOPY) -O ihex $^ $@

# -*- makefile -*-

# Copyright (c) 2014, Analog Devices, Inc.  All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted (subject to the limitations in the
# disclaimer below) provided that the following conditions are met:
#
# - Redistributions of source code must retain the above copyright
#   notice, this list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright
#   notice, this list of conditions and the following disclaimer in the
#   documentation and/or other materials provided with the
#   distribution.
#
# - Neither the name of Analog Devices, Inc. nor the names of its
#   contributors may be used to endorse or promote products derived
#   from this software without specific prior written permission.
#
# NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
# GRANTED BY THIS LICENSE.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
# HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Author: Jim Paris <jim.paris@rigado.com>

CROSS_COMPILE = arm-none-eabi-

CC      = $(CROSS_COMPILE)gcc
LD      = $(CROSS_COMPILE)gcc
AS      = $(CROSS_COMPILE)gcc
AR      = $(CROSS_COMPILE)ar
NM      = $(CROSS_COMPILE)nm
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
STRIP   = $(CROSS_COMPILE)strip

CFLAGS_OPT ?= -Os
CFLAGS_DEBUG ?= -ggdb3 -fomit-frame-pointer
CFLAGS += $(CFLAGS_OPT) $(CFLAGS_DEBUG)
CFLAGS += -std=gnu99
CFLAGS += -ffreestanding -mcpu=cortex-m3 -mthumb -mno-thumb-interwork
CFLAGS += -ffunction-sections -fdata-sections -fno-common -fno-builtin
CFLAGS += -flto

ifdef WERROR
  CFLAGS += -Wall -Werror
  # These warnings are triggered by existing Contiki code
  CFLAGS += -Wno-error=pointer-sign
  CFLAGS += -Wno-error=char-subscripts
  CFLAGS += -Wno-error=unused-variable
  CFLAGS += -Wno-error=unused-but-set-variable
endif

# UIP code does not follow C aliasing rules
CFLAGS += -fno-strict-aliasing

LDFLAGS  = $(CFLAGS)
LDFLAGS += -specs=nosys.specs -nostartfiles

# TODO: When it becomes more commonly available, switch to newlib-nano
# for significant size reduction, by uncommenting this:
# LDFLAGS += -specs=nano.specs

LDFLAGS += -Wl,--gc-sections
LDFLAGS += -Wl,-T$(CONTIKI_CPU)/Common/GCC/ADuCRF101.ld

ASFLAGS += -c $(CFLAGS)

# Compiler-specific startup code
CONTIKI_CPU_DIRS += Common/GCC
CONTIKI_SOURCEFILES += crt0.S

# Rules
%.hex: %
	$(OBJCOPY) -O ihex $^ $@


Update plot.

Update plot.

# Note you need gnuplot 4.4 for the pdfcairo terminal.

# set terminal pdfcairo font "Gill Sans,9" linewidth 4 rounded fontscale 1.0
set terminal pdfcairo font "Gill Sans,7" linewidth 1 rounded fontscale 1.0

# Line style for axes
set style line 80 lt rgb "#808080"

# Line style for grid
set style line 81 lt 0  # dashed
set style line 81 lt rgb "#808080"  # grey

set grid back linestyle 81
set border 3 back linestyle 80 # Remove border on top and right.  These
             # borders are useless and make it harder
             # to see plotted lines near the border.
    # Also, put it in grey; no need for so much emphasis on a border.
# set xtics nomirror
# set ytics nomirror

#set log x
#set mxtics 10    # Makes logscale look good.

# Line styles: try to pick pleasing colors, rather
# than strictly primary colors or hard-to-see colors
# like gnuplot's default yellow.  Make the lines thick
# so they're easy to see in small plots in papers.
set style line 1 lt rgb "#A00000" lw 2 pt 1
# set style line 2 lt rgb "#00A000" lw 2 pt 6
# set style line 3 lt rgb "#5060D0" lw 2 pt 2
# set style line 4 lt rgb "#F25900" lw 2 pt 9

set output outputname
set xlabel "Time in Seconds"
set ylabel "MB/client Transmitted"

set key bottom right

set datafile missing '0'

# log scale on the y axis
set logscale y 2
# set format y ""
# set ytics 1e-6, 10, 1
# set ytics add ("1" 1, ".1" 0.1, ".01" 0.01, "10^-3" 0.001, \
#                "10^-4" 0.0001)
# set mytics 10

# set xrange [0:60]
# set yrange [0.5:64]

# Input file contains comma-separated values fields
set datafile separator ","

plot inputfile1 using 1:3 title "OR-Set, G-Counter" with linespoints, \
     inputfile2 using 1:3 title "OR-Set, G-Counter, Deltas" with linespoints

# Note you need gnuplot 4.4 for the pdfcairo terminal.

# set terminal pdfcairo font "Gill Sans,9" linewidth 4 rounded fontscale 1.0
set terminal pdfcairo font "Gill Sans,9" linewidth 2 rounded fontscale 1.0

# Line style for axes
set style line 80 lt rgb "#808080"

# Line style for grid
set style line 81 lt 0  # dashed
set style line 81 lt rgb "#808080"  # grey

set grid back linestyle 81
set border 3 back linestyle 80 # Remove border on top and right.  These
             # borders are useless and make it harder
             # to see plotted lines near the border.
    # Also, put it in grey; no need for so much emphasis on a border.
# set xtics nomirror
# set ytics nomirror

#set log x
#set mxtics 10    # Makes logscale look good.

# Line styles: try to pick pleasing colors, rather
# than strictly primary colors or hard-to-see colors
# like gnuplot's default yellow.  Make the lines thick
# so they're easy to see in small plots in papers.
set style line 1 lt rgb "#A00000" lw 2 pt 1
# set style line 2 lt rgb "#00A000" lw 2 pt 6
# set style line 3 lt rgb "#5060D0" lw 2 pt 2
# set style line 4 lt rgb "#F25900" lw 2 pt 9

set output outputname
set xlabel "Time in Seconds"
set ylabel "MB/client Transmitted"

set key top left

set datafile missing '0'

# log scale on the y axis
# set logscale y 2
# set format y ""
# set ytics 1e-6, 10, 1
# set ytics add ("1" 1, ".1" 0.1, ".01" 0.01, "10^-3" 0.001, \
#                "10^-4" 0.0001)
# set mytics 10

# set xrange [0:60]
# set yrange [0.5:64]

# Input file contains comma-separated values fields
set datafile separator ","

plot inputfile1 using 1:3 title "OR-Set, G-Counter" with linespoints, \
     inputfile2 using 1:3 title "OR-Set, G-Counter, Deltas" with linespoints


Fix ur_option UTs

Fix ur_option UTs

:- use_module(ur_option).
:- use_module(u(v)).

:- begin_tests(ur_option, [setup(setup_options)]).

test(single_option_nonrep, [setup(setup_options)]) :-

   options_object(test_pred1, [height(-1), length(3)], Obj),
   assertion(Obj / length =^= length(3)),
   assertion(Obj / height =^= height(-1)).

test(single_option_unknown,
     [error(domain_error(valid_option, Option), _)]) :-

   Option = width(3),
   options_object(test_pred1, [Option], _).

test(single_option_no_default, [setup(setup_options)]) :-

   options_object(test_pred1, [], Obj),
   Obj / length ^= Length,
   assertion(Length =@= _).

test(single_option_default, [setup(setup_options)]) :-

   options_object(test_pred3, [], Obj),
   assertion(Obj / length =^= length(4)).

test(single_option_default_overriden, [setup(setup_options)]) :-

   options_object(test_pred3, [length(3)], Obj),
   assertion(Obj / length =^= length(3)).

test(single_option_rep1,
     [error(domain_error(consistent_options, Options),
            _)]) :-

   Options = [length(3), length(_)],
   options_object(test_pred1, Options, Obj),
   assertion(Obj / length =^= length(3)).

test(single_option_rep2,
     [error(domain_error(nonrepeating_options, Options),
            _)]) :-

   Options = [length(3), length(3)],
   options_object(test_pred1, Options, Obj),
   assertion(Obj / length =^= length(3)).

test(single_option_rep3,
     [error(domain_error(consistent_options, Options),
            _)]) :-

   Options = [length(3), length(4)],
   options_object(test_pred1, Options, Obj),
   assertion(Obj / length =^= length(3)).

test(single_option_meta1) :-

   options_object(test_pred2, [generator(test_pred1)],
                  Obj),
   context_module(That),
   assertion(Obj / generator
            =^= generator(That:test_pred1)).

test(single_option_meta2) :-

   options_object(test_pred2, [generator(dummy:test_pred1)],
                  Obj),
   assertion(Obj / generator
            =^= generator(dummy:test_pred1)).

test(single_option_meta3) :-

   options_object(test_pred1, [length(_:test_pred1)],
                  Obj),
   assertion(Obj / length =^= length(_:test_pred1)).

test(single_option_bad_default1,
     [error(invalid_option_definition(Rule), _)]) :-

   Rule = [meta_option(length/1), default(len(3))],
   ur_options(test_pred4, [Rule]).

test(single_option_bad_default1,
     [error(invalid_option_definition(Rule), _)]) :-

   Rule = [option(length/1), default(length(3, 4))],
   ur_options(test_pred5, [Rule]).

test(single_option_repeated1, [fail]) :-

   ur_options(test_pred6, [[option(length/1)],
                           [option(width/1)],
                           [option(length/1)]]).

test(single_option_repeated2, [fail]) :-

   ur_options(test_pred7, [[option(length/1)],
                           [option(width/1)],
                           [option(length/3)]]).

setup_options :-

   current_prolog_flag(verbose, Old_Verbose),
   set_prolog_flag(verbose, silent),
   reload_all_classes,
   set_prolog_flag(verbose, Old_Verbose),

   ur_options(test_pred1, [[option(length/1)], [option(height/1)]]),
   ur_options(test_pred2, [[meta_option(generator/1)]]),
   ur_options(test_pred3, [[option(length/1), default(length(4))]]).

test_pred1(_).
test_pred2(_).
test_pred3(_).
test_pred4(_).
test_pred5(_).
test_pred6(_).
test_pred7(_).

:- end_tests(ur_option).

:- use_module(ur_option).
:- use_module(u(v)).

:- begin_tests(ur_option, [setup(setup_options)]).

test(single_option_nonrep, [setup(setup_options)]) :-

   options_object(test_pred1, [width(-1), length(3)], Obj),
   assertion(Obj / length =^= length(3)),
   assertion(Obj / width =^= width(-1)),

test(single_option_unknown,
     [error(domain_error(valid_option, Option), _)]) :-

   Option = width(3),
   options_object(test_pred1, [Option], _).

test(single_option_no_default, [setup(setup_options)]) :-

   options_object(test_pred1, [], Obj),
   Obj / length ^= Length,
   assertion(Length =@= _).

test(single_option_default, [setup(setup_options)]) :-

   options_object(test_pred3, [], Obj),
   assertion(Obj / length =^= length(4)).

test(single_option_default_overriden, [setup(setup_options)]) :-

   options_object(test_pred3, [length(3)], Obj),
   assertion(Obj / length =^= length(3)).

test(single_option_rep1,
     [error(domain_error(consistent_options, Options),
            _)]) :-

   Options = [length(3), length(_)],
   options_object(test_pred1, Options, Obj),
   assertion(Obj / length =^= length(3)).

test(single_option_rep2,
     [error(domain_error(nonrepeating_options, Options),
            _)]) :-

   Options = [length(3), length(3)],
   options_object(test_pred1, Options, Obj),
   assertion(Obj / length =^= length(3)).

test(single_option_rep3,
     [error(domain_error(consistent_options, Options),
            _)]) :-

   Options = [length(3), length(4)],
   options_object(test_pred1, Options, Obj),
   assertion(Obj / length =^= length(3)).

test(single_option_meta1) :-

   options_object(test_pred2, [generator(test_pred1)],
                  Obj),
   context_module(That),
   assertion(Obj / generator
            =^= generator(That:test_pred1)).

test(single_option_meta2) :-

   options_object(test_pred2, [generator(dummy:test_pred1)],
                  Obj),
   assertion(Obj / generator
            =^= generator(dummy:test_pred1)).

test(single_option_meta3) :-

   options_object(test_pred1, [length(_:test_pred1)],
                  Obj),
   assertion(Obj / length =^= length(_:test_pred1)).

test(single_option_bad_default1,
     [error(invalid_option_definition(Rule), _)]) :-

   Rule = [meta_option(length/1), default(len(3))],
   ur_options(test_pred4, [Rule]).

test(single_option_bad_default1,
     [error(invalid_option_definition(Rule), _)]) :-

   Rule = [option(length/1), default(length(3, 4))],
   ur_options(test_pred5, [Rule]).

test(single_option_repeated1, [fail]) :-

   ur_options(test_pred6, [[option(length/1)],
                           [option(width/1)],
                           [option(length/1)]]).

test(single_option_repeated2, [fail]) :-

   ur_options(test_pred7, [[option(length/1)],
                           [option(width/1)],
                           [option(length/3)]]).

setup_options :-

   current_prolog_flag(verbose, Old_Verbose),
   set_prolog_flag(verbose, silent),
   reload_all_classes,
   set_prolog_flag(verbose, Old_Verbose),

   ur_options(test_pred1, [[option(length/1)], [option(width/1)]]),
   ur_options(test_pred2, [[meta_option(generator/1)]]),
   ur_options(test_pred3, [[option(length/1), default(length(4))]]).

test_pred1(_).
test_pred2(_).
test_pred3(_).
test_pred4(_).
test_pred5(_).
test_pred6(_).
test_pred7(_).

:- end_tests(ur_option).


More UTs

More UTs

:- begin_tests(v).
:- use_module(u(v)).

test(obj_rebase_bug1) :-

   obj_construct(man_v, [sex, name], [man, 'Adam'], Obj1_0),
   obj_rebase((object_v -> db_object_v), Obj1_0, Obj1),

   obj_construct(man_v, [sex, name], [man, 'Adam'], Obj2_0),
   obj_rebase((object_v -> db_object_v), Obj2_0, Obj2),

   arg(1, Obj1, Class_Id1),
   arg(1, Obj2, Class_Id2),

   assertion(Class_Id1 =:= Class_Id2),

   obj_rebase((db_object_v -> object_v), Obj2, Obj3),

   arg(1, Obj2_0, Class_Id0),
   arg(1, Obj3, Class_Id3),
   assertion(Class_Id0 =:= Class_Id3),
   assertion(Obj2_0 == Obj3).

test(obj_construct_bug1) :-

   class_fields(man_v, Field_Names),
   obj_construct(man_v, Field_Names, Field_Names, Obj),
   Obj =.. [man_v, _|Field_Names2],

   assertion(Field_Names == Field_Names2).

:- end_tests(v).

:- begin_tests(v).
:- use_module(u(v)).

test(obj_rebase_bug1) :-

   obj_construct(man_v, [sex, name], [man, 'Adam'], Obj1_0),
   obj_rebase((object_v -> db_object_v), Obj1_0, Obj1),

   obj_construct(man_v, [sex, name], [man, 'Adam'], Obj2_0),
   obj_rebase((object_v -> db_object_v), Obj2_0, Obj2),

   arg(1, Obj1, Class_Id1),
   arg(1, Obj2, Class_Id2),

   assertion(Class_Id1 =:= Class_Id2).

test(obj_construct_bug1) :-

   class_fields(man_v, Field_Names),
   obj_construct(man_v, Field_Names, Field_Names, Obj),
   Obj =.. [man_v, _|Field_Names2],

   assertion(Field_Names == Field_Names2).

:- end_tests(v).


tools/fix: Fix latency frequency plot scaling

We're so fast now that the generated latency graph is almost useless as
it groups all the latency observations under one 10 microsecond bar.

Fix that up.

Signed-off-by: Pekka Enberg <add4fcd06328a394f0ad91feda7ee057316dc5ed@iki.fi>

reset

set terminal unknown

plot file

set terminal svg size 600, 460 fname 'Verdana' fsize 10
set output "histogram.svg"

set xrange [0:]
set yrange [0:]

unset xtics
set xtics 0, 5
set xtics font ",8"
set ytics font ",8"

set xlabel "RTT (μs)"
set ylabel "Frequency"
set xlabel font ",8"
set ylabel font ",8"

plot file using ($1):(1.0) smooth freq w boxes lc rgb "blue" notitle

reset

set terminal unknown

plot file
xmin = GPVAL_DATA_Y_MIN
xmax = GPVAL_DATA_Y_MAX

round(x, width) = width * floor(x / width) + width / 2.0

set terminal svg size 600, 460 fname 'Verdana' fsize 10
set output "histogram.svg"

xmax = max > 0 ? max : xmax

set xrange [xmin:xmax]
set yrange [0:]

unset xtics
set xtics font ",8"
set ytics font ",8"

set xlabel "RTT (μs)"
set ylabel "Frequency"
set xlabel font ",8"
set ylabel font ",8"

plot file using (round($1, width)):(1.0) smooth freq w boxes lc rgb "blue" notitle


Plots fill now.

Plots fill now.

# BBN ratios plotter
mpl_top    = 0.4 #inch  outer top margin, title goes here
mpl_bot    = 0.7 #inch  outer bottom margin, x label goes here
mpl_left   = 0.8 #inch  outer left margin, y label goes here
mpl_right  = 0.1 #inch  outer right margin, y2 label goes here
mpl_height = 2.0 #inch  height of individual plots
mpl_width  = 3.0 #inch  width of individual plots
mpl_dx     = 0.3 #inch  inter-plot horizontal spacing
mpl_dy     = 0.3 #inch  inter-plot vertical spacing
mpl_ny     = 3   #number of rows
mpl_nx     = 1   #number of columns

# calculate full dimensions
xsize = mpl_left+mpl_right+(mpl_width*mpl_nx)+(mpl_nx-1)*mpl_dx
ysize = mpl_top+mpl_bot+(mpl_ny*mpl_height)+(mpl_ny-1)*mpl_dy

# placement functions
#   rows are numbered from bottom to top
bot(n) = (mpl_bot+(n-1)*mpl_height+(n-1)*mpl_dy)/ysize
top(n)  = 1-((mpl_top+(mpl_ny-n)*(mpl_height+mpl_dy))/ysize)
#   columns are numbered from left to right
left(n) = (mpl_left+(n-1)*mpl_width+(n-1)*mpl_dx)/xsize
right(n)  = 1-((mpl_right+(mpl_nx-n)*(mpl_width+mpl_dx))/xsize)

#set terminal latex
set terminal postscript eps enhanced color dl 2.0 size xsize,ysize "Helvetica" 14
set encoding iso_8859_1
set tics scale 1.5

set output 'bbn-fierz.eps'

set offsets
set autoscale fix
set size 1,1
set nokey

# define x-axis settings for all subplots
set xrange [ -0.2 : 0.2  ] noreverse nowriteback
#set xrange [-4:4]
set xlabel 'Fierz b'
#set format x ''
set xtics 1
set mxtics 10

# start plotting
set multiplot

#-----------------------------------------------
# Yp
# subplot  1-3
#  set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
#  set horizontal margins for third row (top)
set tmargin at screen top(3)
set bmargin at screen bot(3)

set title 'BBN from Fierz'
set xlabel ''

set yrange [ 0.22 : 0.27 ] noreverse nowriteback

set ylabel "Yp"
set format y "%1.2f"
#set ytics mirror 1
#set ytics 10
set mytics 5

plot 'fierz-study.dat' u 1:3:2 "%lf %lf %lf" w filledcu, \
      '' u 1:3 lt -1 notitle, '' u 1:2 lt -1 notitle;
# 'fierz-study.dat' u 1:6:7 "%lf %lf %lf" w filledcu, \
#      '' u 1:6 lt -1 notitle, '' u 1:7 lt -1 notitle, \
# 'fierz-study.dat' u 1:8:9 "%lf %lf %lf" w filledcu, \
#      '' u 1:8 lt -1 notitle, '' u 1:9 lt -1 notitle, \
# 'fierz-study.dat' u 1:10:11 "%lf %lf %lf" w filledcu, \
#      '' u 1:10 lt -1 notitle, '' u 1:11 lt -1 notitle, \
# 'fierz-study.dat' u 1:12:13 "%lf %lf %lf" w filledcu, \
#      '' u 1:12 lt -1 notitle, '' u 1:13 lt -1 notitle \
#;

#-----------------------------------------------
# D/H and He3/H
# subplot  1-2
#  set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
#  set horizontal margins for third row (top)
set tmargin at screen top(2)
set bmargin at screen bot(2)

set title ''
set xlabel ''

set yrange [ 1e-6 : 1e-4 ] noreverse nowriteback
set logscale y 10

set ylabel "He3/H\t\t\tD/H"
set format y "%1.e"
set mytics 10

plot 'fierz-study.dat' using 1:5:4 with filledcurves;
#      '' u 1:5 lt 1 notitle, '' u 1:4 lt 1 notitle;
plot 'fierz-study.dat' using 1:6:7 with filledcurves;
#      '' u 1:7 lt 2 notitle, '' u 1:6 lt 2 notitle;
#plot 'fierz-study.dat' u 1:8:9 "%lf %lf %lf" w filledcu, \
#      '' u 1:8 lt -1 notitle, '' u 1:9 lt -1 notitle;
# 'fierz-study.dat' u 1:10:11 "%lf %lf %lf" w filledcu, \
#      '' u 1:10 lt -1 notitle, '' u 1:11 lt -1 notitle, \
# 'fierz-study.dat' u 1:12:13 "%lf %lf %lf" w filledcu, \
#      '' u 1:12 lt -1 notitle, '' u 1:13 lt -1 notitle \
#;

#-----------------------------------------------
# Li7/H
# subplot  1-1
#  set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
#  set horizontal margins for third row (top)
set tmargin at screen top(1)
set bmargin at screen bot(1)

set title ''
set xlabel 'Fierz b'

set yrange [ 1e-10 : 1e-9 ] noreverse nowriteback
set logscale y 10

set ylabel "Li7/H"
set format y "%1.e"
#set ytics mirror 1
#set ytics 1
set mytics 10

plot 'fierz-study.dat' using 1:8:9 with filledcurves;
#      '' u 1:8 lt -1 notitle, '' u 1:9 lt -1 notitle;
#plot 'fierz-study.dat' u 1:10:11 "%lf %lf %lf" w filledcu, \
#      '' u 1:10 lt -1 notitle, '' u 1:11 lt -1 notitle;
# 'fierz-study.dat' u 1:12:13 "%lf %lf %lf" w filledcu, \
#      '' u 1:12 lt -1 notitle, '' u 1:13 lt -1 notitle \
#;

unset multiplot;

# BBN ratios plotter
mpl_top    = 0.4 #inch  outer top margin, title goes here
mpl_bot    = 0.7 #inch  outer bottom margin, x label goes here
mpl_left   = 0.8 #inch  outer left margin, y label goes here
mpl_right  = 0.1 #inch  outer right margin, y2 label goes here
mpl_height = 2.0 #inch  height of individual plots
mpl_width  = 3.0 #inch  width of individual plots
mpl_dx     = 0.3 #inch  inter-plot horizontal spacing
mpl_dy     = 0.3 #inch  inter-plot vertical spacing
mpl_ny     = 3   #number of rows
mpl_nx     = 1   #number of columns

# calculate full dimensions
xsize = mpl_left+mpl_right+(mpl_width*mpl_nx)+(mpl_nx-1)*mpl_dx
ysize = mpl_top+mpl_bot+(mpl_ny*mpl_height)+(mpl_ny-1)*mpl_dy

# placement functions
#   rows are numbered from bottom to top
bot(n) = (mpl_bot+(n-1)*mpl_height+(n-1)*mpl_dy)/ysize
top(n)  = 1-((mpl_top+(mpl_ny-n)*(mpl_height+mpl_dy))/ysize)
#   columns are numbered from left to right
left(n) = (mpl_left+(n-1)*mpl_width+(n-1)*mpl_dx)/xsize
right(n)  = 1-((mpl_right+(mpl_nx-n)*(mpl_width+mpl_dx))/xsize)

#set terminal latex
set terminal postscript eps enhanced color dl 2.0 size xsize,ysize "Helvetica" 14
set encoding iso_8859_1
set tics scale 1.5

set output 'bbn-fierz.eps'

set offsets
set autoscale fix
set size 1,1
set nokey

# define x-axis settings for all subplots
set xrange [ -0.2 : 0.2  ] noreverse nowriteback
#set xrange [-4:4]
set xlabel 'Fierz b'
#set format x ''
set xtics 1
set mxtics 10

# start plotting
set multiplot

#-----------------------------------------------
# Yp
# subplot  1-3
#  set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
#  set horizontal margins for third row (top)
set tmargin at screen top(3)
set bmargin at screen bot(3)

set title 'BBN from Fierz'
set xlabel ''

set yrange [ 0.22 : 0.27 ] noreverse nowriteback

set ylabel "Yp"
set format y "%f"
#set ytics mirror 1
#set ytics 10
set mytics 5

plot 'fierz-study.dat' u 1:3:2 "%lf %lf %lf" w filledcu, \
      '' u 1:3 lt -1 notitle, '' u 1:2 lt -1 notitle;
# 'fierz-study.dat' u 1:6:7 "%lf %lf %lf" w filledcu, \
#      '' u 1:6 lt -1 notitle, '' u 1:7 lt -1 notitle, \
# 'fierz-study.dat' u 1:8:9 "%lf %lf %lf" w filledcu, \
#      '' u 1:8 lt -1 notitle, '' u 1:9 lt -1 notitle, \
# 'fierz-study.dat' u 1:10:11 "%lf %lf %lf" w filledcu, \
#      '' u 1:10 lt -1 notitle, '' u 1:11 lt -1 notitle, \
# 'fierz-study.dat' u 1:12:13 "%lf %lf %lf" w filledcu, \
#      '' u 1:12 lt -1 notitle, '' u 1:13 lt -1 notitle \
#;

#-----------------------------------------------
# D/H and He3/H
# subplot  1-2
#  set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
#  set horizontal margins for third row (top)
set tmargin at screen top(2)
set bmargin at screen bot(2)

set title ''
set xlabel ''

set yrange [ 1e-6 : 1e-4 ] noreverse nowriteback
set logscale y 10

set ylabel "He3/H\t\t\tD/H"
set format y "%1.E0"
set mytics 10

plot 'fierz-study.dat' u 1:5:4 "%lf %lf %lf" w filledcu, \
      '' u 1:5 lt 1 notitle, '' u 1:4 lt 1 notitle;
plot 'fierz-study.dat' u 1:6:7 "%lf %lf %lf" w filledcu, \
      '' u 1:7 lt 2 notitle, '' u 1:6 lt 2 notitle;
#plot 'fierz-study.dat' u 1:8:9 "%lf %lf %lf" w filledcu, \
#      '' u 1:8 lt -1 notitle, '' u 1:9 lt -1 notitle;
# 'fierz-study.dat' u 1:10:11 "%lf %lf %lf" w filledcu, \
#      '' u 1:10 lt -1 notitle, '' u 1:11 lt -1 notitle, \
# 'fierz-study.dat' u 1:12:13 "%lf %lf %lf" w filledcu, \
#      '' u 1:12 lt -1 notitle, '' u 1:13 lt -1 notitle \
#;

#-----------------------------------------------
# Li7/H
# subplot  1-1
#  set horizontal margins for first column
set lmargin at screen left(1)
set rmargin at screen right(1)
#  set horizontal margins for third row (top)
set tmargin at screen top(1)
set bmargin at screen bot(1)

set title ''
set xlabel 'Fierz b'

set yrange [ 1e-10 : 1e-9 ] noreverse nowriteback
set logscale y 10

set ylabel "Li7/H"
set format y "%1.E0"
#set ytics mirror 1
#set ytics 1
set mytics 10

plot 'fierz-study.dat' u 1:8:9 "%lf %lf %lf" w filledcu, \
      '' u 1:8 lt -1 notitle, '' u 1:9 lt -1 notitle;
#plot 'fierz-study.dat' u 1:10:11 "%lf %lf %lf" w filledcu, \
#      '' u 1:10 lt -1 notitle, '' u 1:11 lt -1 notitle;
# 'fierz-study.dat' u 1:12:13 "%lf %lf %lf" w filledcu, \
#      '' u 1:12 lt -1 notitle, '' u 1:13 lt -1 notitle \
#;

unset multiplot;