root/library/tests/square_mat_prep.cpp @ 467

Revision 467, 1.7 kB (checked in by vbarta, 15 years ago)

added a program (square_mat_prep) to generate configurably random matrices, changed square_mat_stress to use the generated agenda

Line 
1#include "base/bdmbase.h"
2#include "base/user_info.h"
3#include "generator.h"
4#include "additive_generator.h"
5#include "size_generator.h"
6#include <iostream>
7#include <iomanip>
8#include <memory>
9#include <stdlib.h>
10
11using namespace std;
12using namespace bdm;
13using namespace itpp;
14
15UIREGISTER(size_generator);
16UIREGISTER(additive_generator);
17
18const char *generator_file_name = "generator.cfg";
19const char *agenda_file_name = "agenda.cfg";
20int agenda_length = 10;
21
22int main(int argc, char const *argv[]) {
23    RNG_randomize();
24
25    bool unknown = false;
26    int update_next = 0; // 1 generator file, 2 agenda file, 3 agenda length
27    const char **param = argv + 1;
28    while (*param && !unknown) {
29        if (update_next) {
30            if (update_next == 1) {
31                generator_file_name = *param;
32            } else if (update_next == 2) {
33                agenda_file_name = *param;
34            } else {
35                int length = atoi(*param);
36                if (length > 0) {
37                    agenda_length = length;
38                } else {
39                    cerr << "invalid agenda length value ignored" << endl;
40                }
41            }
42
43            update_next = 0;
44        } else {
45            if (!strcmp(*param, "-a")) {
46                update_next = 2;
47            } else if (!strcmp(*param, "-g")) {
48                update_next = 1;
49            } else if (!strcmp(*param, "-l")) {
50                update_next = 3;
51            } else {
52                unknown = true;
53            }
54        }
55
56        ++param;
57    }
58
59    if (unknown || update_next) {
60        cerr << "usage: " << argv[0] << " [ -g generator.cfg ] [ -a agenda_output.cfg ] [ -l agenda_length ]" << endl;
61    } else {
62        Array<mat> mag(agenda_length);
63
64        UIFile gspec(generator_file_name);
65        auto_ptr<generator> gen(UI::build<generator>(gspec, "generator"));
66        for (int i = 0; i < agenda_length; ++i) {
67            mag(i) = gen->next();
68        }
69
70        UIFile fag;
71        UI::save(mag, fag, "agenda");
72        fag.save(agenda_file_name);
73    }
74}
Note: See TracBrowser for help on using the browser.