import fix

import fix

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

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

test(options_to_assoc1) :-
   options_object(test_pred1, [], O),
   O / [options_in, nested] ^= [In, Nested],
   assertion(In == []),
   is_assoc(Nested),
   assoc_to_list(Nested, NL),
   assertion(NL == []).

test(options_to_assoc2) :-
   options_object(test_pred1, [length(1)], O),
   O / nested ^= Nested,
   is_assoc(Nested),
   assoc_to_list(Nested, NL),
   assertion(NL == []).

test(options_to_assoc3) :-
   options_object(test_pred10, [length(1), empty], O),
   O / nested ^= Nested,
   is_assoc(Nested),
   assoc_to_list(Nested, NL),
   assertion(NL == []).

test(options_to_assoc4) :-
   options_object(test_pred10, [test_pred10_a-[z]], O),
   O / nested ^= Nested,
   is_assoc(Nested),
   assoc_to_list(Nested, [test_pred10_a-NO]),
   assertion(NO/z =^= z).

test(options_to_assoc5) :-
   options_object(test_pred10, [test_pred10_a-[z], test_pred10_b-[zz]], O),
   O / nested ^= Nested,
   is_assoc(Nested),
   get_assoc(test_pred10_a, Nested, NO1),
   get_assoc(test_pred10_b, Nested, NO2),
   assertion(NO1/z =^= z),
   assertion(NO2/zz =^= zz).

test(options_to_assoc6) :-
   options_object(test_pred10,
                  mod1:[test_pred10_a-[z], test_pred10_b-[zz]],
                  O),
   O / [context_module, nested] ^= [Module, Nested],
   assertion(Module == mod1),
   is_assoc(Nested),
   get_assoc(test_pred10_a, Nested, NO1),
   get_assoc(test_pred10_b, Nested, NO2),
   assertion(NO1/z =^= z),
   assertion(NO2/zz =^= zz).

test(options_to_assoc7) :-
   options_object(test_pred10,
                  [empty, test_pred10_a-[z], test_pred10_b-[zz]],
                  O),
   O / [nested, length] ^= [Nested, Length],
   assertion(Length == [empty]),
   is_assoc(Nested),
   get_assoc(test_pred10_a, Nested, NO1),
   get_assoc(test_pred10_b, Nested, NO2),
   assertion(NO1/z =^= z),
   assertion(NO2/zz =^= zz).

test(options_to_assoc8) :-
   options_object(test_pred10,
                  [test_pred10_a-[z], length(4),
                   test_pred10_b-[zz], length(5)], O),
   O / [nested, length] ^= [Nested, Length1],
   msort(Length1, Length),
   assertion(Length == [length(4), length(5)]),
   is_assoc(Nested),
   get_assoc(test_pred10_a, Nested, NO1),
   get_assoc(test_pred10_b, Nested, NO2),
   assertion(NO1/z =^= z),
   assertion(NO2/zz =^= zz).

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,
     [error(invalid_option_definition(Options), _)]
    ) :-

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

test(single_option_repeated2) :-

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

test(group_option_repeated1,
     [error(invalid_option_definition(O), _)]) :-

   O = [[group(length),
         option(length/1), option(length/3)],
        [option(width/1)],
        [option(length/3)]],
   ur_options(test_pred8, O).

test(group_option1) :-
   options_object(test_pred9,
                  [empty, generator(test_pred1)],
                  Obj),
   context_module(That),
   assertion(Obj / length =^= empty),
   assertion(Obj/generator=^=generator(That:test_pred1)).

test(group_option2,
    [error(domain_error(one_option_per_group, _), _)]) :-

   options_object(test_pred9,
                  [empty, generator(test_pred1),
                   length(1)], _).

test(group_option3) :-
   options_object(test_pred9, [], Obj),
   assertion(Obj / length =^= _).

test(multi_group_option1) :-

   OL = [empty, length(5), length(5), length(9)],
   options_object(test_pred10, OL, Obj),
   Obj / length ^= OL2,
   msort(OL2, OL3),
   msort(OL, OL4),
   assertion(OL3 == OL4).

test(multi_group_option2,
     [error(invalid_option_definition(O), _)]) :-

   O = [multi_group(length),
        option(empty/0), option(length/1),
        option(length/1)],
   ur_options(test_pred11, [O]).

test(multi_group_option3,
     [error(invalid_option_definition(O), _)]) :-

   O = [multi_group(length),
        option(empty/0), option(length/1),
        meta_option(length/1)],
   ur_options(test_pred12, [O]).

test(multi_group_option4,
     [error(invalid_option_definition(O), _)]) :-

   O = [multi_group(length),
        option(empty/0), option(length/1),
        default(empty/0)],
   ur_options(test_pred13, [O]).

test(multi_group_option5,
     [error(invalid_option_definition(O), _)]) :-

   O = [multi_group(length),
        option(empty/0), option(length/1),
        default([length/1, width/2])],
   ur_options(test_pred14, [O]).

test(options_group_list1, [List =@= [length(_)]]) :-
   options_group_list(test_pred1, length, List1),
   msort(List1, List).

test(options_group_list2, List =@= [generator(_)]) :-
   options_group_list(test_pred2, generator, List1),
   msort(List1, List).

test(options_group_list3,
     List =@= [empty, length(_), length_pred(_), length(_, _)]) :-
   options_group_list(test_pred9, length, List1),
   msort(List1, List).

test(options_group_list4,
     List =@= [empty, length(_), length_pred(_), length(_, _)]) :-
   options_group_list(test_pred10, length, List1),
   msort(List1, List).

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))]]),
   ur_options(test_pred9,
              [[group(length), option(empty/0),
                option(length/1), option(length/2),
                meta_option(length_pred/1)],
               [meta_option(generator/1)]]),
   ur_options(test_pred10,
              [[multi_group(length), option(empty/0),
                option(length/1), option(length/2),
                default([empty, length(1, 80)]),
                meta_option(length_pred/1)],
               [meta_option(generator/1)]]),
   ur_options(global:test_pred10_a, [[option(z/0)]]),
   ur_options(global:test_pred10_b, [[option(zz/0)]]).

test_pred1(_).
test_pred2(_).
test_pred3(_).
test_pred4(_).
test_pred5(_).
test_pred6(_).
test_pred7(_).
test_pred8(_).
test_pred9(_).
test_pred10(_).
test_pred11(_).
test_pred12(_).
test_pred13(_).
test_pred14(_).

:- end_tests(ur_option).

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

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

test(options_to_assoc1) :-
   options_object(test_pred1, [], O),
   O / [options_in, nested] ^= [In, Nested],
   assertion(In == []),
   is_assoc(Nested),
   assoc_to_list(Nested, NL),
   assertion(NL == []).

test(options_to_assoc2) :-
   options_object(test_pred1, [length(1)], O),
   O / nested ^= Nested,
   is_assoc(Nested),
   assoc_to_list(Nested, NL),
   assertion(NL == []).

test(options_to_assoc3) :-
   options_object(test_pred10, [length(1), empty], O),
   O / nested ^= Nested,
   is_assoc(Nested),
   assoc_to_list(Nested, NL),
   assertion(NL == []).

test(options_to_assoc4) :-
   options_object(test_pred10, [test_pred10_a-[z]], O),
   O / nested ^= Nested,
   is_assoc(Nested),
   assoc_to_list(Nested, [test_pred10_a-NO]),
   assertion(NO/z =^= z).

test(options_to_assoc5) :-
   options_object(test_pred10, [test_pred10_a-[z], test_pred10_b-[zz]], O),
   O / nested ^= Nested,
   is_assoc(Nested),
   get_assoc(test_pred10_a, Nested, NO1),
   get_assoc(test_pred10_b, Nested, NO2),
   assertion(NO1/z =^= z),
   assertion(NO2/zz =^= zz).

test(options_to_assoc6) :-
   options_object(test_pred10,
                  mod1:[test_pred10_a-[z], test_pred10_b-[zz]],
                  O),
   O / [context_module, nested] ^= [Module, Nested],
   assertion(Module == mod1),
   is_assoc(Nested),
   get_assoc(test_pred10_a, Nested, NO1),
   get_assoc(test_pred10_b, Nested, NO2),
   assertion(NO1/z =^= z),
   assertion(NO2/zz =^= zz).

test(options_to_assoc7) :-
   options_object(test_pred10,
                  [empty, test_pred10_a-[z], test_pred10_b-[zz]],
                  O),
   O / [nested, length] ^= [Nested, Length],
   assertion(Length == [empty]),
   is_assoc(Nested),
   get_assoc(test_pred10_a, Nested, NO1),
   get_assoc(test_pred10_b, Nested, NO2),
   assertion(NO1/z =^= z),
   assertion(NO2/zz =^= zz).

test(options_to_assoc8) :-
   options_object(test_pred10,
                  [test_pred10_a-[z], length(4),
                   test_pred10_b-[zz], length(5)], O),
   O / [nested, length] ^= [Nested, Length1],
   msort(Length1, Length),
   assertion(Length == [length(4), length(5)]),
   is_assoc(Nested),
   get_assoc(test_pred10_a, Nested, NO1),
   get_assoc(test_pred10_b, Nested, NO2),
   assertion(NO1/z =^= z),
   assertion(NO2/zz =^= zz).

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,
     [error(invalid_option_definition(Options), _)]
    ) :-

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

test(single_option_repeated2) :-

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

test(group_option_repeated1,
     [error(invalid_option_definition(O), _)]) :-

   O = [[group(length),
         option(length/1), option(length/3)],
        [option(width/1)],
        [option(length/3)]],
   ur_options(test_pred8, O).

test(group_option1) :-
   options_object(test_pred9,
                  [empty, generator(test_pred1)],
                  Obj),
   context_module(That),
   assertion(Obj / length =^= empty),
   assertion(Obj/generator=^=generator(That:test_pred1)).

test(group_option2,
    [error(domain_error(one_option_per_group, _), _)]) :-

   options_object(test_pred9,
                  [empty, generator(test_pred1),
                   length(1)], _).

test(group_option3) :-
   options_object(test_pred9, [], Obj),
   assertion(Obj / length =^= _).

test(multi_group_option1) :-

   OL = [empty, length(5), length(5), length(9)],
   options_object(test_pred10, OL, Obj),
   Obj / length ^= OL2,
   msort(OL2, OL3),
   msort(OL, OL4),
   assertion(OL3 == OL4).

test(multi_group_option2,
     [error(invalid_option_definition(O), _)]) :-

   O = [multi_group(length),
        option(empty/0), option(length/1),
        option(length/1)],
   ur_options(test_pred11, [O]).

test(multi_group_option3,
     [error(invalid_option_definition(O), _)]) :-

   O = [multi_group(length),
        option(empty/0), option(length/1),
        meta_option(length/1)],
   ur_options(test_pred12, [O]).

test(multi_group_option4,
     [error(invalid_option_definition(O), _)]) :-

   O = [multi_group(length),
        option(empty/0), option(length/1),
        default(empty/0)],
   ur_options(test_pred13, [O]).

test(multi_group_option5,
     [error(invalid_option_definition(O), _)]) :-

   O = [multi_group(length),
        option(empty/0), option(length/1),
        default([length/1, width/2])],
   ur_options(test_pred14, [O]).

test(options_group_list1, [List =@= [length(_)]]) :-
   options_group_list(test_pred1, length, List1),
   msort(List1, List).

test(options_group_list2, List =@= [generator(_)]) :-
   options_group_list(test_pred2, generator, List1),
   msort(List1, List).

test(options_group_list3,
     List =@= [empty, length(_), length_pred(_), length(_, _)]) :-
   options_group_list(test_pred9, length, List1),
   msort(List1, List).

test(options_group_list4,
     List =@= [empty, length(_), length_pred(_), length(_, _)]) :-
   options_group_list(test_pred10, length, List1),
   msort(List1, List).

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))]]),
   ur_options(test_pred9,
              [[group(length), option(empty/0),
                option(length/1), option(length/2),
                meta_option(length_pred/1)],
               [meta_option(generator/1)]]),
   ur_options(test_pred10,
              [[multi_group(length), option(empty/0),
                option(length/1), option(length/2),
                default([empty, length(1, 80)]),
                meta_option(length_pred/1)],
               [meta_option(generator/1)]]),
   ur_options(global:test_pred10_a, [[option(z/0)]]),
   ur_options(global:test_pred10_b, [[option(zz/0)]]).

test_pred1(_).
test_pred2(_).
test_pred3(_).
test_pred4(_).
test_pred5(_).
test_pred6(_).
test_pred7(_).
test_pred8(_).
test_pred9(_).
test_pred10(_).
test_pred11(_).
test_pred12(_).
test_pred13(_).
test_pred14(_).

:- end_tests(ur_option).


Add initial gnuplot data plotting script


Add obj_sort_parents_bug1 UT

Add obj_sort_parents_bug1 UT

:- begin_tests(v).
:- use_module(u(v)).
:- use_module(u(internal/objects_i)).
:- use_module(u(http/v/http_user_v)).

test(class_create1) :-
   % test class_create/3 version

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

   class_create(class_create_test_v, citizen_v, [a, c, b]),
   obj_construct(class_create_test_v, [birthday], [1976], CCTO),
   class_fields(citizen_v, CF), sort(CF, CFS),
   class_fields(class_create_test_v, CCTF), sort(CCTF, CCTFS),
   class_fields_new(class_create_test_v, CCTFN),
   assertion(CF == CFS),
   assertion(CCTF = CCTFS),
   assertion(CCTFN == [a, b, c]),

   ord_subtract(CCTF, CF, New_Fields),
   assertion(New_Fields == CCTFN),

   obj_field(CCTO, age, Age),
   integer(Age),

   obj_key(CCTO, Key),
   assertion(Key == [id]).

test(class_create2) :-
   % test class_create/4 version

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

   class_create(class_create_test_v, citizen_v, [a, c, b],
                [birthday, a]),
   obj_construct(class_create_test_v, [birthday], [1976], CCTO),
   class_fields(citizen_v, CF), sort(CF, CFS),
   class_fields(class_create_test_v, CCTF), sort(CCTF, CCTFS),
   class_fields_new(class_create_test_v, CCTFN),
   assertion(CF == CFS),
   assertion(CCTF = CCTFS),
   assertion(CCTFN == [a, b, c]),

   ord_subtract(CCTF, CF, New_Fields),
   assertion(New_Fields == CCTFN),

   obj_field(CCTO, age, Age),
   integer(Age),

   obj_key(CCTO, Key),
   assertion(Key == [a, birthday]).

test(class_create_feature1) :-
   % It is a strange feature

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

   class_create(class_create_test_v, citizen_v, [a, c, b], []),
   obj_construct(class_create_test_v, [birthday], [1976], CCTO),
   obj_key(CCTO, Key),
   assertion(Key == []).

% test(class_descendant1,
%      [List == [callup_v, citizen_v, class_create_test_v]]
%     ) :-

%   findall(X, class_descendant(man_v, X), List0),
%   msort(List0, List).

% test(class_descendant2, [List == []]) :-

%   findall(X, class_descendant(callup_v, X), List).

% test(class_descendant3, [List == []]) :-

%   obj_construct(tarjan_vertex_v, [], [], V),
%   obj_rebase((object_v -> callup_v), V, _),
%   findall(X, class_descendant(callup_v, X), List).

% test(class_same_or_descendant1,
%      [List == [callup_v, citizen_v, class_create_test_v, man_v]]
%     ) :-

%   findall(X, class_same_or_descendant(man_v, X), List0),
%   msort(List0, List).

% test(class_same_or_descendant2,
%      [List == [callup_v]]
%     ) :-

%   findall(X, class_same_or_descendant(callup_v, X), List).

% test(class_same_or_descendant3, [List == [callup_v]]) :-

%   obj_construct(tarjan_vertex_v, [], [], V),
%   obj_rebase((object_v -> callup_v), V, _),
%   findall(X, class_same_or_descendant(callup_v, X), List).

test(class_parent1, [Parent == man_v]) :-

   class_parent(citizen_v, Parent).

test(class_parent2,
     [L == [callup_v, class_create_test_v]]) :-

   findall(Desc, class_parent(Desc, citizen_v), LU),
   msort(LU, L).

test(class_parent3) :-

   findall(p(A, B), class_parent(A, B), L),
   length(L, N),
   assertion(N > 10).

test(eval_obj_expr,
     [[E1, E2, E3] =@= [HTTP_Result, WWW_Addr, Url]]
     ) :-

   Url = 'http://kogorta.dp.ua',
   obj_construct(www_address_v,
                 [http_request_url], [Url], WWW_Addr),
   obj_construct(http_result_v,
                 [www_address], [WWW_Addr], HTTP_Result),
   eval_obj_expr(HTTP_Result, E1),
   eval_obj_expr(HTTP_Result/www_address, E2),
   eval_obj_expr(HTTP_Result/www_address/http_request_url, E3).

test(obj_construct_with_evals1) :-

    obj_construct(citizen_v,
                  [functor, class, birthday],
                  [citizen_v, citizen_v, 1994], O1),
    obj_field(O1, class, Class1),
    assertion(Class1 == citizen_v),

    obj_construct(citizen_v,
                  [birthday, functor, class],
                  [1994, citizen_v, citizen_v], O2),
    obj_field(O2, class, Class2),
    assertion(Class2 == citizen_v),

    obj_construct(citizen_v,
                  [birthday, sex, functor, class],
                  [1994, man, citizen_v, callup_v], O3),
    obj_field(O3, class, Class3),
    assertion(Class3 == callup_v),

    obj_construct(citizen_v,
                  [functor, class, birthday, sex],
                  [citizen_v, callup_v, 1994, man], O4),
    obj_field(O4, class, Class4),
    assertion(Class4 == callup_v),

    obj_construct(citizen_v,
                  [functor, class, birthday, sex],
                  [X, Y, 1994, man], O5),
    obj_field(O5, class, Class5),
    assertion(Class5 == callup_v),
    assertion(X = citizen_v),
    assertion(Y = callup_v).

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).

test(obj_diff1,
     [Diff == [diff(name, 'Sergei', 'Artemiy')]]) :-

   obj_construct(man_v, [name, surname], ['Sergei', 'Lodyagin'], M1),
   obj_construct(man_v, [name, surname], ['Artemiy', 'Lodyagin'], M2),
   obj_diff(M1, M2, Diff).

test(obj_diff2,
     [Diff == [diff(name, 'Sergei', 'Artemiy')]]) :-

   obj_construct(man_v, [name, surname], ['Sergei', 'Lodyagin'], M1_0),
   obj_rebase((object_v -> db_object_v), M1_0, M1),
   obj_construct(man_v, [name, surname], ['Artemiy', 'Lodyagin'], M2),
   obj_diff(M1, M2, Diff).

% After some time it will always fails (because it depends
% on the current year).
test(obj_downcast1,
     [C1 =@= callup_v(Class_Id, 1994, _, _, _, _, _, man, _, _)]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], C0),
   obj_downcast(C0, C1),
   arg(1, C1, Class_Id).

test(obj_field1, [Flds == Vals]) :-

   class_fields(citizen_v, Flds),
   obj_construct(citizen_v, Flds, Flds, Obj),
   findall(Val, (obj_field(Obj, Fld, Val), member(Fld, Flds)), Vals).

test(obj_field2, [Flds3 == Flds4]) :-
% Each eval field must be evaluable only once

   class_fields(citizen_v, Flds),
   obj_construct(citizen_v, Flds, Flds, Obj),
   findall(Fld, obj_field(Obj, Fld, _), Flds2),
   sort(Flds2, Flds3),
   msort(Flds2, Flds4).

test(obj_field3, [Surname == 'Grisha']) :-

   obj_construct(man_v, [], [], Man),
   obj_field(Man, name, Name),
   obj_field(Man, surname, Name),
   Name = 'Grisha',
   obj_field(Man, surname, Surname).

test(obj_field_bug1, [fail]) :-

   obj_construct(citizen_v, [sex], [woman], Obj),
   obj_field(Obj, sex, man).

test(obj_is_descendant1, [List == [object_base_v, object_v]]) :-

   obj_construct(man_v, [], [], Man),
   findall(X, obj_is_descendant(Man, X), List0),
   msort(List0, List).

test(obj_is_descendant2) :-

   obj_construct(man_v, [], [], Man),
   \+ obj_is_descendant(Man, db_object_v),
   obj_rebase((object_v -> db_object_v), Man, Man2),
   obj_is_descendant(Man2, db_object_v).

test(obj_set_field1, [Surname =@= _]) :-

   obj_construct(man_v, [], [], Man),
   obj_set_field(Man, name, Name),
   obj_set_field(Man, surname, Name),
   Name = 'Grisha',
   obj_field(Man, surname, Surname).

test(obj_set_field2, [Surname =@= 'Grisha']) :-

   obj_construct(man_v, [name, surname], [Name, Name], Man),
   obj_set_field(Man, name, 'Grisha'),
   obj_field(Man, surname, Surname).

test(obj_key1) :-

   obj_construct(man_v, [sex, name], [man, 'Adam'], Man1),
   obj_key(Man1, Key1),
   assertion(Key1 == [name, surname]),
   obj_key_value(Man1, Key_Value1),
   assertion(Key_Value1 =@= ['Adam', _]),

   obj_construct(citizen_v,
                 [sex, surname, country],
                 [man, 'Mayakovsky', ['Soviet Union']],
                 Man2),
   obj_key(Man2, Key2),
   assertion(Key2 == [id]),
   obj_key_value(Man2, Key_Value2),
   assertion(Key_Value2 =@= [_]).

test(obj_key2) :-

   obj_construct(man_v, [sex, name], [man, 'Adam'], Man1_0),
   obj_rebase((object_v -> db_object_v), Man1_0, Man1),
   obj_key(Man1, Key1),
   assertion(Key1 == [name, surname]),
   obj_key_value(Man1, Key_Value1),
   assertion(Key_Value1 =@= ['Adam', _]),

   obj_construct(citizen_v,
                 [sex, surname, country],
                 [man, 'Mayakovsky', ['Soviet Union']],
                 Man2_0),
   obj_rebase((object_v -> db_object_v), Man2_0, Man2),
   obj_key(Man2, Key2),
   assertion(Key2 == [id]),
   obj_key_value(Man2, Key_Value2),
   assertion(Key_Value2 =@= [_]).

test(obj_list1,
     [List =@= [country = ['Soviet Union'],
                sex = man,
                surname = 'Mayakovsky']]
     ) :-

   obj_construct(citizen_v,
                 [sex, surname, country],
                 [man, 'Mayakovsky', ['Soviet Union']],
                 Man),
   obj_list(Man, List).

test(obj_list2, [List =@= []]) :-

   obj_construct(citizen_v, [], [], Man),
   obj_list(Man, List).

test(obj_parents1_1,
     [P = [citizen_v, man_v, object_v, object_base_v]]) :-

   obj_construct(citizen_v, [], [], V),
   obj_parents(V, P).

test(obj_parents2_1) :-

   obj_construct(citizen_v,
                 [sex, surname, country],
                 [man, 'Mayakovsky', ['Soviet Union']],
                 Man1),
   New_Parents_Order = [man_v, citizen_v, object_v, object_base_v],
   obj_parents(Man1, New_Parents_Order, Man2),
   obj_parents(Man1, P1),
   assertion(P1 == [citizen_v, man_v, object_v, object_base_v]),
   obj_parents(Man2, P2),
   assertion(P2 == New_Parents_Order),
   obj_list(Man1, L1),
   obj_list(Man2, L2),
   assertion(L1 == L2),
   obj_field(Man1, class, C1),
   obj_field(Man2, class, C2),
   obj_field(Man1, functor, F1),
   obj_field(Man2, functor, F2),
   assertion([F1, F2, C1, C2] == [citizen_v, man_v, callup_v, callup_v]).

test(obj_rebase1) :-

   obj_construct(http_request_headers_v, [], [], V1),
   obj_parents(V1, P1),
   assertion(P1 == [http_request_headers_v, http_headers_v,
                    object_v,object_base_v]),
   obj_rebase((http_headers_v -> http_response_headers_v),
              V1, V2),
   obj_parents(V2, P2),
   assertion(P2 == [http_request_headers_v,
                    http_response_headers_v,http_headers_v,
                    object_v,object_base_v]),
   obj_rebase((http_request_headers_v ->
               http_invalid_mixed_headers_v), V2, V3),
   obj_parents(V3, P3),
   assertion(P3 == [http_invalid_mixed_headers_v,
                    http_invalid_headers_v,
                    http_headers_v,
                    object_v,object_base_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_rebase_bug2) :-

   obj_construct(citizen_v, [sex], [man], Obj1_0),
   obj_rebase((object_v -> db_object_v), Obj1_0, Obj1),

   obj_construct(citizen_v, [sex], [man], 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_rebase_bug3_1) :-

   obj_construct(db_object_v, [], [], Obj1_0),
   obj_rebase((object_v -> db_object_v), Obj1_0, Obj1),

   obj_construct(db_object_v, [], [], 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),

   class_primary_id(object_v, Object_V_Id),
   assertion(Obj3 == object_v(Object_V_Id)).

test(obj_rebase_bug3_2) :-

   obj_construct(citizen_v, [], [], Obj1_0),
   obj_rebase((man_v -> citizen_v), Obj1_0, Obj1),

   obj_construct(citizen_v, [], [], Obj2_0),
   obj_rebase((object_v -> man_v), Obj2_0, Obj2),

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

   assertion(Class_Id1 =:= Class_Id2).

test(obj_rebase_bug4,
     [throws(error(cant_rebase_to_object_base_v,
                   context(obj_rebase/3, _)))]) :-

   obj_construct(citizen_v, [], [], Obj1_0),
   obj_rebase((citizen_v -> object_base_v), Obj1_0, Obj1),

   obj_construct(citizen_v, [], [], Obj2_0),
   obj_rebase((citizen_v -> object_base_v), Obj2_0, Obj2),

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

   assertion(Class_Id1 =:= Class_Id2),

   obj_rebase((object_base_v -> citizen_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_reset_fields1) :-

   obj_construct(man_v,
                 [sex, name, weight, height],
                 [man, 'Simeon', 63, 1.75], Man0),

   obj_reset_fields([name, height], Man0, Man1),
   obj_class_id(Man1, Class_Id),
   assertion(Man1 =@= man_v(Class_Id, _, _, man, _, 63)),

   obj_reset_fields([weight], Man1, Man2),
   assertion(Man2 =@= man_v(Class_Id, _, _, man, _, _)),

   obj_reset_fields([], Man2, Man3),
   assertion(Man3 =@= Man2).

test(obj_reset_fields2, [fail]) :-

   obj_construct(man_v,
                 [sex, name, weight, height],
                 [man, 'Simeon', 63, 1.75], Man0),

   obj_reset_fields([name, height, age], Man0, _).

test(obj_reset_fields_weak) :-

   obj_construct(man_v,
                 [sex, name, weight, height],
                 [man, 'Simeon', 63, 1.75], Man0),

   obj_reset_fields_weak([name, height, age], Man0, Man1),
   obj_class_id(Man1, Class_Id),
   assertion(Man1 =@= man_v(Class_Id, _, _, man, _, 63)).

test(obj_reset_fields_with_evals, [fail]) :-

   obj_construct(citizen_v, [sex], [man], O),
   obj_reset_fields([age], O, _).

test(obj_rewrite) :-

   obj_construct(man_v,
                 [name, height, weight],
                 ['Luda', 1.40, 99], Luda1),
   obj_rewrite(Luda1,
               [height, weight, name],
               [Old_Height, Old_Weight, Name],
               [1.44, 69, Name],
               Luda2),
   assertion([Old_Height, Old_Weight] =@= [1.40, 99]),
   obj_rewrite(Luda2,
               [height, weight, name],
               Luda2_Pars,
               [1.45, 64, _],
               Luda3),
   assertion(Luda2_Pars =@= [1.44, 69, 'Luda']),
   named_args_unify(Luda3, [height, weight, name], Luda3_Pars),
   assertion(Luda3_Pars =@= [1.45, 64, _]).

test(obj_rewrite_weak1,
     [throws(error(no_object_field(Luda1, country), _))]) :-

   obj_construct(man_v,
                 [name, height, weight],
                 ['Luda', 1.40, 99], Luda1),
   obj_rewrite(Luda1,
               [height, weight, name, country],
               _,
               [1.44, 69, _, 'UK'],
               _).

test(obj_rewrite_weak2,
     [[Old_Height, Old_Weight, Name, Old_Country]
     =@= [1.40, 99, 'Luda', _]]
     ) :-

   obj_construct(man_v,
                 [name, height, weight],
                 ['Luda', 1.40, 99], Luda1),
   obj_rewrite(Luda1, weak,
               [height, weight, name, country],
               [Old_Height, Old_Weight, Name, Old_Country],
               [1.44, 69, Name, 'UK'],
               _).

test(obj_rewrite_weak3, [fail]) :-

   obj_construct(man_v,
                 [name, height, weight],
                 ['Luda', 1.40, 99], Luda1),
   obj_rewrite(Luda1, fail,
               [height, weight, name, country],
               _,
               [1.44, 69, _, 'UK'],
               _).

test(obj_rewrite_with_evals1, [X == callup_v]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], O),
   obj_rewrite(O, [class], [X], [callup_v], _).

test(obj_rewrite_with_evals2, [fail]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], O),
   obj_rewrite(O, [class], [_], [citizen_v], _).

test(obj_rewrite_with_evals3, [X == callup_v]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], O),
   obj_rewrite(O, [class], [X], [X], _).

test(obj_rewrite_with_evals4) :-
% <NB> can't reset eval field, compare with test(obj_rewrite)

   obj_construct(citizen_v, [sex, birthday], [man, 1994], O),
   obj_rewrite(O, [class], [_], [_], _).

test(obj_sort_parents1,
     [P4 == [http_invalid_mixed_headers_v,
             http_invalid_headers_v,
             http_request_headers_v,
             http_response_headers_v,
             http_headers_v,
             object_v, object_base_v]]
     ) :-

   obj_construct(http_request_headers_v, [], [], V1),
   obj_rebase((http_headers_v -> http_response_headers_v),
              V1, V2),
   obj_rebase((http_headers_v -> http_invalid_mixed_headers_v),
              V2, V3),

   obj_sort_parents(V3, [http_invalid_bulk_headers_v,
                         http_invalid_mixed_headers_v,
                         http_invalid_headers_v,
                         http_request_headers_v,
                         http_response_headers_v,
                         http_headers_v,
                         tarjan_vertex_v,
                         db_object_v,
                         object_v, object_base_v], V4),
   obj_parents(V4, P4),
   functor(V4, F4, _),
   assertion(F4 == http_invalid_mixed_headers_v).

test(obj_sort_parents2,
     [throws(error(insufficient_class_order(Order,
                                            Orig_Order), _))]
     ) :-

   Order = [http_invalid_bulk_headers_v,
            http_invalid_mixed_headers_v,
            http_request_headers_v,
            http_response_headers_v,
            http_headers_v,
            tarjan_vertex_v,
            db_object_v,
            object_v, object_base_v],

   obj_construct(http_request_headers_v, [], [], V1),
   obj_rebase((http_headers_v -> http_response_headers_v),
              V1, V2),
   obj_rebase((http_headers_v -> http_invalid_mixed_headers_v),
              V2, V3),

   obj_parents(V3, Orig_Order),
   obj_sort_parents(V3, Order, _).

test(obj_sort_parents_bug1) :-

   new_http_user(HTTP_User),
   obj_rebase((object_v -> citizen_v),
              HTTP_User, U1),

   class_parents(http_user_v, HTTP_User_Parents),
   append([citizen_v, man_v], HTTP_User_Parents,
          Parents_Order),

   obj_sort_parents(U1, Parents_Order, HTTP_Citizen),
   % citizen_v -> man_v -> http_user_v -> ...object_base_v

   obj_copy(HTTP_Citizen, HTTP_Citizen_Copy),
   obj_field(HTTP_Citizen, cookie_db_key, Key1),
   obj_field(HTTP_Citizen_Copy, cookie_db_key, Key2),
   assertion(Key1 \= Key2).

test(class_fields) :-

   class_fields(object_base_v, Object_Base_V_Fields),
   assertion(Object_Base_V_Fields == []),

   class_fields_new(object_base_v, Object_Base_V_New_Fields),
   assertion(Object_Base_V_New_Fields == []),

   class_fields(object_v, Object_V_Fields),
   assertion(Object_V_Fields == []),

   class_fields_new(object_v, Object_V_New_Fields),
   assertion(Object_V_New_Fields == []),

   class_fields(man_v, Man_V_Fields),
   assertion(Man_V_Fields == [height, name, sex, surname, weight]),

   class_fields_new(man_v, Man_V_New_Fields),
   assertion(Man_V_New_Fields == [height, name, sex, surname,
                                  weight]),

   class_fields(citizen_v, Citizen_V_Fields),
   assertion(Citizen_V_Fields == [birthday, country, height, id,
                                  name, sex, surname, weight]),

   class_fields_new(citizen_v, Citizen_V_New_Fields),
   assertion(Citizen_V_New_Fields == [birthday, country, id]).

% After some time it will always fails (because it depends
% on the current year, see The Uranium Book).
test(eval_fields1, [Class == callup_v]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], C),
   obj_field(C, class, Class).

test(cleanup_obj_rebase, [blocked(transaction_bug), N1 =:= N2]) :-

   aggregate(count, A^B^C^(objects:class_id(A, B, C)), N1),
   catch((obj_construct(numeric_id_v, [], [], Obj1),
          obj_rebase((object_v -> citizen_v), Obj1, _)),
         E, true),
   E = error(EX, _), functor(EX, duplicate_field, _),
   aggregate(count, A^B^C^(objects:class_id(A, B, C)), N2).

:- end_tests(v).

:- begin_tests(v).
:- use_module(u(v)).
:- use_module(u(internal/objects_i)).

test(class_create1) :-
   % test class_create/3 version

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

   class_create(class_create_test_v, citizen_v, [a, c, b]),
   obj_construct(class_create_test_v, [birthday], [1976], CCTO),
   class_fields(citizen_v, CF), sort(CF, CFS),
   class_fields(class_create_test_v, CCTF), sort(CCTF, CCTFS),
   class_fields_new(class_create_test_v, CCTFN),
   assertion(CF == CFS),
   assertion(CCTF = CCTFS),
   assertion(CCTFN == [a, b, c]),

   ord_subtract(CCTF, CF, New_Fields),
   assertion(New_Fields == CCTFN),

   obj_field(CCTO, age, Age),
   integer(Age),

   obj_key(CCTO, Key),
   assertion(Key == [id]).

test(class_create2) :-
   % test class_create/4 version

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

   class_create(class_create_test_v, citizen_v, [a, c, b],
                [birthday, a]),
   obj_construct(class_create_test_v, [birthday], [1976], CCTO),
   class_fields(citizen_v, CF), sort(CF, CFS),
   class_fields(class_create_test_v, CCTF), sort(CCTF, CCTFS),
   class_fields_new(class_create_test_v, CCTFN),
   assertion(CF == CFS),
   assertion(CCTF = CCTFS),
   assertion(CCTFN == [a, b, c]),

   ord_subtract(CCTF, CF, New_Fields),
   assertion(New_Fields == CCTFN),

   obj_field(CCTO, age, Age),
   integer(Age),

   obj_key(CCTO, Key),
   assertion(Key == [a, birthday]).

test(class_create_feature1) :-
   % It is a strange feature

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

   class_create(class_create_test_v, citizen_v, [a, c, b], []),
   obj_construct(class_create_test_v, [birthday], [1976], CCTO),
   obj_key(CCTO, Key),
   assertion(Key == []).

% test(class_descendant1,
%      [List == [callup_v, citizen_v, class_create_test_v]]
%     ) :-

%   findall(X, class_descendant(man_v, X), List0),
%   msort(List0, List).

% test(class_descendant2, [List == []]) :-

%   findall(X, class_descendant(callup_v, X), List).

% test(class_descendant3, [List == []]) :-

%   obj_construct(tarjan_vertex_v, [], [], V),
%   obj_rebase((object_v -> callup_v), V, _),
%   findall(X, class_descendant(callup_v, X), List).

% test(class_same_or_descendant1,
%      [List == [callup_v, citizen_v, class_create_test_v, man_v]]
%     ) :-

%   findall(X, class_same_or_descendant(man_v, X), List0),
%   msort(List0, List).

% test(class_same_or_descendant2,
%      [List == [callup_v]]
%     ) :-

%   findall(X, class_same_or_descendant(callup_v, X), List).

% test(class_same_or_descendant3, [List == [callup_v]]) :-

%   obj_construct(tarjan_vertex_v, [], [], V),
%   obj_rebase((object_v -> callup_v), V, _),
%   findall(X, class_same_or_descendant(callup_v, X), List).

test(class_parent1, [Parent == man_v]) :-

   class_parent(citizen_v, Parent).

test(class_parent2,
     [L == [callup_v, class_create_test_v]]) :-

   findall(Desc, class_parent(Desc, citizen_v), LU),
   msort(LU, L).

test(class_parent3) :-

   findall(p(A, B), class_parent(A, B), L),
   length(L, N),
   assertion(N > 10).

test(eval_obj_expr,
     [[E1, E2, E3] =@= [HTTP_Result, WWW_Addr, Url]]
     ) :-

   Url = 'http://kogorta.dp.ua',
   obj_construct(www_address_v,
                 [http_request_url], [Url], WWW_Addr),
   obj_construct(http_result_v,
                 [www_address], [WWW_Addr], HTTP_Result),
   eval_obj_expr(HTTP_Result, E1),
   eval_obj_expr(HTTP_Result/www_address, E2),
   eval_obj_expr(HTTP_Result/www_address/http_request_url, E3).

test(obj_construct_with_evals1) :-

    obj_construct(citizen_v,
                  [functor, class, birthday],
                  [citizen_v, citizen_v, 1994], O1),
    obj_field(O1, class, Class1),
    assertion(Class1 == citizen_v),

    obj_construct(citizen_v,
                  [birthday, functor, class],
                  [1994, citizen_v, citizen_v], O2),
    obj_field(O2, class, Class2),
    assertion(Class2 == citizen_v),

    obj_construct(citizen_v,
                  [birthday, sex, functor, class],
                  [1994, man, citizen_v, callup_v], O3),
    obj_field(O3, class, Class3),
    assertion(Class3 == callup_v),

    obj_construct(citizen_v,
                  [functor, class, birthday, sex],
                  [citizen_v, callup_v, 1994, man], O4),
    obj_field(O4, class, Class4),
    assertion(Class4 == callup_v),

    obj_construct(citizen_v,
                  [functor, class, birthday, sex],
                  [X, Y, 1994, man], O5),
    obj_field(O5, class, Class5),
    assertion(Class5 == callup_v),
    assertion(X = citizen_v),
    assertion(Y = callup_v).

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).

test(obj_diff1,
     [Diff == [diff(name, 'Sergei', 'Artemiy')]]) :-

   obj_construct(man_v, [name, surname], ['Sergei', 'Lodyagin'], M1),
   obj_construct(man_v, [name, surname], ['Artemiy', 'Lodyagin'], M2),
   obj_diff(M1, M2, Diff).

test(obj_diff2,
     [Diff == [diff(name, 'Sergei', 'Artemiy')]]) :-

   obj_construct(man_v, [name, surname], ['Sergei', 'Lodyagin'], M1_0),
   obj_rebase((object_v -> db_object_v), M1_0, M1),
   obj_construct(man_v, [name, surname], ['Artemiy', 'Lodyagin'], M2),
   obj_diff(M1, M2, Diff).

% After some time it will always fails (because it depends
% on the current year).
test(obj_downcast1,
     [C1 =@= callup_v(Class_Id, 1994, _, _, _, _, _, man, _, _)]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], C0),
   obj_downcast(C0, C1),
   arg(1, C1, Class_Id).

test(obj_field1, [Flds == Vals]) :-

   class_fields(citizen_v, Flds),
   obj_construct(citizen_v, Flds, Flds, Obj),
   findall(Val, (obj_field(Obj, Fld, Val), member(Fld, Flds)), Vals).

test(obj_field2, [Flds3 == Flds4]) :-
% Each eval field must be evaluable only once

   class_fields(citizen_v, Flds),
   obj_construct(citizen_v, Flds, Flds, Obj),
   findall(Fld, obj_field(Obj, Fld, _), Flds2),
   sort(Flds2, Flds3),
   msort(Flds2, Flds4).

test(obj_field3, [Surname == 'Grisha']) :-

   obj_construct(man_v, [], [], Man),
   obj_field(Man, name, Name),
   obj_field(Man, surname, Name),
   Name = 'Grisha',
   obj_field(Man, surname, Surname).

test(obj_field_bug1, [fail]) :-

   obj_construct(citizen_v, [sex], [woman], Obj),
   obj_field(Obj, sex, man).

test(obj_is_descendant1, [List == [object_base_v, object_v]]) :-

   obj_construct(man_v, [], [], Man),
   findall(X, obj_is_descendant(Man, X), List0),
   msort(List0, List).

test(obj_is_descendant2) :-

   obj_construct(man_v, [], [], Man),
   \+ obj_is_descendant(Man, db_object_v),
   obj_rebase((object_v -> db_object_v), Man, Man2),
   obj_is_descendant(Man2, db_object_v).

test(obj_set_field1, [Surname =@= _]) :-

   obj_construct(man_v, [], [], Man),
   obj_set_field(Man, name, Name),
   obj_set_field(Man, surname, Name),
   Name = 'Grisha',
   obj_field(Man, surname, Surname).

test(obj_set_field2, [Surname =@= 'Grisha']) :-

   obj_construct(man_v, [name, surname], [Name, Name], Man),
   obj_set_field(Man, name, 'Grisha'),
   obj_field(Man, surname, Surname).

test(obj_key1) :-

   obj_construct(man_v, [sex, name], [man, 'Adam'], Man1),
   obj_key(Man1, Key1),
   assertion(Key1 == [name, surname]),
   obj_key_value(Man1, Key_Value1),
   assertion(Key_Value1 =@= ['Adam', _]),

   obj_construct(citizen_v,
                 [sex, surname, country],
                 [man, 'Mayakovsky', ['Soviet Union']],
                 Man2),
   obj_key(Man2, Key2),
   assertion(Key2 == [id]),
   obj_key_value(Man2, Key_Value2),
   assertion(Key_Value2 =@= [_]).

test(obj_key2) :-

   obj_construct(man_v, [sex, name], [man, 'Adam'], Man1_0),
   obj_rebase((object_v -> db_object_v), Man1_0, Man1),
   obj_key(Man1, Key1),
   assertion(Key1 == [name, surname]),
   obj_key_value(Man1, Key_Value1),
   assertion(Key_Value1 =@= ['Adam', _]),

   obj_construct(citizen_v,
                 [sex, surname, country],
                 [man, 'Mayakovsky', ['Soviet Union']],
                 Man2_0),
   obj_rebase((object_v -> db_object_v), Man2_0, Man2),
   obj_key(Man2, Key2),
   assertion(Key2 == [id]),
   obj_key_value(Man2, Key_Value2),
   assertion(Key_Value2 =@= [_]).

test(obj_list1,
     [List =@= [country = ['Soviet Union'],
                sex = man,
                surname = 'Mayakovsky']]
     ) :-

   obj_construct(citizen_v,
                 [sex, surname, country],
                 [man, 'Mayakovsky', ['Soviet Union']],
                 Man),
   obj_list(Man, List).

test(obj_list2, [List =@= []]) :-

   obj_construct(citizen_v, [], [], Man),
   obj_list(Man, List).

test(obj_parents1_1,
     [P = [citizen_v, man_v, object_v, object_base_v]]) :-

   obj_construct(citizen_v, [], [], V),
   obj_parents(V, P).

test(obj_parents2_1) :-

   obj_construct(citizen_v,
                 [sex, surname, country],
                 [man, 'Mayakovsky', ['Soviet Union']],
                 Man1),
   New_Parents_Order = [man_v, citizen_v, object_v, object_base_v],
   obj_parents(Man1, New_Parents_Order, Man2),
   obj_parents(Man1, P1),
   assertion(P1 == [citizen_v, man_v, object_v, object_base_v]),
   obj_parents(Man2, P2),
   assertion(P2 == New_Parents_Order),
   obj_list(Man1, L1),
   obj_list(Man2, L2),
   assertion(L1 == L2),
   obj_field(Man1, class, C1),
   obj_field(Man2, class, C2),
   obj_field(Man1, functor, F1),
   obj_field(Man2, functor, F2),
   assertion([F1, F2, C1, C2] == [citizen_v, man_v, callup_v, callup_v]).

test(obj_rebase1) :-

   obj_construct(http_request_headers_v, [], [], V1),
   obj_parents(V1, P1),
   assertion(P1 == [http_request_headers_v, http_headers_v,
                    object_v,object_base_v]),
   obj_rebase((http_headers_v -> http_response_headers_v),
              V1, V2),
   obj_parents(V2, P2),
   assertion(P2 == [http_request_headers_v,
                    http_response_headers_v,http_headers_v,
                    object_v,object_base_v]),
   obj_rebase((http_request_headers_v ->
               http_invalid_mixed_headers_v), V2, V3),
   obj_parents(V3, P3),
   assertion(P3 == [http_invalid_mixed_headers_v,
                    http_invalid_headers_v,
                    http_headers_v,
                    object_v,object_base_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_rebase_bug2) :-

   obj_construct(citizen_v, [sex], [man], Obj1_0),
   obj_rebase((object_v -> db_object_v), Obj1_0, Obj1),

   obj_construct(citizen_v, [sex], [man], 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_rebase_bug3_1) :-

   obj_construct(db_object_v, [], [], Obj1_0),
   obj_rebase((object_v -> db_object_v), Obj1_0, Obj1),

   obj_construct(db_object_v, [], [], 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),

   class_primary_id(object_v, Object_V_Id),
   assertion(Obj3 == object_v(Object_V_Id)).

test(obj_rebase_bug3_2) :-

   obj_construct(citizen_v, [], [], Obj1_0),
   obj_rebase((man_v -> citizen_v), Obj1_0, Obj1),

   obj_construct(citizen_v, [], [], Obj2_0),
   obj_rebase((object_v -> man_v), Obj2_0, Obj2),

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

   assertion(Class_Id1 =:= Class_Id2).

test(obj_rebase_bug4,
     [throws(error(cant_rebase_to_object_base_v,
                   context(obj_rebase/3, _)))]) :-

   obj_construct(citizen_v, [], [], Obj1_0),
   obj_rebase((citizen_v -> object_base_v), Obj1_0, Obj1),

   obj_construct(citizen_v, [], [], Obj2_0),
   obj_rebase((citizen_v -> object_base_v), Obj2_0, Obj2),

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

   assertion(Class_Id1 =:= Class_Id2),

   obj_rebase((object_base_v -> citizen_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_reset_fields1) :-

   obj_construct(man_v,
                 [sex, name, weight, height],
                 [man, 'Simeon', 63, 1.75], Man0),

   obj_reset_fields([name, height], Man0, Man1),
   obj_class_id(Man1, Class_Id),
   assertion(Man1 =@= man_v(Class_Id, _, _, man, _, 63)),

   obj_reset_fields([weight], Man1, Man2),
   assertion(Man2 =@= man_v(Class_Id, _, _, man, _, _)),

   obj_reset_fields([], Man2, Man3),
   assertion(Man3 =@= Man2).

test(obj_reset_fields2, [fail]) :-

   obj_construct(man_v,
                 [sex, name, weight, height],
                 [man, 'Simeon', 63, 1.75], Man0),

   obj_reset_fields([name, height, age], Man0, _).

test(obj_reset_fields_weak) :-

   obj_construct(man_v,
                 [sex, name, weight, height],
                 [man, 'Simeon', 63, 1.75], Man0),

   obj_reset_fields_weak([name, height, age], Man0, Man1),
   obj_class_id(Man1, Class_Id),
   assertion(Man1 =@= man_v(Class_Id, _, _, man, _, 63)).

test(obj_reset_fields_with_evals, [fail]) :-

   obj_construct(citizen_v, [sex], [man], O),
   obj_reset_fields([age], O, _).

test(obj_rewrite) :-

   obj_construct(man_v,
                 [name, height, weight],
                 ['Luda', 1.40, 99], Luda1),
   obj_rewrite(Luda1,
               [height, weight, name],
               [Old_Height, Old_Weight, Name],
               [1.44, 69, Name],
               Luda2),
   assertion([Old_Height, Old_Weight] =@= [1.40, 99]),
   obj_rewrite(Luda2,
               [height, weight, name],
               Luda2_Pars,
               [1.45, 64, _],
               Luda3),
   assertion(Luda2_Pars =@= [1.44, 69, 'Luda']),
   named_args_unify(Luda3, [height, weight, name], Luda3_Pars),
   assertion(Luda3_Pars =@= [1.45, 64, _]).

test(obj_rewrite_weak1,
     [throws(error(no_object_field(Luda1, country), _))]) :-

   obj_construct(man_v,
                 [name, height, weight],
                 ['Luda', 1.40, 99], Luda1),
   obj_rewrite(Luda1,
               [height, weight, name, country],
               _,
               [1.44, 69, _, 'UK'],
               _).

test(obj_rewrite_weak2,
     [[Old_Height, Old_Weight, Name, Old_Country]
     =@= [1.40, 99, 'Luda', _]]
     ) :-

   obj_construct(man_v,
                 [name, height, weight],
                 ['Luda', 1.40, 99], Luda1),
   obj_rewrite(Luda1, weak,
               [height, weight, name, country],
               [Old_Height, Old_Weight, Name, Old_Country],
               [1.44, 69, Name, 'UK'],
               _).

test(obj_rewrite_weak3, [fail]) :-

   obj_construct(man_v,
                 [name, height, weight],
                 ['Luda', 1.40, 99], Luda1),
   obj_rewrite(Luda1, fail,
               [height, weight, name, country],
               _,
               [1.44, 69, _, 'UK'],
               _).

test(obj_rewrite_with_evals1, [X == callup_v]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], O),
   obj_rewrite(O, [class], [X], [callup_v], _).

test(obj_rewrite_with_evals2, [fail]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], O),
   obj_rewrite(O, [class], [_], [citizen_v], _).

test(obj_rewrite_with_evals3, [X == callup_v]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], O),
   obj_rewrite(O, [class], [X], [X], _).

test(obj_rewrite_with_evals4) :-
% <NB> can't reset eval field, compare with test(obj_rewrite)

   obj_construct(citizen_v, [sex, birthday], [man, 1994], O),
   obj_rewrite(O, [class], [_], [_], _).

test(obj_sort_parents1,
     [P4 == [http_invalid_mixed_headers_v,
             http_invalid_headers_v,
             http_request_headers_v,
             http_response_headers_v,
             http_headers_v,
             object_v, object_base_v]]
     ) :-

   obj_construct(http_request_headers_v, [], [], V1),
   obj_rebase((http_headers_v -> http_response_headers_v),
              V1, V2),
   obj_rebase((http_headers_v -> http_invalid_mixed_headers_v),
              V2, V3),

   obj_sort_parents(V3, [http_invalid_bulk_headers_v,
                         http_invalid_mixed_headers_v,
                         http_invalid_headers_v,
                         http_request_headers_v,
                         http_response_headers_v,
                         http_headers_v,
                         tarjan_vertex_v,
                         db_object_v,
                         object_v, object_base_v], V4),
   obj_parents(V4, P4),
   functor(V4, F4, _),
   assertion(F4 == http_invalid_mixed_headers_v).

test(obj_sort_parents2,
     [throws(error(insufficient_class_order(Order,
                                            Orig_Order), _))]
     ) :-

   Order = [http_invalid_bulk_headers_v,
            http_invalid_mixed_headers_v,
            http_request_headers_v,
            http_response_headers_v,
            http_headers_v,
            tarjan_vertex_v,
            db_object_v,
            object_v, object_base_v],

   obj_construct(http_request_headers_v, [], [], V1),
   obj_rebase((http_headers_v -> http_response_headers_v),
              V1, V2),
   obj_rebase((http_headers_v -> http_invalid_mixed_headers_v),
              V2, V3),

   obj_parents(V3, Orig_Order),
   obj_sort_parents(V3, Order, _).

test(class_fields) :-

   class_fields(object_base_v, Object_Base_V_Fields),
   assertion(Object_Base_V_Fields == []),

   class_fields_new(object_base_v, Object_Base_V_New_Fields),
   assertion(Object_Base_V_New_Fields == []),

   class_fields(object_v, Object_V_Fields),
   assertion(Object_V_Fields == []),

   class_fields_new(object_v, Object_V_New_Fields),
   assertion(Object_V_New_Fields == []),

   class_fields(man_v, Man_V_Fields),
   assertion(Man_V_Fields == [height, name, sex, surname, weight]),

   class_fields_new(man_v, Man_V_New_Fields),
   assertion(Man_V_New_Fields == [height, name, sex, surname,
                                  weight]),

   class_fields(citizen_v, Citizen_V_Fields),
   assertion(Citizen_V_Fields == [birthday, country, height, id,
                                  name, sex, surname, weight]),

   class_fields_new(citizen_v, Citizen_V_New_Fields),
   assertion(Citizen_V_New_Fields == [birthday, country, id]).

% After some time it will always fails (because it depends
% on the current year, see The Uranium Book).
test(eval_fields1, [Class == callup_v]) :-

   obj_construct(citizen_v, [sex, birthday], [man, 1994], C),
   obj_field(C, class, Class).

test(cleanup_obj_rebase, [blocked(transaction_bug), N1 =:= N2]) :-

   aggregate(count, A^B^C^(objects:class_id(A, B, C)), N1),
   catch((obj_construct(numeric_id_v, [], [], Obj1),
          obj_rebase((object_v -> citizen_v), Obj1, _)),
         E, true),
   E = error(EX, _), functor(EX, duplicate_field, _),
   aggregate(count, A^B^C^(objects:class_id(A, B, C)), N2).

:- end_tests(v).


Tweaked cavity.plt.

Tweaked cavity.plt.

# Terminal type is: 0 - X11, 1 - PS, 2 - PNG, 3 - JPG
term_type = 0;

# On-axis long. E-field [V/m] vs. z [mm].
file1 = "axisData_41.txt";

# Transverse higher order E-field [V/m] ([V] for dipole) vs. z [mm].
# Dipole.
file2 = "Multipole41/CaviMlp_EDipole_41.txt";
# First half of defocusing component.
file3 = "Multipole41/CaviMlp_EFocus1_41.txt";
# Second half of defocusing component.
file4 = "Multipole41/CaviMlp_EFocus2_41.txt";
# Quadrupole.
file5 = "Multipole41/CaviMlp_EQuad_41.txt";

# Tranverse higher order H-field [A/m] ([A] for dipole) vs. z [mm]
file6 = "Multipole41/CaviMlp_HDipole_41.txt";
file7 = "Multipole41/CaviMlp_HMono_41.txt";
file8 = "Multipole41/CaviMlp_HQuad_41.txt";
file9 = "Multipole41/thinlenlon_41.txt";

if (term_type == 0) set terminal x11;
if (term_type == 1) set terminal postscript landscape enhanced color solid \
  lw 2 "Times-Roman" 15;
#if (term_type == 2) set terminal pngcairo size 350, 262 enhanced \
#  font 'Verdana,10';
if (term_type == 2) set terminal pngcairo enhanced font "Times-Roman";
if (term_type == 3) set terminal jpeg enhanced;

set grid;

set style line 1 lt 1 lw 1 lc rgb "blue";
set style line 2 lt 1 lw 1 lc rgb "cyan";
set style line 3 lt 1 lw 1 lc rgb "green";
set style line 4 lt 1 lw 1 lc rgb "red";
set style line 5 lt 1 lw 1 lc rgb "dark-green";
set style line 6 lt 1 lw 1 lc rgb "dark-orange";
set style line 7 lt 1 lw 1 lc rgb "dark-violet";
set style line 8 lt 1 lw 1 lc rgb "orange-red";

if (term_type == 1) set output "cavity_1.ps"
if (term_type == 2) set output "cavity_1.png"
if (term_type == 3) set output "cavity_1.jpg"

set title "Cavity Fundamental Mode: axisData";
set xlabel "z [cm]"; set ylabel "E_{/Symbol \174\174} [MV/m]";
plot file1 using (1e-1*$1):(1e-6*$2) notitle with lines ls 1;

if (term_type == 0) pause mouse "click on graph to cont.\n";

if (term_type == 1) set output "cavity_2.ps"
if (term_type == 2) set output "cavity_2.png"
if (term_type == 3) set output "cavity_2.jpg"

set multiplot;

set size 0.5, 0.5; set origin 0.0, 0.5;
set title "Cavity Mode: EDipole";
set xlabel "r [cm]"; set ylabel "E_{/Symbol \\136} [MV]";
plot file2 using (1e-1*$1):(1e-6*$2) notitle with lines ls 3;

set origin 0.5, 0.5;
set title "Cavity Mode: EQuad";
set xlabel "r [cm]"; set ylabel "E_{/Symbol \\136} [MV/m]";
plot file5 using (1e-1*$1):(1e-6*$2) notitle with lines ls 3;

set origin 0.0, 0.0;
set title "Cavity: EFocus1 & EFocus2";
set xlabel "r [cm]"; set ylabel "E_{/Symbol \\136} [MV/m]";
plot file3 using (1e-1*$1):(1e-6*$2) notitle with lines ls 3, \
     file4 using (1e-1*$1):(1e-6*$2) notitle with lines ls 3;

unset multiplot;
if (term_type == 0) pause mouse "click on graph to cont.\n";

if (term_type == 1) set output "cavity_3.ps"
if (term_type == 2) set output "cavity_3.png"
if (term_type == 3) set output "cavity_3.jpg"

set multiplot;

set size 0.5, 0.5; set origin 0.0, 0.5;
set title "Cavity Mode: HDipole";
set xlabel "r [cm]"; set ylabel "H_{/Symbol \\136} [A]";
plot file6 using (1e-1*$1):(1e-3*$2) notitle with lines ls 3;

set origin 0.5, 0.5;
set title "Cavity Mode: HMono";
set xlabel "r [cm]"; set ylabel "H_{/Symbol \\136} [A/m]";
plot file7 using (1e-1*$1):(1e-3*$2) notitle with lines ls 3;

set origin 0.0, 0.0;
set title "Cavity Mode: HQuad";
set xlabel "r [cm]"; set ylabel "H_{/Symbol \\136} [A/m]";
plot file8 using (1e-1*$1):(1e-3*$2) notitle with lines ls 3;

unset multiplot;
if (term_type == 0) pause mouse "click on graph to cont.\n";

if (term_type == 1) set output "cavity_4.ps"
if (term_type == 2) set output "cavity_4.png"
if (term_type == 3) set output "cavity_4.jpg"

set multiplot;

set size 1.0, 0.5; set origin 0.0, 0.5;
set title "Cavity Thin Lens Model: Longitudinal Kick";
set xlabel "z [cm]"; set ylabel "{/Symbol q}_{/Symbol \174\174} [mrad?]";
set xrange [-13:];
plot file9 using (1e-1*$1):($4) notitle with impulses ls 1;

set origin 0.0, 0.0;
set title "Transverse Kick";
set xlabel "z [cm]"; set ylabel "{/Symbol q}_{/Symbol \\136} [mrad?]";
set xrange [-13:];
plot file9 using (1e-1*$1):($6) axis x1y2 notitle with impulses ls 3;

unset multiplot;
if (term_type == 0) pause mouse "click on graph to cont.\n";

# Terminal type is: 0 - X11, 1 - PS, 2 - PNG, 3 - JPG
term_type = 1;

# On-axis long. E-field [V/m] vs. z [mm].
file1 = "axisData_41.txt";

# Transverse higher order E-field [V/m] ([V] for dipole) vs. z [mm].
# Dipole.
file2 = "Multipole41/CaviMlp_EDipole_41.txt";
# First half of defocusing component.
file3 = "Multipole41/CaviMlp_EFocus1_41.txt";
# Second half of defocusing component.
file4 = "Multipole41/CaviMlp_EFocus2_41.txt";
# Quadrupole.
file5 = "Multipole41/CaviMlp_EQuad_41.txt";

# Tranverse higher order H-field [A/m] ([A] for dipole) vs. z [mm]
file6 = "Multipole41/CaviMlp_HDipole_41.txt";
file7 = "Multipole41/CaviMlp_HMono_41.txt";
file8 = "Multipole41/CaviMlp_HQuad_41.txt";
file9 = "Multipole41/thinlenlon_41.txt";

if (term_type == 0) set terminal x11;
if (term_type == 1) set terminal postscript landscape enhanced color solid \
  lw 2 "Times-Roman" 15;
#if (term_type == 2) set terminal pngcairo size 350, 262 enhanced \
#  font 'Verdana,10';
if (term_type == 2) set terminal pngcairo enhanced font "Times-Roman";
if (term_type == 3) set terminal jpeg enhanced;

set grid;

set style line 1 lt 1 lw 1 lc rgb "blue";
set style line 2 lt 1 lw 1 lc rgb "cyan";
set style line 3 lt 1 lw 1 lc rgb "green";
set style line 4 lt 1 lw 1 lc rgb "red";
set style line 5 lt 1 lw 1 lc rgb "dark-green";
set style line 6 lt 1 lw 1 lc rgb "dark-orange";
set style line 7 lt 1 lw 1 lc rgb "dark-violet";
set style line 8 lt 1 lw 1 lc rgb "orange-red";

if (term_type == 1) set output "cavity_1.ps"
if (term_type == 2) set output "cavity_1.png"
if (term_type == 3) set output "cavity_1.jpg"

set title "Cavity Fundamental Mode: axisData";
set xlabel "z [cm]"; set ylabel "E_{/Symbol \174\174} [MV/m]";
plot file1 using (1e-1*$1):(1e-6*$2) notitle with lines ls 1;

if (term_type == 0) pause mouse "click on graph to cont.\n";

if (term_type == 1) set output "cavity_2.ps"
if (term_type == 2) set output "cavity_2.png"
if (term_type == 3) set output "cavity_2.jpg"

set multiplot;

set size 0.5, 0.5; set origin 0.0, 0.5;
set title "Cavity Mode: EDipole";
set xlabel "r [cm]"; set ylabel "E_{/Symbol \\136} [MV]";
plot file2 using (1e-1*$1):(1e-6*$2) notitle with lines ls 3;

set origin 0.5, 0.5;
set title "Cavity Mode: EQuad";
set xlabel "r [cm]"; set ylabel "E_{/Symbol \\136} [MV/m]";
plot file5 using (1e-1*$1):(1e-6*$2) notitle with lines ls 3;

set origin 0.0, 0.0;
set title "Cavity: EFocus1 & EFocus2";
set xlabel "r [cm]"; set ylabel "E_{/Symbol \\136} [MV/m]";
plot file3 using (1e-1*$1):(1e-6*$2) notitle with lines ls 3, \
     file4 using (1e-1*$1):(1e-6*$2) notitle with lines ls 3;

unset multiplot;
if (term_type == 0) pause mouse "click on graph to cont.\n";

if (term_type == 1) set output "cavity_3.ps"
if (term_type == 2) set output "cavity_3.png"
if (term_type == 3) set output "cavity_3.jpg"

set multiplot;

set size 0.5, 0.5; set origin 0.0, 0.5;
set title "Cavity Mode: HDipole";
set xlabel "r [cm]"; set ylabel "H_{/Symbol \\136} [A]";
plot file6 using (1e-1*$1):(1e-3*$2) notitle with lines ls 3;

set origin 0.5, 0.5;
set title "Cavity Mode: HMono";
set xlabel "r [cm]"; set ylabel "H_{/Symbol \\136} [A/m]";
plot file7 using (1e-1*$1):(1e-3*$2) notitle with lines ls 3;

set origin 0.0, 0.0;
set title "Cavity Mode: HQuad";
set xlabel "r [cm]"; set ylabel "H_{/Symbol \\136} [A/m]";
plot file8 using (1e-1*$1):(1e-3*$2) notitle with lines ls 3;

unset multiplot;
if (term_type == 0) pause mouse "click on graph to cont.\n";

if (term_type == 1) set output "cavity_4.ps"
if (term_type == 2) set output "cavity_4.png"
if (term_type == 3) set output "cavity_4.jpg"

set multiplot;

set size 1.0, 0.5; set origin 0.0, 0.5;
set title "Cavity Thin Lens Model: Longitudinal Kick";
set xlabel "z [cm]"; set ylabel "{/Symbol q}_{/Symbol \174\174} [mrad?]";
set xrange [-13:];
plot file9 using (1e-1*$1):($4) notitle with impulses ls 1;

set origin 0.0, 0.0;
set title "Transverse Kick";
set xlabel "z [cm]"; set ylabel "{/Symbol q}_{/Symbol \\136} [mrad?]";
set xrange [-13:];
plot file9 using (1e-1*$1):($6) axis x1y2 notitle with impulses ls 3;

unset multiplot;
if (term_type == 0) pause mouse "click on graph to cont.\n";


fine-tuning

fine-tuning

#!/usr/bin/env gnuplot

# graph of CPU temperature

# datafiles
ifnameh = "/tmp/lnxdiagd/mysql4gnuplot/sql11h.csv"
ifnamed = "/tmp/lnxdiagd/mysql4gnuplot/sql11d.csv"
ifnamew = "/tmp/lnxdiagd/mysql4gnuplot/sql11w.csv"
ifnamey = "/tmp/lnxdiagd/mysql4gnuplot/sql11y.csv"
set output "/tmp/lnxdiagd/site/img/day11.png"

# ******************************************************* General settings *****
set terminal png truecolor enhanced font "Vera,9" size 1280,640
set style fill transparent solid 0.25 noborder
set datafile separator ';'
set datafile missing "NaN"    # Ignore missing values
set grid front
tz_offset = utc_offset / 3600 # GNUplot only works with UTC. Need to compensate
                              # for timezone ourselves.
if (GPVAL_VERSION == 4.6) {epoch_compensate = 946684800} else {if (GPVAL_VERSION == 5.0) {epoch_compensate = 0}}
# Positions of split between graphs
LMARG = 0.06
LMPOS = 0.40
MRPOS = 0.73
RMARG = 0.94
TTPOS = 0.95
TBPOS = 0.55
BTPOS = 0.48
BBPOS = 0.08

min(x,y) = (x < y) ? x : y
max(x,y) = (x > y) ? x : y

# ********************************************************* Statistics (R) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnameh using 1 name "X" nooutput

Xh_min = X_min + utc_offset - epoch_compensate
Xh_max = X_max + utc_offset - epoch_compensate

# stats to be calculated here for Y-axes
stats ifnameh using 2 name "Yh" nooutput

# ********************************************************* Statistics (M) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamed using 1 name "X" nooutput

Xd_min = X_min + utc_offset - epoch_compensate
Xd_max = X_max + utc_offset - epoch_compensate

# stats to be calculated here for Y-axes
stats ifnamed using 3 name "Yd" nooutput

# ********************************************************* Statistics (L) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamew using 1 name "X" nooutput
Xw_min = X_min + utc_offset - epoch_compensate
Xw_max = X_max + utc_offset - epoch_compensate

# stats for Y-axis
stats ifnamew using 4 name "Yw" nooutput

Ymax = max(max(Yd_max, Yh_max), Yw_max) +1
Ymin = min(min(Yd_min, Yh_min), Yw_min) -1

# ********************************************************* Statistics (Y) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamey using 1 name "X" nooutput
Xy_min = X_min + utc_offset - epoch_compensate
Xy_max = X_max + utc_offset - epoch_compensate

set multiplot layout 2, 3 title "CPU Temperature ".strftime("( %Y-%m-%dT%H:%M:%S )", time(0)+utc_offset)
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                                  UPPER ROW
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set tmargin at screen TTPOS
set bmargin at screen TBPOS
set lmargin at screen LMARG
set rmargin at screen RMARG

# ***************************************************************** X-axis *****
set xlabel "past week"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%b"            # Display time in 24 hour notation on the X axis
set xrange [ Xy_min : Xy_max ]

# ***************************************************************** Y-axis *****
set ylabel "Temperature [degC]"
set yrange [ : ]

# ***************************************************************** Legend *****
set key inside top left horizontal box
set key samplen 1
set key reverse Left

# ***************************************************************** Output *****
# ***** PLOT *****
plot ifnamey \
      using ($1+utc_offset):2:4 notitle with filledcurves lc rgb "#bb0000" \
  ,'' using ($1+utc_offset):3   title " Temperature [degC]" with points pt 5 ps 0.2 fc rgb "#bb0000"

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                                  LOWER ROW
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                       LEFT PLOT: past week
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past week"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%a %d"            # Display time in 24 hour notation on the X axis
set xrange [ Xw_min : Xw_max ]

# ***************************************************************** Y-axis *****
set ylabel "Temperature [degC]"
set yrange [ Ymin : Ymax ]

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
# set arrow from graph 0,graph 0 to graph 0,graph 1 nohead lc rgb "red" front
# set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
#set object 1 rect from screen 0,0 to screen 1,1 behind
#set object 1 rect fc rgb "#eeeeee" fillstyle solid 1.0 noborder
#set object 2 rect from graph 0,0 to graph 1,1 behind
#set object 2 rect fc rgb "#ffffff" fillstyle solid 1.0 noborder

set tmargin at screen BTPOS
set bmargin at screen BBPOS
set lmargin at screen LMARG
set rmargin at screen LMPOS

# ***** PLOT *****
plot ifnamew \
      using ($1+utc_offset):2:4 with filledcurves lc rgb "#bb0000" \
  ,'' using ($1+utc_offset):3 with lines lw 0.1 fc rgb "#bb0000"

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                     MIDDLE PLOT:  past day
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past day"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xd_min : Xd_max ]

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ Ymin : Ymax ]

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen LMPOS+0.001
set rmargin at screen MRPOS

# ***** PLOT *****
plot ifnamed \
      using ($1+utc_offset):2:4 with filledcurves lc rgb "#bb0000" \
  ,'' using ($1+utc_offset):3 with points pt 5 ps 0.2 fc rgb "#bb0000"

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                      RIGHT PLOT: past hour
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past hour"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xh_min : Xh_max ]
set xtics textcolor rgb "red"

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ Ymin : Ymax ]

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen MRPOS+0.001
set rmargin at screen RMARG

# ***** PLOT *****
plot ifnameh \
      using ($1+utc_offset):2 with points pt 5 ps 0.2 fc rgb "#bb0000" \

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                                 FINALIZING
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

unset multiplot

#!/usr/bin/env gnuplot

# graph of CPU temperature

# datafiles
ifnameh = "/tmp/lnxdiagd/mysql4gnuplot/sql11h.csv"
ifnamed = "/tmp/lnxdiagd/mysql4gnuplot/sql11d.csv"
ifnamew = "/tmp/lnxdiagd/mysql4gnuplot/sql11w.csv"
ifnamey = "/tmp/lnxdiagd/mysql4gnuplot/sql11y.csv"
set output "/tmp/lnxdiagd/site/img/day11.png"

# ******************************************************* General settings *****
set terminal png truecolor enhanced font "Vera,9" size 1280,640
set style fill transparent solid 0.25 noborder
set datafile separator ';'
set datafile missing "NaN"    # Ignore missing values
set grid front
tz_offset = utc_offset / 3600 # GNUplot only works with UTC. Need to compensate
                              # for timezone ourselves.
if (GPVAL_VERSION == 4.6) {epoch_compensate = 946684800} else {if (GPVAL_VERSION == 5.0) {epoch_compensate = 0}}
# Positions of split between graphs
LMARG = 0.06
LMPOS = 0.40
MRPOS = 0.73
RMARG = 0.94
TTPOS = 0.95
TBPOS = 0.55
BTPOS = 0.48
BBPOS = 0.08

min(x,y) = (x < y) ? x : y
max(x,y) = (x > y) ? x : y

# ********************************************************* Statistics (R) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnameh using 1 name "X" nooutput

Xh_min = X_min + utc_offset - epoch_compensate
Xh_max = X_max + utc_offset - epoch_compensate

# stats to be calculated here for Y-axes
stats ifnameh using 2 name "Yh" nooutput

# ********************************************************* Statistics (M) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamed using 1 name "X" nooutput

Xd_min = X_min + utc_offset - epoch_compensate
Xd_max = X_max + utc_offset - epoch_compensate

# stats to be calculated here for Y-axes
stats ifnamed using 3 name "Yd" nooutput

# ********************************************************* Statistics (L) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamew using 1 name "X" nooutput
Xw_min = X_min + utc_offset - epoch_compensate
Xw_max = X_max + utc_offset - epoch_compensate

# stats for Y-axis
stats ifnamew using 4 name "Yw" nooutput

Ymax = max(max(Yd_max, Yh_max), Yw_max) +1
Ymin = min(min(Yd_min, Yh_min), Yw_min) -1

# ********************************************************* Statistics (Y) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamey using 1 name "X" nooutput
Xy_min = X_min + utc_offset - epoch_compensate
Xy_max = X_max + utc_offset - epoch_compensate

set multiplot layout 2, 3 title "CPU Temperature ".strftime("( %Y-%m-%dT%H:%M:%S )", time(0)+utc_offset)
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                                  UPPER ROW
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set tmargin at screen TTPOS
set bmargin at screen TBPOS
set lmargin at screen LMARG
set rmargin at screen RMARG

# ***************************************************************** X-axis *****
set xlabel "past week"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%a %d"            # Display time in 24 hour notation on the X axis
set xrange [ Xy_min : Xy_max ]

# ***************************************************************** Y-axis *****
set ylabel "Temperature [degC]"
set yrange [ : ]

# ***************************************************************** Legend *****
set key inside top left horizontal box
set key samplen 1
set key reverse Left

# ***************************************************************** Output *****
# ***** PLOT *****
plot ifnamey \
      using ($1+utc_offset):2:4 with filledcurves lc rgb "#bb0000" \
  ,'' using ($1+utc_offset):3 with points pt 5 ps 0.2 fc rgb "#bb0000"

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                                  LOWER ROW
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                       LEFT PLOT: past week
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past week"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%a %d"            # Display time in 24 hour notation on the X axis
set xrange [ Xw_min : Xw_max ]

# ***************************************************************** Y-axis *****
set ylabel "Temperature [degC]"
set yrange [ Ymin : Ymax ]

# ***************************************************************** Legend *****
set key inside top left horizontal box
set key samplen 1
set key reverse Left

# ***************************************************************** Output *****
# set arrow from graph 0,graph 0 to graph 0,graph 1 nohead lc rgb "red" front
# set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
#set object 1 rect from screen 0,0 to screen 1,1 behind
#set object 1 rect fc rgb "#eeeeee" fillstyle solid 1.0 noborder
#set object 2 rect from graph 0,0 to graph 1,1 behind
#set object 2 rect fc rgb "#ffffff" fillstyle solid 1.0 noborder

set tmargin at screen BTPOS
set bmargin at screen BBPOS
set lmargin at screen LMARG
set rmargin at screen LMPOS

# ***** PLOT *****
plot ifnamew \
      using ($1+utc_offset):2:4 notitle with filledcurves lc rgb "#bb0000" \
  ,'' using ($1+utc_offset):3 title " Temperature [degC]" with lines lw 0.1 fc rgb "#bb0000"

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                     MIDDLE PLOT:  past day
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past day"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xd_min : Xd_max ]

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ Ymin : Ymax ]

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen LMPOS+0.001
set rmargin at screen MRPOS

# ***** PLOT *****
plot ifnamed \
      using ($1+utc_offset):2:4 with filledcurves lc rgb "#bb0000" \
  ,'' using ($1+utc_offset):3 with points pt 5 ps 0.2 fc rgb "#bb0000"

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                      RIGHT PLOT: past hour
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past hour"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xh_min : Xh_max ]
set xtics textcolor rgb "red"

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ Ymin : Ymax ]

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen MRPOS+0.001
set rmargin at screen RMARG

# ***** PLOT *****
plot ifnameh \
      using ($1+utc_offset):2 with points pt 5 ps 0.2 fc rgb "#bb0000" \

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                                 FINALIZING
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

unset multiplot


v6.42

v6.42

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


fix height

fix height

reset
set ylabel 'time(sec)'
set style fill solid
set title 'perfomance comparison'
set term png enhanced font 'Verdana,10'
set output 'runtime1.png'

plot [:][:10]'output.txt' using 2:xtic(1) with histogram title 'original', \
'' using 3:xtic(1) with histogram title 'optimized'  , \
'' using 4:xtic(1) with histogram title 'B+ tree' , \
'' using 5:xtic(1) with histogram title 'B+ tree bulk' , \
'' using ($0-0.1):(1.9):2 with labels title ' ' textcolor lt 1, \
'' using ($0-0.1):(1.6):3 with labels title ' ' textcolor lt 2, \
'' using ($0-0.1):(1.3):4 with labels title ' ' textcolor lt 3, \
'' using ($0-0.1):(1):5 with labels title ' ' textcolor lt 4, \

reset
set ylabel 'time(sec)'
set style fill solid
set title 'perfomance comparison'
set term png enhanced font 'Verdana,10'
set output 'runtime1.png'

plot [:][:0.0005]'output.txt' using 2:xtic(1) with histogram title 'original', \
'' using 3:xtic(1) with histogram title 'optimized'  , \
'' using 4:xtic(1) with histogram title 'B+ tree' , \
'' using 5:xtic(1) with histogram title 'B+ tree bulk' , \
'' using ($0+0.1):(0.0001):2 with labels title ' ' textcolor lt 1, \
'' using ($0+0.1):(0.00012):3 with labels title ' ' textcolor lt 2, \
'' using ($0+0.1):(0.00014):4 with labels title ' ' textcolor lt 3, \
'' using ($0+0.1):(0.00016):5 with labels title ' ' textcolor lt 4, \


Made this script work

Made this script work

git-svn-id: b233c5b81dcfbfdfca783093b3213ccfd2356b3a@552 3eb578c0-666c-0410-8428-3510748880ad

set terminal png
set yr[0:]
set output "../planar-axiall5b6.d0g1.d-3DF.png"
plot "../planar-axiall5b6.d0DF.txt" using 2:5 every ::33::43, "../analytical_data/BBR_axial_mix.txt" using 1:3 every ::33::43

set output "../planar-axiall5b6.d0g1.d-2DF.png"
plot "../planar-axiall5b6.d0DF.txt" using 2:5 every ::66::76, "../analytical_data/BBR_axial_mix.txt" using 1:3 every ::66::76

set output "../planar-axiall5b6.d0g1.d-1DF.png"
plot "../planar-axiall5b6.d0DF.txt" using 2:5 every ::99::108, "../analytical_data/BBR_axial_mix.txt" using 1:3 every ::99::108

set output "../planar-biaxiall5b6.d0g1.d-3DF.png"
plot "../planar-biaxiall5b6.d0DF.txt" using 2:5 every ::33::43, "../analytical_data/BBR_biaxial_mix.txt" using 1:3 every ::33::43

set output "../planar-biaxiall5b6.d0g1.d-2DF.png"
plot "../planar-biaxiall5b6.d0DF.txt" using 2:5 every ::66::76, "../analytical_data/BBR_biaxial_mix.txt" using 1:3 every ::66::76

set output "../planar-biaxiall5b6.d0g1.d-1DF.png"
plot "../planar-biaxiall5b6.d0DF.txt" using 2:5 every ::99::108, "../analytical_data/BBR_biaxial_mix.txt" using 1:3 every ::99::108

set terminal png
set yr[0:]
set output "../planar-axiall6b6.d0g1.d-3DF.png"
plot "../planar-axiall6b6.d0DF.txt" using 2:5 every ::33::43, "../analytical_data/BBR_axial_mix.txt" using 1:3 every ::33::43

set output "../planar-axiall6b6.d0g1.d-2DF.png"
plot "../planar-axiall6b6.d0DF.txt" using 2:5 every ::66::76, "../analytical_data/BBR_axial_mix.txt" using 1:3 every ::66::76

set output "../planar-axiall6b6.d0g1.d-1DF.png"
plot "../planar-axiall6b6.d0DF.txt" using 2:5 every ::99::108, "../analytical_data/BBR_axial_mix.txt" using 1:3 every ::99::108

set output "../planar-biaxiall6b6.d0g1.d-3DF.png"
plot "../planar-biaxiall6b6.d0DF.txt" using 2:5 every ::33::43, "../analytical_data/BBR_biaxial_mix.txt" using 1:3 every ::33::43

set output "../planar-biaxiall6b6.d0g1.d-2DF.png"
plot "../planar-biaxiall6b6.d0DF.txt" using 2:5 every ::66::76, "../analytical_data/BBR_biaxial_mix.txt" using 1:3 every ::66::76

set output "../planar-biaxiall6b6.d0g1.d-1DF.png"
plot "../planar-biaxiall6b6.d0DF.txt" using 2:5 every ::99::108, "../analytical_data/BBR_biaxial_mix.txt" using 1:3 every ::99::108


tweaked

tweaked


small change

small change

set auto x
#set yrange [0:15]
set yrange [0:10]
set xtics rotate
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set xtics font "Arial, 18"
set xrange [-0.5:7.5]
set boxwidth 0.9
set ylabel "Energy efficiency order" font "Arial Bold,18"
set term post eps

plot 'plots/shared.dat' using 3:xtic(2) ti col fc rgb "blue" fs solid 0.5 border -1, '' u 4 ti col fc rgb "red" fs solid 0.5 border -1, '' u 5 ti col fc rgb "green" fs solid 0.5 border -1

#plot 'plots/shared.dat' using ($6/60):xtic(2) ti col fc rgb "blue" fs solid 0.5 border -1, '' u ($7/30) ti col fc rgb "red" fs solid 0.5 border -1, '' u ($8/50) ti col fc rgb "green" fs solid 0.5 border -1

set auto x
#set yrange [0:15]
set yrange [0:10]
set xtics rotate
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set xtics font "Arial, 18"
set xrange [-0.5:7.5]
set ylabel "Energy efficiency order" font "Arial Bold,18"
set term post eps

plot 'plots/shared.dat' using 3:xtic(2) ti col fc rgb "blue" fs solid 0.5 border -1, '' u 4 ti col fc rgb "red" fs solid 0.5 border -1, '' u 5 ti col fc rgb "green" fs solid 0.5 border -1

#plot 'plots/shared.dat' using ($6/60):xtic(2) ti col fc rgb "blue" fs solid 0.5 border -1, '' u ($7/30) ti col fc rgb "red" fs solid 0.5 border -1, '' u ($8/50) ti col fc rgb "green" fs solid 0.5 border -1


analysis.gnu for a value

analysis.gnu for a value

Signed-off-by: Eric, Hsu-yao Tsai <ad8e9cf61b582456bbe32d188af06658a1707686@araisrobot.com>

plot \
    "wou_steps.log" using 1:2 title "pos_cmd[0]", \
    "wou_steps.log" using 1:3 title "cur_pos[0]", \
    "wou_steps.log" using 1:4 title "pos_fb[0]", \
    "wou_steps.log" using 1:7 title "pos_cmd[1]", \
    "wou_steps.log" using 1:8 title "cur_pos[1]", \
    "wou_steps.log" using 1:9 title "pos_fb[1]", \
    "wou_steps.log" using 1:12 title "pos_cmd[2]", \
    "wou_steps.log" using 1:13 title "cur_pos[2]", \
    "wou_steps.log" using 1:14 title "pos_fb[2]", \
    "wou_steps.log" using 1:17 title "pos_cmd[3]", \
    "wou_steps.log" using 1:18 title "cur_pos[3]" \
    "wou_steps.log" using 1:19 title "pos_fb[3]",

plot \
    "wou_steps.log" using 1:2 title "pos_cmd[0]", \
    "wou_steps.log" using 1:3 title "cur_pos[0]", \
    "wou_steps.log" using 1:($4/100) title "match_ac[0]", \
    "wou_steps.log" using 1:($5/10) title "curr_vel[0]"

plot \
    "wou_steps.log_1209" using 1:2 title "pos_cmd[0]", \
    "wou_steps.log_1209" using 1:3 title "cur_pos[0]", \
    "wou_steps.log_1209" using 1:($4/100) title "match_ac[0]", \
    "wou_steps.log_1209" using 1:($5/10) title "curr_vel[0]"

plot \
    "wou_steps.log" using 1:6 title "pos_cmd[1]", \
    "wou_steps.log" using 1:7 title "cur_pos[1]", \
    "wou_steps.log" using 1:($8/100) title "match_ac[1]", \
    "wou_steps.log" using 1:($9/10) title "curr_vel[1]"

plot \
    "wou_steps.log" using 1:10 title "pos_cmd[2]", \
    "wou_steps.log" using 1:11 title "cur_pos[2]", \
    "wou_steps.log" using 1:($12/100) title "match_ac[2]", \
    "wou_steps.log" using 1:($13/10) title "curr_vel[2]"

plot \
    "wou_steps.log" using 1:14 title "pos_cmd[3]", \
    "wou_steps.log" using 1:15 title "cur_pos[3]", \
    "wou_steps.log" using 1:($16/100) title "match_ac[3]", \
    "wou_steps.log" using 1:($17/10) title "curr_vel[3]"

# to plot trajectory planning trace dumped by src/emc/motion/control.c
plot \
    "control.log" using 1:2 title "x", \
    "control.log" using 1:3 title "y", \
    "control.log" using 1:6 title "tp_pos[0]", \
    "control.log" using 1:7 title "tp_pos[1]", \
    "control.log" using 1:10 title "cubic_pos[0]", \
    "control.log" using 1:11 title "cubic_pos[1]"

# to plot trajectory planning trace dumped by src/emc/motion/control.c
plot \
    "control.log" using 1:2 title "x", \
    "control.log" using 1:3 title "y", \
    "control.log" using 1:4 title "z", \
    "control.log" using 1:5 title "a", \
    "control.log" using 1:6 title "tp_pos[0]", \
    "control.log" using 1:7 title "tp_pos[1]", \
    "control.log" using 1:8 title "tp_pos[2]", \
    "control.log" using 1:9 title "tp_pos[3]", \
    "control.log" using 1:10 title "cubic_pos[0]", \
    "control.log" using 1:11 title "cubic_pos[1]", \
    "control.log" using 1:12 title "cubic_pos[2]", \
    "control.log" using 1:13 title "cubic_pos[3]"

# to plot trace dumped by src/emc/kinematics/tp.c
plot \
    "tp.log" using 1:2 title "newaccel", \
    "tp.log" using 1:3 title "newvel", \
    "tp.log" using 1:4 title "cur_vel", \
    "tp.log" using 1:5 title "progress"

#tc.c plot

plot \
    "tc.log" using 1:2 title "u", \
    "tc.log" using 1:3 title "l"

plot \
    "tc.log" using 1:7 title "delta_d", \
    "tc.log" using 1:8 title "delta_l", \
    "tc.log" using 2:3 title "u vs l"

plot \
    "tc.log" using 1:4 title "x", \
    "tc.log" using 1:5 title "y", \
    "tc.log" using 1:6 title "z", \
    "tc.log" using 1:9 title "a"

plot  "tc.log" using 2:3 title "u vs l"

plot  "tc.log" using 4:5 title "x vs y"

plot \
    "wou_steps.log" using 1:2 title "pos_cmd[0]", \
    "wou_steps.log" using 1:3 title "cur_pos[0]", \
    "wou_steps.log" using 1:4 title "pos_fb[0]", \
    "wou_steps.log" using 1:7 title "pos_cmd[1]", \
    "wou_steps.log" using 1:8 title "cur_pos[1]", \
    "wou_steps.log" using 1:9 title "pos_fb[1]", \
    "wou_steps.log" using 1:12 title "pos_cmd[2]", \
    "wou_steps.log" using 1:13 title "cur_pos[2]", \
    "wou_steps.log" using 1:14 title "pos_fb[2]", \
    "wou_steps.log" using 1:17 title "pos_cmd[3]", \
    "wou_steps.log" using 1:18 title "cur_pos[3]" \
    "wou_steps.log" using 1:19 title "pos_fb[3]",

plot \
    "wou_steps.log" using 1:2 title "pos_cmd[0]", \
    "wou_steps.log" using 1:3 title "cur_pos[0]", \
    "wou_steps.log" using 1:($4/100) title "match_ac[0]", \
    "wou_steps.log" using 1:($5/10) title "curr_vel[0]"

plot \
    "wou_steps.log_1209" using 1:2 title "pos_cmd[0]", \
    "wou_steps.log_1209" using 1:3 title "cur_pos[0]", \
    "wou_steps.log_1209" using 1:($4/100) title "match_ac[0]", \
    "wou_steps.log_1209" using 1:($5/10) title "curr_vel[0]"

plot \
    "wou_steps.log" using 1:6 title "pos_cmd[1]", \
    "wou_steps.log" using 1:7 title "cur_pos[1]", \
    "wou_steps.log" using 1:($8/100) title "match_ac[1]", \
    "wou_steps.log" using 1:($9/10) title "curr_vel[1]"

plot \
    "wou_steps.log" using 1:10 title "pos_cmd[2]", \
    "wou_steps.log" using 1:11 title "cur_pos[2]", \
    "wou_steps.log" using 1:($12/100) title "match_ac[2]", \
    "wou_steps.log" using 1:($13/10) title "curr_vel[2]"

plot \
    "wou_steps.log" using 1:14 title "pos_cmd[3]", \
    "wou_steps.log" using 1:15 title "cur_pos[3]", \
    "wou_steps.log" using 1:($16/100) title "match_ac[3]", \
    "wou_steps.log" using 1:($17/10) title "curr_vel[3]"

# to plot trajectory planning trace dumped by src/emc/motion/control.c
plot \
    "control.log" using 1:2 title "x", \
    "control.log" using 1:3 title "y", \
    "control.log" using 1:6 title "tp_pos[0]", \
    "control.log" using 1:7 title "tp_pos[1]", \
    "control.log" using 1:10 title "cubic_pos[0]", \
    "control.log" using 1:11 title "cubic_pos[1]"

# to plot trajectory planning trace dumped by src/emc/motion/control.c
plot \
    "control.log" using 1:2 title "x", \
    "control.log" using 1:3 title "y", \
    "control.log" using 1:4 title "z", \
    "control.log" using 1:5 title "a", \
    "control.log" using 1:6 title "tp_pos[0]", \
    "control.log" using 1:7 title "tp_pos[1]", \
    "control.log" using 1:8 title "tp_pos[2]", \
    "control.log" using 1:9 title "tp_pos[3]", \
    "control.log" using 1:10 title "cubic_pos[0]", \
    "control.log" using 1:11 title "cubic_pos[1]", \
    "control.log" using 1:12 title "cubic_pos[2]", \
    "control.log" using 1:13 title "cubic_pos[3]"

# to plot trace dumped by src/emc/kinematics/tp.c
plot \
    "tp.log" using 1:2 title "newaccel", \
    "tp.log" using 1:3 title "newvel", \
    "tp.log" using 1:4 title "cur_vel", \
    "tp.log" using 1:5 title "progress"

#tc.c plot

plot \
    "tc.log" using 1:2 title "u", \
    "tc.log" using 1:3 title "l"

plot \
    "tc.log" using 1:7 title "delta_d", \
    "tc.log" using 1:8 title "delta_l", \
    "tc.log" using 2:3 title "u vs l"

plot \
    "tc.log" using 1:4 title "x", \
    "tc.log" using 1:5 title "y", \
    "tc.log" using 1:6 title "z"

plot  "tc.log" using 2:3 title "u vs l"

plot  "tc.log" using 4:5 title "x vs y"