« lib/App/SeismicUnixGui/misc/gui_history.pm
↑ Summary
lib/App/SeismicUnixGui/messages/SuMessages.pm »
| 1 | package App::SeismicUnixGui::misc::oop_flows; | ||
| 2 | use Moose; | ||
| 3 | our $VERSION = '0.0.3'; | ||
| 4 | use aliased 'App::SeismicUnixGui::messages::message_director'; | ||
| 5 | use aliased 'App::SeismicUnixGui::misc::L_SU_path'; | ||
| 6 | |||
| 7 | my $L_SU_messages = message_director->new(); | ||
| 8 | my $L_SU_path = L_SU_path->new(); | ||
| 9 | |||
| 10 | =head2 initialize shared anonymous hash | ||
| 11 | |||
| 12 | key/value pairs | ||
| 13 | |||
| 14 | =cut | ||
| 15 | |||
| 16 | my $oop_flows = { | ||
| 17 | _corrected_prog_names_aref => '', | ||
| 18 | _corrected_prog_versions_aref => '', | ||
| 19 | _message_w => '', | ||
| 20 | _num_progs4flow => '', | ||
| 21 | _prog_name => '', | ||
| 22 | _prog_version => '', | ||
| 23 | _prog_names_aref => '', | ||
| 24 | _prog_versions_aref => '', | ||
| 25 | _symbols_aref => '', | ||
| 26 | }; | ||
| 27 | |||
| 28 | my @lines; | ||
| 29 | |||
| 30 | =head2 sub get_section | ||
| 31 | |||
| 32 | final assemblage of text for perl script | ||
| 33 | this section covers the defined flows | ||
| 34 | Removed in V 0.0.2: | ||
| 35 | if ( ($prog_name[$prog_idx] ne 'data_in') && ($prog_name[$prog_idx] ne 'data_out') ) { | ||
| 36 | 12.3.20 corrected symbol at index 3 | ||
| 37 | |||
| 38 | =cut | ||
| 39 | |||
| 40 | sub get_section { | ||
| 41 | |||
| 42 | my $self = @_; | ||
| 43 | my @prog_name = @{ $oop_flows->{_corrected_prog_names_aref} }; | ||
| 44 | my @version = @{ $oop_flows->{_corrected_prog_versions_aref} }; | ||
| 45 | my @symbol = @{ $oop_flows->{_symbols_aref} }; | ||
| 46 | my $num_progs4flow = $oop_flows->{_num_progs4flow}; | ||
| 47 | my $j = 0; | ||
| 48 | my $prog_idx = 0; | ||
| 49 | my @lines; | ||
| 50 | |||
| 51 | $lines[$j] = "\t" . ' @items' . "\t" . '= ('; | ||
| 52 | |||
| 53 | if ( $num_progs4flow >= 0 ) { | ||
| 54 | |||
| 55 | for ( | ||
| 56 | $prog_idx = 0, $j = 1 ; | ||
| 57 | $prog_idx < ( $num_progs4flow - 1 ) ; | ||
| 58 | $prog_idx++, $j++ | ||
| 59 | ) | ||
| 60 | { | ||
| 61 | |||
| 62 | # print(" oop_flows,get_section,symbols are @symbol \n"); | ||
| 63 | # print("oop_flows,get_section,prog_name=$prog_name[$prog_idx]\n"); | ||
| 64 | # print("oop_flows,get_section,num_progs4flow=$num_progs4flow\n"); | ||
| 65 | # print("oop_flows,get_section,version=$version[$prog_idx]\n"); | ||
| 66 | # print("oop_flows,get_section,symbol=$symbol[$prog_idx]\n"); | ||
| 67 | |||
| 68 | $lines[$j] = | ||
| 69 | "\t\t " . '$' | ||
| 70 | . $prog_name[$prog_idx] . '[' | ||
| 71 | . "$version[$prog_idx]" . '], ' | ||
| 72 | . $symbol[$prog_idx] . ','; | ||
| 73 | |||
| 74 | } | ||
| 75 | if ( ( $prog_name[$prog_idx] ne 'data_in' ) | ||
| 76 | && ( $prog_name[$prog_idx] ne 'data_out' ) ) | ||
| 77 | { | ||
| 78 | |||
| 79 | $lines[$j] = | ||
| 80 | "\t\t " . '$' | ||
| 81 | . $prog_name[$prog_idx] . '[' | ||
| 82 | . "$version[$prog_idx]" . '],'; | ||
| 83 | |||
| 84 | } | ||
| 85 | elsif ( $prog_name[$prog_idx] eq 'data_in' ) { | ||
| 86 | |||
| 87 | $lines[$j] = "\t\t " . '$data_in[1],'; | ||
| 88 | |||
| 89 | } | ||
| 90 | elsif ( $prog_name[$prog_idx] eq 'data_out' ) { | ||
| 91 | |||
| 92 | $lines[$j] = "\t\t " . '$data_out[1],'; | ||
| 93 | } | ||
| 94 | |||
| 95 | $j++; | ||
| 96 | $lines[$j] = "\t\t " . '$go'; | ||
| 97 | $j++; | ||
| 98 | $lines[$j] = "\t\t " . ');'; | ||
| 99 | $j++; | ||
| 100 | $lines[$j] = "\t" . '$flow[1] = $run->modules(\@items);'; | ||
| 101 | |||
| 102 | return ( \@lines ); | ||
| 103 | |||
| 104 | } | ||
| 105 | else { | ||
| 106 | print("oop_flows,get_section,missing num_progs4flow \n"); | ||
| 107 | } | ||
| 108 | |||
| 109 | } | ||
| 110 | |||
| 111 | sub set_num_progs4flow { | ||
| 112 | |||
| 113 | my ( $self, $hash_ref ) = @_; | ||
| 114 | $oop_flows->{_num_progs4flow} = $hash_ref->{_num_progs4flow}; | ||
| 115 | |||
| 116 | #print("1. flows,set_num_progs4flow,number=$oop_flows->{_num_progs4flow}\n"); | ||
| 117 | return (); | ||
| 118 | } | ||
| 119 | |||
| 120 | =head2 sub set_message (widget) | ||
| 121 | |||
| 122 | =cut | ||
| 123 | |||
| 124 | sub set_message { | ||
| 125 | my ( $self, $hash_ref ) = @_; | ||
| 126 | |||
| 127 | if ($hash_ref) { | ||
| 128 | $oop_flows->{_message_w} = $hash_ref->{_message_w}; | ||
| 129 | |||
| 130 | # my $message_w = $oop_flows->{_message_w}; | ||
| 131 | # my $m = "oop_flows,set_message,$message_w\n"; | ||
| 132 | # $message_w->delete("1.0",'end'); | ||
| 133 | # $message_w->insert('end', $m); | ||
| 134 | # print("oop_text,set_message, message=$oop_text->{_message}\n"); | ||
| 135 | } | ||
| 136 | return (); | ||
| 137 | } | ||
| 138 | |||
| 139 | sub set_prog_name { | ||
| 140 | my ( $self, $prog_name_href ) = @_; | ||
| 141 | |||
| 142 | if ($prog_name_href) { | ||
| 143 | $oop_flows->{_prog_name} = $prog_name_href->{_prog_name}; | ||
| 144 | |||
| 145 | #print("1. flows,set_prog_name,prog_name,$oop_flows->{_prog_name}\n"); | ||
| 146 | } | ||
| 147 | return (); | ||
| 148 | } | ||
| 149 | |||
| 150 | =head2 sub set_prog_names_aref | ||
| 151 | |||
| 152 | =cut | ||
| 153 | |||
| 154 | sub set_prog_names_aref { | ||
| 155 | my ( $self, $prog_names_href ) = @_; | ||
| 156 | |||
| 157 | if ($prog_names_href) { | ||
| 158 | $oop_flows->{_prog_names_aref} = $prog_names_href->{_prog_names_aref}; | ||
| 159 | |||
| 160 | #print("oop_flows,set_prog_names_aref, prog_names=@{$oop_flows->{_prog_names_aref}}\n"); | ||
| 161 | } | ||
| 162 | return (); | ||
| 163 | } | ||
| 164 | |||
| 165 | =head2 sub set_prog_version_aref | ||
| 166 | print("oop_flows,set_prog_version_aref,prog_version_aref=@{$hash_aref->{_prog_version_aref}}\n"); | ||
| 167 | |||
| 168 | =cut | ||
| 169 | |||
| 170 | sub set_prog_version_aref { | ||
| 171 | my ( $self, $hash_aref ) = @_; | ||
| 172 | |||
| 173 | if ($hash_aref) { | ||
| 174 | $oop_flows->{_prog_version_aref} = $hash_aref->{_prog_version_aref}; | ||
| 175 | |||
| 176 | # print("oop_flows,set_prog_version_aref,prog_version_aref=@{$oop_flows->{_prog_version_aref}}\n"); | ||
| 177 | } | ||
| 178 | return (); | ||
| 179 | } | ||
| 180 | |||
| 181 | =head2 sub set_specs | ||
| 182 | |||
| 183 | if first program is data_in | ||
| 184 | switch with the second program in the list that | ||
| 185 | moves to first location in the flow | ||
| 186 | |||
| 187 | if second file is data_in then OK | ||
| 188 | do nothing set symbol to '<' ($in) | ||
| 189 | |||
| 190 | if there is only one item in a flow, do not run the flow | ||
| 191 | |||
| 192 | my $num_progs4flow = $oop_flows->{_num_progs4flow}; | ||
| 193 | |||
| 194 | First program has index=0 | ||
| 195 | |||
| 196 | =cut | ||
| 197 | |||
| 198 | sub set_specs { | ||
| 199 | my ($self) = @_; | ||
| 200 | |||
| 201 | # use Module::Refresh; # reload updated module | ||
| 202 | # my $refresher = Module::Refresh->new; | ||
| 203 | |||
| 204 | my ( @specs, @prog, @symbols ); | ||
| 205 | my (@module_spec); | ||
| 206 | my ( $message_w, $message, $second2last_idx ); | ||
| 207 | my @corrected_prog_names; | ||
| 208 | my @corrected_prog_versions; | ||
| 209 | my $reverse = 0; | ||
| 210 | my $prog_names_aref = $oop_flows->{_prog_names_aref}; | ||
| 211 | my $prog_names_version_aref = $oop_flows->{_prog_version_aref}; | ||
| 212 | my @prog_names = @$prog_names_aref; | ||
| 213 | my @prog_versions = @$prog_names_version_aref; | ||
| 214 | my $num_progs4flow = $oop_flows->{_num_progs4flow}; | ||
| 215 | my $last_idx = $num_progs4flow - 1; | ||
| 216 | $message_w = $oop_flows->{_message_w}; | ||
| 217 | |||
| 218 | # print("1. oop_flows,set_specs, prog_names_aref=@{$prog_names_aref}\n"); | ||
| 219 | # print( | ||
| 220 | #"1. oop_flows,set_specs, prog_version_aref=@{$prog_names_version_aref}\n" | ||
| 221 | # ); | ||
| 222 | # print("1. oop_flows,set_specs, num_progs4flow=$num_progs4flow\n"); | ||
| 223 | |||
| 224 | =head2 STEP 1 | ||
| 225 | |||
| 226 | If data_in is first program in flow | ||
| 227 | REVERSE first two items in the flow | ||
| 228 | i.e., switch the order of the program and data_in | ||
| 229 | |||
| 230 | =cut | ||
| 231 | |||
| 232 | if ( $num_progs4flow > 1 ) { | ||
| 233 | |||
| 234 | $second2last_idx = $num_progs4flow - 2; | ||
| 235 | |||
| 236 | if ( $prog_names[0] eq 'data_in' ) { $reverse = 1; } | ||
| 237 | |||
| 238 | if ($reverse) { | ||
| 239 | my $temp_prog_name = $prog_names[1]; | ||
| 240 | my $temp_prog_version = $prog_versions[1]; | ||
| 241 | |||
| 242 | $prog_names[1] = $prog_names[0]; | ||
| 243 | $prog_versions[1] = $prog_versions[0]; | ||
| 244 | |||
| 245 | $prog_names[0] = $temp_prog_name; | ||
| 246 | $prog_versions[0] = $temp_prog_version; | ||
| 247 | |||
| 248 | for ( my $i = 2 ; $i < $num_progs4flow ; $i++ ) { | ||
| 249 | |||
| 250 | $prog_names[$i] = @{$prog_names_aref}[$i]; | ||
| 251 | $prog_versions[$i] = @{$prog_names_version_aref}[$i]; | ||
| 252 | } | ||
| 253 | } | ||
| 254 | } | ||
| 255 | elsif ( $num_progs4flow == 1 ) { | ||
| 256 | |||
| 257 | # Not enough items in a flow sequence | ||
| 258 | # NULL CASE | ||
| 259 | |||
| 260 | print( | ||
| 261 | "1.Warning Only one item in flow--flow may not run: oop_flows,set_specs,length = 0 or 1 \n" | ||
| 262 | ); | ||
| 263 | |||
| 264 | # for example unif2 can run as a standalone item | ||
| 265 | |||
| 266 | my $message_w = $oop_flows->{_message_w}; | ||
| 267 | my $message = $L_SU_messages->flows(4); | ||
| 268 | |||
| 269 | $message_w->delete( "1.0", 'end' ); | ||
| 270 | $message_w->insert( 'end', $message ); | ||
| 271 | |||
| 272 | } | ||
| 273 | else { | ||
| 274 | print( | ||
| 275 | "2.Warning No item in flow--flow will not run: oop_flows,set_specs,length = 0 \n" | ||
| 276 | ); | ||
| 277 | |||
| 278 | my $message_w = $oop_flows->{_message_w}; | ||
| 279 | my $message = $L_SU_messages->flows(5); | ||
| 280 | |||
| 281 | $message_w->delete( "1.0", 'end' ); | ||
| 282 | $message_w->insert( 'end', $message ); | ||
| 283 | } | ||
| 284 | |||
| 285 | # results of STEP 1 - reversal of first two modules in flow | ||
| 286 | |||
| 287 | $oop_flows->{_corrected_prog_names_aref} = \@prog_names; | ||
| 288 | $oop_flows->{_corrected_prog_versions_aref} = \@prog_versions; | ||
| 289 | @corrected_prog_names = @{ $oop_flows->{_corrected_prog_names_aref} }; | ||
| 290 | @corrected_prog_versions = @{ $oop_flows->{_corrected_prog_versions_aref} }; | ||
| 291 | |||
| 292 | # END of STEP 1 | ||
| 293 | |||
| 294 | # if(@prog_names) { | ||
| 295 | # print("2. oop_flows,set_specs, new prog_names= @{$oop_flows->{_corrected_prog_names_aref}}\n"); | ||
| 296 | # print("3. oop_flows,set_specs, old prog names = @{$oop_flows->{_prog_names_aref}}\n"); | ||
| 297 | # print("2. oop_flows,set_specs, new prog_versions= @{$oop_flows->{_corrected_prog_versions_aref}}\n"); | ||
| 298 | # print("3. oop_flows,set_specs, old prog versions = @{$oop_flows->{_prog_version_aref}}\n"); | ||
| 299 | #} | ||
| 300 | |||
| 301 | =head2 | ||
| 302 | |||
| 303 | Using corrected names and versions (from STEP 1), | ||
| 304 | arrange symbols within a flow sequence. | ||
| 305 | Estimate first the redirect and pipe sequences | ||
| 306 | arrange programs and symbols (>,<,|) in order. | ||
| 307 | |||
| 308 | =cut | ||
| 309 | |||
| 310 | for ( my $i = 0 ; $i < $num_progs4flow ; $i++ ) { | ||
| 311 | |||
| 312 | my $program_name = $corrected_prog_names[$i]; | ||
| 313 | |||
| 314 | $L_SU_path->set_program_name($program_name); | ||
| 315 | |||
| 316 | my $pathNmodule_spec_w_slash_pm = | ||
| 317 | $L_SU_path->get_pathNmodule_spec_w_slash_pm(); | ||
| 318 | my $pathNmodule_spec_w_colon = | ||
| 319 | $L_SU_path->get_pathNmodule_spec_w_colon(); | ||
| 320 | |||
| 321 | require $pathNmodule_spec_w_slash_pm; | ||
| 322 | |||
| 323 | $module_spec[$i] = $pathNmodule_spec_w_colon; | ||
| 324 | |||
| 325 | # INSTANTIATE | ||
| 326 | $prog[$i] = ( $module_spec[$i] )->new; | ||
| 327 | |||
| 328 | # print ("oop_flows,set_specs, instantiate $module_spec[$i]\n"); | ||
| 329 | |||
| 330 | $specs[$i] = $prog[$i]->variables(); | ||
| 331 | |||
| 332 | } | ||
| 333 | |||
| 334 | if ( $num_progs4flow == 2 ) { | ||
| 335 | |||
| 336 | # CASE 1 with 2 programs in flow | ||
| 337 | # i.e., num_progs4flow = 2 | ||
| 338 | # first item has index 0 and has already been reordered | ||
| 339 | # previously, e.g., | ||
| 340 | # data_in, evince would now be evince, data_in | ||
| 341 | # for symbol index = 0, 1 | ||
| 342 | |||
| 343 | if ( $specs[0]->{_is_first_of_2} ) { | ||
| 344 | |||
| 345 | # print(" 1. oop_flows,first item is $module_spec[0]\n"); | ||
| 346 | |||
| 347 | if ( $specs[1]->{_is_last_of_2} ) { | ||
| 348 | |||
| 349 | # CASE 1A data_out is last program | ||
| 350 | # only if second item is data_out | ||
| 351 | if ( $corrected_prog_names[1] eq 'data_out' ) { | ||
| 352 | |||
| 353 | # print(" 1. flows, second item is now $module_spec[1]\n"); | ||
| 354 | $symbols[0] = '$out'; | ||
| 355 | |||
| 356 | # only if second item is NOT data_out, i.e. probably data_in | ||
| 357 | # BUT not certain this will be the case always TODO | ||
| 358 | } | ||
| 359 | elsif (( $corrected_prog_names[1] ne 'data_out' ) | ||
| 360 | && ( $corrected_prog_names[1] ne 'data_in' ) ) | ||
| 361 | { | ||
| 362 | |||
| 363 | # print(" 2. flows, second item is now $module_spec[1]\n"); | ||
| 364 | $symbols[0] = '$to'; # pipe | ||
| 365 | |||
| 366 | } | ||
| 367 | elsif ( $corrected_prog_names[1] eq 'data_in' ) { | ||
| 368 | |||
| 369 | if ( $specs[0]->{_is_suprog} ) { | ||
| 370 | |||
| 371 | # print(" 3. flows, second item is now $module_spec[1]\n"); | ||
| 372 | $symbols[0] = '$in'; # redirect | ||
| 373 | } | ||
| 374 | elsif ( not $specs[0]->{_is_suprog} ) { | ||
| 375 | |||
| 376 | # print(" 4. flows, second item is now $module_spec[1]\n"); | ||
| 377 | |||
| 378 | if ( $specs[0]->{_has_redirect_in} ) { | ||
| 379 | |||
| 380 | # print(" 5. flows, second item is now $module_spec[1]\n"); | ||
| 381 | $symbols[0] = '$in'; # redirect | ||
| 382 | } | ||
| 383 | elsif ( not $specs[0]->{_has_redirect_in} ) { | ||
| 384 | |||
| 385 | # print(" 6. flows, second item is now $module_spec[1]\n"); | ||
| 386 | $symbols[0] = | ||
| 387 | " "; # nothing, e.g., evince file_name.ps | ||
| 388 | |||
| 389 | } | ||
| 390 | else { | ||
| 391 | print( | ||
| 392 | " 1. oop_flows, set_specs first item has bad spec file\n" | ||
| 393 | ); | ||
| 394 | } | ||
| 395 | |||
| 396 | } | ||
| 397 | else { | ||
| 398 | print( | ||
| 399 | " 2. oop_flows, set_specs first item has bad spec file\n" | ||
| 400 | ); | ||
| 401 | } | ||
| 402 | } | ||
| 403 | else { | ||
| 404 | print(" oop_flows, set_specs unexpected case\n"); | ||
| 405 | } | ||
| 406 | } | ||
| 407 | else { | ||
| 408 | print( | ||
| 409 | " Warning: Second item ($module_spec[1]) is not allowed. Check *spec.pm file (oop_flows,set_specs)\n" | ||
| 410 | ); | ||
| 411 | print(" oop_flows, set_specs, unexpected input\n"); | ||
| 412 | $message = $L_SU_messages->flows(0); | ||
| 413 | $message_w->delete( "1.0", 'end' ); | ||
| 414 | $message_w->insert( 'end', $message ); | ||
| 415 | } | ||
| 416 | |||
| 417 | } | ||
| 418 | else { | ||
| 419 | $message = $L_SU_messages->flows(1); | ||
| 420 | $message_w->delete( "1.0", 'end' ); | ||
| 421 | $message_w->insert( 'end', $message ); | ||
| 422 | print(" Warning: First item is not allowed. Use another program\n"); | ||
| 423 | } # first of two | ||
| 424 | |||
| 425 | } # length =2 | ||
| 426 | |||
| 427 | if ( $num_progs4flow == 3 ) { | ||
| 428 | |||
| 429 | # CASE 2.1 first and second items | ||
| 430 | # for symbol whose index=0 | ||
| 431 | # e.g., sugain < data_in | | ||
| 432 | |||
| 433 | # print("CASE = 2.1; items in flow; length,num_progs4flow=3\n"); | ||
| 434 | |||
| 435 | if ( $specs[0]->{_is_first_of_3or_more} | ||
| 436 | && $corrected_prog_names[1] eq 'data_in' ) | ||
| 437 | { | ||
| 438 | |||
| 439 | $symbols[0] = '$in'; | ||
| 440 | |||
| 441 | # print(" oop_flows,set_specs,case 2.1\n"); | ||
| 442 | |||
| 443 | # print(" Between items 1 and 2 symbol=$symbols[0], with index=0 \n"); | ||
| 444 | |||
| 445 | # for Third item | ||
| 446 | if ( $specs[2]->{_is_last_of_3or_more} ) { | ||
| 447 | |||
| 448 | # CASE 3.1.1 | ||
| 449 | # for symbol 1 | ||
| 450 | # e.g., sugain < data_in > data_out | ||
| 451 | if ( $corrected_prog_names[2] eq 'data_out' ) { | ||
| 452 | |||
| 453 | $symbols[1] = '$out'; | ||
| 454 | |||
| 455 | # print(" oop_flows,set_specs,case 3.1.1\n"); | ||
| 456 | |||
| 457 | } | ||
| 458 | |||
| 459 | # CASE 3.1.2 | ||
| 460 | # e.g., sugain < data_in | suximage | ||
| 461 | # fors symbols[1] | ||
| 462 | elsif ($specs[2]->{_is_suprog} | ||
| 463 | && $corrected_prog_names[1] eq 'data_in' | ||
| 464 | && $specs[2]->{_has_pipe_in} ) | ||
| 465 | { | ||
| 466 | |||
| 467 | # print(" oop_flows,set_specs,corrected_prog_names[1]= $corrected_prog_names[1]\n"); | ||
| 468 | $symbols[1] = '$to'; | ||
| 469 | |||
| 470 | } | ||
| 471 | elsif ($specs[2]->{_is_suprog} | ||
| 472 | && $specs[2]->{_has_outpar} ) | ||
| 473 | { | ||
| 474 | |||
| 475 | # print(" oop_flows,set_specs,corrected_prog_names[1]= $corrected_prog_names[1]\n"); | ||
| 476 | $symbols[1] = '$tty'; | ||
| 477 | |||
| 478 | } | ||
| 479 | else { | ||
| 480 | $message = $L_SU_messages->flows(2); | ||
| 481 | $message_w->delete( "1.0", 'end' ); | ||
| 482 | $message_w->insert( 'end', $message ); | ||
| 483 | |||
| 484 | # print(" 1. Warning: Last item is not allowed. Use data_out or a program (oop_flows,set_specs)\n"); | ||
| 485 | } | ||
| 486 | } | ||
| 487 | else { | ||
| 488 | print( | ||
| 489 | " 2. Warning: Last item is not allowed. (oop_flows,set_specs)\n" | ||
| 490 | ); | ||
| 491 | } | ||
| 492 | |||
| 493 | # CASE 3.2 first and second items, | ||
| 494 | # where the first program has internal access to files | ||
| 495 | # e.g., suop2 | sugain | ||
| 496 | # for symbols[0] | ||
| 497 | } | ||
| 498 | elsif ($specs[0]->{_is_first_of_3or_more} | ||
| 499 | && $specs[0]->{_has_pipe_out} | ||
| 500 | && $specs[1]->{_is_suprog} | ||
| 501 | && $specs[1]->{_has_pipe_in} ) | ||
| 502 | { | ||
| 503 | |||
| 504 | $symbols[0] = '$to'; | ||
| 505 | |||
| 506 | # for Third item | ||
| 507 | if ( $specs[2]->{_is_last_of_3or_more} ) { | ||
| 508 | |||
| 509 | # CASE 3.2.1 | ||
| 510 | # e.g., suop2 | sugain > data_out | ||
| 511 | # for symbols[1] | ||
| 512 | if ( $corrected_prog_names[2] eq 'data_out' ) { | ||
| 513 | |||
| 514 | $symbols[1] = '$out'; | ||
| 515 | |||
| 516 | # CASE 3.2.2 | ||
| 517 | # e.g., suop2 | sugain | suximage | ||
| 518 | # for second symbol symbol[1] between | ||
| 519 | # second and thrid program | ||
| 520 | } | ||
| 521 | elsif ($specs[2]->{_is_suprog} | ||
| 522 | && $specs[1]->{_has_pipe_out} | ||
| 523 | && $specs[2]->{_has_pipe_in} ) | ||
| 524 | { | ||
| 525 | |||
| 526 | $symbols[1] = '$to'; | ||
| 527 | |||
| 528 | } | ||
| 529 | else { | ||
| 530 | $message = $L_SU_messages->flows(2); | ||
| 531 | $message_w->delete( "1.0", 'end' ); | ||
| 532 | $message_w->insert( 'end', $message ); | ||
| 533 | |||
| 534 | # print(" Warning: Last item is not allowed. Use data_out or program (oop_flows,set_specs)\n"); | ||
| 535 | } | ||
| 536 | } | ||
| 537 | } | ||
| 538 | else { | ||
| 539 | $message = $L_SU_messages->flows(3); | ||
| 540 | $message_w->delete( "1.0", 'end' ); | ||
| 541 | $message_w->insert( 'end', $message ); | ||
| 542 | |||
| 543 | # print(" Warning: First or second items are not allowed. (oop_flows,set_specs)\n"); | ||
| 544 | } | ||
| 545 | |||
| 546 | } | ||
| 547 | |||
| 548 | # end of CASE with 3 items in flow | ||
| 549 | |||
| 550 | # CASE 4 | ||
| 551 | # when there are >=4 items in flow | ||
| 552 | if ( $num_progs4flow >= 4 ) { | ||
| 553 | |||
| 554 | # print("oop_flows,set_specs,num_progs=$num_progs4flow\n"); | ||
| 555 | |||
| 556 | # CASE 4.1 | ||
| 557 | # first and second items, of 4 or more | ||
| 558 | # e.g., sugain < data_in ...| suprog | ||
| 559 | # for symbols[0] | ||
| 560 | if ( $specs[0]->{_is_first_of_4or_more} | ||
| 561 | && $corrected_prog_names[1] eq 'data_in' ) | ||
| 562 | { | ||
| 563 | |||
| 564 | $symbols[0] = '$in'; | ||
| 565 | |||
| 566 | # print(" oop_flows,set_specs,case 4.1\n"); | ||
| 567 | |||
| 568 | # CASE 4.1.1 | ||
| 569 | # For symbol[1] between second item (index=1) and third item (index=2) | ||
| 570 | # for symbols[1] | ||
| 571 | |||
| 572 | if ( $specs[2]->{_is_suprog} | ||
| 573 | && $specs[1]->{_has_pipe_out} | ||
| 574 | && $specs[2]->{_has_pipe_in} ) | ||
| 575 | { | ||
| 576 | |||
| 577 | $symbols[1] = '$to'; | ||
| 578 | |||
| 579 | # print(" oop_flows,set_specs,case 4.1.1; symbols[1] =$symbols[1]\n"); | ||
| 580 | |||
| 581 | } | ||
| 582 | else { | ||
| 583 | print( | ||
| 584 | " Warning: Problem with item 2 or beyond, item OK (oop_flows,set_specs)\n" | ||
| 585 | ); | ||
| 586 | } | ||
| 587 | |||
| 588 | # End CASE 4.1.1 | ||
| 589 | |||
| 590 | # Start CASE 4.1.2 | ||
| 591 | # Third item and above, of 4 or more items | ||
| 592 | # e.g., sugain < data_in | suprog ... > data_out or | suximage | ||
| 593 | # for third item and second symbol and up to symbol between the | ||
| 594 | # second- ($j) and third-to-last ($i) of 4 or more items | ||
| 595 | # for symbols[2 and above] | ||
| 596 | for ( | ||
| 597 | my $i = 2, my $j = 3 ; | ||
| 598 | $i < ( $num_progs4flow - 2 ) ; | ||
| 599 | $i++, $j++ | ||
| 600 | ) | ||
| 601 | { | ||
| 602 | |||
| 603 | if ( $specs[$i]->{_is_suprog} | ||
| 604 | && $specs[$i]->{_has_pipe_out} | ||
| 605 | && $specs[$j]->{_has_pipe_in} ) | ||
| 606 | { | ||
| 607 | |||
| 608 | # print(" oop_flows,set_specs,case 4.1.2\n"); | ||
| 609 | $symbols[$i] = '$to'; | ||
| 610 | |||
| 611 | } | ||
| 612 | else { | ||
| 613 | print( | ||
| 614 | " Case 4.1.2 Warning: Problem with item 3 or beyond, items 1 and 2 OK (oop_flows,set_specs)\n" | ||
| 615 | ); | ||
| 616 | |||
| 617 | # print( | ||
| 618 | # " Case 4.1.2 oop_flows,set_specs,\n | ||
| 619 | # \tspecs[$i]->{_is_suprog}=$specs[$i]->{_is_suprog} \n | ||
| 620 | # \tspecs[$i]->{_has_pipe_out}=$specs[$i]->{_has_pipe_out} \n | ||
| 621 | # \tspecs[$j]->{_has_pipe_in}=$specs[$j]->{_has_pipe_in}\n" | ||
| 622 | # ); | ||
| 623 | } | ||
| 624 | } | ||
| 625 | |||
| 626 | # End CASE 4.1.2 | ||
| 627 | |||
| 628 | # CASE 4.1.3 | ||
| 629 | # For last symbol | ||
| 630 | # print( | ||
| 631 | # " Case 4.1.3 oop_flows,set_specs,\n | ||
| 632 | # \tspecs[$last_idx]->{_is_suprog}=$specs[$last_idx]->{_is_suprog} \n | ||
| 633 | # \tspecs[$last_idx]->{_is_last_of_4or_more}=$specs[$last_idx]->{_is_last_of_4or_more} \n | ||
| 634 | # \tspecs[$last_idx]->{_has_pipe_in}=$specs[$last_idx]->{_has_pipe_in}\n" | ||
| 635 | # ); | ||
| 636 | if ( $specs[$last_idx]->{_is_last_of_4or_more} ) { | ||
| 637 | |||
| 638 | # print(" oop_flows,set_specs,case 4.1.3.1\n"); | ||
| 639 | # e.g., sugain < data_in | suprog > data_out | ||
| 640 | |||
| 641 | # CASE 4.1.3.1 | ||
| 642 | if ( $corrected_prog_names[$last_idx] eq 'data_out' ) { | ||
| 643 | |||
| 644 | $symbols[$second2last_idx] = '$out'; | ||
| 645 | |||
| 646 | # print(" oop_flows,set_specs,case 4.1.3.1\n"); | ||
| 647 | |||
| 648 | # CASE 4.1.3.2 sugain < data_in | suprog | suprog | ||
| 649 | } | ||
| 650 | elsif ($specs[$last_idx]->{_is_suprog} | ||
| 651 | && $specs[$last_idx]->{_has_pipe_in} ) | ||
| 652 | { | ||
| 653 | |||
| 654 | # print(" oop_flows,set_specs,case 4.1.3.2\n"); | ||
| 655 | # print("oop_flows,set_specs,second_last_idx=$second_last_idx\n"); | ||
| 656 | $symbols[$second2last_idx] = '$to'; | ||
| 657 | |||
| 658 | } | ||
| 659 | else { | ||
| 660 | $message = $L_SU_messages->flows(2); | ||
| 661 | $message_w->delete( "1.0", 'end' ); | ||
| 662 | $message_w->insert( 'end', $message ); | ||
| 663 | print( | ||
| 664 | " Warning: 3. unexpected last item (oop_flows,set_specs)\n" | ||
| 665 | ); | ||
| 666 | print( | ||
| 667 | " Warning: 3 Last item is not allowed. Use data_out or program (oop_flows,set_specs)\n" | ||
| 668 | ); | ||
| 669 | } | ||
| 670 | |||
| 671 | } | ||
| 672 | else { | ||
| 673 | $message = $L_SU_messages->flows(2); | ||
| 674 | $message_w->delete( "1.0", 'end' ); | ||
| 675 | $message_w->insert( 'end', $message ); | ||
| 676 | print( | ||
| 677 | " Warning: 4. unexpected last item (oop_flows,set_specs)\n" | ||
| 678 | ); | ||
| 679 | print( | ||
| 680 | " Warning: 4. Last item is not allowed. Use data_out or program (oop_flows,set_specs)\n" | ||
| 681 | ); | ||
| 682 | } | ||
| 683 | |||
| 684 | # End CASE 4.1.3 | ||
| 685 | |||
| 686 | # CASE 4.2 | ||
| 687 | # for 1st and second item of 4 or more | ||
| 688 | # where the first program has internal access to files | ||
| 689 | # e.g., suop2 | suprog | ... suprog .... > data_out or | suximage | ||
| 690 | # for symbols[0] | ||
| 691 | } | ||
| 692 | elsif ($specs[0]->{_is_first_of_4or_more} | ||
| 693 | && $specs[0]->{_has_pipe_out} | ||
| 694 | && $specs[1]->{_has_pipe_in} | ||
| 695 | && $specs[1]->{_is_suprog} ) | ||
| 696 | { | ||
| 697 | $symbols[0] = '$to'; | ||
| 698 | |||
| 699 | # print(" oop_flows,set_specs,case 4.2\n"); | ||
| 700 | # print ("Between programs 1 and 2, symbol=$symbols[0], with index=0\n"); | ||
| 701 | |||
| 702 | # CASE 4.2.1 | ||
| 703 | # For symbol between second and third items | ||
| 704 | # for symbols[1] | ||
| 705 | if ( $specs[1]->{_is_suprog} | ||
| 706 | && $specs[1]->{_has_pipe_out} | ||
| 707 | && $specs[2]->{_has_pipe_in} ) | ||
| 708 | { | ||
| 709 | |||
| 710 | $symbols[1] = '$to'; | ||
| 711 | |||
| 712 | # print(" oop_flows,set_specs,case 4.2.1\n"); | ||
| 713 | # print ("Between programs 2 and 3, symbol=$symbols[1], with index=1\n"); | ||
| 714 | } | ||
| 715 | else { | ||
| 716 | print( | ||
| 717 | " Warning: Problem with item 2 or beyond, item OK (oop_flows,set_specs)\n" | ||
| 718 | ); | ||
| 719 | |||
| 720 | } | ||
| 721 | |||
| 722 | # CASE 4.2.2 | ||
| 723 | # Third item and above of 4 or more | ||
| 724 | # e.g., suop2 | sugain | suprog ... > data_out or | suximage | ||
| 725 | # for third item and up to symbol between the | ||
| 726 | # second- ($j) and third-to-last ($i) of 4 or more items | ||
| 727 | # for symbols [2 and beyond] | ||
| 728 | for ( | ||
| 729 | my $i = 2, my $j = 3 ; | ||
| 730 | $i < ( $num_progs4flow - 2 ) ; | ||
| 731 | $i++, $j++ | ||
| 732 | ) | ||
| 733 | { | ||
| 734 | |||
| 735 | if ( $specs[$i]->{_is_suprog} | ||
| 736 | && $specs[$i]->{_has_pipe_out} | ||
| 737 | && $specs[$j]->{_has_pipe_in} ) | ||
| 738 | { | ||
| 739 | |||
| 740 | $symbols[$i] = '$to'; | ||
| 741 | |||
| 742 | # print(" oop_flows,set_specs,case 4.2.1\n"); | ||
| 743 | # print ("Between programs $j and ($j+1), symbol=$symbols[$i], with index=$i\n"); | ||
| 744 | } | ||
| 745 | else { | ||
| 746 | print( | ||
| 747 | " Case 4.2.2 Warning: Problem with item 3 or beyond, items 1 and 2 OK (oop_flows,set_specs)\n" | ||
| 748 | ); | ||
| 749 | } | ||
| 750 | } | ||
| 751 | |||
| 752 | # CASE 4.2.3 | ||
| 753 | # Last item and its previous symbol ( last symbol) | ||
| 754 | if ( $specs[$last_idx]->{_is_last_of_4or_more} ) { | ||
| 755 | |||
| 756 | # CASE 4.2.3.1 | ||
| 757 | # e.g., sugain | suprog | suprog > data_out | ||
| 758 | # Last item and its previous symbol ( last symbol) | ||
| 759 | if ( $corrected_prog_names[$last_idx] eq 'data_out' ) { | ||
| 760 | |||
| 761 | $symbols[$second2last_idx] = '$out'; | ||
| 762 | |||
| 763 | # print(" oop_flows,set_specs,case 4.2.3.1\n"); | ||
| 764 | |||
| 765 | # CASE 4.2.3.2 sugain | suprog | suprog | suprog | ||
| 766 | # for last symbol | ||
| 767 | } | ||
| 768 | elsif ($specs[$last_idx]->{_is_suprog} | ||
| 769 | && $specs[$last_idx]->{_has_pipe_in} ) | ||
| 770 | { | ||
| 771 | |||
| 772 | # print(" oop_flows,set_specs,case 4.2.3.2\n"); | ||
| 773 | $symbols[$second2last_idx] = '$to'; | ||
| 774 | |||
| 775 | } | ||
| 776 | else { | ||
| 777 | $message = $L_SU_messages->flows(2); | ||
| 778 | $message_w->delete( "1.0", 'end' ); | ||
| 779 | $message_w->insert( 'end', $message ); | ||
| 780 | print( | ||
| 781 | " Warning: 1. unexpected last item (oop_flows,set_specs)\n" | ||
| 782 | ); | ||
| 783 | print( | ||
| 784 | " Warning: 1 Last item is not allowed. Use data_out or program (oop_flows,set_specs)\n" | ||
| 785 | ); | ||
| 786 | } | ||
| 787 | |||
| 788 | } | ||
| 789 | else { | ||
| 790 | |||
| 791 | $message = $L_SU_messages->flows(2); | ||
| 792 | $message_w->delete( "1.0", 'end' ); | ||
| 793 | $message_w->insert( 'end', $message ); | ||
| 794 | print( | ||
| 795 | " Warning: 2. unexpected last item (oop_flows,set_specs)\n" | ||
| 796 | ); | ||
| 797 | print( | ||
| 798 | " Warning: 2 Last item is not allowed. Use data_out or program (oop_flows,set_specs)\n" | ||
| 799 | ); | ||
| 800 | |||
| 801 | } | ||
| 802 | |||
| 803 | # End CASE 4.2.3 | ||
| 804 | |||
| 805 | } | ||
| 806 | else { | ||
| 807 | print(" Warning: unexpected first item (oop_flows,set_specs)\n"); | ||
| 808 | } # CASE 4.2 | ||
| 809 | |||
| 810 | } # CASE 4; 4 or more items or more | ||
| 811 | |||
| 812 | $oop_flows->{_symbols_aref} = \@symbols; | ||
| 813 | |||
| 814 | # print( | ||
| 815 | #" oop_flows,set_specs,symbols are ***@{$oop_flows->{_symbols_aref}}*** \n" | ||
| 816 | # ); | ||
| 817 | return (); | ||
| 818 | } | ||
| 819 | |||
| 820 | 1; |