Algorithmique Numérique Distribuée Public GIT Repository
1 #!/usr/bin/perl -w
2 use strict;
3 #use Data::Dumper;
4 use XFig;
6 my(\$grid_Y_size)=225; # xfig
7 my(\$grid_X_size)=225; # xfig
10     my(%Cat);
11     my(\$filename)=@_;
12     my(\$line);
14     open INPUT, \$filename;
16     while (defined(\$line=<INPUT>)) {
17         chomp \$line;
18         if(\$line =~ /^7\s/) {
19             my(\$event,\$date,\$id,\$type,\$father,@name) = split(/\s+/,\$line);
21             \$Cat{\$id}{name}="@name ";
22             \$Cat{\$id}{name}=~s/\"//g;
23             \$Cat{\$id}{father}=\$father;
24             \$Cat{\$id}{type}=\$type;
25             \$Cat{\$id}{date}=\$date;
26         }
27     }
28     close INPUT;
29     return \%Cat;
30 }
34     my(\$filename,\$Cat)=@_;
35     my(\$line);
37     open INPUT, \$filename;
39     while (defined(\$line=<INPUT>)) {
40         chomp \$line;
41         if(\$line =~ /^11\s/) {
42             my(\$event,\$date,\$type,\$id,\$state) = split(/\s+/,\$line);
43             push @{\$\$Cat{\$id}{state}}, [\$date,\$state];
44         }
45         if(\$line =~ /^12\s/) {
46             my(\$event,\$date,\$type,\$id) = split(/\s+/,\$line);
47             push @{\$\$Cat{\$id}{state}}, [\$date];
48         }
49     }
50     close INPUT;
51 }
54     my(\$filename)=@_;
55     my(\$line);
58     open INPUT, \$filename;
60     while (defined(\$line=<INPUT>)) {
61         chomp \$line;
62         if(\$line =~ /^16\s/) {
63             my(\$event,\$date,\$type,\$father,\$channel,\$src,\$key) = split(/\s+/,\$line);
66         }
67         if(\$line =~ /^17\s/) {
68             my(\$event,\$date,\$type,\$father,\$channel,\$dst,\$key) = split(/\s+/,\$line);
71         }
72     }
73     close INPUT;
75 }
78 sub build_cat_tree {
79     my(\$root,\$Cat)=@_;
80     my(@childs)=();
81     my(\$cat);
83     foreach \$cat (keys %\$Cat) {
84         if(\$\$Cat{\$cat}{father} eq \$root) {
85             push @childs, build_cat_tree(\$cat,\$Cat);
86         }
87 #       print "\$\$Cat{\$cat}{name}\t\t \$Cat{\$cat}{father}\n";
88     }
90     return [\$root,@childs];
91 }
93 sub build_cat_list {
94     my(\$tree,\$cat_list)=@_;
95     my(\$root) = shift @\$tree;
96     my(\$u);
98     push @\$cat_list,\$root;
100     foreach \$u (@\$tree) {
101         build_cat_list(\$u,\$cat_list);
102     }
103     unshift @\$tree, \$root;
104 }
107 sub set_cat_position {
108     my(\$Cat,\$cat_list)=@_;
109     my(\$i)=0;
110     my(\$cat);
111     foreach \$cat (@\$cat_list) {
112         \$\$Cat{\$cat}{Y_min} = \$i;
113         \$\$Cat{\$cat}{Y_max} = \$i+1;
114         \$i++;
115     }
116 }
118 sub create_fig {
119     my(\$filename)=shift;
120     my(\$fig)=new XFig;
121     \$fig->{object} = 'compound'; # Compound
122     \$fig->{elements} = [];
123     \$fig->{version} = 3.2;
124     \$fig->{orientation}   = 'Landscape';
125     \$fig->{justification} = 'Center';
126     \$fig->{units}         = 'Metric';
127     \$fig->{papersize}     = 'A4';
128     \$fig->{magnification} = '100.00';
129     \$fig->{multiplepage}  = 'Single';
130     \$fig->{transparent}   = '-2';
131     \$fig->{resolution}    = '1200';
132     \$fig->{coordsystem}   = '2';
133     \$fig->{filename}   = \$filename;
134     return \$fig;
135 }
137 sub draw_cat {
140     foreach \$cat (keys %\$Cat) {
141         next unless (defined(\$\$Cat{\$cat}{Y_min}) &&
142                      defined(\$\$Cat{\$cat}{Y_max}));
143         my(\$text) = new XFig ('text');
144         \$text->{'text'} = \$\$Cat{\$cat}{name};
145         \$text->{'y'} = (\$\$Cat{\$cat}{Y_min}+\$\$Cat{\$cat}{Y_max})/2*\$grid_Y_size+68;
147     }
148     foreach \$cat (keys %\$Cat) {
149         next unless (defined(\$\$Cat{\$cat}{Y_min}) &&
150                      defined(\$\$Cat{\$cat}{Y_max}));
151         my(@states)=();
152         my(\$e);
153         foreach \$e (@{\$\$Cat{\$cat}{state}}) {
154             my(\$new_date,\$state) = (\$\$e[0],\$\$e[1]);
155             if(defined(\$state)) {
156                 push @states, \$e;
157             } else {
158                 my(\$old_event) = pop @states;
159                 my(\$old_date) = \$\$old_event[0];
160                 \$state = \$\$old_event[1];
162                 my(\$line) = new XFig ('polyline');
164                 \$line->{'subtype'} = 1;  # line
165                 \$line->{'points'} = [ [\$old_date*\$grid_X_size, \$\$Cat{\$cat}{Y_min}*\$grid_Y_size],
166                                       [\$new_date*\$grid_X_size, \$\$Cat{\$cat}{Y_min}*\$grid_Y_size],
167                                       [\$new_date*\$grid_X_size, \$\$Cat{\$cat}{Y_max}*\$grid_Y_size],
168                                       [\$old_date*\$grid_X_size, \$\$Cat{\$cat}{Y_max}*\$grid_Y_size] ];
169                 \$line->{'areafill'} = 20;
170                 if(\$state eq "S") {
171                     \$line->{'fillcolor'} = 1;
172                 } elsif (\$state eq "E") {
173                     \$line->{'fillcolor'} = 2;
174                 } elsif (\$state eq "B") {
175                     \$line->{'fillcolor'} = 3;
176                 } elsif (\$state eq "C") {
177                     \$line->{'fillcolor'} = 4;
178                 }
180             }
181         }
182     }
185         my(\$line) = new XFig ('polyline');
190         \$line->{'subtype'} = 1;  # line
192         \$line->{'points'} = [ [\$src_date*\$grid_X_size,
193                                (\$\$Cat{\$src}{Y_min}+\$\$Cat{\$src}{Y_max})/2*\$grid_Y_size],
194                               [\$dst_date*\$grid_X_size,
195                                (\$\$Cat{\$dst}{Y_min}+\$\$Cat{\$dst}{Y_max})/2*\$grid_Y_size] ];
196         \$line->{'forwardarrow'} = ['1', '1', '1.00', '60.00', '120.00'];
198     }
199 }
201 sub main {
203     my(\$cat_tree)=build_cat_tree("0",\$Cat);
206 #    print Dumper(\$cat_tree);
207 #    print Dumper(\$Cat);
208     my(\$cat_list)=[];
209     build_cat_list(\$cat_tree,\$cat_list);
210     shift @\$cat_list;
211     shift @\$cat_list;
212     print "@\$cat_list \n";
214     set_cat_position(\$Cat,\$cat_list);
216     my(\$fig)=create_fig("toto.fig");