| 1 | package App::SeismicUnixGui::sunix::shapeNcut::suflip; | ||
| 2 | |||
| 3 | =head2 SYNOPSIS | ||
| 4 | |||
| 5 | PERL PROGRAM NAME: | ||
| 6 | |||
| 7 | AUTHOR: Juan Lorenzo (Perl module only) | ||
| 8 | |||
| 9 | DATE: | ||
| 10 | |||
| 11 | DESCRIPTION: | ||
| 12 | |||
| 13 | Version: | ||
| 14 | |||
| 15 | =head2 USE | ||
| 16 | |||
| 17 | =head3 NOTES | ||
| 18 | |||
| 19 | =head4 Examples | ||
| 20 | |||
| 21 | =head2 SYNOPSIS | ||
| 22 | |||
| 23 | =head3 SEISMIC UNIX NOTES | ||
| 24 | SUFLIP - flip a data set in various ways | ||
| 25 | |||
| 26 | |||
| 27 | |||
| 28 | suflip <data1 >data2 flip=1 verbose=0 | ||
| 29 | |||
| 30 | |||
| 31 | |||
| 32 | Required parameters: | ||
| 33 | |||
| 34 | none | ||
| 35 | |||
| 36 | |||
| 37 | |||
| 38 | Optional parameters: | ||
| 39 | |||
| 40 | flip=1 rotational sense of flip | ||
| 41 | |||
| 42 | +1 = flip 90 deg clockwise | ||
| 43 | |||
| 44 | -1 = flip 90 deg counter-clockwise | ||
| 45 | |||
| 46 | 0 = transpose data | ||
| 47 | |||
| 48 | 2 = flip right-to-left | ||
| 49 | |||
| 50 | 3 = flip top-to-bottom | ||
| 51 | |||
| 52 | tmpdir= if non-empty, use the value as a directory path | ||
| 53 | |||
| 54 | prefix for storing temporary files; else if | ||
| 55 | |||
| 56 | the CWP_TMPDIR environment variable is set use | ||
| 57 | |||
| 58 | its value for the path; else use tmpfile() | ||
| 59 | |||
| 60 | |||
| 61 | |||
| 62 | verbose=0 verbose = 1 echoes flip info | ||
| 63 | |||
| 64 | |||
| 65 | |||
| 66 | NOTE: tr.dt header field is lost if flip=-1,+1. It can be | ||
| 67 | |||
| 68 | reset using sushw. | ||
| 69 | |||
| 70 | |||
| 71 | |||
| 72 | EXAMPLE PROCESSING SEQUENCES: | ||
| 73 | |||
| 74 | 1. suflip flip=-1 <data1 | sushw key=dt a=4000 >data2 | ||
| 75 | |||
| 76 | |||
| 77 | |||
| 78 | 2. suflip flip=2 <data1 | suflip flip=2 >data1_again | ||
| 79 | |||
| 80 | |||
| 81 | |||
| 82 | 3. suflip tmpdir=/scratch <data1 | ... | ||
| 83 | |||
| 84 | |||
| 85 | |||
| 86 | Caveat: may fail on large files. | ||
| 87 | |||
| 88 | |||
| 89 | |||
| 90 | Credits: | ||
| 91 | |||
| 92 | CWP: Chris Liner, Jack K. Cohen, John Stockwell | ||
| 93 | |||
| 94 | |||
| 95 | |||
| 96 | Caveat: | ||
| 97 | |||
| 98 | right-left flip (flip = 2) and top-bottom flip (flip = 3) | ||
| 99 | |||
| 100 | don't require the matrix approach. We sacrificed efficiency | ||
| 101 | |||
| 102 | for uniform coding. | ||
| 103 | |||
| 104 | |||
| 105 | |||
| 106 | Trace header fields accessed: ns, dt | ||
| 107 | |||
| 108 | Trace header fields modified: ns, dt, tracl | ||
| 109 | |||
| 110 | |||
| 111 | |||
| 112 | =head2 CHANGES and their DATES - JML | ||
| 113 | |||
| 114 | V0.0.2 April 2024 | ||
| 115 | |||
| 116 | incorporates a list of files to flip individually | ||
| 117 | |||
| 118 | =cut | ||
| 119 | |||
| 120 | use Moose; | ||
| 121 | our $VERSION = '0.0.2'; | ||
| 122 | |||
| 123 | |||
| 124 | =head2 Import packages | ||
| 125 | |||
| 126 | =cut | ||
| 127 | |||
| 128 | use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants'; | ||
| 129 | |||
| 130 | use App::SeismicUnixGui::misc::SeismicUnix qw($flip $in $out $on $go $to $suffix_ascii $off $suffix_su $suffix_bin); | ||
| 131 | use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config'; | ||
| 132 | use aliased 'App::SeismicUnixGui::misc::manage_files_by2'; | ||
| 133 | |||
| 134 | =head2 instantiation of packages | ||
| 135 | |||
| 136 | =cut | ||
| 137 | |||
| 138 | my $get = L_SU_global_constants->new(); | ||
| 139 | my $Project = Project_config->new(); | ||
| 140 | my $manage_files_by2 = manage_files_by2->new(); | ||
| 141 | my $DATA_SEISMIC_SU = $Project->DATA_SEISMIC_SU(); | ||
| 142 | my $DATA_SEISMIC_BIN = $Project->DATA_SEISMIC_BIN(); | ||
| 143 | my $DATA_SEISMIC_TXT = $Project->DATA_SEISMIC_TXT(); | ||
| 144 | |||
| 145 | my $var = $get->var(); | ||
| 146 | my $on = $var->{_on}; | ||
| 147 | my $off = $var->{_off}; | ||
| 148 | my $true = $var->{_true}; | ||
| 149 | my $false = $var->{_false}; | ||
| 150 | my $empty_string = $var->{_empty_string}; | ||
| 151 | |||
| 152 | |||
| 153 | =head2 clear memeory | ||
| 154 | |||
| 155 | |||
| 156 | =cut | ||
| 157 | |||
| 158 | #$manage_files_by2->clear(); | ||
| 159 | |||
| 160 | =head2 Encapsulated | ||
| 161 | |||
| 162 | hash of private variables | ||
| 163 | |||
| 164 | =cut | ||
| 165 | |||
| 166 | my $suflip = { | ||
| 167 | _flip => '', | ||
| 168 | _inbound_list => '', | ||
| 169 | _tmpdir => '', | ||
| 170 | _verbose => '', | ||
| 171 | _Step => '', | ||
| 172 | _note => '', | ||
| 173 | |||
| 174 | }; | ||
| 175 | |||
| 176 | =head2 sub Step | ||
| 177 | |||
| 178 | collects switches and assembles bash instructions | ||
| 179 | by adding the program name | ||
| 180 | |||
| 181 | =cut | ||
| 182 | |||
| 183 | sub Step { | ||
| 184 | |||
| 185 | my ($self) = @_; | ||
| 186 | |||
| 187 | # simple check | ||
| 188 | if ( length $suflip->{_inbound_list} ) { | ||
| 189 | my $file_num; | ||
| 190 | my @Step; | ||
| 191 | my $step; | ||
| 192 | |||
| 193 | my ($inbound_aref) = _get_inbound4base_file_names(); | ||
| 194 | my ($outbound_aref) = _get_outbound4base_file_names(); | ||
| 195 | my @inbound = @$inbound_aref; | ||
| 196 | my @outbound = @$outbound_aref; | ||
| 197 | my $num_of_files = scalar @outbound; | ||
| 198 | |||
| 199 | # print("Step,inbound: @inbound\n"); | ||
| 200 | # print("Step,inbound: @outbound\n"); | ||
| 201 | |||
| 202 | my $last_idx = $num_of_files - 1; | ||
| 203 | |||
| 204 | # All cases when num_traces >=0 | ||
| 205 | # for first file | ||
| 206 | $step = " suflip $suflip->{_Step} < $inbound[0] > $outbound[0] "; | ||
| 207 | |||
| 208 | if ( $last_idx >= 2 ) { | ||
| 209 | |||
| 210 | # CASE: >= 3 operations | ||
| 211 | for ( my $i = 1 ; $i < $last_idx ; $i++ ) { | ||
| 212 | |||
| 213 | $step = | ||
| 214 | $step . "& suflip $suflip->{_Step} < $inbound[$i] > $outbound[$i] "; | ||
| 215 | |||
| 216 | } | ||
| 217 | |||
| 218 | # for last file | ||
| 219 | $suflip->{_Step} = | ||
| 220 | $step . "& suflip $suflip->{_Step} < $inbound[$last_idx] > $outbound[$last_idx]"; | ||
| 221 | |||
| 222 | } | ||
| 223 | elsif ( $last_idx == 1 ) { | ||
| 224 | |||
| 225 | # for last file | ||
| 226 | $suflip->{_Step} = | ||
| 227 | $step . "& suflip $suflip->{_Step} < $inbound[$last_idx] > $outbound[$last_idx] "; | ||
| 228 | |||
| 229 | } | ||
| 230 | elsif ( $last_idx == 0 ) { | ||
| 231 | |||
| 232 | $suflip->{_Step} = $step; | ||
| 233 | |||
| 234 | } | ||
| 235 | else { | ||
| 236 | print("suflip,Step,unexpected case\n"); | ||
| 237 | return(); | ||
| 238 | } | ||
| 239 | |||
| 240 | return ($suflip->{_Step}); | ||
| 241 | |||
| 242 | } | ||
| 243 | elsif ( not length $suflip->{_inbound_list} ) { | ||
| 244 | |||
| 245 | $suflip->{_Step} = 'suflip'.$suflip->{_Step}; | ||
| 246 | return ( $suflip->{_Step} ); | ||
| 247 | } | ||
| 248 | else { | ||
| 249 | print("suflip, Step, incorrect parameters\n"); | ||
| 250 | } | ||
| 251 | } | ||
| 252 | |||
| 253 | |||
| 254 | =head2 sub note | ||
| 255 | |||
| 256 | collects switches and assembles bash instructions | ||
| 257 | by adding the program name | ||
| 258 | |||
| 259 | =cut | ||
| 260 | |||
| 261 | sub note { | ||
| 262 | |||
| 263 | $suflip->{_note} = 'suflip'.$suflip->{_note}; | ||
| 264 | return ( $suflip->{_note} ); | ||
| 265 | |||
| 266 | } | ||
| 267 | |||
| 268 | |||
| 269 | =head2 sub clear | ||
| 270 | |||
| 271 | =cut | ||
| 272 | |||
| 273 | sub clear { | ||
| 274 | |||
| 275 | $suflip->{_flip} = ''; | ||
| 276 | $suflip->{_tmpdir} = ''; | ||
| 277 | $suflip->{_verbose} = ''; | ||
| 278 | $suflip->{_Step} = ''; | ||
| 279 | $suflip->{_note} = ''; | ||
| 280 | } | ||
| 281 | |||
| 282 | #=head2 sub _get_base_file_names_aref | ||
| 283 | # | ||
| 284 | #read a list of file names | ||
| 285 | #remove the su suffix | ||
| 286 | #return array reference of the | ||
| 287 | #list of names without su suffixes | ||
| 288 | # | ||
| 289 | #=cut | ||
| 290 | # | ||
| 291 | #sub _get_base_file_name_aref { | ||
| 292 | # my ($self) = @_; | ||
| 293 | # | ||
| 294 | # if ( length $suflip->{_inbound_list} ) { | ||
| 295 | # | ||
| 296 | # my $inbound_list = $suflip->{_inbound_list}; | ||
| 297 | # | ||
| 298 | # my ( $file_names_aref, $num_files ) = $readfiles->cols_1p($inbound_list); | ||
| 299 | # $control->set_aref($file_names_aref); | ||
| 300 | # $control->remove_su_suffix4aref(); | ||
| 301 | # my $base_file_name_aref = $control->get_base_file_name_aref(); | ||
| 302 | # | ||
| 303 | # print("suflip, _get_base_file_names, values=@$base_file_name_aref\n"); | ||
| 304 | # | ||
| 305 | # my $result_a = $base_file_name_aref; | ||
| 306 | # my $result_b = $num_files; | ||
| 307 | # return ( $result_a, $result_b); | ||
| 308 | # | ||
| 309 | # } | ||
| 310 | # else { | ||
| 311 | # print("_get_base_file_name_aref, missing inbound lsit\n"); | ||
| 312 | # return (); | ||
| 313 | # } | ||
| 314 | #} | ||
| 315 | |||
| 316 | #=head2 sub _get_file_names | ||
| 317 | # | ||
| 318 | #=cut | ||
| 319 | # | ||
| 320 | #sub _get_file_names { | ||
| 321 | # my ($self) = @_; | ||
| 322 | # | ||
| 323 | # if ( length $suflip->{_inbound_list} ) { | ||
| 324 | # | ||
| 325 | ## _set_inbound_list(); | ||
| 326 | # | ||
| 327 | # my $inbound_list = $suflip->{_inbound_list}; | ||
| 328 | # | ||
| 329 | # my ( $file_names_ref, $num_files ) = $readfiles->cols_1p($inbound_list); | ||
| 330 | # my $result_a = $file_names_ref; | ||
| 331 | # my $result_b = $num_files; | ||
| 332 | # | ||
| 333 | # # print("_get_file_names, values=@$file_names_ref\n"); | ||
| 334 | # return ( $result_a, $result_b ); | ||
| 335 | # | ||
| 336 | # } | ||
| 337 | # else { | ||
| 338 | # print("_get_file_names, missing inbound\n"); | ||
| 339 | # return (); | ||
| 340 | # } | ||
| 341 | # | ||
| 342 | #} | ||
| 343 | |||
| 344 | =head2 sub _get_inbound4base_file_names | ||
| 345 | |||
| 346 | =cut | ||
| 347 | |||
| 348 | sub _get_inbound4base_file_names { | ||
| 349 | my ($self) = @_; | ||
| 350 | |||
| 351 | # my ( $array_ref, $num_files ) = _get_base_file_name_aref(); | ||
| 352 | my ( $array_ref, $num_files ) = $manage_files_by2->get_base_file_name_aref(); | ||
| 353 | |||
| 354 | if ( defined $array_ref && @$array_ref ) { | ||
| 355 | |||
| 356 | my @base_file_name = @$array_ref; | ||
| 357 | my @inbound; | ||
| 358 | |||
| 359 | for ( my $i = 0 ; $i < $num_files ; $i++ ) { | ||
| 360 | |||
| 361 | $inbound[$i] = $DATA_SEISMIC_SU . '/' . $base_file_name[$i].$suffix_su; | ||
| 362 | |||
| 363 | } | ||
| 364 | return ( \@inbound ); | ||
| 365 | |||
| 366 | } | ||
| 367 | else { | ||
| 368 | print("suflip,_get_inbound4base_file_names, missing file names\n"); | ||
| 369 | return (); | ||
| 370 | } | ||
| 371 | |||
| 372 | } | ||
| 373 | |||
| 374 | =head2 sub _get_outbound4base_file_names | ||
| 375 | |||
| 376 | =cut | ||
| 377 | |||
| 378 | sub _get_outbound4base_file_names { | ||
| 379 | my ($self) = @_; | ||
| 380 | |||
| 381 | # my ( $array_ref, $num_files ) = _get_base_file_name_aref(); | ||
| 382 | my ( $array_ref, $num_files ) = $manage_files_by2->get_base_file_name_aref(); | ||
| 383 | |||
| 384 | if ( length $array_ref ) { | ||
| 385 | |||
| 386 | my @base_file_name = @$array_ref; | ||
| 387 | my @outbound; | ||
| 388 | |||
| 389 | for ( my $i = 0 ; $i < $num_files ; $i++ ) { | ||
| 390 | |||
| 391 | $outbound[$i] = $DATA_SEISMIC_SU . '/' . $base_file_name[$i]. '_'. $flip.$suffix_su; | ||
| 392 | |||
| 393 | } | ||
| 394 | return ( \@outbound ); | ||
| 395 | |||
| 396 | } | ||
| 397 | else { | ||
| 398 | print("suflip,_get_outbound4basefile_names, missing file names\n"); | ||
| 399 | return (); | ||
| 400 | } | ||
| 401 | |||
| 402 | } | ||
| 403 | |||
| 404 | #=head2 sub _set_inbound_list | ||
| 405 | # | ||
| 406 | #=cut | ||
| 407 | # | ||
| 408 | #sub _set_inbound_list { | ||
| 409 | # my ($self) = @_; | ||
| 410 | # | ||
| 411 | # if ( length $suflip->{_inbound_list} ) { | ||
| 412 | # | ||
| 413 | # my $inbound_list = $suflip->{_inbound_list}; | ||
| 414 | # $control->set_back_slashBgone($inbound_list); | ||
| 415 | # $inbound_list = $control->get_back_slashBgone(); | ||
| 416 | # $suflip->{_inbound_list} = $inbound_list; | ||
| 417 | # | ||
| 418 | # } | ||
| 419 | # else { | ||
| 420 | # print("_set_inbound_list, missing list\n"); | ||
| 421 | # return (); | ||
| 422 | # } | ||
| 423 | # | ||
| 424 | #} | ||
| 425 | |||
| 426 | =head2 sub flip | ||
| 427 | |||
| 428 | |||
| 429 | =cut | ||
| 430 | |||
| 431 | sub flip { | ||
| 432 | |||
| 433 | my ( $self,$flip ) = @_; | ||
| 434 | if ( $flip ne $empty_string ) { | ||
| 435 | |||
| 436 | $suflip->{_flip} = $flip; | ||
| 437 | $suflip->{_note} = $suflip->{_note}.' flip='.$suflip->{_flip}; | ||
| 438 | $suflip->{_Step} = $suflip->{_Step}.' flip='.$suflip->{_flip}; | ||
| 439 | |||
| 440 | } else { | ||
| 441 | print("suflip, flip, missing flip,\n"); | ||
| 442 | } | ||
| 443 | } | ||
| 444 | |||
| 445 | =head2 sub list | ||
| 446 | |||
| 447 | list array | ||
| 448 | |||
| 449 | =cut | ||
| 450 | |||
| 451 | sub list { | ||
| 452 | my ( $self, $list ) = @_; | ||
| 453 | |||
| 454 | if ( length $list ) { | ||
| 455 | |||
| 456 | # clear memory | ||
| 457 | $manage_files_by2->clear(); | ||
| 458 | |||
| 459 | $suflip->{_inbound_list} = $list; | ||
| 460 | |||
| 461 | $manage_files_by2->set_inbound_list($list); | ||
| 462 | |||
| 463 | # _set_inbound_list(); #tbd | ||
| 464 | |||
| 465 | # print("suflip,list is $suflip->{_inbound_list}\n\n"); | ||
| 466 | |||
| 467 | } | ||
| 468 | else { | ||
| 469 | print("suflip, list, missing list,\n"); | ||
| 470 | } | ||
| 471 | return (); | ||
| 472 | } | ||
| 473 | |||
| 474 | =head2 sub tmpdir | ||
| 475 | |||
| 476 | |||
| 477 | =cut | ||
| 478 | |||
| 479 | sub tmpdir { | ||
| 480 | |||
| 481 | my ( $self,$tmpdir ) = @_; | ||
| 482 | if ( $tmpdir ne $empty_string ) { | ||
| 483 | |||
| 484 | $suflip->{_tmpdir} = $tmpdir; | ||
| 485 | $suflip->{_note} = $suflip->{_note}.' tmpdir='.$suflip->{_tmpdir}; | ||
| 486 | $suflip->{_Step} = $suflip->{_Step}.' tmpdir='.$suflip->{_tmpdir}; | ||
| 487 | |||
| 488 | } else { | ||
| 489 | print("suflip, tmpdir, missing tmpdir,\n"); | ||
| 490 | } | ||
| 491 | } | ||
| 492 | |||
| 493 | |||
| 494 | =head2 sub verbose | ||
| 495 | |||
| 496 | |||
| 497 | =cut | ||
| 498 | |||
| 499 | sub verbose { | ||
| 500 | |||
| 501 | my ( $self,$verbose ) = @_; | ||
| 502 | if ( $verbose ne $empty_string ) { | ||
| 503 | |||
| 504 | $suflip->{_verbose} = $verbose; | ||
| 505 | $suflip->{_note} = $suflip->{_note}.' verbose='.$suflip->{_verbose}; | ||
| 506 | $suflip->{_Step} = $suflip->{_Step}.' verbose='.$suflip->{_verbose}; | ||
| 507 | |||
| 508 | } else { | ||
| 509 | print("suflip, verbose, missing verbose,\n"); | ||
| 510 | } | ||
| 511 | } | ||
| 512 | |||
| 513 | |||
| 514 | =head2 sub get_max_index | ||
| 515 | |||
| 516 | max index = number of input variables -1 | ||
| 517 | |||
| 518 | =cut | ||
| 519 | |||
| 520 | sub get_max_index { | ||
| 521 | my ($self) = @_; | ||
| 522 | my $max_index = 3; | ||
| 523 | |||
| 524 | return($max_index); | ||
| 525 | } | ||
| 526 | |||
| 527 | |||
| 528 | 1; |