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

filter: Statementstmt 0.0% 0 / 514 Branchbran 0.0% 0 / 74 Conditioncond 0.0% 0 / 35 MC/DCmcdc 0.0% 0 / 23 Subroutinesub 0.0% 0 / 46 Podpod 0.0% 0 / 36 totaltotal 0.0% 0 / 728 CC 38 SCAR 28.6
CC
38
Cov
0%
get_good_sunix_params
90.0
_good_sunix_params
42.0
get_lines_progs_contain
12.0
CRAP 17.4
1 package App::SeismicUnixGui::misc::sunix_pl;
2  
3 =head1 DOCUMENTATION
4  
5  
6 =head2 SYNOPSIS
7  
8 PERL PROGRAM NAME: sunix_pl
9 AUTHOR: Juan Lorenzo
10 DATE: June 22 2017
11 Oct 1 2018 V0.0.2
12  
13 DESCRIPTION Parse perl scripts written by L_SU
14
15  
16 BASED ON:
17  
18  
19 =cut
20  
21 =head2 USE
22  
23 =head3 NOTES
24  
25 =head4 Examples
26  
27  
28 =head2 CHANGES and their DATES
29  
30 V0.0.2
31 10.1.2018
32 gaps and non-standard characters in a string are allowable e.g. windowtitle='Strange units (m/Pa)
33  
34
35 =cut
36  
37 use Moose;
38 our $VERSION = '0.0.2';
39  
40 use Text::ParseWords;
41 use aliased 'App::SeismicUnixGui::misc::perl_header';
42 use aliased 'App::SeismicUnixGui::misc::perl_use_pkg';
43 use aliased 'App::SeismicUnixGui::misc::perl_instantiate';
44 use aliased 'App::SeismicUnixGui::misc::pod_declare';
45 use aliased 'App::SeismicUnixGui::misc::perl_declare';
46 use aliased 'App::SeismicUnixGui::misc::perl_inbound';
47 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
48  
49 =head2 instantiate modules
50  
51 =cut
52  
53 my $get = L_SU_global_constants->new();
54 my $get_header = perl_header->new();
55 my $get_use_pkg = perl_use_pkg->new();
56 my $pod_declare = pod_declare->new();
57 my $get_declare = perl_declare->new();
58 my $get_inbound = perl_inbound->new();
59 my $get_instantiation = perl_instantiate->new();
60  
61 =head2 declasre variables
62  
63 =cut
64  
65 my $var = $get->var();
66 my $empty_string = $var->{_empty_string};
67 my $false = 0;
68 my $true = 1;
69  
70 my @lines = ();
71 my $file_out;
72 my $file_in;
73 my $self;
74  
75 my @all_lines = ();
76 my @lines_wth_string = ();
77  
78 =head2 initialize shared anonymous hash
79  
80 key/value pairs
81  
82 =cut
83  
84 my $sunix_pl = {
85 _all_lines_aref => \@all_lines,
86 _contain_line_contents => \@all_lines,
87 _contain_prog_lines => \@all_lines,
88 _end_line_contents => \@all_lines,
89 _end_line_nums => \@all_lines,
90 _end_prog_lines => \@all_lines,
91 _good_prog_indices_ref => '',
92 _first_word => '',
93 _last_word => '',
94  
95 # _line_contents => \@all_lines,
96 _line_nums => \@all_lines,
97 _labels_aref2 => @all_lines,
98 _message1 => $false,
99 _num_lines => '',
100 _num_progs => \@all_lines,
101 _path => '',
102 _perl_file_in => '',
103 _prog_names => \@all_lines,
104 _prog_versions => '',
105 _file_in => '',
106 _file_out => '',
107 _string => '',
108 _start_line_contents => \@all_lines,
109 _start_line_nums => '',
110 _start_prog_lines => \@all_lines,
111 _values_aref2 => @all_lines,
112 };
113  
114 =head2 _good_sunix_params
115  
116 extract labels and parameter values
117 for each program
118  
119 =cut
120  
121 sub _good_sunix_params {
122 my ($self) = @_;
123  
124 my @prog_lines_aref_holder; # holds several array refs
125 my @values_aref_holder; # holds several array refs
126 my @labels_aref_holder; # holds several array refs
127 my $ref_prog_lines;
128 my @good_prog_index;
129  
130 my $size = $sunix_pl->{_num_progs};
131  
132 # print("sunix_pl, _good_sunix_params,num_progs: $size \n");
133 my @all_prog_names = @{ $sunix_pl->{_prog_names} };
134  
135 my $prog_number = 0;
136  
137 # for each program, collect lines of information
138 for ( my $prog_count = 0; $prog_count < $size; $prog_count++ ) {
139  
140 my @extract;
141 my ( $line_num, $first, $last );
142  
143 $first = $sunix_pl->{_start_prog_lines}[$prog_count];
144 $last = $sunix_pl->{_end_prog_lines}[$prog_count];
145  
146 # print("sunix_pl, _good_sunix_params, prog num: $prog_count, name: $all_prog_names[$prog_count]\n");
147 # print("sunix_pl, _good_sunix_params,first line : $first\n");
148 # print("sunix_pl, _good_sunix_params,last line : $last\n");
149  
150 # monotonically increasing line numbers are an error check
151 if ( $last >= $first ) {
152  
153 # extract coded sunix program lines
154 for ( my $count = 0, $line_num = $first; $line_num < $last; $count++, $line_num++ ) {
155 $extract[$count] = @{ $sunix_pl->{_all_lines_aref} }[$line_num];
156  
157 # print("sunix_pl,_good_sunix_params, lines for each program: $extract[$count]\n")
158 }
159 push @prog_lines_aref_holder, \@extract;
160 } else {
161  
162 # print("sunix_pl, _good_sunix_params,Warning: bad line numbers for $all_prog_names[$prog_count]\n");
163 }
164 } # for each progam
165  
166 # extract parameter names/labels and values
167 # from lines in each perl program
168 for ( my $prog_count = 0, my $op_prog_count = 0; $prog_count < $size; $prog_count++ ) {
169  
170 my $ref_prog_lines = $prog_lines_aref_holder[$prog_count];
171 my ( @temp_values, @temp_labels );
172 my $value_index = 0;
173 my $label_index = 0;
174  
175 my ( @labels_holder, @values_holder ); # holds one array of values and labels per program
176 # print("sunix_pl,_good_sunix_params,prog_lines: @$ref_prog_lines\n");
177 # print("sunix_pl,_good_sunix_params,prog#: $prog_count\n");
178 # print("\n sunix_pl,_good_sunix_params,prog_name: $sunix_pl->{_prog_names}[$prog_count]\n");
179  
180 # extract labels and parameter values from lines
181 foreach my $line (@$ref_prog_lines) {
182 my @values;
183 my @values1;
184 my @values2;
185 my @labels = ();
186 my ( $line1, $line2 );
187  
188 # print(" sunix_pl,_good_sunix_params_values,line:--$line");
189  
190 # from start ^ to end $ of the string
191 # matches label names, e.g., ->(agc) with
192 # look behind the arrow head and exclude the arrow (?=< ....) >))
193 # look for zero or more spaces between the arrow head and the first parenthesis
194 # exclude any spaces
195 # extract () only the text
196  
197 @labels = $line =~ m/(?<=>)\s*(\w+)/g;
198 # print("sunix_pl,_good_sunix_params,labels:---@labels\n");
199 my $label_length = scalar @labels;
200  
201 #print("sunix_pl,_good_sunix_params,label length:---$label_length\n");
202  
203 # zero more spaces between the first parenthesis and
204 # [ the word or number (+ or -ve)
205 # matches the following values between parentheses
206 # 1 '1' 111 '111' $on 'on' on -100 -100.00 100.00 -.5
207 # '1,2,3', or quotemeta(ANYTHING)
208 # or $sufile[1]
209  
210 # print("1. sunix_pl,_good_sunix_params, line=$line \n");
211 # In order to get the useful value
212 # Step 1
213  
214 # remove ONLY the prefix and the suffix inside the quotemeta parentheses i.e. $DATA_SEISMIC_SU.'/'. and .$suffix_su
215 # substitute $ \$
216 # substitute one or more words \w+
217 # substitute .'/'. \.'\/'\.
218  
219 $line =~ s/quotemeta\(\$\w+\.'\/'\./quotemeta\(/;
220 # print("1. sunix_pl,_good_sunix_params, line=$line \n");
221  
222 # Step 2
223 # substitute quotemeta with nothing
224 # substitute
225 $line =~ s/quotemeta//;
226  
227 # print("2. sunix_pl,_good_sunix_params, line=$line \n");
228  
229 # Step 3
230 # substitute double parentheses with single parentheses
231 $line =~ s/\(\(/\(/;
232 $line =~ s/\)\)/\)/;
233  
234 # Step 4
235 # substitute .$suffix_su) with )
236 # substitute
237 $line =~ s/\.\$\w+\);/\)/;
238  
239 # print("2. sunix_pl,_good_sunix_params, line=$line \n");
240  
241 # group anyhting which lies within parentheses \( \)
242 @values = $line =~ m/\((\'\w+\'|.+|(\(.+\))|\w+|\$\w+|-?(.|\d+)\.\d+)\)/g;
243  
244 print("4. sunix_pl,_good_sunix_params, values = @values, values[0]=$values[0]\n");
245  
246 # TBD @values = $line=~m/\((\'\w+\'|.+|(quotemeta\(.+\))|\w+|\$\w+|-?(.|\d+)\.\d+)\)/g;
247  
248 #@values length is longer by one **
249 my $value_length = scalar @values;
250  
251 # print("1. sunix_pl,_good_sunix_params,prog: $prog_count number of values:---$value_length \n");
252 if ( $value_length > 0 ) {
253  
254 # ** this one never works: print("1. sunix_pl,_good_sunix_params,prog: $prog_count values:---@values---\n");
255 print("sunix_pl,_good_sunix_params, value[0] =-- $values[0]---\n\n");
256 } elsif ( !$values[0] ) {
257 print("sunix_pl,_good_sunix_params, values[0] is empty: =-----\n\n");
258 } else {
259 print("sunix_pl,_good_sunix_params, value[0] =---$values[0]--\n\n");
260 }
261  
262 # assume label and value lengths are always 1
263 if ( $label_length > 0 and $value_length > 0 ) {
264 $labels_holder[$label_index] = $labels[0];
265 $values_holder[$value_index] = $values[0];
266 $value_index++;
267 $label_index++;
268  
269 # print("1. sunix_pl,_good_sunix_params,values[0]:--$values[0]\n");
270 # print("1. sunix_pl,_good_sunix_params,labels[0]:--$labels[0]\n");
271 # print("1. sunix_pl,_good_sunix_params,values_holder:--@values_holder\n");
272 # print("1. sunix_pl,_good_sunix_params,values_holder:--@values_holder----prog_count:$prog_count\n");
273 } else {
274  
275 # print("sunix_pl,_good_sunix_params_values, either no label or value exists\n");
276 }
277  
278 } # over each line in for a single program
279  
280 # print("2. sunix_pl,_good_sunix_params_values,prog: $prog_count---temp values:---@temp_values\n\n");
281 # store value and label for each program only if a value has been found
282 my $long = ( $value_index - 1 );
283 if ( $long > -1 ) { #
284 @temp_values = @values_holder[ 0 .. $long ];
285 @temp_labels = @labels_holder[ 0 .. $long ];
286 $values_aref_holder[$op_prog_count] = \@temp_values;
287 $labels_aref_holder[$op_prog_count] = \@temp_labels;
288 $good_prog_index[$op_prog_count] = $prog_count; # remember which prgrams are useful for later
289 $op_prog_count++;
290  
291 # print(" sunix_pl,_good_sunix_params,prog: $prog_count---temp values:---@temp_values\n\n");
292 # print(" sunix_pl,_good_sunix_params,prog: $prog_count---values:---@{$values_aref_holder[$prog_count]}\n\n");
293 # print(" sunix_pl,_good_sunix_params,prog: $prog_count---temp labels:---@temp_labels\n\n");
294 # print(" sunix_pl,g_good_sunix_params,prog: $prog_count---labels:---@{$labels_aref_holder[$prog_count]}\n\n");
295 } else {
296  
297 # label and values are not assigned to array elements
298 # BUT array continues to increment
299 # print("warning: sunix_pl,_good_sunix_params, no value found: long = $long\n");
300 }
301  
302 } # over each program
303  
304 # for all programs
305 # my $num_progs = $size;
306 # print("sunix_pl,i/p num_progs: $num_progs\n");
307  
308 $sunix_pl->{_labels_aref2} = \@labels_aref_holder;
309 $sunix_pl->{_values_aref2} = \@values_aref_holder;
310  
311 my $new_num_progs = scalar @values_aref_holder;
312  
313 #print("sunix_pl,o/p num_progs: $new_num_progs\n");
314  
315 #for(my $i=0; $i < $new_num_progs; $i++) {
316 # my $num_params = scalar @{$values_aref_holder[$i]};
317 # print("sunix_pl, prog: $i---num_params: $num_params---\n");
318 # print("sunix_pl, original good program index: $good_prog_index[$i]\n");
319  
320 #for (my $j=0; $j <$num_params; $j++ ){
321 # print("sunix_pl,_good_sunix_params,labels: @{@{$sunix_pl->{_labels_aref2}}[$i]}[$j]\n");
322 # print("sunix_pl,_good_sunix_params,values: @{@{$sunix_pl->{_values_aref2}}[$i]}[$j]\n");
323 # }
324 #}
325 $sunix_pl->{_good_prog_indices_ref} = \@good_prog_index;
326  
327 # print("sunix_pl,_good_sunix_names,good_prog_indices, @{$sunix_pl->{_good_prog_indices_ref}} \n");
328 return ($sunix_pl);
329 }
330  
331 =pod sub all
332 inbound
333 open and write
334 to the file
335  
336 =cut
337  
338 sub all {
339 my ($self) = @_;
340  
341 # = shift;
342 open( $file_out, '>', @{ $self->{_file_out} }[1] )
343 || print("Can't open file_out, $!\n");
344  
345 # header();
346 # use_pkg();
347 # use_external();
348 #
349 # instantiation();
350 # instantiation_external();
351 #
352 # for ($i=0; $i < $max_progs; $i++) {
353 # set_programs()
354 # params();
355 # }
356 #
357 # pod_declare();
358 # declare();
359 # declare_external();
360 write_inbound();
361  
362 flows();
363  
364 run();
365  
366 logs();
367  
368 close($file_out);
369 }
370  
371 =head2 sub declare
372  
373 =cut
374  
375 sub declare {
376  
377 my $ref_array = $get_declare->section();
378  
379 foreach (@$ref_array) {
380 print $file_out "$_\n";
381 }
382 }
383  
384 =head2 sub flows
385  
386 =cut
387  
388 sub flows {
389  
390 print $file_out "\n" . ' $flow[1] = $run->modules(\@items);' . "\n\n";
391  
392 }
393  
394 =head2 get_all_labels
395  
396 get all active and default
397 parameter names from a program in a perl flow
398  
399 =cut
400  
401 =head2 sub get_error_messages
402  
403 =cut
404  
405 sub get_error_messages {
406 my ($self) = @_;
407  
408 if ( $sunix_pl->{_messages1} ) {
409  
410 my $error_message = {
411 _program_name => 'sunix_pl',
412 _message_number => 1
413 };
414  
415 my $results = $error_message;
416  
417 return ($results);
418  
419 } else {
420  
421 return ();
422 print("sunix_pl, get_error_messages, none to return\n");
423 }
424  
425 }
426  
427 =head2 sub get_lines_progs_contain
428  
429 return line numbers that contain a particular
430 word or string
431  
432  
433 =cut
434  
435 sub get_lines_progs_contain {
436 my ($self) = @_;
437  
438 my ( $line, $count_all_lines, $case_num );
439 my ( @line_nums, @line_contents );
440  
441 if ( $sunix_pl->{_string} ) {
442  
443 my $string = $sunix_pl->{_string};
444  
445 # print("sunix_pl,get_lines_progs_contain, string:$string\n");
446  
447 $count_all_lines = 0;
448 $case_num = 0;
449  
450 my @all_lines = @{ $sunix_pl->{_all_lines_aref} };
451  
452 my $length = scalar @all_lines;
453  
454 # print("sunix_pl, get_lines_progs_contain, num_lines= $length, all_lines[104]= $all_lines[104]\n");
455  
456 for ( my $i = 0; $i < $length; $i++ ) {
457  
458 $line = $all_lines[$i];
459  
460 # print("sunix_pl, get_lines_progs_contain, line= $i\n");
461  
462 if ( $line =~ /$string/ ) {
463  
464 $line_nums[$case_num] = $count_all_lines;
465 $line_contents[$case_num] = $line;
466 $case_num++;
467  
468 # print("sunix_pl, get_lines_progs_contain, line= $i\n");
469 }
470 $count_all_lines++;
471 }
472  
473 $sunix_pl->{_contain_prog_lines} = \@line_nums;
474 $sunix_pl->{_contain_line_contents} = \@line_contents;
475 return ( \@line_nums );
476  
477 } else {
478 print("sunix_pl, get_lines_progs_contain, missing string\n");
479 }
480  
481 }
482  
483 =head2 sub get_lines_progs_end_with
484  
485 return line numbers that contain a particular
486 word or string
487 print("progs_end_with,@{$sunix_pl->{_end_prog_lines}}\n");i
488 print("progs_end_with,@{$sunix_pl->{_end_line_contents}}\n");
489  
490 =cut
491  
492 sub get_lines_progs_end_with {
493 my ($self) = @_;
494 my ( $line, $count_all_lines, $case_num );
495 my ( @line_nums, @line_contents );
496  
497 my $string = $sunix_pl->{_last_word};
498  
499 $count_all_lines = 0;
500 $case_num = 0;
501  
502 my @all_lines = $sunix_pl->{_all_lines_aref};
503  
504 foreach my $line (@all_lines) {
505 if ( $line =~ /$string/ ) {
506 $line_nums[$case_num] = $count_all_lines;
507 $line_contents[$case_num] = $line;
508 $case_num++;
509 }
510 $count_all_lines++;
511 }
512  
513 $sunix_pl->{_end_prog_lines} = \@line_nums;
514 $sunix_pl->{_end_line_contents} = \@line_contents;
515  
516 return ( \@line_nums );
517 }
518  
519 =head2 sub get_lines_progs_start_with
520  
521 return line numbers that contain a particular
522 word or string
523 print("$case_num cases in $count_all_lines lines,\n");
524 print("at line(s): @{$sunix_pl->{_line_nums}}\n");
525 print("progs_start_with, length is $size\n");
526 print ("word is $word\n");
527 print ("word is $string\n");
528  
529 =cut
530  
531 sub get_lines_progs_start_with {
532 my ($self) = @_;
533  
534 my ( $line, $count_all_lines, $case_num );
535 my ( @line_nums, @line_contents );
536 my $string = $sunix_pl->{_first_word};
537  
538 $count_all_lines = 0;
539 $case_num = 0;
540  
541 my @all_lines = $sunix_pl->{_all_lines_aref};
542  
543 foreach my $line (@all_lines) {
544 if ( $line =~ /$string/ ) {
545 $line_nums[$case_num] = $count_all_lines;
546 $line_contents[$case_num] = $line;
547 $case_num++;
548 }
549 $count_all_lines++;
550 }
551  
552 $sunix_pl->{_start_prog_lines} = \@line_nums;
553 $sunix_pl->{_start_line_contents} = \@line_contents;
554  
555 return ( \@line_nums );
556 }
557  
558 =head2 sub get_num_good_progs
559  
560 get_good_sunix_params should have been run first
561  
562 =cut
563  
564 sub get_num_good_progs {
565 my ($self) = @_;
566  
567 my $num_good_progs = scalar @{ $sunix_pl->{_good_prog_names} };
568  
569 # print("sunix_pl, get_num_progs: $num_good_progs\n");
570 return ($num_good_progs);
571 }
572  
573 =head2 sub get_num_progs
574  
575 =cut
576  
577 sub get_num_progs {
578 my ($self) = @_;
579  
580 my $num_progs = $sunix_pl->{_num_progs};
581  
582 # print("sunix_pl, get_num_progs: $num_progs\n");
583 return ($num_progs);
584 }
585  
586 =cut
587  
588  
589 #
590 #=head2 sub set_progs_end_with
591 #
592 # return line numbers that contain a particular
593 # word or string
594 # print("progs_end_with,@{$sunix_pl->{_end_prog_lines}}\n");i
595 # print("progs_end_with,@{$sunix_pl->{_end_line_contents}}\n");
596 #
597 #=cut
598 #
599 # sub set_progs_end_with {
600 # my ($self,$word) = @_;
601 # $sunix_pl->{_last_word} = $word;
602 #
603 # return();
604 #}
605 #
606 #
607 #=head2 sub set_progs_start_with
608 #
609 # return line numbers that contain a particular
610 # word or string
611 # print("$case_num cases in $count_all_lines lines,\n");
612 # print("at line(s): @{$sunix_pl->{_line_nums}}\n");
613 # print("set_progs_start_with, length is $size\n");
614 # print ("word is $word\n");
615 # print ("word is $string\n");
616 #
617 #=cut
618 #
619 # sub set_progs_start_with {
620 # my ($self,$word) = @_;
621 #
622 # $sunix_pl ->{_first_word} = $word;
623 # return();
624 #}
625  
626 #=head2 sub print
627 #
628 # return characters from particular lines
629 # particular lines = $ref_line
630 #
631 #=cut
632 #
633 # sub print{
634 # my ($self,$hash_ref_line) = @_;
635 # my $i=0;
636 # my ($seq,@print);
637 # #print( "self is $self,\n");
638 # #print("prog_line is @$ref_line\n");
639 # foreach $seq (@{$ref_line}) {
640 # $print[$i] = @{$sunix_pl->{_all_lines_aref}}[@{$ref_line}[$i]];
641 # #print ("line: $i @{$ref_line}[$i]\n");
642 # $i++;
643 # }i
644 # return(\@print);
645 #}
646  
647 =head2 get_all_labels
648  
649 return all active and default
650 parameter labels from a program in a perl flow
651  
652 =cut
653  
654 =head2 get_all_values
655  
656 return all active and default
657 parameter values from a program in a perl flow
658  
659 =cut
660  
661 =head2 sub get_all_sunix_names
662  
663 foreach my $keys (sort keys %$psunix) {
664 print("keys $keys value @{$sunix_pl->{$keys}}[1]\n");
665 }
666 this subroutine needs file read by sub lines_with
667 print ("i: $i fields are: @{$hash_ref->{_line_contents}}[$i] \n");
668 print("self is $self hash ref is $hash_ref\n");
669  
670 =cut
671  
672 sub get_all_sunix_names {
673  
674 my ($self) = @_;
675 my $i = 0;
676 my $line;
677 my @fields = ();
678 my ( @prog_name, @extraction );
679  
680 foreach ( @{ $sunix_pl->{_start_line_contents} } ) {
681  
682 # print ("$i fields are: @{$sunix_pl->{_start_line_contents}}[$i] ");
683 $line = @{ $sunix_pl->{_start_line_contents} }[$i];
684  
685 # print ("$i line is: $line ");
686 # match in list format @fields =
687 # g search globally
688 # \s match any whitespace character
689 # + match \s one or more times
690 # [A-za-z]+ match any letter one or more times
691 # [0-9]* match any number, none or more times
692 @fields = $line =~ /\s+\$[A-za-z]+[0-9]*[A-za-z]+[0-9]*/g;
693  
694 # print ("sunix_pl,get_all_sunix_names, $i field 0 is:...$fields[0]...\n ");
695  
696 @extraction = split /\s+\$/, $fields[0], 2;
697  
698 # print("sunix_pl,get_all_sunix_names, $i prog_name [$extraction[1]]\n");
699  
700 $prog_name[$i] = $extraction[1];
701 $i++;
702 }
703 $sunix_pl->{_prog_names} = \@prog_name;
704  
705 # print("sunix_pl, get_all_sunix_names, sunix_names, @{$sunix_pl->{_prog_names}}\n");
706 return ( \@prog_name );
707 }
708  
709 =head2 sub get_all_versions
710  
711 =cut
712  
713 sub get_all_versions {
714 my ($self) = @_;
715 my @version;
716  
717 #print("self is $self array ref is $sunix_pl->{_prog_versions}\n");
718 my $num_progs = scalar @$sunix_pl{_num_progs};
719  
720 #print("num_progs $num_progs\n");
721 # always first program is version 1
722 $version[0] = 1;
723  
724 # 2nd program
725 for ( my $this = 1; $this < $num_progs; $this++ ) {
726 $version[$this] = 1;
727 for ( my $up_to = 0; $up_to < $this; $up_to++ ) {
728 if ( @{ $sunix_pl->{_prog_names} }[$this] eq @{ $sunix_pl->{_prog_names} }[$up_to] ) {
729 $version[$this]++;
730 }
731 }
732 }
733  
734 $sunix_pl->{_prog_versions} = \@version;
735  
736 # print("versions, @{$sunix_pl->{_prog_versions}}\n");
737 # print("versions, names:@{$sunix_pl->{_prog_names}}\n");
738 return ( \@version );
739 }
740  
741 =head2 sub get_good_sunix_names
742  
743 only those sunix programs
744 that have useful parameter
745 values and labels
746
747 MUST run get_good_sunix_params first (externally called)
748 to have
749 $good_prog_indices_ref
750  
751 =cut
752  
753 sub get_good_sunix_names {
754  
755 my ($self) = @_;
756 my ( @good_prog_indices, @all_prog_names );
757 my (@good_prog_names);
758 my $good_prog_indices = $sunix_pl->{_good_prog_indices_ref};
759  
760 if ($good_prog_indices) {
761 @good_prog_indices = @{ $sunix_pl->{_good_prog_indices_ref} };
762  
763 # print("sunix_pl,get_good_sunix_names,good_prog_indices, @good_prog_indices \n");
764  
765 @all_prog_names = @{ $sunix_pl->{_prog_names} };
766  
767 # print("sunix_pl,get_good_sunix_names,all_prog_names: @all_prog_names \n");
768 my $length = scalar @good_prog_indices;
769  
770 for ( my $i = 0; $i < $length; $i++ ) {
771  
772 my $good_idx = $good_prog_indices[$i];
773 $good_prog_names[$i] = $all_prog_names[$good_idx];
774 }
775  
776 $sunix_pl->{_good_prog_names} = \@good_prog_names;
777  
778 # print("sunix_pl, get_good_sunix_names, @{$sunix_pl->{_good_prog_names}}\n");
779 return ( \@good_prog_names );
780  
781 } else {
782  
783 print("suix_pl,warning: get_good_sunix_names: must run sunix_params first\n");
784  
785 _get_good_sunix_params();
786 @good_prog_indices = @{ $sunix_pl->{_good_prog_indices_ref} };
787  
788 # print("sunix_pl,get_good_sunix_names,good_prog_indices, @good_prog_indices \n");
789  
790 @all_prog_names = @{ $sunix_pl->{_prog_names} };
791  
792 # print("sunix_pl,get_good_sunix_names,all_prog_names: @all_prog_names \n");
793 my $length = scalar @good_prog_indices;
794 for ( my $i = 0; $i < $length; $i++ ) {
795 my $good_idx = $good_prog_indices[$i];
796 $good_prog_names[$i] = $all_prog_names[$good_idx];
797 }
798  
799 $sunix_pl->{_good_prog_names} = \@good_prog_names;
800  
801 #print("sunix_pl, get_good_sunix_names, @{$sunix_pl->{_good_prog_names}}\n");
802 return ( \@good_prog_names );
803 }
804 }
805  
806 =head2 get_good_sunix_params
807  
808 From a file containing a perl-scripted flow,
809 extract labels and parameter values
810 for each program
811
812 10-1-2018 sunix text sequences are now allowable gaps via quotemeta
813 10-5-2018 sunix text sequences can have suffixes and prefixes to the value as well
814 11-25-2018 account for programs with NULL parameters, e.g. suspecfx
815  
816 =cut
817  
818 sub get_good_sunix_params {
819 my ($self) = @_;
820  
821 use File::Basename;
822  
823 my @prog_lines_aref_holder; # holds several array refs
824 my @values_aref_holder; # holds several array refs
825 my @labels_aref_holder; # holds several array refs
826 my $ref_prog_lines;
827 my @good_prog_index;
828  
829 my $size = $sunix_pl->{_num_progs};
830  
831 # print("sunix_pl, get_good_sunix_params,num_progs: $size \n");
832 my @all_prog_names = @{ $sunix_pl->{_prog_names} };
833  
834 my $prog_number = 0;
835  
836 # for each program, collect lines of information
837 for ( my $prog_count = 0; $prog_count < $size; $prog_count++ ) {
838  
839 my @extract;
840 my ( $line_num, $first );
841 my $last = 9999; # very large default
842  
843 $first = $sunix_pl->{_start_prog_lines}[$prog_count];
844 $last = $sunix_pl->{_end_prog_lines}[$prog_count];
845  
846 # print("1. sunix_pl, get_good_sunix_params, prog num: $prog_count, name: $all_prog_names[$prog_count]\n");
847 # print("sunix_pl, get_good_sunix_params,first line : $first\n");
848 # print("sunix_pl, get_good_sunix_params,last line : $last\n");
849  
850 # monotonically increasing line numbers are an error check
851 if ( $last >= $first ) {
852  
853 # print("sunix_pl,get_good_sunix_params, lines for each program: @{$sunix_pl->{_all_lines_aref}} \n");
854  
855 # extract coded sunix program lines
856 for ( my $count = 0, $line_num = $first; $line_num < $last; $count++, $line_num++ ) {
857 $extract[$count] = @{ $sunix_pl->{_all_lines_aref} }[$line_num];
858  
859 # print("sunix_pl,get_good_sunix_params, lines with parameter names and their values, for each program: $extract[$count]\n")
860 }
861 push @prog_lines_aref_holder, \@extract;
862  
863 } else {
864 print("sunix_pl, get_good_sunix_params,Warning: bad line numbers for $all_prog_names[$prog_count]\n");
865 }
866 } # for each progam
867  
868 # extract parameter names/labels and values
869 # from lines in each program
870 for ( my $prog_count = 0, my $op_prog_count = 0; $prog_count < $size; $prog_count++ ) {
871  
872 my $ref_prog_lines = $prog_lines_aref_holder[$prog_count];
873 my ( @temp_values, @temp_labels );
874 my $value_index = 0;
875 my $label_index = 0;
876  
877 # holds one array of values and labels per program
878 my ( @labels_holder, @values_holder );
879  
880 # print("sunix_pl,get_good_sunix_params,prog_lines: @$ref_prog_lines\n");
881 # print("sunix_pl,get_good_sunix_params,prog#: $prog_count\n");
882 # print("\n sunix_pl,get_good_sunix_params,prog_name: $sunix_pl->{_prog_names}[$prog_count]\n");
883  
884 # extract labels and parameter values from lines
885 foreach my $line (@$ref_prog_lines) {
886 my @values;
887  
888 # $values[0] = $empty_string; # initialize empty
889 my @values1;
890 my @values2;
891 my @labels = ();
892 my ( $line1, $line2 );
893  
894 # print(" 893: sunix_pl,get_good_sunix_params_values,line:--$line\n");
895  
896 # from start ^ to end $ of the string
897 # matches label names, e.g., ->(agc) with
898 # look behind the arrow head and exclude the arrow (?=< ....) >))
899 # look for zero or more spaces between the arrow head and the first parenthesis
900 # exclude any spaces
901 # extract () only the text
902  
903 @labels = $line =~ m/(?<=>)\s*(\w+)/g;
904  
905 # print("sunix_pl,get_good_sunix_params,labels:---@labels\n");
906 my $label_length = scalar @labels;
907  
908 # print("sunix_pl,get_good_sunix_params,label length:---$label_length\n");
909  
910 # zero more spaces between the first parenthesis and
911 # [ the word or number (+ or -ve)
912 # matches the following values between parentheses
913 # 1 '1' 111 '111' $on 'on' on -100 -100.00 100.00 -.5
914 # '1,2,3', or quotemeta(ANYTHING)
915 # or $sufile[1]
916  
917 # print("1. sunix_pl,get_good_sunix_params, line=$line \n");
918 # In order to get the useful value
919 # Step 1
920  
921 # remove ONLY the prefix and the suffix inside the quotemeta parentheses i.e. $DATA_SEISMIC_SU.'/'. and .$suffix_su
922 # substitute $ \$
923 # substitute one or more words \w+
924 # substitute .'/'. \.'\/'\.
925  
926 $line =~ s/quotemeta\(\$\w+\.'\/'\./quotemeta\(/;
927  
928 # print("1. sunix_pl,get_good_sunix_params, line=$line \n");
929  
930 # Step 2
931 # substitute quotemeta with nothing
932 # substitute
933 $line =~ s/quotemeta//;
934  
935 #print("2. sunix_pl,get_good_sunix_params, line=$line \n");
936  
937 # Step 3
938 # substitute double parentheses with single parentheses
939 $line =~ s/\(\(/\(/;
940 $line =~ s/\)\)/\)/;
941  
942 # print("21. sunix_pl,get_good_sunix_params, line=$line \n");
943 # Step 4
944 # substitute .$suffix_su) with )
945 # substitute
946 $line =~ s/\.\$\w+\);/\)/;
947  
948 # print("Step 4 sunix_pl,get_good_sunix_params, line=$line \n");
949 #Step 5
950 # substitute regular extensions )
951 # e.g. .bin .txt .SGY .sgy .SEGY .segy)
952 $line =~ s/\.[a-z]+\);/\)/;
953 $line =~ s/\.[A-Z]+\);/\)/;
954  
955 # print("Step 5 sunix_pl,get_good_sunix_params, line=$line \n");
956  
957 # group anything which lies within parentheses \( \)
958 @values = $line =~ m/\((\'\w+\'|.+|(\(.+\))|\w+|\$\w+|-?(.|\d+)\.\d+)\)/g;
959  
960 # print("4. sunix_pl,get_good_sunix_params, values = @values, values[0]=$values[0]\n");
961  
962 # extract name, path will however affect Project parameters which are directories
963 # my ($name,$path) = fileparse($values[0]);
964  
965 # print("5. sunix_pl,get_good_sunix_params, name\n");
966  
967 #@values length is longer by one **
968 my $value_length = scalar @values;
969  
970 # print("1. sunix_pl,get_good_sunix_params,prog: $prog_count number of values:---$value_length \n");
971 if ( $value_length > 0 ) {
972  
973 # ** this one never works: print("1. sunix_pl,get_good_sunix_params,prog: $prog_count values:---@values---\n");
974 # print ("sunix_pl,get_good_sunix_params, value[0] =-- $values[0]---\n\n");
975 } elsif ( !$values[0] ) {
976  
977 # print ("sunix_pl,get_good_sunix_params, values[0]
978 # is empty: =-----\n\n");
979 } else {
980 print("sunix_pl,get_good_sunix_params, unexpected value[0] =---$values[0]--\n\n");
981 }
982  
983 # number of labels and values are always >= 1
984 if ( $label_length >= 1 or $value_length >= 1 ) {
985  
986 $values_holder[$value_index] = $values[0];
987 $labels_holder[$label_index] = $labels[0];
988 $value_index++;
989 $label_index++;
990  
991 # if($values[0]) { print("1. sunix_pl,get_good_sunix_params,values[0]:--$values[0]--\n")};
992 # if($labels[0]) { print("1. sunix_pl,get_good_sunix_params,labels[0]:--$labels[0]--\n")};
993 # print("1. sunix_pl,get_good_sunix_params,values_holder:--@values_holder\n");
994 # print("1. sunix_pl,get_good_sunix_params,values_holder:--@values_holder----prog_count:$prog_count\n");
995 } else {
996 print("sunix_pl,get_good_sunix_params_values, either no value or label exists\n");
997 }
998  
999 # USER ERRORS
1000 # CASE 1 : label that is not 'clear' but is is empty
1001 # print("1. sunix_pl,get_good_sunix_params,labels[0]:--$labels[0]--\n");
1002 if ( $labels[0] ne 'clear'
1003 and ( !$labels[0] or $labels[0] eq $empty_string ) ) {
1004  
1005 # print(
1006 # "1 USER ERROR: edit your flow; Cannot continue; A program is missing all its values\n"
1007 # );
1008 # print(
1009 # "prog_name is $sunix_pl->{_prog_names}[$prog_count]\n\n ");
1010 $sunix_pl->{_message1} = $true;
1011  
1012 # CASE 2: label exists and is not 'clear'
1013 } elsif ( $labels[0] ne 'clear'
1014 and ( $labels[0] or $labels[0] ne $empty_string ) ) {
1015  
1016 # Case 2A: value is empty
1017 if ( !$values[0] or $values[0] eq $empty_string ) {
1018  
1019 # print("2 USER ERROR: Gedit your flow; Cannot continue; A program is missing all its values\n");
1020 # print("prog_name is $sunix_pl->{_prog_names}[$prog_count]\n\n ");
1021 # $sunix_pl->{_message1} = $true;
1022 # exit;
1023  
1024 } else {
1025  
1026 # Case 2B: value is not empty
1027 # print("sunix_pl,get_good_sunix_params_values,a good value NADA\n")
1028 }
1029  
1030 } else {
1031  
1032 # print("sunix_pl,get_good_sunix_params_values,unexpected or 'clear' NADA\n")
1033 }
1034  
1035 } # over each line in for a single program
1036  
1037 # print("2. sunix_pl,get_good_sunix_params_values,prog: $prog_count---temp values:---@temp_values\n\n");
1038 # store value and label for each program only if a value has been found
1039 my $long = ( $value_index - 1 );
1040 if ( $long > -1 ) { #
1041 @temp_values = @values_holder[ 0 .. $long ];
1042 @temp_labels = @labels_holder[ 0 .. $long ];
1043 $values_aref_holder[$op_prog_count] = \@temp_values;
1044 $labels_aref_holder[$op_prog_count] = \@temp_labels;
1045 $good_prog_index[$op_prog_count] = $prog_count; # remember which programs are useful for later
1046 $op_prog_count++;
1047  
1048 # print(" sunix_pl,get_good_sunix_params,prog: $prog_count---temp values:---@temp_values\n\n");
1049 # print(" sunix_pl,get_good_sunix_params,prog: $prog_count---values:---@{$values_aref_holder[$prog_count]}\n\n");
1050 # print(" sunix_pl,get_good_sunix_params,prog: $prog_count---temp labels:---@temp_labels\n\n");
1051 # print(" sunix_pl,gget_good_sunix_params,prog: $prog_count---labels:---@{$labels_aref_holder[$prog_count]}\n\n");
1052 } else {
1053  
1054 # label and values are not assigned to array elements
1055 # BUT array continues to increment
1056 print("warning: sunix_pl,get_good_sunix_params, no value found: long = $long\n");
1057 }
1058  
1059 } # over each program
1060  
1061 # for all programs
1062 # my $num_progs = $size;
1063 # print("sunix_pl,i/p num_progs: $num_progs\n");
1064  
1065 $sunix_pl->{_labels_aref2} = \@labels_aref_holder;
1066 $sunix_pl->{_values_aref2} = \@values_aref_holder;
1067  
1068 my $new_num_progs = scalar @values_aref_holder;
1069  
1070 #print("sunix_pl,o/p num_progs: $new_num_progs\n");
1071  
1072 # for(my $i=0; $i < $new_num_progs; $i++) {
1073 # my $num_params = scalar @{$values_aref_holder[$i]};
1074 # print("sunix_pl, prog: $i---num_params: $num_params---\n");
1075 # print("sunix_pl, original good program index: $good_prog_index[$i]\n");
1076 #
1077 # for (my $j=0; $j <$num_params; $j++ ){
1078 # print("sunix_pl,get_good_sunix_params,labels: @{@{$sunix_pl->{_labels_aref2}}[$i]}[$j]\n");
1079 # print("sunix_pl,get_good_sunix_params,values: @{@{$sunix_pl->{_values_aref2}}[$i]}[$j]\n");
1080 # }
1081 # }
1082 $sunix_pl->{_good_prog_indices_ref} = \@good_prog_index;
1083  
1084 # print("sunix_pl,get_good_sunix_names,good_prog_indices, @{$sunix_pl->{_good_prog_indices_ref}} \n");
1085 return ($sunix_pl);
1086 }
1087  
1088 =head2 sub get_good_sunix_namessions
1089  
1090 =cut
1091  
1092 sub get_good_prog_versions {
1093 my ($self) = @_;
1094 my @version;
1095 my $num_good_progs = scalar @{ $sunix_pl->{_good_prog_names} };
1096  
1097 # print("sunix.pl, get_good_prog_versions:num_progs $num_good_progs\n");
1098 # always first program is version 1
1099  
1100 $version[0] = 1;
1101  
1102 # 2nd program
1103 for ( my $this = 0; $this < $num_good_progs; $this++ ) {
1104 $version[$this] = 1;
1105 for ( my $up_to = 0; $up_to < $this; $up_to++ ) {
1106 if ( @{ $sunix_pl->{_good_prog_names} }[$this] eq @{ $sunix_pl->{_good_prog_names} }[$up_to] ) {
1107 $version[$this]++;
1108 }
1109 }
1110 }
1111 $sunix_pl->{_good_prog_versions} = \@version;
1112  
1113 # print("versions, @{$sunix_pl->{_good_prog_versions}}\n");
1114 # print("versions, names:@{$sunix_pl->{_good_prog_names}}\n");
1115 return ( \@version );
1116 }
1117  
1118 =pod sub get_whole
1119  
1120 get the complete file
1121 line by line
1122  
1123 =cut
1124  
1125 sub get_whole {
1126 my ($self) = @_;
1127  
1128 if ( $sunix_pl->{_all_lines_aref} ) {
1129  
1130 my $all_lines_aref = $sunix_pl->{_all_lines_aref};
1131  
1132 # print(" sunix_pl, get_whole, @{$sunix_pl->{_all_lines_aref}}\n");
1133  
1134 # for (my $i=0; $i < $sunix_pl->{_num_lines}; $i++ ) {
1135 # print("sunix_pl, whole, all_lines_aref: @{$sunix_pl->{_all_lines_aref}}[$i] \n");
1136 # }
1137  
1138 return ($all_lines_aref);
1139  
1140 } else {
1141 print(" sunix_pl, get_whole, missing: sunix_pl->{_all_lines_aref}\n");
1142 }
1143  
1144 }
1145  
1146 =pod sub header
1147  
1148 import standard perl
1149 headers
1150 and write to output file
1151  
1152 =cut
1153  
1154 sub header {
1155  
1156 my $ref_array = $get_header->section();
1157  
1158 foreach (@$ref_array) {
1159 print $file_out "$_\n";
1160 }
1161  
1162 }
1163  
1164 =head2 sub instantiation
1165  
1166 =cut
1167  
1168 sub instantiation {
1169  
1170 my $ref_array = $get_instantiation->section();
1171  
1172 foreach (@$ref_array) {
1173 print $file_out "$_\n";
1174 }
1175  
1176 }
1177  
1178 sub length {
1179 my ($self) = shift;
1180 return ($sunix_pl);
1181 }
1182  
1183 =head2 sub lines_with
1184  
1185 return line numbers that contain a particular
1186 word or string
1187  
1188 =cut
1189  
1190 sub lines_with {
1191 my ( $self, $word ) = @_;
1192 my $string = $word;
1193 my ( $line, $count_all_lines, $case_num );
1194 my ( @line_nums, @line_contents );
1195  
1196 $count_all_lines = 0;
1197 $case_num = 0;
1198  
1199 # print("got to sunix_pl, lines_with, $word\n");
1200 # print("got to sunix_pl,all_lines: $sunix_pl->{_all_lines_aref}\n");
1201  
1202 if ( $sunix_pl->{_all_lines_aref} ) {
1203 my @all_lines = @{ $sunix_pl->{_all_lines_aref} };
1204  
1205 # print("got to sunix_pl,all_lines: @all_lines\n");
1206 foreach my $line (@all_lines) {
1207  
1208 if ( $line =~ /$string/ ) {
1209  
1210 # print ("sunix_pl,line= $line \n");
1211 $line_nums[$case_num] = $count_all_lines;
1212 $line_contents[$case_num] = $line;
1213 $case_num++;
1214 }
1215 $count_all_lines++;
1216 }
1217  
1218 $sunix_pl->{_line_nums} = \@line_nums;
1219 $sunix_pl->{_line_contents} = \@line_contents;
1220  
1221 return ($sunix_pl);
1222  
1223 } else {
1224 print("sunix_pl,lines_with, missing: all_lines_aref\n");
1225 }
1226  
1227 }
1228  
1229 =head2 sub logs
1230  
1231 =cut
1232  
1233 sub logs {
1234  
1235 print $file_out ' print "$flow[1]";' . "\n\n";
1236 print $file_out ' $log->file($flow[1]);' . "\n\n";
1237  
1238 }
1239  
1240 sub need {
1241 print("sub need \n");
1242 return ();
1243  
1244 }
1245  
1246 #=head2 sub get_pod_declare
1247 #
1248 #=cut
1249 #
1250 #sub get_pod_declare {
1251 #
1252 # my $ref_array = $pod_declare->section();
1253 # foreach (@$ref_array) {
1254 # print $file_out "$_\n";
1255 # }
1256 #}
1257  
1258 =head2 sub run
1259  
1260 =cut
1261  
1262 sub run {
1263  
1264 print $file_out ' $run->flow(\$flow[1]);' . "\n\n";
1265  
1266 }
1267  
1268 =head2 sub set_file_in
1269  
1270  
1271 =cut
1272  
1273 sub set_file_in {
1274 my ( $self, $file_aref ) = @_;
1275  
1276 if ($file_aref) {
1277  
1278 # print("sunix_pl,set_file_in, @$file_aref[0]\n");
1279  
1280 $sunix_pl->{_file_in} = @$file_aref[0];
1281  
1282 } else {
1283 print("sunix_pl,set_file_in, missing file-aref\n");
1284 }
1285 }
1286  
1287 =head2 sub set_file_in_sref
1288  
1289 print("set_file_in is $sunix_pl->{_file_in}\n");
1290  
1291 =cut
1292  
1293 sub set_file_in_sref {
1294 my ( $self, $file_sref ) = @_;
1295  
1296 if ($file_sref) {
1297  
1298 # print("sunix_pl,set_file_in, $$file_sref\n");
1299  
1300 $sunix_pl->{_file_in} = $$file_sref;
1301  
1302 } else {
1303 print("sunix_pl,set_file_in_sref, missing file_sref\n");
1304 }
1305 }
1306  
1307 =head2 sub set_file_out
1308  
1309 print("set_file_out is $sunix_pl->{_file_out}\n");
1310  
1311 =cut
1312  
1313 sub set_file_out {
1314 my ( $self, $file_aref ) = @_;
1315 $sunix_pl->{_file_out} = @$file_aref[0];
1316 }
1317  
1318 =head2 sub set_good_labels
1319  
1320 enter only those active
1321 parameter values from a program in a perl flow
1322
1323
1324  
1325 =cut
1326  
1327 =head2 sub set_good_values
1328  
1329 enter only those active
1330 parameter values from a program in a perl flow
1331  
1332 =cut
1333  
1334 =head2 sub set_num_progs
1335  
1336 =cut
1337  
1338 sub set_num_progs {
1339 my ($self) = @_;
1340  
1341 if ( $sunix_pl->{_start_line_contents} ) {
1342  
1343 $sunix_pl->{_num_progs} = scalar @{ $sunix_pl->{_start_line_contents} };
1344  
1345 # print("sunix_pl, set_num_progs: $sunix_pl->{_num_progs}\n");
1346  
1347 } else {
1348 print("sunix_pl, set_num_progs: missing $sunix_pl->{_start_line_contents}\n");
1349 }
1350 return ();
1351 }
1352  
1353 =head2 sub set_path_in_ref
1354  
1355
1356 =cut
1357  
1358 sub set_path_in_sref {
1359  
1360 my ( $self, $path_in_sref ) = @_;
1361  
1362 if ($path_in_sref) {
1363  
1364 $sunix_pl->{_path} = $$path_in_sref;
1365  
1366 # print("sunix_pl,set_path_in_sref, $sunix_pl->{_path}\n");
1367  
1368 } else {
1369 print("sunix_pl,set_path_in_sref,missing path_in\n");
1370 }
1371  
1372 return ();
1373 }
1374  
1375 =head2 sub set_perl_file_in
1376  
1377
1378 =cut
1379  
1380 sub set_perl_file_in {
1381  
1382 my ( $self, $file_in ) = @_;
1383  
1384 if ($file_in) {
1385  
1386 $sunix_pl->{_perl_file_in} = $file_in;
1387 $sunix_pl->{_file_in} = $file_in;
1388  
1389 # print("sunix_pl,set_perl_file_in, $file_in\n");
1390  
1391 } else {
1392 print("sunix_pl,set_perl_file_in,missing file_in\n");
1393 }
1394  
1395 return ();
1396 }
1397  
1398 =head2 sub set_perl_path
1399  
1400 working file name
1401
1402 =cut
1403  
1404 sub set_perl_path {
1405  
1406 my ( $self, $path ) = @_;
1407  
1408 if ($path) {
1409  
1410 # print("sunix_pl,set_perl_path, $path\n");
1411 $sunix_pl->{_path} = $path;
1412  
1413 } else {
1414 print("perl_flow,missing path\n");
1415 }
1416 return ();
1417 }
1418  
1419 =head2 sub set_perl_path_in
1420  
1421 working file name
1422
1423 =cut
1424  
1425 sub set_perl_path_in {
1426  
1427 my ( $self, $path ) = @_;
1428  
1429 if ($path) {
1430  
1431 # print("sunix_pl,set_perl_path_in, $path\n");
1432 $sunix_pl->{_path} = $path;
1433  
1434 } else {
1435 print("perl_flow,missing path\n");
1436 }
1437 return ();
1438 }
1439  
1440 =head2 sub set_progs_contain
1441  
1442 return line numbers that contain a particular
1443 word or string
1444  
1445 =cut
1446  
1447 sub set_progs_contain {
1448  
1449 my ( $self, $string ) = @_;
1450  
1451 if ($string) {
1452  
1453 $sunix_pl->{_string} = $string;
1454  
1455 # print("sunix_pl,set_progs_contain, string:[$string]\n");
1456  
1457 } else {
1458 print("sunix_pl,set_progs_contain, missing string\n");
1459 }
1460  
1461 return ();
1462 }
1463  
1464 =head2 sub set_progs_end_with
1465  
1466 return line numbers that contain a particular
1467 word or string
1468 print("progs_end_with,@{$sunix_pl->{_end_prog_lines}}\n");i
1469 print("progs_end_with,@{$sunix_pl->{_end_line_contents}}\n");
1470  
1471 =cut
1472  
1473 sub set_progs_end_with {
1474 my ( $self, $word ) = @_;
1475  
1476 if ( $word && $sunix_pl->{_all_lines_aref} ) {
1477  
1478 my $string = $word;
1479 my ( $line, $count_all_lines, $case_num );
1480 my ( @line_nums, @line_contents );
1481  
1482 my @all_lines = @{ $sunix_pl->{_all_lines_aref} };
1483  
1484 $count_all_lines = 0;
1485 $case_num = 0;
1486  
1487 foreach my $line (@all_lines) {
1488  
1489 if ( $line =~ /$string/ ) {
1490 $line_nums[$case_num] = $count_all_lines;
1491 $line_contents[$case_num] = $line;
1492 $case_num++;
1493  
1494 # print("sunix_pl,set_progs_end_with, found $string at line $line \n");
1495 }
1496  
1497 $count_all_lines++;
1498 }
1499  
1500 $sunix_pl->{_end_prog_lines} = \@line_nums;
1501 $sunix_pl->{_end_line_contents} = \@line_contents;
1502  
1503 # print("sunix_pl,set_progs_end_with, end lines: @{$sunix_pl->{_end_prog_lines}}\n");
1504  
1505 } else {
1506 print("sunix_pl,set_progs_end_with, missing word\n");
1507 }
1508  
1509 return ();
1510 }
1511  
1512 =head2 sub set_progs_start_with
1513  
1514 return line numbers that contain a particular
1515 word or string
1516 print("$case_num cases in $count_all_lines lines,\n");
1517 print("at line(s): @{$sunix_pl->{_line_nums}}\n");
1518 print("set_progs_start_with, length is $size\n");
1519 print ("word is $word\n");
1520 print ("word is $string\n");
1521  
1522 =cut
1523  
1524 sub set_progs_start_with {
1525 my ( $self, $word ) = @_;
1526  
1527 if ( $word && $sunix_pl->{_all_lines_aref} ) {
1528  
1529 my $string = $word;
1530 my ( $line, $count_all_lines, $case_num );
1531 my ( @line_nums, @line_contents );
1532  
1533 my @all_lines = @{ $sunix_pl->{_all_lines_aref} };
1534  
1535 $count_all_lines = 0;
1536 $case_num = 0;
1537  
1538 foreach my $line (@all_lines) {
1539 if ( $line =~ /$string/ ) {
1540 $line_nums[$case_num] = $count_all_lines;
1541 $line_contents[$case_num] = $line;
1542 $case_num++;
1543  
1544 # print("sunix_pl,set_progs_start_with, found $string at line $line \n");
1545 }
1546 $count_all_lines++;
1547 }
1548  
1549 $sunix_pl->{_start_prog_lines} = \@line_nums;
1550 $sunix_pl->{_start_line_contents} = \@line_contents;
1551  
1552 # print("sunix_pl,set_progs_start_with, start lines: @{$sunix_pl->{_start_prog_lines}}\n");
1553  
1554 } else {
1555 print("sunix_pl,set_progs_start_with, missing word\n");
1556 }
1557  
1558 return ();
1559 }
1560  
1561 =head2 sub use_pkg
1562  
1563 =cut
1564  
1565 sub use_pkg {
1566  
1567 my $ref_array = $get_use_pkg->section();
1568 foreach (@$ref_array) {
1569 print $file_out "$_\n";
1570 }
1571 }
1572  
1573 =pod sub whole
1574  
1575 open and read
1576 the complete file
1577 line by line
1578 #print ("lines are @{$sunix_pl->{_all_lines_aref}}\n");
1579 print ("We seem to have $sunix_pl->{_num_lines} lines total\n");
1580  
1581 =cut
1582  
1583 sub whole {
1584 my ($self) = @_;
1585 my @all_lines;
1586  
1587 if ( $sunix_pl->{_path} && $sunix_pl->{_file_in} ) {
1588  
1589 # full directory path plus file name
1590 my $inbound = $sunix_pl->{_path} . '/' . $sunix_pl->{_file_in};
1591 # print("sunix_pl, whole, $inbound\n");
1592  
1593 my $i = 0;
1594 open( my $fh, '<', $inbound )
1595 or die "Could not open file '$sunix_pl->{_file_in}' $!";
1596 while ( my $row = <$fh> ) {
1597 chomp $row;
1598 $all_lines[$i] = $row;
1599  
1600 # print "I read: " . $all_lines[$i] . "from the file, i=" . $i . "\n";
1601 $i++;
1602 }
1603  
1604 $sunix_pl->{_all_lines_aref} = \@all_lines;
1605 close($fh);
1606 $sunix_pl->{_num_lines} = scalar @{ $sunix_pl->{_all_lines_aref} };
1607  
1608 # $sunix_pl->{_num_lines} = 16;
1609  
1610 # print("sunix_pl, whole, num_lines: $sunix_pl->{_num_lines}\n");
1611 #for (my $i=14; $i < $sunix_pl->{_num_lines}; $i++ ) {
1612 # print("sunix_pl, whole, all_lines_aref: @{$sunix_pl->{_all_lines_aref}}[$i] \n");
1613 #}
1614 # print("sunix_pl, whole, all_lines_aref: @{$sunix_pl->{_all_lines_aref}} \n");
1615 } else {
1616 # print("sunix_pl, whole, missing path or file name \n");
1617 }
1618  
1619 return ();
1620 }
1621  
1622 #
1623 #=head2 sub write_inbound
1624 #
1625 # import standard perl
1626 # inbound files and their paths
1627 #
1628 #=cut
1629 #
1630 # sub write_inbound {
1631 #
1632 # my ($file_in) = @_;
1633 #
1634 # print (" 3. file in is $self->{ref_file_in}\n");
1635 # my $ref_array = $get_inbound->section($self->{ref_file_in});
1636 #
1637 # foreach (@$ref_array) {
1638 # print $file_out "$_\n";
1639 # }
1640 #}
1641  
1642 1;