« lib/App/SeismicUnixGui/misc/oop_prog_params.pm
↑ Summary
lib/App/SeismicUnixGui/big_streams/iShowNselect_picks.pm »
| 1 | package App::SeismicUnixGui::misc::control; | ||
| 2 | |||
| 3 | =head1 DOCUMENTATION | ||
| 4 | |||
| 5 | |||
| 6 | =head2 SYNOPSIS | ||
| 7 | |||
| 8 | PERL PERL PROGRAM NAME: control.pm | ||
| 9 | AUTHOR: Juan Lorenzo | ||
| 10 | DATE: V 0.0.2 Oct 3 2018 | ||
| 11 | |||
| 12 | DESCRIPTION | ||
| 13 | |||
| 14 | |||
| 15 | BASED ON: | ||
| 16 | Version 0.0.1 made in early 2018 | ||
| 17 | V 0.0.3 7.10.21 | ||
| 18 | |||
| 19 | |||
| 20 | =cut | ||
| 21 | |||
| 22 | =head2 USE | ||
| 23 | |||
| 24 | =head3 NOTES | ||
| 25 | |||
| 26 | =head4 Examples | ||
| 27 | |||
| 28 | =head3 | ||
| 29 | |||
| 30 | =head2 CHANGES and their DATES | ||
| 31 | |||
| 32 | Version 0.0.2 | ||
| 33 | allows 'no' as well as the parameter values in the Project configuration files | ||
| 34 | |||
| 35 | Version 0.0.3 | ||
| 36 | handles numeric-based names that should be handled as strings | ||
| 37 | |||
| 38 | 0.0.3.1 can control value and suffix combination if needed | ||
| 39 | |||
| 40 | =cut | ||
| 41 | |||
| 42 | use Moose; | ||
| 43 | our $VERSION = '0.0.3'; | ||
| 44 | |||
| 45 | use Carp; | ||
| 46 | use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants'; | ||
| 47 | use aliased 'App::SeismicUnixGui::misc::L_SU_path'; | ||
| 48 | |||
| 49 | my $L_SU_global_constants = L_SU_global_constants->new(); | ||
| 50 | my $alias_superflow_names_h = $L_SU_global_constants->alias_superflow_names_h(); | ||
| 51 | my $var = $L_SU_global_constants->var(); | ||
| 52 | my $empty_string = $var->{_empty_string}; | ||
| 53 | my $forward_slash = $var->{_forward_slash}; | ||
| 54 | my $L_SU_path = L_SU_path->new(); | ||
| 55 | |||
| 56 | my $no = $var->{_no}; | ||
| 57 | my $yes = $var->{_yes}; | ||
| 58 | |||
| 59 | =head2 private hash control | ||
| 60 | |||
| 61 | |||
| 62 | =cut | ||
| 63 | |||
| 64 | my $control = { | ||
| 65 | _aref => '', | ||
| 66 | _file_name => '', | ||
| 67 | _file_name_sref => '', | ||
| 68 | _first_name => '', | ||
| 69 | _first_name_string => '', | ||
| 70 | _first_name_w_single_quotes => '', | ||
| 71 | _flow_index => '', | ||
| 72 | _infected_string => '', | ||
| 73 | _parameter_index4array => '', | ||
| 74 | _prog_names_aref => '', | ||
| 75 | _stringWcommas => '', | ||
| 76 | _stringWback_slash => '', | ||
| 77 | _suffix4oop => '', | ||
| 78 | _value => '', | ||
| 79 | }; | ||
| 80 | |||
| 81 | |||
| 82 | =head2 sub clear | ||
| 83 | |||
| 84 | Clear all memory | ||
| 85 | |||
| 86 | =cut | ||
| 87 | |||
| 88 | sub clear { | ||
| 89 | my $self = @_; | ||
| 90 | $control->{_aref} = ''; | ||
| 91 | $control->{_file_name} = ''; | ||
| 92 | $control->{_file_name_sref} = ''; | ||
| 93 | $control->{_first_name} = ''; | ||
| 94 | $control->{_first_name_string} = ''; | ||
| 95 | $control->{_first_name_w_single_quotes} = ''; | ||
| 96 | $control->{_flow_index} = ''; | ||
| 97 | $control->{_infected_string} = ''; | ||
| 98 | $control->{_parameter_index4array} = ''; | ||
| 99 | $control->{_prog_names_aref} = ''; | ||
| 100 | $control->{_stringWcommas} = ''; | ||
| 101 | $control->{_stringWback_slash} = ''; | ||
| 102 | $control->{_suffix4oop} = ''; | ||
| 103 | $control->{_value} = ''; | ||
| 104 | |||
| 105 | } | ||
| 106 | |||
| 107 | =head2 sub _get_no_quotes | ||
| 108 | |||
| 109 | remove starting and ending single and double quotes | ||
| 110 | An entering zero exits as a zero | ||
| 111 | |||
| 112 | =cut | ||
| 113 | |||
| 114 | sub _get_no_quotes { | ||
| 115 | |||
| 116 | my ($entry_value) = @_; | ||
| 117 | |||
| 118 | if ( defined $entry_value ) { # =0 case is OK | ||
| 119 | |||
| 120 | if ( $entry_value ne $empty_string ) { | ||
| 121 | |||
| 122 | my $exit_value; | ||
| 123 | |||
| 124 | # print("control,_get_no_quotes, entry_value = $entry_value\n"); | ||
| 125 | |||
| 126 | # 1. remove double quotes if they exist | ||
| 127 | # anywhere in the line | ||
| 128 | $entry_value =~ tr/"//d; | ||
| 129 | |||
| 130 | # 2. remove extra single quotes if they exist at the start of the string | ||
| 131 | $entry_value =~ s/^'//; | ||
| 132 | |||
| 133 | # 3. remove extra single quotes if they exist at the end of the string | ||
| 134 | $entry_value =~ s/'$//; | ||
| 135 | $exit_value = $entry_value; | ||
| 136 | |||
| 137 | # print("control,_get_no_quotes, result: $exit_value\n"); | ||
| 138 | return ($exit_value); | ||
| 139 | |||
| 140 | } | ||
| 141 | else { | ||
| 142 | |||
| 143 | # print("control,_get_no_quotes, equals $empty_string\n"); | ||
| 144 | return ($empty_string); | ||
| 145 | } | ||
| 146 | |||
| 147 | } | ||
| 148 | else { | ||
| 149 | |||
| 150 | # print("control,_get_no_quotes, undefined value\n"); | ||
| 151 | return ($empty_string); | ||
| 152 | } | ||
| 153 | |||
| 154 | } | ||
| 155 | |||
| 156 | =head2 sub _get_string_or_number | ||
| 157 | |||
| 158 | Put quotes on strings | ||
| 159 | Generally, file names are strings but | ||
| 160 | numeric names will be interpreted as numbers, | ||
| 161 | i.e., '1000.txt' will be seen as a number and not a file name | ||
| 162 | |||
| 163 | =cut | ||
| 164 | |||
| 165 | sub _get_string_or_number { | ||
| 166 | |||
| 167 | my ($entry_value) = @_; | ||
| 168 | my $program; | ||
| 169 | |||
| 170 | if ( length $entry_value ) { | ||
| 171 | |||
| 172 | # print( | ||
| 173 | # "1. control, _get_string_or_number, entering value to test = $entry_value\n" | ||
| 174 | # ); | ||
| 175 | |||
| 176 | use Scalar::Util qw(looks_like_number); | ||
| 177 | |||
| 178 | # remove any exisitng quotes | ||
| 179 | my $clean_value = _get_no_quotes($entry_value); | ||
| 180 | |||
| 181 | if ( length( $control->{_prog_names_aref} ) | ||
| 182 | && ( length $control->{_flow_index} ) ) | ||
| 183 | { | ||
| 184 | |||
| 185 | # CASE 1 Flow is previously saved to disk | ||
| 186 | # or to RAM, (e.g., either via "param_flows") | ||
| 187 | # list of program names in flow and currently | ||
| 188 | # active program is used | ||
| 189 | |||
| 190 | # A few programs have specific requirements | ||
| 191 | $program = | ||
| 192 | @{ $control->{_prog_names_aref} }[ ( $control->{_flow_index} ) ]; | ||
| 193 | |||
| 194 | # print("2. control, _get_string_or_number, working with $program\n"); | ||
| 195 | |||
| 196 | if ( | ||
| 197 | length $program | ||
| 198 | and ( $program eq 'data_in' | ||
| 199 | or $program eq 'data_out' ) | ||
| 200 | ) | ||
| 201 | { | ||
| 202 | |||
| 203 | # print("CASE 1A control, _get_string_or_number, working with data_in, or data_out -- special cases\n"); | ||
| 204 | |||
| 205 | # specific requirements for data_in and data_out in first item (index =0) | ||
| 206 | my $index = $control->{_parameter_index4array}; | ||
| 207 | |||
| 208 | if ( length $index ) { | ||
| 209 | |||
| 210 | if ( $index == 0 ) { | ||
| 211 | |||
| 212 | # expected for index=0 in both data_in and data_out | ||
| 213 | # CASE 1A.1 always returns string | ||
| 214 | |||
| 215 | my $exit_value_as_string = '\'' . $clean_value . '\''; | ||
| 216 | |||
| 217 | # print("CASE 1A.1 control, _get_string_or_number, value into a string: $exit_value_as_string\n"); | ||
| 218 | return ($exit_value_as_string); | ||
| 219 | |||
| 220 | } | ||
| 221 | else { # remaining parameters for data_in and data_out | ||
| 222 | # determine whether we have a string or a number | ||
| 223 | my $fmt = 0; | ||
| 224 | $fmt = looks_like_number($clean_value); | ||
| 225 | |||
| 226 | # print("2. control, _get_string_or_number, entry_value = $clean_value\n"); | ||
| 227 | if ($fmt) { | ||
| 228 | |||
| 229 | # keep numbers as they are | ||
| 230 | # print( | ||
| 231 | # "CASE 1A.2, numbers, control, _get_string_or_number,$clean_value looks like a number\n" | ||
| 232 | # ); | ||
| 233 | my $exit_value_as_number = $clean_value; | ||
| 234 | return ($exit_value_as_number); | ||
| 235 | |||
| 236 | } | ||
| 237 | else { | ||
| 238 | # print("CASE 1A.3 control, strings, _get_string_or_number, exit_value looks like string\n"); | ||
| 239 | my $exit_value_as_string = | ||
| 240 | '\'' . $clean_value . '\''; | ||
| 241 | |||
| 242 | # print("control, get_string_or_number, value into a string: $exit_value_as_string\n"); | ||
| 243 | return ($exit_value_as_string); | ||
| 244 | } | ||
| 245 | } | ||
| 246 | } | ||
| 247 | else { | ||
| 248 | print("control, _get_string_or_number, missing index \n"); | ||
| 249 | } | ||
| 250 | |||
| 251 | } # for data_in and data_out | ||
| 252 | elsif ( length $program | ||
| 253 | and $program eq 'segyread' ) | ||
| 254 | { | ||
| 255 | # CASE 1B ALWAYS exists as a string within quotes | ||
| 256 | my $exit_value_as_string = '\'' . $clean_value . '\''; | ||
| 257 | |||
| 258 | # print("CASE 1B control, _get_string_or_number,value = $exit_value_as_string\n"); | ||
| 259 | |||
| 260 | } | ||
| 261 | elsif ( length $program | ||
| 262 | and $program eq 'suop2' ) | ||
| 263 | { | ||
| 264 | # CASE 1C ALWAYS exists as a string within quotes | ||
| 265 | my $exit_value_as_string = '\'' . $clean_value . '\''; | ||
| 266 | |||
| 267 | # print("CASE 1C control, _get_string_or_number,value = $exit_value_as_string\n"); | ||
| 268 | } | ||
| 269 | |||
| 270 | elsif ( ( length $program ) | ||
| 271 | and ( $program ne 'data_in' ) | ||
| 272 | and ( $program ne 'data_out' ) | ||
| 273 | and ( $program ne 'segyread' ) | ||
| 274 | and ( $program ne 'suop2' ) ) | ||
| 275 | { | ||
| 276 | |||
| 277 | # determine whether we have a string or a number | ||
| 278 | # print( | ||
| 279 | #"CASE 1D control,_get_string_or_number, flow is already saved on disk or in RAM, \n | ||
| 280 | # (e.g., in param_flow_color_pkg') -- for most programs\n" | ||
| 281 | # ); | ||
| 282 | |||
| 283 | # first remove any exisitng quotes | ||
| 284 | |||
| 285 | my $clean_value = _get_no_quotes($entry_value); | ||
| 286 | |||
| 287 | my $fmt = 0; | ||
| 288 | $fmt = looks_like_number($clean_value); | ||
| 289 | |||
| 290 | # print("control, _get_string_or_number, CASE 1C entry_value = $entry_value\n"); | ||
| 291 | if ($fmt) { | ||
| 292 | |||
| 293 | # print( | ||
| 294 | #"CASE 1D.1, number, control, _get_string_or_number,$entry_value looks like a number\n" | ||
| 295 | # ); | ||
| 296 | |||
| 297 | my $exit_value_as_number = $clean_value; | ||
| 298 | return ($exit_value_as_number); | ||
| 299 | |||
| 300 | } | ||
| 301 | else { | ||
| 302 | # print( | ||
| 303 | #"control, _get_string_or_number, exit_value does not look like a number \n" | ||
| 304 | # ); | ||
| 305 | my $exit_value_as_string = '\'' . $clean_value . '\''; | ||
| 306 | |||
| 307 | # print( | ||
| 308 | #"CASE 1D.2, string, control, get_string_or_number, value into a string: $exit_value_as_string\n" | ||
| 309 | # ); | ||
| 310 | return ($exit_value_as_string); | ||
| 311 | } | ||
| 312 | |||
| 313 | } | ||
| 314 | else { | ||
| 315 | |||
| 316 | # print("55. control, _get_string_or_number, entry_value = $clean_value\n"); | ||
| 317 | |||
| 318 | # General, CASE 2 when flow is not yet saved | ||
| 319 | # to disk or RAM, (e.g., either via "param_flows") | ||
| 320 | # or disk | ||
| 321 | # print( | ||
| 322 | # "CASE 2 control,_get_string_or_number, flow not yet saved, without need for knowledge of program name or flow index \n" | ||
| 323 | # ); | ||
| 324 | |||
| 325 | # determine whether we have a string or a number | ||
| 326 | my $fmt = 0; | ||
| 327 | $fmt = looks_like_number($clean_value); | ||
| 328 | |||
| 329 | if ($fmt) { | ||
| 330 | |||
| 331 | # print("CASE 2.1 control, _get_string_or_number,$clean_value looks like a number\n"); | ||
| 332 | my $exit_value_as_number = $clean_value; | ||
| 333 | |||
| 334 | # print("561. control, _get_string_or_number, entry_value = $clean_value\n"); | ||
| 335 | return ($exit_value_as_number); | ||
| 336 | |||
| 337 | } | ||
| 338 | else { | ||
| 339 | |||
| 340 | # print("control, _get_string_or_number, exit_value like a string\n"); | ||
| 341 | my $exit_value_as_string = '\'' . $clean_value . '\''; | ||
| 342 | |||
| 343 | # print("CASE 2.2, control, get_string_or_number, value into a string: $exit_value_as_string\n"); | ||
| 344 | return ($exit_value_as_string); | ||
| 345 | } | ||
| 346 | } # end CASES 2 | ||
| 347 | |||
| 348 | } | ||
| 349 | elsif (not( length( $control->{_prog_names_aref} ) ) | ||
| 350 | or not( ( length $control->{_flow_index} ) ) ) | ||
| 351 | { | ||
| 352 | |||
| 353 | print( | ||
| 354 | "control, _get_string_or_number, no program name list or selected flow index\n" | ||
| 355 | ); | ||
| 356 | return ($empty_string); | ||
| 357 | |||
| 358 | } | ||
| 359 | else { | ||
| 360 | |||
| 361 | # print("control,_get_string_or_number, missing program names and/or flow index\n"); | ||
| 362 | |||
| 363 | #print("57. control, _get_string_or_number, entry_value = $clean_value\n"); | ||
| 364 | # print( | ||
| 365 | # "control, _get_string_or_number, control->{_prog_names_aref}=$control->{_prog_names_aref}, | ||
| 366 | # control->{_flow_index}=$control->{_flow_index}\n" | ||
| 367 | # ); | ||
| 368 | print("control, _get_string_or_number, unexpected result\n"); | ||
| 369 | return ($empty_string); | ||
| 370 | } # end test for program name and/or flow index | ||
| 371 | |||
| 372 | } | ||
| 373 | else { | ||
| 374 | |||
| 375 | # print("59. control,_get_string_or_number, missing entry_value=$clean_value, NADA\n"); | ||
| 376 | return ($empty_string); | ||
| 377 | } | ||
| 378 | |||
| 379 | } # end sub | ||
| 380 | |||
| 381 | =head2 sub _get_string_or_number4aref | ||
| 382 | |||
| 383 | Put quotes on strings | ||
| 384 | |||
| 385 | =cut | ||
| 386 | |||
| 387 | sub _get_string_or_number4aref { | ||
| 388 | |||
| 389 | my ($array_ref) = @_; | ||
| 390 | |||
| 391 | if ($array_ref) { | ||
| 392 | |||
| 393 | my $exit_array_ref; | ||
| 394 | my @array = @{$array_ref}; | ||
| 395 | my $length = scalar @array; | ||
| 396 | |||
| 397 | for ( my $i = 0 ; $i < $length ; $i++ ) { | ||
| 398 | |||
| 399 | _set_parameter_index4array($i); | ||
| 400 | |||
| 401 | $array[$i] = _get_string_or_number( $array[$i] ); | ||
| 402 | |||
| 403 | } | ||
| 404 | |||
| 405 | $exit_array_ref = \@array; | ||
| 406 | |||
| 407 | # print("control, _get_string_or_number4aref, result=@array\n"); | ||
| 408 | return ($exit_array_ref); | ||
| 409 | |||
| 410 | } | ||
| 411 | else { | ||
| 412 | # print("control, _get_string_or_number4aref, bad array reference\n"); | ||
| 413 | return (); | ||
| 414 | } | ||
| 415 | } | ||
| 416 | |||
| 417 | =head2 sub reset_suffix4loop | ||
| 418 | |||
| 419 | blank out suffix4loop | ||
| 420 | |||
| 421 | =cut | ||
| 422 | |||
| 423 | sub reset_suffix4loop { | ||
| 424 | |||
| 425 | my ($self) = @_; | ||
| 426 | |||
| 427 | if ( length $control->{_suffix4loop} ) { | ||
| 428 | |||
| 429 | $control->{_suffix4loop} = $empty_string; | ||
| 430 | |||
| 431 | print( | ||
| 432 | "control, _reset_suffix4loop, control->{_suffix4loop}= $control->{_suffix4loop}\n" | ||
| 433 | ); | ||
| 434 | |||
| 435 | } | ||
| 436 | else { | ||
| 437 | print( | ||
| 438 | "control, _reset_suffix4loop, control->{_suffix4loop}=$control->{_suffix4loop}\n" | ||
| 439 | ); | ||
| 440 | } | ||
| 441 | |||
| 442 | return (); | ||
| 443 | } | ||
| 444 | |||
| 445 | =head2 sub _set_parameter_index4array | ||
| 446 | Keep track of item index | ||
| 447 | for a program | ||
| 448 | |||
| 449 | =cut | ||
| 450 | |||
| 451 | sub _set_parameter_index4array { | ||
| 452 | my ($index) = @_; | ||
| 453 | |||
| 454 | if ( length $index ) { | ||
| 455 | |||
| 456 | $control->{_parameter_index4array} = $index; | ||
| 457 | |||
| 458 | } | ||
| 459 | else { | ||
| 460 | print("control, _set_parameter_index4array, missing index value\n"); | ||
| 461 | } | ||
| 462 | return ($empty_string); | ||
| 463 | } | ||
| 464 | |||
| 465 | =head2 sub commas | ||
| 466 | |||
| 467 | Replace commas in strings | ||
| 468 | needed by Seismic Unix | ||
| 469 | |||
| 470 | =cut | ||
| 471 | |||
| 472 | sub commas { | ||
| 473 | my ( $self, $sref_entry_value ) = @_; | ||
| 474 | my $freq_string; | ||
| 475 | |||
| 476 | # print("-1.control,freq,old ref value is $sref_entry_value-\n"); | ||
| 477 | # print("0.control,freq, old value is $$sref_entry_value-\n"); | ||
| 478 | if ( ref($$sref_entry_value) eq "ARRAY" ) { | ||
| 479 | $freq_string = join( ",", @{$$sref_entry_value} ); | ||
| 480 | $freq_string = '\'' . $freq_string . '\''; | ||
| 481 | |||
| 482 | # print("1.control,freq,value is $freq_string-\n"); | ||
| 483 | } | ||
| 484 | if ( ref($sref_entry_value) eq "SCALAR" ) { | ||
| 485 | $freq_string = $$sref_entry_value; | ||
| 486 | |||
| 487 | # print("4.control,freq,value is $$sref_entry_value-\n"); | ||
| 488 | } | ||
| 489 | return ($freq_string); | ||
| 490 | } | ||
| 491 | |||
| 492 | =head2 sub commify | ||
| 493 | place commas between list elements | ||
| 494 | |||
| 495 | =cut | ||
| 496 | |||
| 497 | sub commify { | ||
| 498 | my ( $self, $array_ref ) = @_; | ||
| 499 | |||
| 500 | if ( $array_ref ne $empty_string ) { | ||
| 501 | |||
| 502 | my @array = @$array_ref; | ||
| 503 | |||
| 504 | my $aa = join ',', @array; | ||
| 505 | |||
| 506 | # print $aa."\n"; | ||
| 507 | return ($aa); | ||
| 508 | |||
| 509 | } | ||
| 510 | else { | ||
| 511 | print("control, commify, unexpected array reference\n"); | ||
| 512 | return (); | ||
| 513 | } | ||
| 514 | |||
| 515 | } | ||
| 516 | |||
| 517 | =head2 sub empty_string | ||
| 518 | test for interpreted arrays that should be | ||
| 519 | |||
| 520 | if defined(empty scalar) is found, nothing is done | ||
| 521 | |||
| 522 | $sref_entry_value should be scalar reference | ||
| 523 | i/p scalar reference | ||
| 524 | |||
| 525 | DB | ||
| 526 | $$sref_entry_value = 'nu'; | ||
| 527 | |||
| 528 | package control replaces commas in strings | ||
| 529 | needed by Seismic Unix | ||
| 530 | |||
| 531 | =cut | ||
| 532 | |||
| 533 | sub empty_string { | ||
| 534 | my ( $self, $sref_entry_value ) = @_; | ||
| 535 | my $null_scalar; # has nothing | ||
| 536 | print("1.control,empty_string,entry value =----$$sref_entry_value----\n"); | ||
| 537 | |||
| 538 | if ( ref($$sref_entry_value) eq "ARRAY" ) { | ||
| 539 | $$sref_entry_value = ''; | ||
| 540 | print("1.control,empty_string,new value is $$sref_entry_value-\n"); | ||
| 541 | |||
| 542 | } | ||
| 543 | elsif ( $$sref_entry_value eq 'nu' ) { | ||
| 544 | |||
| 545 | $$sref_entry_value = $null_scalar; | ||
| 546 | print( | ||
| 547 | "4.control,empty_string,='nu',new value =----$$sref_entry_value----\n" | ||
| 548 | ); | ||
| 549 | |||
| 550 | } | ||
| 551 | elsif ( !defined($$sref_entry_value) ) { | ||
| 552 | |||
| 553 | $$sref_entry_value = $null_scalar; | ||
| 554 | print( | ||
| 555 | "5.control,empty_string,undefined,new value =----$$sref_entry_value----\n" | ||
| 556 | ); | ||
| 557 | } | ||
| 558 | return ($$sref_entry_value); | ||
| 559 | |||
| 560 | } | ||
| 561 | |||
| 562 | =head2 sub empty_directory | ||
| 563 | |||
| 564 | =cut | ||
| 565 | |||
| 566 | sub empty_directory { | ||
| 567 | my ( $self, $sref_entry_value ) = @_; | ||
| 568 | |||
| 569 | my $null_scalar = '/'; # contains nothing | ||
| 570 | |||
| 571 | if ($sref_entry_value) { | ||
| 572 | |||
| 573 | if ( ref($$sref_entry_value) eq "ARRAY" ) | ||
| 574 | { # should not agree because we have a scalar reference instead | ||
| 575 | $$sref_entry_value = ''; | ||
| 576 | |||
| 577 | # print("1.control,array with empty_string,new value is $$sref_entry_value-\n"); | ||
| 578 | |||
| 579 | } | ||
| 580 | elsif ( ref($$sref_entry_value) eq "SCALAR" ) { # is a scalar | ||
| 581 | |||
| 582 | if ( $$sref_entry_value eq '' ) { | ||
| 583 | $$sref_entry_value = $null_scalar; | ||
| 584 | |||
| 585 | # print("1.control,scalar with empty_string,new value is now $$sref_entry_value-\n"); | ||
| 586 | } | ||
| 587 | else { | ||
| 588 | |||
| 589 | # leave the value unchanged; | ||
| 590 | } | ||
| 591 | |||
| 592 | } | ||
| 593 | else { | ||
| 594 | |||
| 595 | #print("4.control,empty_directory, neither array or scalar... ??? \n"); | ||
| 596 | } | ||
| 597 | |||
| 598 | } | ||
| 599 | else { | ||
| 600 | |||
| 601 | print( | ||
| 602 | "control,empty_directory,missing scalar reference to entry value \n" | ||
| 603 | ); | ||
| 604 | |||
| 605 | } | ||
| 606 | return ($$sref_entry_value); | ||
| 607 | } | ||
| 608 | |||
| 609 | =head2 sub get_back_slashBgone | ||
| 610 | |||
| 611 | Remove backslash in string | ||
| 612 | needed by Seismic Unix | ||
| 613 | |||
| 614 | =cut | ||
| 615 | |||
| 616 | sub get_back_slashBgone { | ||
| 617 | my ($self) = @_; | ||
| 618 | |||
| 619 | if ( $control->{_stringWback_slash} ne $empty_string ) { | ||
| 620 | |||
| 621 | my $stringWback_slash; | ||
| 622 | |||
| 623 | # print("control,get_back_slashBgone, control->{_stringWback_slash}: $control->{_stringWback_slash}\n"); | ||
| 624 | $stringWback_slash = $control->{_stringWback_slash}; | ||
| 625 | $stringWback_slash =~ s/\\//g; | ||
| 626 | |||
| 627 | # print("control,get_back_slashBgone, stringWback_slash}: $stringWback_slash\n"); | ||
| 628 | return ($stringWback_slash); | ||
| 629 | |||
| 630 | } | ||
| 631 | else { | ||
| 632 | print( | ||
| 633 | "control,get_back_slashBgone, error: need to set stringWbackslash first\n" | ||
| 634 | ); | ||
| 635 | } | ||
| 636 | |||
| 637 | } | ||
| 638 | |||
| 639 | =head2 sub get_base_file_name_aref | ||
| 640 | |||
| 641 | |||
| 642 | =cut | ||
| 643 | |||
| 644 | sub get_base_file_name_aref { | ||
| 645 | my ($self) = @_; | ||
| 646 | |||
| 647 | if ( length $control->{_base_file_name_aref} ) { | ||
| 648 | |||
| 649 | my $result = $control->{_base_file_name_aref}; | ||
| 650 | |||
| 651 | # print("control,get_base_file_name_aref,$control->{_base_file_name_aref}\n"); | ||
| 652 | return ($result); | ||
| 653 | |||
| 654 | } | ||
| 655 | else { | ||
| 656 | print("control,get_base_file_name, error: missing array reference\n"); | ||
| 657 | return (); | ||
| 658 | } | ||
| 659 | |||
| 660 | } | ||
| 661 | |||
| 662 | =head2 sub get_commas2space | ||
| 663 | |||
| 664 | Replace commas in strings | ||
| 665 | needed by Seismic Unix | ||
| 666 | |||
| 667 | =cut | ||
| 668 | |||
| 669 | sub get_commas2space { | ||
| 670 | my ($self) = @_; | ||
| 671 | |||
| 672 | if ( $control->{_stringWcommas} ne $empty_string ) { | ||
| 673 | |||
| 674 | my $stringWcommas; | ||
| 675 | |||
| 676 | # print("control,get_commas2space, control->{_stringWcommas}: $control->{_stringWcommas}\n"); | ||
| 677 | $stringWcommas = $control->{_stringWcommas}; | ||
| 678 | $stringWcommas =~ s/\,/\ /g; | ||
| 679 | |||
| 680 | # print("control,get_commas2space, stringWcommas}: $stringWcommas\n"); | ||
| 681 | return ($stringWcommas); | ||
| 682 | |||
| 683 | } | ||
| 684 | else { | ||
| 685 | print( | ||
| 686 | "control,get_stringWcommas, error: need to set stringWcommas first\n" | ||
| 687 | ); | ||
| 688 | } | ||
| 689 | |||
| 690 | } | ||
| 691 | |||
| 692 | =head2 get_first_name | ||
| 693 | |||
| 694 | must run set_first_name first | ||
| 695 | |||
| 696 | =cut | ||
| 697 | |||
| 698 | sub get_first_name { | ||
| 699 | my ($self) = @_; | ||
| 700 | my $first_name; | ||
| 701 | $first_name = $control->{_first_name}; | ||
| 702 | return ($first_name); | ||
| 703 | } | ||
| 704 | |||
| 705 | =head2 get_max_index | ||
| 706 | |||
| 707 | get (maximum number of parameters -1) | ||
| 708 | instantiate specific spec files on the fly | ||
| 709 | obtain max index from the corresponding spec file | ||
| 710 | |||
| 711 | make sure to use the proper alias in order to locate | ||
| 712 | the spec file | ||
| 713 | |||
| 714 | =cut | ||
| 715 | |||
| 716 | sub get_max_index { | ||
| 717 | my ( $self, $program_name ) = @_; | ||
| 718 | |||
| 719 | my $max_index; | ||
| 720 | |||
| 721 | my $alias_program_name = $alias_superflow_names_h->{$program_name}; | ||
| 722 | |||
| 723 | if ( length($alias_program_name) ) { | ||
| 724 | |||
| 725 | # print(" control, get_max_index,alias_superflow_names_h:\n"); | ||
| 726 | # print("alias for $program_name is $alias_superflow_names_h->{$program_name}\n"); | ||
| 727 | $program_name = $alias_program_name; # only for superflows | ||
| 728 | |||
| 729 | } | ||
| 730 | else { | ||
| 731 | |||
| 732 | # do nothing for simple sunix-type programs | ||
| 733 | } | ||
| 734 | |||
| 735 | if ( length $program_name ) { | ||
| 736 | |||
| 737 | $L_SU_path->set_program_name($program_name); | ||
| 738 | my $pathNmodule_spec_w_slash_pm = | ||
| 739 | $L_SU_path->get_pathNmodule_spec_w_slash_pm(); | ||
| 740 | my $pathNmodule_spec_w_colon = | ||
| 741 | $L_SU_path->get_pathNmodule_spec_w_colon(); | ||
| 742 | |||
| 743 | require $pathNmodule_spec_w_slash_pm; | ||
| 744 | |||
| 745 | # INSTANTIATE | ||
| 746 | my $package = $pathNmodule_spec_w_colon->new(); | ||
| 747 | |||
| 748 | my $specs = $package->variables(); | ||
| 749 | |||
| 750 | # print("control,get_max_index,first_of_2,$specs->{_is_first_of_2}\n"); | ||
| 751 | |||
| 752 | $max_index = $specs->{_max_index}; | ||
| 753 | |||
| 754 | # print (" control,get_max_index, max index = $max_index\n"); | ||
| 755 | } | ||
| 756 | return ($max_index); | ||
| 757 | } | ||
| 758 | |||
| 759 | =head2 sub get_no_leading_zeros | ||
| 760 | |||
| 761 | remove starting and ending single and double quotes | ||
| 762 | |||
| 763 | =cut | ||
| 764 | |||
| 765 | sub get_no_leading_zeros { | ||
| 766 | |||
| 767 | my ($self) = @_; | ||
| 768 | |||
| 769 | my $result; | ||
| 770 | |||
| 771 | if ( length $control->{_infected_string} ) { | ||
| 772 | |||
| 773 | my $file_name_out = $control->{_infected_string}; | ||
| 774 | $file_name_out =~ s/^0+(?=[0-9])//; | ||
| 775 | $result = $file_name_out; | ||
| 776 | print("control, get_no_leading_zeros,file_name_out=$result\n"); | ||
| 777 | |||
| 778 | } | ||
| 779 | else { | ||
| 780 | print("control,get_no_leading_zeros, undefined entry_value NADA\n"); | ||
| 781 | } | ||
| 782 | |||
| 783 | return ($result); | ||
| 784 | } | ||
| 785 | |||
| 786 | =head2 sub get_no_quotes | ||
| 787 | |||
| 788 | remove starting and ending single and double quotes | ||
| 789 | |||
| 790 | =cut | ||
| 791 | |||
| 792 | sub get_no_quotes { | ||
| 793 | |||
| 794 | my ( $self, $entry_value ) = @_; | ||
| 795 | |||
| 796 | if ( defined $entry_value ) { # =0 case is OK | ||
| 797 | |||
| 798 | if ( length $entry_value ) { # must not be of zero length | ||
| 799 | |||
| 800 | my $exit_value; | ||
| 801 | |||
| 802 | # print("control,no_quotes, entry_value = $entry_value\n"); | ||
| 803 | |||
| 804 | # 1. remove double quotes if they exist | ||
| 805 | # anywhere in the line | ||
| 806 | $entry_value =~ tr/"//d; | ||
| 807 | |||
| 808 | # 2. remove extra single quotes if they exist at the start of the string | ||
| 809 | $entry_value =~ s/^'//g; | ||
| 810 | |||
| 811 | # 3. remove extra single quotes if they exist at the end of the string | ||
| 812 | $entry_value =~ s/'$//g; | ||
| 813 | |||
| 814 | # print("after removing only a last single quote: $x\n "); | ||
| 815 | |||
| 816 | $exit_value = $entry_value; | ||
| 817 | |||
| 818 | return ($exit_value); | ||
| 819 | |||
| 820 | } | ||
| 821 | else { | ||
| 822 | |||
| 823 | # print("control,get_no_quotes, missing entry_value or empty\n"); | ||
| 824 | return ($empty_string); | ||
| 825 | } | ||
| 826 | |||
| 827 | } | ||
| 828 | else { | ||
| 829 | |||
| 830 | # print("control,get_no_quotes, undefined entry_value NADA\n"); | ||
| 831 | return (); | ||
| 832 | } | ||
| 833 | } | ||
| 834 | |||
| 835 | =head2 sub get_no_quotes4array | ||
| 836 | |||
| 837 | remove starting and ending single and double quotes | ||
| 838 | |||
| 839 | =cut | ||
| 840 | |||
| 841 | sub get_no_quotes4array { | ||
| 842 | |||
| 843 | my ( $self, $array_ref ) = @_; | ||
| 844 | |||
| 845 | if ($array_ref) { | ||
| 846 | |||
| 847 | my $exit_array_ref; | ||
| 848 | |||
| 849 | my @array = @{$array_ref}; | ||
| 850 | my $length = scalar @array; | ||
| 851 | |||
| 852 | for ( my $i = 0 ; $i < $length ; $i++ ) { | ||
| 853 | |||
| 854 | # print("control, get_no_quotes4array,entry value is $array[$i] \n"); | ||
| 855 | $array[$i] = _get_no_quotes( $array[$i] ); | ||
| 856 | |||
| 857 | # print("control, get_no_quotes4array,exit value is $array[$i] \n"); | ||
| 858 | } | ||
| 859 | |||
| 860 | $exit_array_ref = \@array; | ||
| 861 | |||
| 862 | return ($exit_array_ref); | ||
| 863 | |||
| 864 | } | ||
| 865 | else { | ||
| 866 | print("control, get_no_quotes4array, bad array reference\n"); | ||
| 867 | return (); | ||
| 868 | } | ||
| 869 | } | ||
| 870 | |||
| 871 | =head2 sub get_path_wo_last_slash | ||
| 872 | |||
| 873 | first check to see if a final slash | ||
| 874 | exists | ||
| 875 | |||
| 876 | =cut | ||
| 877 | |||
| 878 | sub get_path_wo_last_slash { | ||
| 879 | my ($self) = @_; | ||
| 880 | |||
| 881 | if ( length $control->{_path} ) { | ||
| 882 | |||
| 883 | my $path = $control->{_path}; | ||
| 884 | |||
| 885 | my $last_character = substr( $path, -1 ); | ||
| 886 | # print ("old path=$path\n\n"); | ||
| 887 | |||
| 888 | if ( $last_character eq $forward_slash ) { | ||
| 889 | |||
| 890 | $path =~ s/\/$//; | ||
| 891 | # print ("path new $path\n\n"); | ||
| 892 | } | ||
| 893 | else { | ||
| 894 | # print ("path unchanged $path\n\n"); | ||
| 895 | } | ||
| 896 | |||
| 897 | my $result = $path; | ||
| 898 | |||
| 899 | # print("control,get_path_wo_last_slash, : $result\n"); | ||
| 900 | return ($result); | ||
| 901 | |||
| 902 | } | ||
| 903 | else { | ||
| 904 | print("control, get_path_wo_last_slash, missing argument \n"); | ||
| 905 | } | ||
| 906 | return (); | ||
| 907 | } | ||
| 908 | |||
| 909 | =head2 sub get_string_or_number | ||
| 910 | |||
| 911 | Put quotes on strings | ||
| 912 | |||
| 913 | =cut | ||
| 914 | |||
| 915 | sub get_string_or_number { | ||
| 916 | |||
| 917 | my ( $self, $entry_value ) = @_; | ||
| 918 | |||
| 919 | if ( defined($entry_value) ) { | ||
| 920 | |||
| 921 | if ( $entry_value ne $empty_string ) { | ||
| 922 | use Scalar::Util qw(looks_like_number); | ||
| 923 | |||
| 924 | # print ("control, get_string_or_number, entry_value: $entry_value\n"); | ||
| 925 | # determine whether we have a string or a number | ||
| 926 | my $fmt = 0; | ||
| 927 | $fmt = looks_like_number($entry_value); | ||
| 928 | |||
| 929 | if ($fmt) { | ||
| 930 | |||
| 931 | # print("control, get_string_or_number,$entry_value looks like a number \n"); | ||
| 932 | # do nothing | ||
| 933 | my $exit_value_as_number = $entry_value; | ||
| 934 | return ($exit_value_as_number); | ||
| 935 | |||
| 936 | } | ||
| 937 | else { | ||
| 938 | |||
| 939 | # print("control, get_string_or_number, exit_value does not look like a number \n"); | ||
| 940 | my $exit_value_as_string = '\'' . $entry_value . '\''; | ||
| 941 | |||
| 942 | # print("control, get_string_or_number, value into a string: $exit_value_as_string\n"); | ||
| 943 | return ($exit_value_as_string); | ||
| 944 | } | ||
| 945 | } | ||
| 946 | else { | ||
| 947 | |||
| 948 | # print("control,get_string_or_number, missing entry_value or empty\n"); | ||
| 949 | return ($empty_string); | ||
| 950 | } | ||
| 951 | |||
| 952 | } | ||
| 953 | else { # empty string becomes: '' | ||
| 954 | # print("control,get_string_or_number, undefined entry value NADA \n"); | ||
| 955 | my $exit_value_as_empty_string = '\'' . '\''; | ||
| 956 | |||
| 957 | # print ("control, get_string_or_number, value into a string: $exit_value_as_empty_string\n"); | ||
| 958 | return ($exit_value_as_empty_string); | ||
| 959 | } | ||
| 960 | } | ||
| 961 | |||
| 962 | =head2 sub get_string_or_number_aref2 | ||
| 963 | Put quotes on strings | ||
| 964 | |||
| 965 | =cut | ||
| 966 | |||
| 967 | sub get_string_or_number_aref2 { | ||
| 968 | |||
| 969 | my ( $self, $array_aref2 ) = @_; | ||
| 970 | |||
| 971 | # print("control,get_string_or_number_aref2, self=$self\n"); | ||
| 972 | |||
| 973 | if ( length $array_aref2 ) { | ||
| 974 | |||
| 975 | my @array_of_arrays = @{$array_aref2}; | ||
| 976 | my $num_progs4flow = scalar @array_of_arrays; | ||
| 977 | |||
| 978 | # print("\ncontrol, get_string_or_number_aref2, num_progs4flow=$num_progs4flow\n"); | ||
| 979 | |||
| 980 | for ( my $prog_idx = 0 ; $prog_idx < $num_progs4flow ; $prog_idx++ ) { | ||
| 981 | |||
| 982 | my @array = @{ $array_of_arrays[$prog_idx] }; | ||
| 983 | |||
| 984 | # print("1. control, get_string_or_number_aref2, array = @array\n"); | ||
| 985 | |||
| 986 | @array = @{ _get_string_or_number4aref( \@array ) }; | ||
| 987 | |||
| 988 | # print("control, get_string_or_number_aref2, out= @array\n"); | ||
| 989 | $array_of_arrays[$prog_idx] = \@array; | ||
| 990 | |||
| 991 | # print("2. control, get_string_or_number_aref2, array = @array\n"); | ||
| 992 | |||
| 993 | } | ||
| 994 | |||
| 995 | my $result_array_ref2 = \@array_of_arrays; | ||
| 996 | return ($result_array_ref2); | ||
| 997 | |||
| 998 | } | ||
| 999 | else { | ||
| 1000 | print("control, get_string_or_number_aref2, bad or missing array\n"); | ||
| 1001 | return (); | ||
| 1002 | } | ||
| 1003 | |||
| 1004 | } #end sub | ||
| 1005 | |||
| 1006 | =head2 sub get_string_or_number4aref | ||
| 1007 | |||
| 1008 | Put quotes on strings | ||
| 1009 | |||
| 1010 | =cut | ||
| 1011 | |||
| 1012 | sub get_string_or_number4aref { | ||
| 1013 | |||
| 1014 | my ( $self, $array_ref ) = @_; | ||
| 1015 | |||
| 1016 | if ($array_ref) { | ||
| 1017 | |||
| 1018 | my $exit_array_ref; | ||
| 1019 | my @array = @{$array_ref}; | ||
| 1020 | my $length = scalar @array; | ||
| 1021 | |||
| 1022 | for ( my $i = 0 ; $i < $length ; $i++ ) { | ||
| 1023 | |||
| 1024 | _set_parameter_index4array($i); | ||
| 1025 | |||
| 1026 | # print("\n1. control, get_string_or_number4aref, entering _get_string_or_number=$array[$i], idx=$i\n"); | ||
| 1027 | $array[$i] = _get_string_or_number( $array[$i] ); | ||
| 1028 | |||
| 1029 | # print("1. control, get_string_or_number4aref, leaving _get_string_or_number: $array[$i], idx=$i\n"); | ||
| 1030 | } | ||
| 1031 | |||
| 1032 | # print("2. control, get_string_or_number4aref, array=@array\n"); | ||
| 1033 | $exit_array_ref = \@array; | ||
| 1034 | return ($exit_array_ref); | ||
| 1035 | |||
| 1036 | } | ||
| 1037 | else { | ||
| 1038 | print("control, get_string_or_number4aref, bad array reference\n"); | ||
| 1039 | return (); | ||
| 1040 | } | ||
| 1041 | } | ||
| 1042 | |||
| 1043 | =head2 get_suffix | ||
| 1044 | |||
| 1045 | =cut | ||
| 1046 | |||
| 1047 | sub get_suffix { | ||
| 1048 | |||
| 1049 | my ($self) = @_; | ||
| 1050 | my $suffix; | ||
| 1051 | $suffix = $control->{_suffix}; | ||
| 1052 | return ($suffix); | ||
| 1053 | } | ||
| 1054 | |||
| 1055 | =head2 sub get_new_file_name | ||
| 1056 | |||
| 1057 | |||
| 1058 | =cut | ||
| 1059 | |||
| 1060 | sub get_new_file_name { | ||
| 1061 | my ($self) = @_; | ||
| 1062 | my ( $file_name, $suffix, $first_name ); | ||
| 1063 | |||
| 1064 | $first_name = $control->{_first_name}; | ||
| 1065 | |||
| 1066 | if ( $control->{_suffix} eq 'su' ) { | ||
| 1067 | $file_name = $first_name; | ||
| 1068 | } | ||
| 1069 | |||
| 1070 | if ( $control->{_suffix} eq 'config' ) { | ||
| 1071 | $file_name = $first_name; | ||
| 1072 | } | ||
| 1073 | |||
| 1074 | return ($file_name); | ||
| 1075 | } | ||
| 1076 | |||
| 1077 | =head sub get_ticksBgone | ||
| 1078 | |||
| 1079 | remove ALL ticks from a name | ||
| 1080 | |||
| 1081 | =cut | ||
| 1082 | |||
| 1083 | sub get_ticksBgone { | ||
| 1084 | my ($self) = @_; | ||
| 1085 | my $working_string; | ||
| 1086 | if ( $control->{_infected_string} ) { | ||
| 1087 | |||
| 1088 | # print("control,get_ticksBgone, infected_string $control->{_infected_string}\n"); | ||
| 1089 | $working_string = $control->{_infected_string}; | ||
| 1090 | $working_string =~ s/\'//g; | ||
| 1091 | |||
| 1092 | # print("control,get_ticksBgone, disinfected string: $working_string\n"); | ||
| 1093 | return ($working_string); | ||
| 1094 | |||
| 1095 | } | ||
| 1096 | else { | ||
| 1097 | print( | ||
| 1098 | "control,get_ticksBgone, error: need to set the infected string first\n" | ||
| 1099 | ); | ||
| 1100 | } | ||
| 1101 | } | ||
| 1102 | |||
| 1103 | =head2 sub get_value4oop | ||
| 1104 | |||
| 1105 | add quotes to string | ||
| 1106 | |||
| 1107 | =cut | ||
| 1108 | |||
| 1109 | sub get_value4oop { | ||
| 1110 | my ($self) = @_; | ||
| 1111 | |||
| 1112 | my $result; | ||
| 1113 | |||
| 1114 | if ( length $control->{_suffix4oop} ) { | ||
| 1115 | |||
| 1116 | # print("control,get_value4loop,suffix4loop=$control->{_suffix4oop}\n"); | ||
| 1117 | |||
| 1118 | if ( length $control->{_value} ) { | ||
| 1119 | |||
| 1120 | my $value = $control->{_value}; | ||
| 1121 | |||
| 1122 | $value = '\'' . $value . '\''; | ||
| 1123 | |||
| 1124 | $result = $value; | ||
| 1125 | |||
| 1126 | } | ||
| 1127 | else { | ||
| 1128 | print("control, get_value_4oop, unexpected missing variable\n"); | ||
| 1129 | } | ||
| 1130 | |||
| 1131 | } | ||
| 1132 | elsif ( length $control->{_value} ) { | ||
| 1133 | |||
| 1134 | # print( | ||
| 1135 | #"control, get_value_4oop, suffix is missing but value exists- OK NADA\n" | ||
| 1136 | # ); | ||
| 1137 | |||
| 1138 | } | ||
| 1139 | else { | ||
| 1140 | print("control, get_value_4oop, missing value and suffix \n"); | ||
| 1141 | } | ||
| 1142 | |||
| 1143 | # print("control,get_value_4oop,: $result\n"); | ||
| 1144 | |||
| 1145 | return ($result); | ||
| 1146 | } | ||
| 1147 | |||
| 1148 | =head2 sub w_quotes | ||
| 1149 | |||
| 1150 | add single quotes | ||
| 1151 | |||
| 1152 | =cut | ||
| 1153 | |||
| 1154 | sub get_w_single_quotes { | ||
| 1155 | my ($self) = @_; | ||
| 1156 | |||
| 1157 | my $first_name_string = $control->{_first_name_string}; | ||
| 1158 | |||
| 1159 | # print("-1.control,w_single_quotes, value is: $first_name_string\n"); | ||
| 1160 | |||
| 1161 | if ($first_name_string) { | ||
| 1162 | |||
| 1163 | my $first_name_w_single_quotes; | ||
| 1164 | |||
| 1165 | #for complex names, in addition to plain letters | ||
| 1166 | $first_name_w_single_quotes = ("'$first_name_string'"); | ||
| 1167 | return ($first_name_w_single_quotes); | ||
| 1168 | |||
| 1169 | } | ||
| 1170 | else { | ||
| 1171 | print("4.control,w_single_quotes, missing first_name-string\n"); | ||
| 1172 | return (); | ||
| 1173 | } | ||
| 1174 | } | ||
| 1175 | |||
| 1176 | =head2 ors | ||
| 1177 | |||
| 1178 | remove logical ors and use only the label | ||
| 1179 | in front of the 'or' to write out to | ||
| 1180 | the perl script | ||
| 1181 | |||
| 1182 | =cut | ||
| 1183 | |||
| 1184 | sub ors { | ||
| 1185 | my ( $self, $label ) = @_; | ||
| 1186 | my @label; | ||
| 1187 | $label[0] = $label; | ||
| 1188 | |||
| 1189 | # susbtitute spaces with empties | ||
| 1190 | # print("1. control, $label\n"); | ||
| 1191 | $label =~ s/^\s+|\s+$//g; | ||
| 1192 | |||
| 1193 | # print("2. control,--$label--\n"); | ||
| 1194 | |||
| 1195 | # find if there are logical ors | ||
| 1196 | if ( $label =~ m/\|/ ) { | ||
| 1197 | |||
| 1198 | # print("3. control, $label\n"); | ||
| 1199 | |||
| 1200 | # split label by logical ors | ||
| 1201 | # only produce the first item | ||
| 1202 | @label = split( /\|/, $label ); | ||
| 1203 | |||
| 1204 | # print("4. control, $label[0]\n"); | ||
| 1205 | } | ||
| 1206 | |||
| 1207 | # print("5. control,ors,label=$label[0]\n"); | ||
| 1208 | $label = $label[0]; | ||
| 1209 | return ($label); | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | =head2 sub remove_su_suffix4aref | ||
| 1213 | |||
| 1214 | =cut | ||
| 1215 | |||
| 1216 | sub remove_su_suffix4aref { | ||
| 1217 | my ($self) = @_; | ||
| 1218 | |||
| 1219 | if ( length $control->{_aref} ) { | ||
| 1220 | |||
| 1221 | my @name; | ||
| 1222 | my @array = @{ $control->{_aref} }; | ||
| 1223 | my $length = scalar @array; | ||
| 1224 | |||
| 1225 | for ( my $i = 0 ; $i < $length ; $i++ ) { | ||
| 1226 | |||
| 1227 | $name[$i] = $array[$i]; | ||
| 1228 | # print("control,remove_su_suffix, name=$name[$i]\n"); | ||
| 1229 | my $last_3_char = substr( $name[$i], -3 ); | ||
| 1230 | |||
| 1231 | # print("$last_3_char\n"); | ||
| 1232 | $name[$i] =~ s{\.[^.]+$}{}; | ||
| 1233 | |||
| 1234 | # print("control,remove_su_suffix, missing aref; base_name= $name\n"); | ||
| 1235 | } | ||
| 1236 | |||
| 1237 | $control->{_base_file_name_aref} = \@name; | ||
| 1238 | } | ||
| 1239 | else { | ||
| 1240 | print("control,remove_su_suffix, missing aref\n"); | ||
| 1241 | |||
| 1242 | } | ||
| 1243 | } | ||
| 1244 | |||
| 1245 | =head2 sub remove_su_suffix | ||
| 1246 | |||
| 1247 | For a scalar reference remove the .su extension | ||
| 1248 | For a scalar also remove the .su extension | ||
| 1249 | For an array reference do nothig | ||
| 1250 | returns a non-empty string if EXPR is a reference, the empty string otherwise. | ||
| 1251 | If EXPR is not specified, $_ will be used. The value returned depends on the | ||
| 1252 | type of thing the reference is a reference to. | ||
| 1253 | |||
| 1254 | # || ref($$sref_entry_value) or ref($$sref_entry_value)crashes program | ||
| 1255 | TODO: if may not properly catch all variations of the input | ||
| 1256 | currently works for file_name_strings like '1.su' Nov 17 2017 | ||
| 1257 | |||
| 1258 | =cut | ||
| 1259 | |||
| 1260 | sub remove_su_suffix4sref { | ||
| 1261 | my ($self) = @_; | ||
| 1262 | |||
| 1263 | my $first_name_sref = $control->{_file_name_sref}; | ||
| 1264 | my $first_name_string; | ||
| 1265 | |||
| 1266 | # print("-1.control,remove_su_suffix4sref, value is: $$first_name_sref\n"); | ||
| 1267 | |||
| 1268 | if ( ref($first_name_sref) ) { | ||
| 1269 | |||
| 1270 | # print("-2. ref_entry_value is a reference-\n"); | ||
| 1271 | if ( ref($first_name_sref) eq "ARRAY" ) { # do nothing | ||
| 1272 | print("0.control,remove_su_suffix4sref,file_name: is ARRAY-\n"); | ||
| 1273 | |||
| 1274 | } | ||
| 1275 | elsif ( ref($first_name_sref) eq "SCALAR" ) { | ||
| 1276 | |||
| 1277 | # print("2.control,remove_su_suffix4sref: is SCALAR -\n"); | ||
| 1278 | |||
| 1279 | $first_name_string = $$first_name_sref; | ||
| 1280 | $first_name_string =~ s{\.[^.]+$}{}; | ||
| 1281 | |||
| 1282 | # print("4.control,remove_su_suffix4sref,old ref value is now $first_name_string-\n"); | ||
| 1283 | |||
| 1284 | $control->{_first_name_string} = $first_name_string; | ||
| 1285 | return (); | ||
| 1286 | |||
| 1287 | } | ||
| 1288 | } | ||
| 1289 | else { # not a reference | ||
| 1290 | print("3.control,remove_su_suffix4sref,missing reference\n"); | ||
| 1291 | return (); | ||
| 1292 | |||
| 1293 | # $first_name_string = $$sref_entry_value; | ||
| 1294 | # $first_name_string =~ s{\.[^.]+$}{}; | ||
| 1295 | # $first_name_string = "'".$first_name_string."'"; #for complex names, in addition to plain letters | ||
| 1296 | } | ||
| 1297 | } | ||
| 1298 | |||
| 1299 | =head2 set_aref | ||
| 1300 | |||
| 1301 | =cut | ||
| 1302 | |||
| 1303 | sub set_aref { | ||
| 1304 | my ( $self, $aref ) = @_; | ||
| 1305 | |||
| 1306 | if ( length $aref ) { | ||
| 1307 | |||
| 1308 | $control->{_aref} = $aref; | ||
| 1309 | |||
| 1310 | # print("control,set_aref, $control->{_aref}\n"); | ||
| 1311 | } | ||
| 1312 | else { | ||
| 1313 | print("control,set_aref, missing aref value\n"); | ||
| 1314 | } | ||
| 1315 | return (); | ||
| 1316 | } | ||
| 1317 | |||
| 1318 | =head2 sub set_back_slashBgome | ||
| 1319 | |||
| 1320 | remove back_slash in a string | ||
| 1321 | needed by Seismic Unix | ||
| 1322 | |||
| 1323 | =cut | ||
| 1324 | |||
| 1325 | sub set_back_slashBgone { | ||
| 1326 | my ( $self, $stringWback_slash ) = @_; | ||
| 1327 | |||
| 1328 | # print("control,set_back_slashBgone, stringWback_slash: $stringWback_slash\n"); | ||
| 1329 | |||
| 1330 | if ( $stringWback_slash ne $empty_string ) { | ||
| 1331 | |||
| 1332 | $control->{_stringWback_slash} = $stringWback_slash; | ||
| 1333 | |||
| 1334 | # print("control,set_back_slashBgome, : $stringWback_slash\n"); | ||
| 1335 | } | ||
| 1336 | return (); | ||
| 1337 | } | ||
| 1338 | |||
| 1339 | =head2 sub set_commas2space | ||
| 1340 | |||
| 1341 | Replace commas in strings | ||
| 1342 | needed by Seismic Unix | ||
| 1343 | |||
| 1344 | =cut | ||
| 1345 | |||
| 1346 | sub set_commas2space { | ||
| 1347 | my ( $self, $stringWcommas ) = @_; | ||
| 1348 | |||
| 1349 | # print("control,set_commas2space, stringWcommas: $stringWcommas\n"); | ||
| 1350 | |||
| 1351 | if ( $stringWcommas ne $empty_string ) { | ||
| 1352 | |||
| 1353 | $control->{_stringWcommas} = $stringWcommas; | ||
| 1354 | |||
| 1355 | # print("control,set_commas2space, : $stringWcommas\n"); | ||
| 1356 | } | ||
| 1357 | return (); | ||
| 1358 | } | ||
| 1359 | |||
| 1360 | =head2 set_empty_str2logic | ||
| 1361 | |||
| 1362 | =cut | ||
| 1363 | |||
| 1364 | sub set_empty_str2logic { | ||
| 1365 | |||
| 1366 | my ( $self, $string ) = @_; | ||
| 1367 | my $logic = -1; | ||
| 1368 | |||
| 1369 | if ($string) { | ||
| 1370 | print("control,set_empty_str2logic: string = $string\n"); | ||
| 1371 | if ( $string eq 'yes' ) { $logic = 1; } | ||
| 1372 | |||
| 1373 | } | ||
| 1374 | else { # error check | ||
| 1375 | $logic = 0; | ||
| 1376 | print("control,set_empty_str2logic,empty string, logic= $logic\n"); | ||
| 1377 | } | ||
| 1378 | print("control,set_empty_str2logic: logic = $logic\n"); | ||
| 1379 | return ($logic); | ||
| 1380 | } | ||
| 1381 | |||
| 1382 | =head2 set_file_name | ||
| 1383 | |||
| 1384 | |||
| 1385 | =cut | ||
| 1386 | |||
| 1387 | sub set_file_name { | ||
| 1388 | my ( $self, $file_name_sref ) = @_; | ||
| 1389 | |||
| 1390 | if ($file_name_sref) { | ||
| 1391 | $control->{_file_name} = $$file_name_sref; | ||
| 1392 | |||
| 1393 | # print("control,file_name, $control->{_file_name}\n"); | ||
| 1394 | } | ||
| 1395 | |||
| 1396 | return (); | ||
| 1397 | } | ||
| 1398 | |||
| 1399 | =head2 set_file_name_sref | ||
| 1400 | |||
| 1401 | |||
| 1402 | =cut | ||
| 1403 | |||
| 1404 | sub set_file_name_sref { | ||
| 1405 | my ( $self, $file_name_sref ) = @_; | ||
| 1406 | |||
| 1407 | if ($file_name_sref) { | ||
| 1408 | $control->{_file_name_sref} = $file_name_sref; | ||
| 1409 | |||
| 1410 | # print("control,file_name, $control->{_file_name_sref}\n"); | ||
| 1411 | } | ||
| 1412 | |||
| 1413 | return (); | ||
| 1414 | } | ||
| 1415 | |||
| 1416 | =head2 set_first_name | ||
| 1417 | |||
| 1418 | =cut | ||
| 1419 | |||
| 1420 | sub set_first_name { | ||
| 1421 | |||
| 1422 | my ($self) = @_; | ||
| 1423 | my ( $first_name, $suffix, $file_name ); | ||
| 1424 | |||
| 1425 | # split by the escaped period | ||
| 1426 | $file_name = $control->{_file_name}; | ||
| 1427 | ( $first_name, $suffix ) = split( /\./, $file_name ); | ||
| 1428 | $control->{_first_name} = $first_name; | ||
| 1429 | |||
| 1430 | # print("control,set_first_name,is: $control->{_first_name}\n"); | ||
| 1431 | return (); | ||
| 1432 | } | ||
| 1433 | |||
| 1434 | =head sub set_first_name_string | ||
| 1435 | |||
| 1436 | =cut | ||
| 1437 | |||
| 1438 | sub set_first_name_string { | ||
| 1439 | my ( $self, $infected_string2B ) = @_; | ||
| 1440 | |||
| 1441 | # print("control,set_first_name_string, infected_string2B: $infected_string2B\n"); | ||
| 1442 | |||
| 1443 | if ($infected_string2B) { | ||
| 1444 | $control->{_first_name_string} = $infected_string2B; | ||
| 1445 | |||
| 1446 | # print("control,set_first_name_string, infected_string2B: $infected_string2B\n"); | ||
| 1447 | } | ||
| 1448 | return (); | ||
| 1449 | } | ||
| 1450 | |||
| 1451 | =head2 sub set_flow_program_name_sref | ||
| 1452 | |||
| 1453 | Which program in the flow is active | ||
| 1454 | |||
| 1455 | =cut | ||
| 1456 | |||
| 1457 | sub set_flow_program_name_sref { | ||
| 1458 | |||
| 1459 | my ( $self, $flow_program_name_sref ) = @_; | ||
| 1460 | |||
| 1461 | if ( length $flow_program_name_sref ) { | ||
| 1462 | |||
| 1463 | my $program_aref; | ||
| 1464 | my @program; | ||
| 1465 | $program[0] = $$flow_program_name_sref; | ||
| 1466 | $program_aref = \@program; | ||
| 1467 | $control->{_prog_names_aref} = $program_aref; | ||
| 1468 | |||
| 1469 | # print("control, set_flow_program_name_sref, program=$$flow_program_name_sref \n"); | ||
| 1470 | |||
| 1471 | } | ||
| 1472 | else { | ||
| 1473 | print("control, set_flow_program_name_sref, unexpected value\n"); | ||
| 1474 | } | ||
| 1475 | |||
| 1476 | return (); | ||
| 1477 | |||
| 1478 | } | ||
| 1479 | |||
| 1480 | =head2 sub set_flow_prog_name_index | ||
| 1481 | Which program in the flow is active | ||
| 1482 | |||
| 1483 | =cut | ||
| 1484 | |||
| 1485 | sub set_flow_prog_name_index { | ||
| 1486 | |||
| 1487 | my ( $self, $flow_index ) = @_; | ||
| 1488 | |||
| 1489 | if ( length $flow_index ) { | ||
| 1490 | |||
| 1491 | if ( $flow_index < 0 ) { | ||
| 1492 | |||
| 1493 | # CASE when any listbox is used for the first time in the GUI | ||
| 1494 | # flow index may still be in its default settings, (<0) | ||
| 1495 | # see gui_hitsory | ||
| 1496 | $control->{_flow_index} = 0; | ||
| 1497 | |||
| 1498 | } | ||
| 1499 | elsif ( $flow_index >= 0 ) { | ||
| 1500 | |||
| 1501 | $control->{_flow_index} = $flow_index; | ||
| 1502 | |||
| 1503 | } | ||
| 1504 | else { | ||
| 1505 | print("control, set_flow_prog_name_index, unexpected value\n"); | ||
| 1506 | } | ||
| 1507 | |||
| 1508 | # print("control, set_flow_prog_name_index, index=$control->{_flow_index} \n"); | ||
| 1509 | |||
| 1510 | } | ||
| 1511 | else { | ||
| 1512 | print("control, set_flow_prog_name_index, missing value\n"); | ||
| 1513 | } | ||
| 1514 | |||
| 1515 | return (); | ||
| 1516 | |||
| 1517 | } | ||
| 1518 | |||
| 1519 | =head sub set_infection | ||
| 1520 | |||
| 1521 | =cut | ||
| 1522 | |||
| 1523 | sub set_infection { | ||
| 1524 | my ( $self, $infected_string ) = @_; | ||
| 1525 | |||
| 1526 | # print("control,set_infection, infected_string: $infected_string\n"); | ||
| 1527 | |||
| 1528 | if ($infected_string) { | ||
| 1529 | $control->{_infected_string} = $infected_string; | ||
| 1530 | |||
| 1531 | # print("control,set_infection, infected_string: $infected_string\n"); | ||
| 1532 | } | ||
| 1533 | return (); | ||
| 1534 | } | ||
| 1535 | |||
| 1536 | |||
| 1537 | =head2 sub set_flow_prog_names_aref | ||
| 1538 | |||
| 1539 | =cut | ||
| 1540 | |||
| 1541 | sub set_flow_prog_names_aref { | ||
| 1542 | my ( $self, $program_names_aref ) = @_; | ||
| 1543 | |||
| 1544 | if ( length $program_names_aref ) { | ||
| 1545 | |||
| 1546 | $control->{_prog_names_aref} = $program_names_aref; | ||
| 1547 | |||
| 1548 | # print("control, set_flow_prog_names_aref: @{$control->{_prog_names_aref}} \n"); | ||
| 1549 | |||
| 1550 | } | ||
| 1551 | else { | ||
| 1552 | $control->{_prog_names_aref} = $program_names_aref; | ||
| 1553 | print("control, set_flow_prog_names_aref: missing array reference\n"); | ||
| 1554 | } | ||
| 1555 | return (); | ||
| 1556 | } | ||
| 1557 | |||
| 1558 | =head2 set_str2logic | ||
| 1559 | |||
| 1560 | only used in Project.pm | ||
| 1561 | |||
| 1562 | =cut | ||
| 1563 | |||
| 1564 | sub set_str2logic { | ||
| 1565 | |||
| 1566 | my ( $self, $string ) = @_; | ||
| 1567 | my $logic = -1; | ||
| 1568 | |||
| 1569 | if ( defined $string ) { | ||
| 1570 | |||
| 1571 | # remove a single quote from the string if it is exists | ||
| 1572 | # e.g. 'no' becomes no, or 'yes' becomes yes , all of which are strings. | ||
| 1573 | # However, no can be compared to $no but the original string can not | ||
| 1574 | # Also yes can be compared to $yes, but 'yes' is not the same as $yes, which does not contain the single quotes | ||
| 1575 | $string =~ s/\'//; | ||
| 1576 | $string =~ s/\'//; | ||
| 1577 | |||
| 1578 | # print("0. control,set_str2logic: string = $string\n"); | ||
| 1579 | # if ($string == $no) { print(" 1. string = $no \n"); }; | ||
| 1580 | # if ($string eq $no) { print(" 2. string = $no \n"); }; | ||
| 1581 | |||
| 1582 | if ($string) { | ||
| 1583 | |||
| 1584 | # print("3. control,set_str2logic: string = $string\n"); | ||
| 1585 | |||
| 1586 | if ( $string eq $yes || $string eq $no ) { | ||
| 1587 | |||
| 1588 | if ( $string eq $no ) { $logic = 0; } | ||
| 1589 | if ( $string eq $yes ) { $logic = 1; } | ||
| 1590 | |||
| 1591 | # print("4. control,set_str2logic: string = $string\n"); | ||
| 1592 | |||
| 1593 | } | ||
| 1594 | else { # error check | ||
| 1595 | # print("control,set_str2logic,change parameter value string in gui to either yes or no\n"); | ||
| 1596 | # print("Did you forget to list an expected variable ?\n"); | ||
| 1597 | # print("control,set_str2logic: string = $string\n"); | ||
| 1598 | } | ||
| 1599 | |||
| 1600 | # print("control,set_str2logic: logic = $logic\n"); | ||
| 1601 | return ($logic); | ||
| 1602 | |||
| 1603 | } | ||
| 1604 | else { | ||
| 1605 | |||
| 1606 | # print("5. control,set_str2logic,missing string\n"); | ||
| 1607 | } | ||
| 1608 | |||
| 1609 | } | ||
| 1610 | else { | ||
| 1611 | |||
| 1612 | #print("3. control,set_str2logic: string is not defined NADA\n"); | ||
| 1613 | } | ||
| 1614 | } | ||
| 1615 | |||
| 1616 | =head2 sub set_path | ||
| 1617 | mark the path | ||
| 1618 | |||
| 1619 | =cut | ||
| 1620 | |||
| 1621 | sub set_path { | ||
| 1622 | my ( $self, $path ) = @_; | ||
| 1623 | |||
| 1624 | if ( length $path ) { | ||
| 1625 | |||
| 1626 | $control->{_path} = $path; | ||
| 1627 | |||
| 1628 | # print("control,set_path, : $path\n"); | ||
| 1629 | } | ||
| 1630 | return (); | ||
| 1631 | } | ||
| 1632 | |||
| 1633 | =head2 set_suffix | ||
| 1634 | |||
| 1635 | =cut | ||
| 1636 | |||
| 1637 | sub set_suffix { | ||
| 1638 | |||
| 1639 | my ($self) = @_; | ||
| 1640 | |||
| 1641 | # my ( $first_name, $suffix, $file_name ); | ||
| 1642 | |||
| 1643 | if ( length $control->{_file_name} ) { | ||
| 1644 | |||
| 1645 | my $first_name; | ||
| 1646 | my $suffix; | ||
| 1647 | |||
| 1648 | # print("control,file_name,is: $control->{_file_name}\n"); | ||
| 1649 | # split by the escaped period | ||
| 1650 | my $file_name = $control->{_file_name}; | ||
| 1651 | ( $first_name, $suffix ) = split( /\./, $file_name ); | ||
| 1652 | $control->{_first_name} = $first_name; | ||
| 1653 | |||
| 1654 | # print("control,first_name,is: $first_name\n"); | ||
| 1655 | # print("control,suffix,is: $suffix\n"); | ||
| 1656 | |||
| 1657 | if ( !($suffix) ) { | ||
| 1658 | $suffix = ''; | ||
| 1659 | } | ||
| 1660 | |||
| 1661 | if ( $suffix eq '' ) { | ||
| 1662 | |||
| 1663 | # print("1. control,set_suffix,is: empty\n"); | ||
| 1664 | $control->{_suffix} = ''; | ||
| 1665 | |||
| 1666 | } | ||
| 1667 | elsif ( $suffix eq 'su' ) { | ||
| 1668 | $control->{_suffix} = 'su'; | ||
| 1669 | |||
| 1670 | # print("control,set_suffix,is: $control->{_suffix}\n"); | ||
| 1671 | |||
| 1672 | } | ||
| 1673 | elsif ( $suffix eq 'config' ) { | ||
| 1674 | $control->{_suffix} = 'config'; | ||
| 1675 | |||
| 1676 | # print("control,set_suffix,is: $control->{_suffix}\n"); | ||
| 1677 | |||
| 1678 | } | ||
| 1679 | elsif ( $suffix eq 'pl' ) { | ||
| 1680 | $control->{_suffix} = 'pl'; | ||
| 1681 | |||
| 1682 | # print("control,set_suffix,is: $control->{_suffix}\n"); | ||
| 1683 | |||
| 1684 | } | ||
| 1685 | elsif ( $suffix eq 'txt' ) { | ||
| 1686 | $control->{_suffix} = 'txt'; | ||
| 1687 | |||
| 1688 | # print("control,set_suffix,is: $control->{_suffix}\n"); | ||
| 1689 | |||
| 1690 | } | ||
| 1691 | else { | ||
| 1692 | $control->{_suffix} = ''; | ||
| 1693 | |||
| 1694 | # print("2. control,set_suffix, suffix:$suffix is empty\n"); | ||
| 1695 | } | ||
| 1696 | } | ||
| 1697 | else { | ||
| 1698 | print("control,set_suffix,file_name missing\n"); | ||
| 1699 | } | ||
| 1700 | |||
| 1701 | return (); | ||
| 1702 | } | ||
| 1703 | |||
| 1704 | =head2 sub set_suffix4oop | ||
| 1705 | |||
| 1706 | As needed by oop_prog_params | ||
| 1707 | |||
| 1708 | =cut | ||
| 1709 | |||
| 1710 | sub set_suffix4oop { | ||
| 1711 | my ( $self, $suffix4oop ) = @_; | ||
| 1712 | |||
| 1713 | my $result; | ||
| 1714 | |||
| 1715 | # print("control,set_suffix4oop, suffix: $suffix4oop\n"); | ||
| 1716 | |||
| 1717 | if ( length $suffix4oop ) { | ||
| 1718 | |||
| 1719 | $control->{_suffix4oop} = $suffix4oop; | ||
| 1720 | |||
| 1721 | print("control,set_suffix4oop, : $suffix4oop\n"); | ||
| 1722 | |||
| 1723 | } | ||
| 1724 | elsif ( not( length $suffix4oop ) ) { | ||
| 1725 | |||
| 1726 | $control->{_suffix4oop} = $suffix4oop; | ||
| 1727 | print("control,set_suffix4oop, suffix is empty\n"); | ||
| 1728 | } | ||
| 1729 | else { | ||
| 1730 | print("control,set_suffix4oop, unexpected\n"); | ||
| 1731 | } | ||
| 1732 | return ($result); | ||
| 1733 | } | ||
| 1734 | |||
| 1735 | =head2 sub set_value | ||
| 1736 | |||
| 1737 | As needed by oop_prog_params | ||
| 1738 | |||
| 1739 | =cut | ||
| 1740 | |||
| 1741 | sub set_value { | ||
| 1742 | my ( $self, $value ) = @_; | ||
| 1743 | |||
| 1744 | # print("control,set_value, value: $value\n"); | ||
| 1745 | |||
| 1746 | if ( length $value ) { | ||
| 1747 | |||
| 1748 | $control->{_value} = $value; | ||
| 1749 | |||
| 1750 | # print("control,set_value, : $value\n"); | ||
| 1751 | |||
| 1752 | } | ||
| 1753 | else { | ||
| 1754 | print("control,set_value, missing value\n"); | ||
| 1755 | } | ||
| 1756 | return (); | ||
| 1757 | } | ||
| 1758 | |||
| 1759 | =head2 sub su_data_name | ||
| 1760 | |||
| 1761 | For a scalar reference remove the .su extension | ||
| 1762 | For a scalar also remove the .su extension | ||
| 1763 | For an array reference do nothig | ||
| 1764 | returns a non-empty string if EXPR is a reference, the empty string otherwise. | ||
| 1765 | If EXPR is not specified, $_ will be used. The value returned depends on the | ||
| 1766 | type of thing the reference is a reference to. | ||
| 1767 | DB | ||
| 1768 | |||
| 1769 | # ref($$sref_entry_value) or ref($$sref_entry_value)crashes program | ||
| 1770 | TODO: if may not properly catch all variations of the input | ||
| 1771 | but currently works for file_name_strings like '1.su' Nov 17 2017 | ||
| 1772 | |||
| 1773 | =cut | ||
| 1774 | |||
| 1775 | sub su_data_name { | ||
| 1776 | my ( $self, $sref_entry_value ) = @_; | ||
| 1777 | |||
| 1778 | # print("-1.control,su_data_name, value is:--$$sref_entry_value--\n"); | ||
| 1779 | |||
| 1780 | if ( | ||
| 1781 | defined $sref_entry_value | ||
| 1782 | && length $$sref_entry_value # must not be of zero length | ||
| 1783 | ) | ||
| 1784 | { | ||
| 1785 | |||
| 1786 | my $first_name_string = $sref_entry_value; | ||
| 1787 | |||
| 1788 | # print("-2.control,su_data_name, value is:--$$first_name_string--\n"); | ||
| 1789 | if ( ref($sref_entry_value) ) { | ||
| 1790 | |||
| 1791 | # print("-2. ref_entry_value is a reference-\n"); | ||
| 1792 | if ( ref($$sref_entry_value) eq "ARRAY" ) { # do nothing | ||
| 1793 | # print("0.control,su_data_name,file_name: is ARRAY-\n"); | ||
| 1794 | |||
| 1795 | } | ||
| 1796 | elsif ( ref($sref_entry_value) eq "SCALAR" ) { | ||
| 1797 | |||
| 1798 | # print("2.control,file_name: is SCALAR -\n"); | ||
| 1799 | $first_name_string = $$sref_entry_value; | ||
| 1800 | $first_name_string =~ s{\.[^.]+$}{}; | ||
| 1801 | |||
| 1802 | # print("1.control,su_data_name,value comes from a reference scalar $first_name_string-\n"); | ||
| 1803 | } | ||
| 1804 | } | ||
| 1805 | else { # not a reference | ||
| 1806 | # print("3.control,su_data_name,entry_value=$sref_entry_value\n"); | ||
| 1807 | $first_name_string = $$sref_entry_value; | ||
| 1808 | $first_name_string =~ s{\.[^.]+$}{}; | ||
| 1809 | $first_name_string = "'" | ||
| 1810 | . $first_name_string | ||
| 1811 | . "'"; #for complex names, in addition to plain letters | ||
| 1812 | } | ||
| 1813 | |||
| 1814 | # print("4.control,su_data_name,old ref value is now--$first_name_string--\n"); | ||
| 1815 | $control->{_first_name_string} = $first_name_string; | ||
| 1816 | return ($first_name_string); | ||
| 1817 | |||
| 1818 | } | ||
| 1819 | else { | ||
| 1820 | # print("5. control,su_data_name, unexpected or missing value--\n"); | ||
| 1821 | return ($empty_string); | ||
| 1822 | } | ||
| 1823 | |||
| 1824 | } | ||
| 1825 | |||
| 1826 | =head2 sub freq | ||
| 1827 | |||
| 1828 | i/p scalar reference | ||
| 1829 | o/p nothing | ||
| 1830 | |||
| 1831 | test for empty scalars | ||
| 1832 | |||
| 1833 | $sref_entry_value can be either scalar reference | ||
| 1834 | or array reference | ||
| 1835 | An array reference is flattened and returned with commas | ||
| 1836 | A scalar reference is returned unchanged, essentially; | ||
| 1837 | the string already has commas. | ||
| 1838 | |||
| 1839 | DB | ||
| 1840 | |||
| 1841 | =cut | ||
| 1842 | |||
| 1843 | 1; |