« lib/App/SeismicUnixGui/big_streams/iSelect_xt.pm
↑ Summary
lib/App/SeismicUnixGui/misc/oop_prog_params.pm »
| 1 | package App::SeismicUnixGui::misc::big_streams_param; | ||
| 2 | |||
| 3 | =head1 DOCUMENTATION | ||
| 4 | |||
| 5 | |||
| 6 | =head2 SYNOPSIS | ||
| 7 | |||
| 8 | PERL PERL PROGRAM NAME: big_streams_param | ||
| 9 | AUTHOR: Juan Lorenzo | ||
| 10 | DATE: June 22 2022 | ||
| 11 | |||
| 12 | DESCRIPTION V 0.0.3 | ||
| 13 | BASED ON: su_params.pm V0.0.3 | ||
| 14 | |||
| 15 | =cut | ||
| 16 | |||
| 17 | =head2 USE | ||
| 18 | |||
| 19 | =head3 NOTES | ||
| 20 | |||
| 21 | =head4 Examples | ||
| 22 | |||
| 23 | |||
| 24 | =head2 CHANGES and their DATES | ||
| 25 | May 5 2018 looks for configurations | ||
| 26 | first in the local directory | ||
| 27 | then in the default configuration | ||
| 28 | directory /usr/local/pl/big_streams/config | ||
| 29 | |||
| 30 | V 0.0.3 June 2022 reference to L_SU_local_user_constants | ||
| 31 | removed | ||
| 32 | L_SU_local_user_constants may create cirularity | ||
| 33 | |||
| 34 | =cut | ||
| 35 | |||
| 36 | =head2 | ||
| 37 | |||
| 38 | parameters for seismic unix programs | ||
| 39 | both macros and individual modules | ||
| 40 | |||
| 41 | =cut | ||
| 42 | |||
| 43 | use Moose; | ||
| 44 | our $VERSION = '0.0.3'; | ||
| 45 | |||
| 46 | use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants'; | ||
| 47 | use aliased 'App::SeismicUnixGui::misc::L_SU_path'; | ||
| 48 | use aliased 'App::SeismicUnixGui::misc::developer'; | ||
| 49 | use aliased 'App::SeismicUnixGui::misc::readfiles'; | ||
| 50 | |||
| 51 | use Shell qw(echo); | ||
| 52 | |||
| 53 | my $L_SU_global_constants = L_SU_global_constants->new(); | ||
| 54 | my $L_SU_path = L_SU_path->new(); | ||
| 55 | my $read = readfiles->new(); | ||
| 56 | my $developer = developer->new(); | ||
| 57 | my $HOME = ` echo \$HOME`; | ||
| 58 | chomp $HOME; | ||
| 59 | |||
| 60 | # magic number TODO | ||
| 61 | my $var = $L_SU_global_constants->var(); | ||
| 62 | my $ACTIVE_PROJECT = $HOME . $var->{_ACTIVE_PROJECT}; | ||
| 63 | my $user_active_project_path = $ACTIVE_PROJECT; | ||
| 64 | |||
| 65 | my $true = $var->{_true}; | ||
| 66 | my $false = $var->{_false}; | ||
| 67 | my $empty_string = $var->{_empty_string}; | ||
| 68 | |||
| 69 | # imports 2 different flow type definisions | ||
| 70 | my $flow_type_href = $L_SU_global_constants->flow_type_href(); | ||
| 71 | |||
| 72 | my $big_streams_param = { | ||
| 73 | _flow_type => '', | ||
| 74 | _name_space => 'name_space', | ||
| 75 | _local_path => '', | ||
| 76 | _path => '', | ||
| 77 | _sub_category_directory => '', | ||
| 78 | _program_config => '', | ||
| 79 | _program_sref => '', | ||
| 80 | _user_active_project_path => $user_active_project_path, | ||
| 81 | _names_aref => '', | ||
| 82 | }; | ||
| 83 | |||
| 84 | sub set_flow_type { | ||
| 85 | |||
| 86 | my ( $self, $flow_type ) = @_; | ||
| 87 | |||
| 88 | if ( defined $flow_type | ||
| 89 | && $flow_type ne $empty_string ) | ||
| 90 | { | ||
| 91 | |||
| 92 | $big_streams_param->{_flow_type} = $flow_type; | ||
| 93 | |||
| 94 | # print("big_streams_param, set_flow_type ,flow_type=$big_streams_param->{_flow_type}\n"); | ||
| 95 | |||
| 96 | } | ||
| 97 | else { | ||
| 98 | print("big_streams_param, set_flow_type , missing value\n"); | ||
| 99 | } | ||
| 100 | |||
| 101 | return (); | ||
| 102 | } | ||
| 103 | |||
| 104 | sub _check4corruption_config { | ||
| 105 | |||
| 106 | my ($self) = @_; | ||
| 107 | |||
| 108 | my $corruption = $false; | ||
| 109 | |||
| 110 | if ( length $big_streams_param->{_path} | ||
| 111 | and length $big_streams_param->{_sub_category_directory} ) | ||
| 112 | { | ||
| 113 | |||
| 114 | my $program_config = _get_program_config(); | ||
| 115 | |||
| 116 | # print( | ||
| 117 | #"big_streams_param, _check4corruption_config, file to read=$program_config\n" | ||
| 118 | # ); | ||
| 119 | |||
| 120 | my ( $names_aref, $values_aref ) = $read->configs($program_config); | ||
| 121 | my @names = @$names_aref; | ||
| 122 | my $length = scalar @names; | ||
| 123 | |||
| 124 | # print( | ||
| 125 | #"big_streams_param,_check4corruption_config, we have $length pairs\n\n" | ||
| 126 | # ); | ||
| 127 | |||
| 128 | for ( my $i = 0 ; $i < $length ; $i++ ) { | ||
| 129 | |||
| 130 | # test for empty names | ||
| 131 | if ( $names[$i] eq $empty_string | ||
| 132 | or $names[$i] eq '0.000' ) | ||
| 133 | { | ||
| 134 | |||
| 135 | $corruption = $true; | ||
| 136 | |||
| 137 | # print( | ||
| 138 | # "big_streams_param,_check4corruption_config, $names[$i]\n"); | ||
| 139 | # print( | ||
| 140 | #"big_streams_param,_check4corruption_config, corruption = $true\n" | ||
| 141 | # ); | ||
| 142 | |||
| 143 | } | ||
| 144 | else { | ||
| 145 | $corruption = $false; | ||
| 146 | |||
| 147 | # print( | ||
| 148 | # "big_streams_param,_check4corruption_config, no corruption, $names[$i]\n") | ||
| 149 | # ; | ||
| 150 | } | ||
| 151 | } | ||
| 152 | |||
| 153 | } | ||
| 154 | else { | ||
| 155 | $corruption = $true; | ||
| 156 | print( | ||
| 157 | "big_streams_param,_check4corruption_config, missing variables\n"); | ||
| 158 | print("as follows: \n"); | ||
| 159 | print("big_streams_param->{_path}=$big_streams_param->{_path}\n"); | ||
| 160 | print( | ||
| 161 | "big_streams_param->{_sub_category_directory}=$big_streams_param->{_sub_category_directory}\n" | ||
| 162 | ); | ||
| 163 | } | ||
| 164 | |||
| 165 | return ($corruption); | ||
| 166 | } | ||
| 167 | |||
| 168 | sub _get_global_lib { | ||
| 169 | |||
| 170 | my ($elf) = @_; | ||
| 171 | |||
| 172 | my $global_libs_href = $L_SU_global_constants->global_libs(); | ||
| 173 | |||
| 174 | if ( defined $global_libs_href | ||
| 175 | && $global_libs_href ne $empty_string | ||
| 176 | && defined $big_streams_param->{_flow_type} ) | ||
| 177 | { | ||
| 178 | |||
| 179 | my $result; | ||
| 180 | |||
| 181 | if ( $big_streams_param->{_flow_type} eq | ||
| 182 | $flow_type_href->{_pre_built_superflow} ) | ||
| 183 | { | ||
| 184 | |||
| 185 | $big_streams_param->{_lib_path} = $global_libs_href->{_param}; | ||
| 186 | |||
| 187 | # print("big_streams_param, _get_global_lib,lib_path= $big_streams_param->{_lib_path}\n"); | ||
| 188 | $result = $big_streams_param->{_lib_path}; | ||
| 189 | return ($result); | ||
| 190 | |||
| 191 | } | ||
| 192 | elsif ( | ||
| 193 | $big_streams_param->{_flow_type} eq $flow_type_href->{_user_built} ) | ||
| 194 | { | ||
| 195 | |||
| 196 | $big_streams_param->{_lib_path} = $global_libs_href->{_param}; | ||
| 197 | |||
| 198 | # print("big_streams_param, _get_global_lib, lib_path: $big_streams_param->{_lib_path}\n"); | ||
| 199 | $result = $big_streams_param->{_lib_path}; | ||
| 200 | return ($result); | ||
| 201 | |||
| 202 | } | ||
| 203 | else { | ||
| 204 | print("big_streams_param, _get_global_lib, unexpected value\n"); | ||
| 205 | return (); | ||
| 206 | } | ||
| 207 | |||
| 208 | } | ||
| 209 | else { | ||
| 210 | print("big_streams_param, _get_global_lib, missing value\n"); | ||
| 211 | } | ||
| 212 | |||
| 213 | return (); | ||
| 214 | |||
| 215 | } | ||
| 216 | |||
| 217 | sub _set_sub_category_directory { | ||
| 218 | |||
| 219 | my ($sub_category_directory) = @_; | ||
| 220 | |||
| 221 | if ( defined $sub_category_directory | ||
| 222 | && $sub_category_directory ne $empty_string ) | ||
| 223 | { | ||
| 224 | |||
| 225 | $big_streams_param->{_sub_category_directory} = $sub_category_directory; | ||
| 226 | |||
| 227 | } | ||
| 228 | else { | ||
| 229 | print( | ||
| 230 | "big_streams_param, _set_sub_category_directory, missing value\n"); | ||
| 231 | |||
| 232 | # print( | ||
| 233 | #"big_streams_param, _set_sub_category_directory, $sub_category_directory\n" | ||
| 234 | # ); | ||
| 235 | } | ||
| 236 | |||
| 237 | return (); | ||
| 238 | } | ||
| 239 | |||
| 240 | sub _set_path { | ||
| 241 | |||
| 242 | my ($path) = @_; | ||
| 243 | |||
| 244 | if ( length $path | ||
| 245 | && $path ne $empty_string ) | ||
| 246 | { | ||
| 247 | |||
| 248 | $big_streams_param->{_path} = $path; | ||
| 249 | |||
| 250 | # print("big_streams_param, _set_path, path=$path\n"); | ||
| 251 | |||
| 252 | } | ||
| 253 | else { | ||
| 254 | print("big_streams_param, _set_path, missing value\n"); | ||
| 255 | } | ||
| 256 | |||
| 257 | return (); | ||
| 258 | } | ||
| 259 | |||
| 260 | sub _set_program_sref { | ||
| 261 | |||
| 262 | my ($program_sref) = @_; | ||
| 263 | |||
| 264 | if ( defined $$program_sref | ||
| 265 | && $$program_sref ne $empty_string ) | ||
| 266 | { | ||
| 267 | |||
| 268 | $big_streams_param->{_program_sref} = $program_sref; | ||
| 269 | |||
| 270 | } | ||
| 271 | else { | ||
| 272 | print("big_streams_param, _set_program_config, missing value\n"); | ||
| 273 | return (); | ||
| 274 | } | ||
| 275 | |||
| 276 | return (); | ||
| 277 | } | ||
| 278 | |||
| 279 | sub _get_program_config { | ||
| 280 | |||
| 281 | my ($path) = @_; | ||
| 282 | |||
| 283 | my ( $program_config, $sub_category_directory, $program_sref ); | ||
| 284 | |||
| 285 | $path = $big_streams_param->{_path}; | ||
| 286 | $sub_category_directory = $big_streams_param->{_sub_category_directory}; | ||
| 287 | $program_sref = $big_streams_param->{_program_sref}; | ||
| 288 | |||
| 289 | if ( length $path | ||
| 290 | && length $sub_category_directory | ||
| 291 | && length $$program_sref ) | ||
| 292 | { | ||
| 293 | |||
| 294 | $program_config = | ||
| 295 | $path . '/' | ||
| 296 | . $sub_category_directory . '/' | ||
| 297 | . $$program_sref | ||
| 298 | . '.config'; | ||
| 299 | |||
| 300 | $big_streams_param->{_program_config} = $program_config; | ||
| 301 | # print("big_streams_param, get_program_config, program_config= $program_config\n"); | ||
| 302 | my $result = $program_config; | ||
| 303 | return ($result); | ||
| 304 | |||
| 305 | } | ||
| 306 | else { | ||
| 307 | print("big_streams_param, _set_program_config, missing value\n"); | ||
| 308 | print("path = $path\n"); | ||
| 309 | print("sub_category_directory = $sub_category_directory\n"); | ||
| 310 | print("program_sref = $$program_sref\n"); | ||
| 311 | return (); | ||
| 312 | } | ||
| 313 | |||
| 314 | } | ||
| 315 | |||
| 316 | =head2 sub get | ||
| 317 | |||
| 318 | returns values | ||
| 319 | as an array | ||
| 320 | input is a scalar reference | ||
| 321 | used both by superflow/pre-built flows and seismic unix configuration files | ||
| 322 | |||
| 323 | Read a default specification file | ||
| 324 | If default specification file does not exist locally (PL_SEISMIC), | ||
| 325 | look in the user's configuration directory | ||
| 326 | ~HOME/.L_SU/configuration/active and if that does not exist, | ||
| 327 | then use the default one defined under global libs | ||
| 328 | |||
| 329 | Check that the configuration file in the local directory is not corrupt | ||
| 330 | |||
| 331 | Debug with | ||
| 332 | print ("this is $this\n"); | ||
| 333 | print ("self is $self,program is $program\n"); | ||
| 334 | |||
| 335 | Changing the namespace variables to lower | ||
| 336 | case is not a general solution because | ||
| 337 | original variables can have mixed upper and lower | ||
| 338 | case names | ||
| 339 | |||
| 340 | DEPRECATED: | ||
| 341 | Older versions may use Config::Simple | ||
| 342 | my $a = Config::Simple->import_from($this,'Z'); | ||
| 343 | foreach my $key ( keys %Z:: ) | ||
| 344 | { | ||
| 345 | my $x = lc $key; | ||
| 346 | print "key is $x\n"; | ||
| 347 | print "$cfg->param($key)\n"; | ||
| 348 | } | ||
| 349 | |||
| 350 | |||
| 351 | =cut | ||
| 352 | |||
| 353 | sub get { | ||
| 354 | |||
| 355 | my ( $self, $program_sref ) = @_; | ||
| 356 | |||
| 357 | if ( defined $program_sref | ||
| 358 | && ( defined $big_streams_param->{_flow_type} ) | ||
| 359 | && ( $big_streams_param->{_flow_type} ne $empty_string ) ) | ||
| 360 | { | ||
| 361 | |||
| 362 | my (@CFG); | ||
| 363 | my ( $length, $names_aref, $values_aref ); | ||
| 364 | my ( $i, $j, $program_config, $path ); | ||
| 365 | my $sub_category_directory; | ||
| 366 | my $config_corrupt; | ||
| 367 | |||
| 368 | $developer->set_program_name($$program_sref); | ||
| 369 | $developer->set_flow_type( $big_streams_param->{_flow_type} ); | ||
| 370 | _set_program_sref($program_sref); | ||
| 371 | |||
| 372 | # reset the following tests to 0 (false) | ||
| 373 | my $local_config_exists = _check4local_config($program_sref); | ||
| 374 | my $user_active_project_path_exists = _check4user_config($program_sref); | ||
| 375 | |||
| 376 | # print( | ||
| 377 | #"B. big_streams_param,get,local_config_exists:$local_config_exists\n" | ||
| 378 | # ); | ||
| 379 | # | ||
| 380 | # print( | ||
| 381 | #"C. big_streams_param,get,user_active_project_path_exists:$user_active_project_path_exists\n" | ||
| 382 | # ); | ||
| 383 | # print( | ||
| 384 | #"D. big_streams_param,get,big_streams_param->{_flow_type}:$big_streams_param->{_flow_type}\n" | ||
| 385 | # ); | ||
| 386 | # print( | ||
| 387 | #"E. big_streams_param,get,flow_type_href->{_pre_built_superflow}:$flow_type_href->{_pre_built_superflow}\n" | ||
| 388 | # ); | ||
| 389 | |||
| 390 | if ( $big_streams_param->{_flow_type} eq | ||
| 391 | $flow_type_href->{_pre_built_superflow} ) | ||
| 392 | { | ||
| 393 | |||
| 394 | if ($local_config_exists) { | ||
| 395 | |||
| 396 | # CASE for previously run | ||
| 397 | # Tools except Project | ||
| 398 | # print( | ||
| 399 | # "big_streams_param, get,CASE 1A: If progam_sref = a pre-built superflow\n" | ||
| 400 | # ); | ||
| 401 | |||
| 402 | # i.e., with tools like Sseg2su.config | ||
| 403 | # but not with Project.config | ||
| 404 | |||
| 405 | use Module::Refresh; # reload updated module | ||
| 406 | my $refresher = Module::Refresh->new(); | ||
| 407 | |||
| 408 | my $program_name = $$program_sref; | ||
| 409 | $L_SU_path->set_program_name($program_name); | ||
| 410 | |||
| 411 | my $pathNmodule_spec_w_slash_pm = | ||
| 412 | $L_SU_path->get_pathNmodule_spec_w_slash_pm(); | ||
| 413 | my $pathNmodule_spec_w_colon = | ||
| 414 | $L_SU_path->get_pathNmodule_spec_w_colon(); | ||
| 415 | |||
| 416 | $refresher->refresh_module($pathNmodule_spec_w_slash_pm); | ||
| 417 | |||
| 418 | # INSTANTIATE | ||
| 419 | my $package = $pathNmodule_spec_w_colon->new(); | ||
| 420 | |||
| 421 | # collect specifications of output directory | ||
| 422 | # from a program_spec.pm module | ||
| 423 | my $specs_h = $package->variables(); | ||
| 424 | my $CONFIG = $specs_h->{_CONFIG}; | ||
| 425 | |||
| 426 | $big_streams_param->{_local_path} = $CONFIG; | ||
| 427 | my $local_path = $big_streams_param->{_local_path}; | ||
| 428 | my $sub_category_directory = '.'; | ||
| 429 | |||
| 430 | _set_path($local_path); | ||
| 431 | _set_sub_category_directory($sub_category_directory); | ||
| 432 | $config_corrupt = _check4corruption_config(); | ||
| 433 | |||
| 434 | } | ||
| 435 | elsif ($user_active_project_path_exists) { | ||
| 436 | |||
| 437 | # CASE 1B: | ||
| 438 | # If progam_sref= Project | ||
| 439 | # and ONLY applies to ./L_SU/configuration/active/Project.config | ||
| 440 | $path = $big_streams_param->{_user_active_project_path}; | ||
| 441 | $sub_category_directory = | ||
| 442 | $developer->get_program_sub_category(); | ||
| 443 | |||
| 444 | # print( | ||
| 445 | #"CASE 1B big_streams_param,get,user_active_project_path_exists= $user_active_project_path_exists\n" | ||
| 446 | # ); | ||
| 447 | # print( | ||
| 448 | #"1B big_streams_param,get,active path is now $big_streams_param->{_user_active_project_path} \n" | ||
| 449 | # ); | ||
| 450 | |||
| 451 | _set_path($path); | ||
| 452 | _set_sub_category_directory($sub_category_directory); | ||
| 453 | $config_corrupt = $false; #_check4corruption_config(); | ||
| 454 | |||
| 455 | } | ||
| 456 | elsif ( not $local_config_exists ) { | ||
| 457 | |||
| 458 | # CASE 1C: for a previously unused pre-built superflow | ||
| 459 | # except Project | ||
| 460 | $path = _get_global_lib(); | ||
| 461 | $sub_category_directory = | ||
| 462 | $developer->get_program_sub_category(); | ||
| 463 | |||
| 464 | # print( | ||
| 465 | # "1C big_streams_param,get,using global lib: path is $path\n" | ||
| 466 | # ); | ||
| 467 | # print( | ||
| 468 | # "1C big_streams_param,get,using global lib: sub_category=$sub_category_directory\n" | ||
| 469 | # ); | ||
| 470 | _set_path($path); | ||
| 471 | _set_sub_category_directory($sub_category_directory); | ||
| 472 | $config_corrupt = $false; | ||
| 473 | } | ||
| 474 | |||
| 475 | } | ||
| 476 | elsif ( | ||
| 477 | $big_streams_param->{_flow_type} eq $flow_type_href->{_user_built} ) | ||
| 478 | { | ||
| 479 | # CASE 2A: for use of sunix programs in user_built_flows | ||
| 480 | $path = _get_global_lib(); | ||
| 481 | $config_corrupt = $false; | ||
| 482 | |||
| 483 | # print( | ||
| 484 | #"CASE 2.A big_streams_param,get,using global lib: path for sunix programs is $path\n" | ||
| 485 | # ); | ||
| 486 | $sub_category_directory = $developer->get_program_sub_category(); | ||
| 487 | |||
| 488 | # print( | ||
| 489 | #"2.A big_streams_param,get,using sub_category_directory: for sunix programs is $sub_category_directory\n" | ||
| 490 | # ); | ||
| 491 | _set_path($path); | ||
| 492 | _set_sub_category_directory($sub_category_directory); | ||
| 493 | $config_corrupt = $false; | ||
| 494 | } | ||
| 495 | else { | ||
| 496 | print("big_streams_param,get,unexpected\n"); | ||
| 497 | } | ||
| 498 | |||
| 499 | if ( $config_corrupt eq $false ) { | ||
| 500 | |||
| 501 | # CASE:3A use the local configuration file | ||
| 502 | # print("CASE 3.A big_streams_param,get\n"); | ||
| 503 | # share local variables with the package namespace | ||
| 504 | $program_config = _get_program_config(); | ||
| 505 | |||
| 506 | # print("big_streams_param, get,program_config=$program_config\n"); | ||
| 507 | |||
| 508 | ( $names_aref, $values_aref ) = $read->configs($program_config); | ||
| 509 | $big_streams_param->{_names_aref} = $names_aref; | ||
| 510 | $length = scalar @$names_aref; | ||
| 511 | |||
| 512 | # print("big_streams_param,get:we have $length pairs\n\n"); | ||
| 513 | for ( $i = 0, $j = 0 ; $i < $length ; $i++, $j = $j + 2 ) { | ||
| 514 | |||
| 515 | $CFG[$j] = $$names_aref[$i]; | ||
| 516 | $CFG[ ( $j + 1 ) ] = $$values_aref[$i]; | ||
| 517 | |||
| 518 | # print("big_streams_param,get,values:--$CFG[$j+1]--\n"); | ||
| 519 | } | ||
| 520 | |||
| 521 | return ( \@CFG ); | ||
| 522 | |||
| 523 | } | ||
| 524 | |||
| 525 | elsif ( $config_corrupt eq $true ) { | ||
| 526 | |||
| 527 | # CASE: use the default file | ||
| 528 | # as if if were a pristine pre-built superflow | ||
| 529 | |||
| 530 | if ($user_active_project_path_exists) { | ||
| 531 | |||
| 532 | # CASE for Project ONLY | ||
| 533 | carp("Warning: Project_configuration file is corrupt\n"); | ||
| 534 | $program_config = _get_program_config(); | ||
| 535 | |||
| 536 | ( $names_aref, $values_aref ) = $read->configs($program_config); | ||
| 537 | $big_streams_param->{_names_aref} = $names_aref; | ||
| 538 | $length = scalar @$names_aref; | ||
| 539 | |||
| 540 | # print("big_streams_param,get:we have $length pairs\n\n"); | ||
| 541 | for ( $i = 0, $j = 0 ; $i < $length ; $i++, $j = $j + 2 ) { | ||
| 542 | |||
| 543 | $CFG[$j] = $$names_aref[$i]; | ||
| 544 | $CFG[ ( $j + 1 ) ] = $$values_aref[$i]; | ||
| 545 | |||
| 546 | # print("big_streams_param,get,values:--$CFG[$j+1]--\n"); | ||
| 547 | } | ||
| 548 | |||
| 549 | return ( \@CFG ); | ||
| 550 | |||
| 551 | } | ||
| 552 | elsif ( not $user_active_project_path_exists ) { | ||
| 553 | |||
| 554 | # CASE: All Tools except Project | ||
| 555 | # get variables from the default files | ||
| 556 | |||
| 557 | $path = _get_global_lib(); | ||
| 558 | $sub_category_directory = | ||
| 559 | $developer->get_program_sub_category(); | ||
| 560 | _set_path($path); | ||
| 561 | _set_sub_category_directory($sub_category_directory); | ||
| 562 | $program_config = _get_program_config(); | ||
| 563 | |||
| 564 | # print("big_streams_param, get, sub_category_directory=$sub_category_directory\n"); | ||
| 565 | # print("big_streams_param, get,program_config=$program_config\n"); | ||
| 566 | ( $names_aref, $values_aref ) = $read->configs($program_config); | ||
| 567 | $big_streams_param->{_names_aref} = $names_aref; | ||
| 568 | $length = scalar @$names_aref; | ||
| 569 | |||
| 570 | # print("big_streams_param,get:we have $length pairs\n\n"); | ||
| 571 | for ( $i = 0, $j = 0 ; $i < $length ; $i++, $j = $j + 2 ) { | ||
| 572 | |||
| 573 | $CFG[$j] = $$names_aref[$i]; | ||
| 574 | $CFG[ ( $j + 1 ) ] = $$values_aref[$i]; | ||
| 575 | |||
| 576 | # print("big_streams_param,get,values:--$CFG[$j+1]--\n"); | ||
| 577 | } | ||
| 578 | |||
| 579 | return ( \@CFG ); | ||
| 580 | |||
| 581 | } | ||
| 582 | |||
| 583 | } | ||
| 584 | else { | ||
| 585 | print("big_streams_param, get, unexpected variable\n"); | ||
| 586 | } | ||
| 587 | |||
| 588 | } | ||
| 589 | else { | ||
| 590 | print( | ||
| 591 | "big_streams_param,get, missing either program_sref or flow type\n" | ||
| 592 | ); | ||
| 593 | print("big_streams_param,get,program_sref:$$program_sref\n"); | ||
| 594 | print( | ||
| 595 | "big_streams_param,get, big_streams_param->{_flow_type}: $big_streams_param->{_flow_type}\n" | ||
| 596 | ); | ||
| 597 | return (); | ||
| 598 | } | ||
| 599 | |||
| 600 | } | ||
| 601 | |||
| 602 | =head2 sub _check4local_config | ||
| 603 | |||
| 604 | needs name_sref | ||
| 605 | |||
| 606 | CASE for any type of flow | ||
| 607 | big streams/superflows or for | ||
| 608 | or sunix programs in user-built flows | ||
| 609 | |||
| 610 | Check for local versions of the configuration files in PL_SEISMIC | ||
| 611 | and also look in specified _CONFIG folder | ||
| 612 | _CONFIG folder is defined as PL_SEISMIC for all but | ||
| 613 | pre-built big streams/superflows (e.g., immodpg) | ||
| 614 | |||
| 615 | (For pre-built big streams, look at program_spec to find | ||
| 616 | the definition for _CONFIG) | ||
| 617 | |||
| 618 | # my $a = $package->variables(); | ||
| 619 | # foreach my $key (sort keys %$a) { | ||
| 620 | # print (" big_streams_param,_check4local_config, , key is $key, value is $a->{$key}\n"); | ||
| 621 | # } | ||
| 622 | # my $ans= $a->{_CONFIG}; | ||
| 623 | # print("2. big_streams_param,_check4local_config,package=$ans\n"); | ||
| 624 | |||
| 625 | =cut | ||
| 626 | |||
| 627 | sub _check4local_config { | ||
| 628 | |||
| 629 | my ($name_sref) = @_; | ||
| 630 | |||
| 631 | my $ans = $false; | ||
| 632 | |||
| 633 | if ( length $name_sref | ||
| 634 | && $name_sref ne $empty_string ) | ||
| 635 | { | ||
| 636 | |||
| 637 | my $program_name = $$name_sref; | ||
| 638 | $L_SU_path->set_program_name($program_name); | ||
| 639 | |||
| 640 | my $pathNmodule_spec_w_slash_pm = | ||
| 641 | $L_SU_path->get_pathNmodule_spec_w_slash_pm(); | ||
| 642 | my $pathNmodule_spec_w_colon = | ||
| 643 | $L_SU_path->get_pathNmodule_spec_w_colon(); | ||
| 644 | |||
| 645 | if ( length $pathNmodule_spec_w_slash_pm | ||
| 646 | and length $pathNmodule_spec_w_colon ) | ||
| 647 | { | ||
| 648 | require $pathNmodule_spec_w_slash_pm; | ||
| 649 | |||
| 650 | # INSTANTIATE | ||
| 651 | my $package = $pathNmodule_spec_w_colon->new(); | ||
| 652 | |||
| 653 | # collect specifications of output directory | ||
| 654 | # from a program_spec.pm module | ||
| 655 | my $specs_h = $package->variables(); | ||
| 656 | my $CONFIG = $specs_h->{_CONFIG}; | ||
| 657 | |||
| 658 | my $prog_name_config = $CONFIG . '/' . $$name_sref . '.config'; | ||
| 659 | |||
| 660 | # print( | ||
| 661 | #"big_streams_param,_check4local_config,prog_name_config =$prog_name_config\n" | ||
| 662 | # ); | ||
| 663 | if ( -e ($prog_name_config) ) { | ||
| 664 | |||
| 665 | # print( | ||
| 666 | #"big_streams_param,_check4local_config,found: $prog_name_config. Using local configuration file\n" | ||
| 667 | # ); | ||
| 668 | $ans = $true; | ||
| 669 | |||
| 670 | } | ||
| 671 | else { | ||
| 672 | $ans = $false; | ||
| 673 | |||
| 674 | # print( | ||
| 675 | #"big_streams_param,_check4local_config, $prog_name_config not found\n" | ||
| 676 | # ); | ||
| 677 | } | ||
| 678 | } # module is found | ||
| 679 | } | ||
| 680 | else { | ||
| 681 | print("big_streams_param,_check4local_config, missing name_sref \n"); | ||
| 682 | $ans = $false; | ||
| 683 | } | ||
| 684 | return ($ans); | ||
| 685 | } | ||
| 686 | |||
| 687 | =head2 sub _check4user_config | ||
| 688 | |||
| 689 | check for versions of the configuration files | ||
| 690 | in the user's configuration directory: | ||
| 691 | .L_SU/configuration/active | ||
| 692 | only needed for Project.config | ||
| 693 | e.g., not for Sseg2su | ||
| 694 | |||
| 695 | =cut | ||
| 696 | |||
| 697 | sub _check4user_config { | ||
| 698 | |||
| 699 | my ($name_sref) = @_; | ||
| 700 | |||
| 701 | my $ans = $false; | ||
| 702 | |||
| 703 | if ( length $ACTIVE_PROJECT | ||
| 704 | and length $name_sref ) | ||
| 705 | { | ||
| 706 | |||
| 707 | if ( -e ( $ACTIVE_PROJECT . '/' . $$name_sref . '.config' ) ) { | ||
| 708 | $ans = $true; | ||
| 709 | } | ||
| 710 | else { | ||
| 711 | $ans = $false; | ||
| 712 | |||
| 713 | # print( | ||
| 714 | #"big_streams_param,_check4user_config, ACTIVE_PROJECT=$ACTIVE_PROJECT\n" | ||
| 715 | # ); | ||
| 716 | |||
| 717 | # print("big_streams_param,_check4user_config, name =$$name_sref\n"); | ||
| 718 | # print( | ||
| 719 | # "big_streams_param,_check4user_config,$$name_sref not found. \n | ||
| 720 | # Going forward will use default (GLOBAL LIBS) configuration file\n" | ||
| 721 | # ); | ||
| 722 | # print( | ||
| 723 | #"big_streams_param,_check4user_config,$$name_sref.config found, Using user configuration file\n" | ||
| 724 | # ); | ||
| 725 | # print("big_streams_param,_check4user_config=$ans\n"); | ||
| 726 | } | ||
| 727 | } | ||
| 728 | return ($ans); #sub check4local_config | ||
| 729 | } | ||
| 730 | |||
| 731 | =head2 sub check4user_config | ||
| 732 | |||
| 733 | check for versions of the Project.config file | ||
| 734 | in the user's configuration directory: | ||
| 735 | .L_SU/configuration/active | ||
| 736 | for Project.config | ||
| 737 | True when for $$name_sref='Project'; | ||
| 738 | |||
| 739 | =cut | ||
| 740 | |||
| 741 | sub check4user_config { | ||
| 742 | |||
| 743 | my ( $self, $name_sref ) = @_; | ||
| 744 | |||
| 745 | my $ans = $false; | ||
| 746 | |||
| 747 | if ($name_sref) { | ||
| 748 | if ( -e ( $ACTIVE_PROJECT . '/' . $$name_sref . '.config' ) ) { | ||
| 749 | $ans = $true; | ||
| 750 | |||
| 751 | # print("big_streams_param,check4user_config,$$name_sref.config found, Using user configuration file\n"); | ||
| 752 | # print("big_streams_param,check4user_config=$ans\n"); | ||
| 753 | } | ||
| 754 | else { | ||
| 755 | $ans = $false; | ||
| 756 | |||
| 757 | # print("big_streams_param,check4user_config,$$name_sref not found. Using default (GLOBAL LIBS) configuration file\n") | ||
| 758 | } | ||
| 759 | } | ||
| 760 | return ($ans); | ||
| 761 | } | ||
| 762 | |||
| 763 | =head2 sub my_length | ||
| 764 | not found | ||
| 765 | This length is twice the number of parameter | ||
| 766 | names | ||
| 767 | print("big_streams_param,length: is $length\n"); | ||
| 768 | |||
| 769 | =cut | ||
| 770 | |||
| 771 | sub my_length { | ||
| 772 | |||
| 773 | my ($self) = @_; | ||
| 774 | if ( $big_streams_param->{_names_aref} ) { | ||
| 775 | my $my_length = | ||
| 776 | ( scalar @{ $big_streams_param->{_names_aref} } ) * 2; | ||
| 777 | return ($my_length); | ||
| 778 | } | ||
| 779 | else { | ||
| 780 | |||
| 781 | print ("big_streams_param,my_length, empty names array reference\n"); | ||
| 782 | } | ||
| 783 | |||
| 784 | } | ||
| 785 | |||
| 786 | 1; |