lib/App/SeismicUnixGui/misc/perl_flow.pm untested

filter: Statementstmt 0.0% 0 / 204 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 281 CC 14 SCAR 20.4
CC
14
Cov
0%
parse
20.0
get_all_values_aref
12.0
get_all_names_aref
6.0
CRAP 7.7
1 package App::SeismicUnixGui::misc::perl_flow;
2  
3 =head1 DOCUMENTATION
4  
5  
6 =head2 SYNOPSIS
7  
8 PERL PROGRAM NAME: perl_flow
9 AUTHOR: Juan Lorenzo
10 DATE: June 22 2017
11  
12 DESCRIPTION Parse perl scripts written by L_SU
13
14  
15 BASED ON:
16  
17  
18 =cut
19  
20 =head2 USE
21  
22 =head3 NOTES Needs sunix_pl.pm
23  
24 =head4 Examples
25  
26  
27 =head2 CHANGES and their DATES
28 April 29, 2019
29 encapsulate $Project_config to sub parse
30  
31
32 =cut
33  
34 use Moose;
35 our $VERSION = '0.0.2';
36 use aliased 'App::SeismicUnixGui::misc::sunix_pl';
37  
38 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
39 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
40  
41 use App::SeismicUnixGui::misc::su_param '0.0.2';
42 use aliased 'App::SeismicUnixGui::misc::param_sunix';
43  
44 my $sunix_pl = sunix_pl->new();
45 my $get = L_SU_global_constants->new();
46 my $var = $get->var();
47  
48 =head2 declare variables
49  
50 =cut
51  
52 my $nu = $var->{_nu};
53 my $on = $var->{_on};
54 my $off = $var->{_off};
55 my $true = $var->{_true};
56 my $false = $var->{_false};
57 my $null_sunix_value = $var->{_null_sunix_value};
58 my $string2startFlowSetUp = $var->{_string2startFlowSetUp};
59 my $string2endFlowSetUp = $var->{_string2endFlowSetUp};
60 my $flow_type_href = $get->flow_type_href();
61  
62 my @file_in;
63 my @file_out;
64 my $i;
65  
66 =head2 set private hash
67  
68 =cut
69  
70 my $perl_flow = {
71  
72 _all_labels_aref2 => '',
73 _all_prog_versions_aref => '',
74 _all_prog_names_aref => '',
75 _all_values_aref2 => '',
76 _check_buttons_settings_aref => '',
77 _file_in => '',
78 _good_labels_aref2 => '',
79 _good_prog_names_aref => '',
80 _good_prog_versions_aref => '',
81 _good_values_aref2 => '',
82 _labels_aref => '',
83 _num_progs => '',
84 _param_sunix_first_idx => '',
85 _param_sunix_length => '',
86 _prog_index => '',
87 _prog_num => '',
88 _values_aref => '',
89  
90 };
91  
92 =head2 sub get_all_names_aref
93
94 =cut
95  
96 sub get_all_names_aref {
97  
98 my ($self) = @_;
99  
100 if ( $perl_flow->{_all_labels_aref2} && ( $perl_flow->{_prog_index} >= 0 ) ) {
101  
102 my $all_labels_aref = @{ $perl_flow->{_all_labels_aref2} }[ $perl_flow->{_prog_index} ];
103  
104 # my $length = scalar @{$all_labels_aref};
105 # print("perl_flow,get_all_names_aref,@{$all_labels_aref} \n");
106 # print("perl_flow,get_all_names_aref,length = $length \n");
107  
108 return ($all_labels_aref);
109  
110 }
111 else {
112 print("perl_flow,get_names,missing labels(names)\n");
113 return ();
114 }
115 }
116  
117 =head2 sub get_all_values_aref
118  
119 parameter values
120 Note that all_values may not be complete and so
121 print method will create an error
122
123 =cut
124  
125 sub get_all_values_aref {
126  
127 my ($self) = @_;
128  
129 if ( $perl_flow->{_all_values_aref2}
130 && ( $perl_flow->{_prog_index} >= 0 ) )
131 {
132  
133 my $all_values_aref = @{ $perl_flow->{_all_values_aref2} }[ $perl_flow->{_prog_index} ];
134  
135 # print("perl_flow,get_all_values_aref,all_values: @{$perl_flow->{_all_values_aref2}}[$perl_flow->{_prog_index}]\n");
136 my $length = scalar @{ @{ $perl_flow->{_all_values_aref2} }[ $perl_flow->{_prog_index} ] };
137  
138 # print("perl_flow,get_all_values_aref, #values=$length\n");
139  
140 if ( $length > 0 ) { # non-empty array
141  
142 # print("perl_flow,get_all_values_aref,@{$all_values_aref}-- #values=$length\n");
143 return ($all_values_aref);
144  
145 }
146 else {
147 print("perl_flow,get_all_values_aref, no values in program n");
148 return ();
149 }
150  
151 }
152 else {
153 print("perl_flow,get_all_values_aref, missing values or program index\n");
154 return ();
155 }
156 }
157  
158 =head2 sub get_check_buttons_settings_aref
159  
160  
161 =cut
162  
163 sub get_check_buttons_settings_aref {
164 my ($self) = @_;
165  
166 if ( $perl_flow->{_check_buttons_settings_aref2} && ( $perl_flow->{_prog_index} >= 0 ) ) {
167  
168 my $check_buttons_settings_aref = @{ $perl_flow->{_check_buttons_settings_aref2} }[ $perl_flow->{_prog_index} ];
169  
170 # print("perl_flow,get_check_buttons_settings_aref,@{$check_buttons_settings_aref} \n");
171 return ($check_buttons_settings_aref);
172  
173 }
174 else {
175 print("perl_flow,missing check_buttons_settings_aref\n");
176 return ();
177 }
178  
179 # print("perl_flow: get_check_buttons_settings_aref\n");
180 }
181  
182 =head2 sub get_num_prog_names
183  
184 working file name
185
186 =cut
187  
188 sub get_num_prog_names {
189  
190 my ($self) = @_;
191  
192 # print("perl_flow,get_num_prog_names,$perl_flow->{_num_progs}\n");
193 if ( $perl_flow->{_num_progs} ) {
194  
195 my $num_progs = $perl_flow->{_num_progs};
196 return ($num_progs);
197  
198 }
199 else {
200 print("perl_flow,missing num_progs\n");
201 return ();
202 }
203 }
204  
205 =head2 sub get_param_sunix_length
206  
207 number of values or labels in a single program
208
209 =cut
210  
211 sub get_param_sunix_length {
212  
213 my ($self) = @_;
214  
215  
216 if ( $perl_flow->{_prog_index} >=0
217 && $perl_flow->{_all_values_aref2} )
218 {
219 my $length = scalar @{ @{ $perl_flow->{_all_values_aref2} }[ $perl_flow->{_prog_index} ] };
220 # print("perl_flow,get_param_sunix_length,$length\n");
221 my $num_params = $length;
222 return ($num_params);
223  
224 }
225 else {
226  
227 print("perl_flow,missing param_sunix_length\n");
228 return ();
229 }
230 }
231  
232 =head2 sub get_prog_name_sref
233 @{$perl_flow->{_all_prog_names_aref}}
234  
235 =cut
236  
237 sub get_prog_name_sref {
238 my ($self) = @_;
239  
240 # print("perl_flow,get_prog_name_sref, _prog_index:$perl_flow->{_prog_index}\n");
241 # print("perl_flow,get_prog_name_sref, prog_name:@{$perl_flow->{_all_prog_names_aref}}[$perl_flow->{_prog_index}]\n");
242 if ( $perl_flow->{_all_prog_names_aref} && ( $perl_flow->{_prog_index} >= 0 ) ) {
243 my $prog_index = $perl_flow->{_prog_index};
244 my @all_prog_names = @{ $perl_flow->{_all_prog_names_aref} };
245 my $program_name = $all_prog_names[$prog_index];
246  
247 # print("perl_flow,get_prog_name_sref, $program_name \n");
248 return ( \$program_name );
249  
250 }
251 else {
252 print("perl_flow,get_prog_name_sref, missing prog_name\n");
253 }
254  
255 }
256  
257 =head2 sub get_parse_errors
258  
259 read perl file line by line to find errors
260 Based on parse
261
262 =cut
263  
264 sub get_parse_errors {
265
266 my ($self) = @_;
267
268 my $result;
269  
270 my $param_sunix = param_sunix->new();
271 my $Project = Project_config->new();
272  
273 my $PL_SEISMIC = $Project->PL_SEISMIC();
274  
275 my ( @all_labels_aref2, @all_values_aref2, @check_buttons_settings_aref2 ); # array of arrays
276  
277 $sunix_pl->set_perl_path($PL_SEISMIC);
278 $sunix_pl->whole();
279 $sunix_pl->set_progs_start_with( $var->{_string2startFlowSetUp} ); # 1st identifier
280 $sunix_pl->set_progs_end_with( $var->{_string2endFlowSetUp} ); # last identifier
281 $sunix_pl->set_num_progs();
282  
283 $perl_flow->{_all_prog_names_aref} = $sunix_pl->get_all_sunix_names();
284 $perl_flow->{_all_prog_versions_aref} = $sunix_pl->get_all_versions();
285  
286 my $length = $sunix_pl->get_num_progs;
287 my $num_progs = $sunix_pl->get_num_progs;
288  
289 # print("perl_flow,o/p num_progs: $length\n");
290  
291 if ($num_progs < 1 ) {
292
293 $result = $true;
294
295 } else{
296 $result = $false;
297 }
298
299 return($result);
300
301 }
302  
303 =head2 sub parse
304  
305 read perl file line by line
306
307 Always,
308 FIRST: get_good_sunix_params
309 THEN: $sunix_pl->get_good_sunix_names();
310 for names of programs
311 "good" values and labels are usually a subset of a much
312 larger available set of
313 values and labels for that program
314
315 foreach my $key (sort keys %$var) {
316 print (" grey_flow key is $key, value is $var\n");
317 }
318
319
320 =cut
321  
322 sub parse {
323 my ($self) = @_;
324  
325 my $param_sunix = param_sunix->new();
326 my $Project = Project_config->new();
327  
328 my $PL_SEISMIC = $Project->PL_SEISMIC();
329  
330 my ( @all_labels_aref2, @all_values_aref2, @check_buttons_settings_aref2 ); # array of arrays
331  
332 $sunix_pl->set_perl_path($PL_SEISMIC);
333 $sunix_pl->whole();
334 $sunix_pl->set_progs_start_with( $var->{_string2startFlowSetUp} ); # 1st identifier
335 $sunix_pl->set_progs_end_with( $var->{_string2endFlowSetUp} ); # last identifier
336 $sunix_pl->set_num_progs();
337  
338 $perl_flow->{_all_prog_names_aref} = $sunix_pl->get_all_sunix_names();
339 $perl_flow->{_all_prog_versions_aref} = $sunix_pl->get_all_versions();
340  
341 my $length = $sunix_pl->get_num_progs;
342 $perl_flow->{_num_progs} = $sunix_pl->get_num_progs;
343  
344 # print("perl_flow,o/p num_progs: $length\n");
345  
346 my $hash_ref = $sunix_pl->get_good_sunix_params();
347 $perl_flow->{_good_prog_names_aref} = $sunix_pl->get_good_sunix_names();
348 $perl_flow->{_good_prog_versions_aref} = $sunix_pl->get_good_prog_versions();
349 my $new_num_progs = $sunix_pl->get_num_good_progs();
350 my @good_prog_names = @{ $perl_flow->{_good_prog_names_aref} };
351 my @good_prog_versions = @{ $perl_flow->{_good_prog_versions_aref} };
352  
353 $perl_flow->{_good_labels_aref2} = $hash_ref->{_labels_aref2};
354 $perl_flow->{_good_values_aref2} = $hash_ref->{_values_aref2};
355  
356 # print("perl_flow,all prog versions: @{$perl_flow->{_all_prog_versions_aref}}\n");
357 # print("perl_flow,all program names: @{$perl_flow->{_all_prog_names_aref}}\n");
358 # print("perl_flow,good program names: @{$perl_flow->{_good_prog_names_aref}}\n");
359 # print("perl_flow,good program versions: @{$perl_flow->{_good_prog_versions_aref}}\n");
360 # print("perl_flow,o/p new_num_progs: $new_num_progs\n");
361 # print("perl_flow,parse:good_labels for program 2 @{@{$perl_flow->{_good_labels_aref2}}[1]}\n");
362 # print("perl_flow,parse: good_values for program 2 @{@{$perl_flow->{_good_values_aref2}}[1]}\n");
363  
364 # incorporate good labels/names and their values read from a script into a full set of labels
365 # and values belonging to each program for use in the GUI
366 #$new_num_progs = 1;
367 # extract one program at a time
368 for ( my $prog_idx = 0; $prog_idx < $new_num_progs; $prog_idx++ ) {
369  
370 my ( @all_labels, @all_values, @check_buttons_settings );
371 my ( @all_labels_aref, @all_values_aref );
372 my @config_labels_aref;
373 my @labels;
374  
375 # number of values (good values and good names) for each program in a perl flow
376 # is usually less than the maximum possible
377 # e.g. num_good_params <= $param_sunix_length, i.e., j <= k
378 # e.g. if only one label carries a value then the num_good_params=1 although there may
379 # be many more labels that are empty.
380  
381 my $num_good_params = scalar @{ @{ $perl_flow->{_good_values_aref2} }[$prog_idx] };
382 my $good_prog_name = $good_prog_names[$prog_idx];
383 my $good_prog_version = $good_prog_versions[$prog_idx];
384  
385 # print("perl_flow, parse prog: $prog_idx--num_good_params: $num_good_params---\n");
386 # print("perl_flow, program name: prog_name, $good_prog_name\n");
387
388 # tell param_sunix the type of flow
389 $param_sunix->set_flow_type($flow_type_href->{_user_built});
390
391 # info about a sunix program from its configuration file e.g., suximage.config
392 $param_sunix->set_program_name( \$good_prog_name );
393 my $sunix_first_idx = $param_sunix->first_idx();
394 my $param_sunix_length = $param_sunix->get_length4perl_flow(); # N.B. = # values or labels
395 my $config_labels_aref = $param_sunix->get_names();
396 my $values_aref = $param_sunix->get_values();
397  
398 # print("perl_flow,parse,labels from config files @$labels_aref\n");
399 # print("0. perl_flow,parse,param_sunix_length,$param_sunix_length\n");
400  
401 # remove the multiple versions of each label that appear in the configuration file
402 # use only the first name, e.g. absclip|clip becomes only absclip and loclip|bclip becomes only loclip
403  
404 for ( my $k = 0; $k < $param_sunix_length; $k++ ) {
405 my $line = @$config_labels_aref[$k];
406  
407 # print (" 1. perl_flow, parse,my label #$k = [$line]\n");
408  
409 # remove a pipe and the following: one or more (+) of the previous (any) character(.)
410 $line =~ s/\|.+//;
411  
412 # print (" 3. perl_flow, parse,my label #$k = [$line]\n\n");
413  
414 $labels[$k] = $line;
415  
416 # print (" config_labels_aref: @$config_labels_aref[$k], is different from line=$line\n");
417 }
418  
419 # for a single program, assign values (if they exist) to their appropriate labels
420 # <= k, k is for ALL possible program parameters
421 # j is only for parameter labels with non-empty values
422 for ( my $k = 0; $k < $param_sunix_length; $k++ ) {
423  
424 my $a_label = $labels[$k];
425  
426 for ( my $j = 0; $j < $num_good_params; $j++ ) {
427  
428 my @good_labels = @{ @{ $perl_flow->{_good_labels_aref2} }[$prog_idx] };
429 my @good_values = @{ @{ $perl_flow->{_good_values_aref2} }[$prog_idx] };
430 my $this_good_label = $good_labels[$j];
431 my $this_good_value = $good_values[$j];
432 # print("perl_flow, parse,-0-$good_values[0],-1-$good_values[1]\n");
433  
434 # compare the label (first module in the case of multiple versions separated by a pipe)
435 # in the standard program config files ( a_label)
436 # against the labels read from the perl flow (this_good_label)
437 if ( $a_label eq $this_good_label ) {
438  
439 # do not change the labels that will appear in the gui
440 # they should be the same as in the configuration files
441 # do not save a_label to the all_labels
442 $all_labels[$k] = @$config_labels_aref[$k];
443  
444 $all_values[$k] = $this_good_value;
445 $check_buttons_settings[$k] = $on;
446  
447 # print("2. perl_flow,parse, MATCH of good label and a_label\n");
448 # print("perl_flow,parse,good value: $all_values[$k] k=$k, j=$j\n");
449 # print("perl_flow,parse, good label: $all_labels[$k], k=$k, j=$j\n");
450  
451 }
452 elsif ( $a_label ne $this_good_label ) {
453  
454 # don't overwrite
455 if ( $all_labels[$k] ) {
456  
457 #NADA
458 # print("2. perl_flow,parse, don't overwrite all_labels[$k] = $all_labels[$k]\n");
459  
460 # CASE of label with empty space in the value column
461 }
462 else {
463  
464 $all_labels[$k] = @$config_labels_aref[$k];
465 $all_values[$k] = ();
466 $check_buttons_settings[$k] = $off;
467  
468 # print("2. perl_flow,parse, MISMATCH of this_good_label $this_good_label and a_label: $a_label, k=$k, j=$j\n");
469  
470 }
471  
472 }
473 else {
474 print("perl_flow,parse: should never get here\n");
475 }
476  
477 } # for good parameter labels, i.e. from perl flow and <= max number
478  
479 } # for all labels
480 $all_labels_aref2[$prog_idx] = \@all_labels; # save one array of labels for each program
481 $all_values_aref2[$prog_idx] = \@all_values; # save one array of values for each program
482 $check_buttons_settings_aref2[$prog_idx] = \@check_buttons_settings; # save one array on|off for each program
483  
484 # print("3. perl_flow,parse,prog_idx:$prog_idx, all_values[0]: $all_values[7] and all_labels[7]: $all_labels[7]\n");
485  
486 } # for each program
487  
488 $perl_flow->{_all_labels_aref2} = \@all_labels_aref2;
489 $perl_flow->{_all_values_aref2} = \@all_values_aref2;
490 $perl_flow->{_check_buttons_settings_aref2} = \@check_buttons_settings_aref2;
491 }
492  
493  
494 =head2 sub set_perl_file_in
495  
496 working file name
497
498 =cut
499  
500 sub set_perl_file_in {
501  
502 my ( $self, $file_in ) = @_;
503  
504 # print("perl_flow,set_perl_file_in, $file_in\n");
505  
506 if ($file_in) {
507  
508 $perl_flow->{_file_in} = $file_in;
509 $sunix_pl->set_perl_file_in( $perl_flow->{_file_in} );
510  
511 }
512 else {
513 # print("perl_flow,missing file_in\n");
514 }
515 return ();
516 }
517  
518 =head2 sub set_prog_index
519  
520 =cut
521  
522 sub set_prog_index {
523 my ( $self, $index ) = @_;
524  
525 if ( $index >= 0 ) {
526 $perl_flow->{_prog_index} = $index;
527  
528 # print("perl_flow,set_prog_index: $index\n");
529 }
530 else {
531 print("perl_flow,set_prog_index, missing prog index\n");
532 }
533 return ();
534 }
535 1;