| 1 | package App::SeismicUnixGui::sunix::statsMath::sumax; | ||
| 2 | |||
| 3 | =head1 DOCUMENTATION | ||
| 4 | |||
| 5 | =head2 SYNOPSIS | ||
| 6 | |||
| 7 | PERL PROGRAM NAME: SUMAX - get trace by trace local/global maxima, minima, or absolute maximum | ||
| 8 | AUTHOR: Juan Lorenzo (Perl module only) | ||
| 9 | DATE: | ||
| 10 | DESCRIPTION: | ||
| 11 | Version: | ||
| 12 | |||
| 13 | =head2 USE | ||
| 14 | |||
| 15 | =head3 NOTES | ||
| 16 | |||
| 17 | =head4 Examples | ||
| 18 | |||
| 19 | =head3 SEISMIC UNIX NOTES | ||
| 20 | |||
| 21 | SUMAX - get trace by trace local/global maxima, minima, or absolute maximum | ||
| 22 | |||
| 23 | sumax <stdin >stdout [optional parameters] | ||
| 24 | |||
| 25 | Required parameters: | ||
| 26 | none | ||
| 27 | |||
| 28 | Optional parameters: | ||
| 29 | output=ascii write ascii data to outpar | ||
| 30 | =binary for binary floats to stdout | ||
| 31 | =segy for SEGY traces to stdout | ||
| 32 | |||
| 33 | mode=maxmin output both minima and maxima | ||
| 34 | =max maxima only | ||
| 35 | =min minima only | ||
| 36 | =abs absolute maxima only | ||
| 37 | =rms RMS | ||
| 38 | =thd search first max above threshold | ||
| 39 | |||
| 40 | threshamp=0 threshold amplitude value | ||
| 41 | threshtime=0 tmin to start search for threshold | ||
| 42 | |||
| 43 | verbose=0 writes global quantities to outpar | ||
| 44 | =1 trace number, values, sample location | ||
| 45 | =2 key1 & key2 instead of trace number | ||
| 46 | key1=fldr key for verbose=2 | ||
| 47 | key2=ep key for verbose=2 | ||
| 48 | |||
| 49 | outpar=/dev/tty output parameter file; contains output | ||
| 50 | from verbose | ||
| 51 | |||
| 52 | Examples: | ||
| 53 | For global max and min values: sumax < segy_data | ||
| 54 | For local and global max and min values: sumax < segy_data verbose=1 | ||
| 55 | To plot values specified by mode: | ||
| 56 | sumax < segy_data output=binary mode=modeval | xgraph n=npairs | ||
| 57 | To plot seismic data with the only values nonzero being those specified | ||
| 58 | by mode=modeval: | ||
| 59 | sumax < segy_data output=segy mode=modeval | suxwigb | ||
| 60 | |||
| 61 | Note: while traces are counted from 1, sample values are counted from 0. | ||
| 62 | Also, if multiple min, max, or abs max values exist on a trace, | ||
| 63 | only the first one is captured. | ||
| 64 | |||
| 65 | See also: suxmax, supsmax | ||
| 66 | |||
| 67 | Credits: | ||
| 68 | CWP : John Stockwell (total rewrite) | ||
| 69 | Geocon : Garry Perratt (all ASCII output changed from 0.000000e+00 to 0.000000e+00) | ||
| 70 | (added mode=rms). | ||
| 71 | ESCI: Reginald Beardsley (added header key option) | ||
| 72 | based on an original program by: | ||
| 73 | SEP: Shuki Ronen | ||
| 74 | CWP: Jack K. Cohen | ||
| 75 | IFM-GEOMAR: Gerald Klein (added threshold option) | ||
| 76 | |||
| 77 | Trace header fields accessed: ns dt & user specified keys | ||
| 78 | |||
| 79 | |||
| 80 | =head2 CHANGES and their DATES | ||
| 81 | |||
| 82 | =cut | ||
| 83 | |||
| 84 | use Moose; | ||
| 85 | our $VERSION = '0.0.1'; | ||
| 86 | |||
| 87 | use App::SeismicUnixGui::misc::L_SU_global_constants; | ||
| 88 | use App::SeismicUnixGui::misc::control '0.0.3'; | ||
| 89 | my $get = App::SeismicUnixGui::misc::L_SU_global_constants->new(); | ||
| 90 | |||
| 91 | my $var = $get->var(); | ||
| 92 | my $empty_string = $var->{_empty_string}; | ||
| 93 | |||
| 94 | my $sumax = { | ||
| 95 | _key1 => '', | ||
| 96 | _key2 => '', | ||
| 97 | _mode => '', | ||
| 98 | _outpar => '', | ||
| 99 | _output => '', | ||
| 100 | _threshamp => '', | ||
| 101 | _threshtime => '', | ||
| 102 | _verbose => '', | ||
| 103 | _Step => '', | ||
| 104 | _note => '', | ||
| 105 | }; | ||
| 106 | |||
| 107 | =head2 sub Step | ||
| 108 | |||
| 109 | collects switches and assembles bash instructions | ||
| 110 | by adding the program name | ||
| 111 | |||
| 112 | =cut | ||
| 113 | |||
| 114 | sub Step { | ||
| 115 | |||
| 116 | $sumax->{_Step} = 'sumax' . $sumax->{_Step}; | ||
| 117 | return ( $sumax->{_Step} ); | ||
| 118 | |||
| 119 | } | ||
| 120 | |||
| 121 | =head2 sub note | ||
| 122 | |||
| 123 | collects switches and assembles bash instructions | ||
| 124 | by adding the program name | ||
| 125 | |||
| 126 | =cut | ||
| 127 | |||
| 128 | sub note { | ||
| 129 | |||
| 130 | $sumax->{_note} = 'sumax' . $sumax->{_note}; | ||
| 131 | return ( $sumax->{_note} ); | ||
| 132 | |||
| 133 | } | ||
| 134 | |||
| 135 | =head2 sub clear | ||
| 136 | |||
| 137 | =cut | ||
| 138 | |||
| 139 | sub clear { | ||
| 140 | |||
| 141 | $sumax->{_key1} = ''; | ||
| 142 | $sumax->{_key2} = ''; | ||
| 143 | $sumax->{_mode} = ''; | ||
| 144 | $sumax->{_outpar} = ''; | ||
| 145 | $sumax->{_output} = ''; | ||
| 146 | $sumax->{_threshamp} = ''; | ||
| 147 | $sumax->{_threshtime} = ''; | ||
| 148 | $sumax->{_verbose} = ''; | ||
| 149 | $sumax->{_Step} = ''; | ||
| 150 | $sumax->{_note} = ''; | ||
| 151 | } | ||
| 152 | |||
| 153 | =head2 sub key1 | ||
| 154 | |||
| 155 | |||
| 156 | =cut | ||
| 157 | |||
| 158 | sub key1 { | ||
| 159 | |||
| 160 | my ( $self, $key1 ) = @_; | ||
| 161 | if ( $key1 ne $empty_string ) { | ||
| 162 | |||
| 163 | $sumax->{_key1} = $key1; | ||
| 164 | $sumax->{_note} = $sumax->{_note} . ' key1=' . $sumax->{_key1}; | ||
| 165 | $sumax->{_Step} = $sumax->{_Step} . ' key1=' . $sumax->{_key1}; | ||
| 166 | |||
| 167 | } | ||
| 168 | else { | ||
| 169 | print("sumax, key1, missing key1,\n"); | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | =head2 sub key2 | ||
| 174 | |||
| 175 | |||
| 176 | =cut | ||
| 177 | |||
| 178 | sub key2 { | ||
| 179 | |||
| 180 | my ( $self, $key2 ) = @_; | ||
| 181 | if ( $key2 ne $empty_string ) { | ||
| 182 | |||
| 183 | $sumax->{_key2} = $key2; | ||
| 184 | $sumax->{_note} = $sumax->{_note} . ' key2=' . $sumax->{_key2}; | ||
| 185 | $sumax->{_Step} = $sumax->{_Step} . ' key2=' . $sumax->{_key2}; | ||
| 186 | |||
| 187 | } | ||
| 188 | else { | ||
| 189 | print("sumax, key2, missing key2,\n"); | ||
| 190 | } | ||
| 191 | } | ||
| 192 | |||
| 193 | =head2 sub mode | ||
| 194 | |||
| 195 | |||
| 196 | =cut | ||
| 197 | |||
| 198 | sub mode { | ||
| 199 | |||
| 200 | my ( $self, $mode ) = @_; | ||
| 201 | if ( $mode ne $empty_string ) { | ||
| 202 | |||
| 203 | $sumax->{_mode} = $mode; | ||
| 204 | $sumax->{_note} = $sumax->{_note} . ' mode=' . $sumax->{_mode}; | ||
| 205 | $sumax->{_Step} = $sumax->{_Step} . ' mode=' . $sumax->{_mode}; | ||
| 206 | |||
| 207 | } | ||
| 208 | else { | ||
| 209 | print("sumax, mode, missing mode,\n"); | ||
| 210 | } | ||
| 211 | } | ||
| 212 | |||
| 213 | =head2 sub outpar | ||
| 214 | |||
| 215 | |||
| 216 | =cut | ||
| 217 | |||
| 218 | sub outpar { | ||
| 219 | |||
| 220 | my ( $self, $outpar ) = @_; | ||
| 221 | if ( defined $outpar | ||
| 222 | && $outpar ne $empty_string ) | ||
| 223 | { | ||
| 224 | |||
| 225 | use Scalar::Util qw(looks_like_number); | ||
| 226 | |||
| 227 | my $control = App::SeismicUnixGui::misc::control->new(); | ||
| 228 | |||
| 229 | # we should have a string and not a number | ||
| 230 | my $fmt = 0; | ||
| 231 | $fmt = looks_like_number($outpar); | ||
| 232 | |||
| 233 | if ($fmt) { | ||
| 234 | |||
| 235 | # print("sumax,outpar, outpar_value looks like a number BUT should be a string\n"); | ||
| 236 | |||
| 237 | } | ||
| 238 | else { | ||
| 239 | # print("sumax,outpar, looks like a string: $outpar\n"); | ||
| 240 | |||
| 241 | $control->set_back_slashBgone($outpar); | ||
| 242 | $outpar = $control->get_back_slashBgone(); | ||
| 243 | |||
| 244 | # print("sumax,outpar without back_slashes looks like $outpar \n"); | ||
| 245 | } | ||
| 246 | |||
| 247 | $sumax->{_outpar} = $outpar; | ||
| 248 | |||
| 249 | # print("sumax,outpar, $outpar\n"); | ||
| 250 | |||
| 251 | if ( defined $sumax->{_output} | ||
| 252 | && $sumax->{_output} ne $empty_string | ||
| 253 | && $sumax->{_outpar} ne '/dev/tty' ) | ||
| 254 | { | ||
| 255 | |||
| 256 | my $Project = Project_config->new(); | ||
| 257 | |||
| 258 | my $base_file_name = $outpar; | ||
| 259 | my $output = $sumax->{_output}; | ||
| 260 | |||
| 261 | if ( $output eq 'segy' ) { | ||
| 262 | |||
| 263 | my $DATA_SEISMIC_SEGY = $Project->DATA_SEISMIC_SEGY(); | ||
| 264 | $sumax->{_outpar} = $DATA_SEISMIC_SEGY . '/' . $base_file_name; | ||
| 265 | |||
| 266 | } | ||
| 267 | elsif ( $output eq 'ascii' ) { | ||
| 268 | |||
| 269 | my $DATA_SEISMIC_TXT = $Project->DATA_SEISMIC_TXT(); | ||
| 270 | $sumax->{_outpar} = $DATA_SEISMIC_TXT . '/' . $base_file_name; | ||
| 271 | |||
| 272 | } | ||
| 273 | elsif ( $output eq 'binary' ) { | ||
| 274 | |||
| 275 | my $DATA_SEISMIC_BIN = $Project->DATA_SEISMIC_BIN(); | ||
| 276 | $sumax->{_outpar} = $DATA_SEISMIC_BIN . '/' . $base_file_name; | ||
| 277 | |||
| 278 | } | ||
| 279 | else { | ||
| 280 | print("sumax,outpar, unexpected output parameter\n"); | ||
| 281 | } | ||
| 282 | |||
| 283 | } | ||
| 284 | else { | ||
| 285 | # print("sumax,outpar,missing output or output is /dev/tty \n"); | ||
| 286 | } | ||
| 287 | |||
| 288 | $sumax->{_note} = $sumax->{_note} . ' outpar=' . $sumax->{_outpar}; | ||
| 289 | $sumax->{_Step} = $sumax->{_Step} . ' outpar=' . $sumax->{_outpar}; | ||
| 290 | |||
| 291 | } | ||
| 292 | else { | ||
| 293 | print("sumax, outpar, missing outpar,\n"); | ||
| 294 | } | ||
| 295 | } | ||
| 296 | |||
| 297 | =head2 sub output | ||
| 298 | |||
| 299 | |||
| 300 | =cut | ||
| 301 | |||
| 302 | sub output { | ||
| 303 | |||
| 304 | my ( $self, $output ) = @_; | ||
| 305 | if ( $output ne $empty_string ) { | ||
| 306 | |||
| 307 | $sumax->{_output} = $output; | ||
| 308 | $sumax->{_note} = $sumax->{_note} . ' output=' . $sumax->{_output}; | ||
| 309 | $sumax->{_Step} = $sumax->{_Step} . ' output=' . $sumax->{_output}; | ||
| 310 | |||
| 311 | } | ||
| 312 | else { | ||
| 313 | print("sumax, output, missing output,\n"); | ||
| 314 | } | ||
| 315 | } | ||
| 316 | |||
| 317 | =head2 sub threshamp | ||
| 318 | |||
| 319 | |||
| 320 | =cut | ||
| 321 | |||
| 322 | sub threshamp { | ||
| 323 | |||
| 324 | my ( $self, $threshamp ) = @_; | ||
| 325 | if ( $threshamp ne $empty_string ) { | ||
| 326 | |||
| 327 | $sumax->{_threshamp} = $threshamp; | ||
| 328 | $sumax->{_note} = | ||
| 329 | $sumax->{_note} . ' threshamp=' . $sumax->{_threshamp}; | ||
| 330 | $sumax->{_Step} = | ||
| 331 | $sumax->{_Step} . ' threshamp=' . $sumax->{_threshamp}; | ||
| 332 | |||
| 333 | } | ||
| 334 | else { | ||
| 335 | print("sumax, threshamp, missing threshamp,\n"); | ||
| 336 | } | ||
| 337 | } | ||
| 338 | |||
| 339 | =head2 sub threshtime | ||
| 340 | |||
| 341 | |||
| 342 | =cut | ||
| 343 | |||
| 344 | sub threshtime { | ||
| 345 | |||
| 346 | my ( $self, $threshtime ) = @_; | ||
| 347 | if ( $threshtime ne $empty_string ) { | ||
| 348 | |||
| 349 | $sumax->{_threshtime} = $threshtime; | ||
| 350 | $sumax->{_note} = | ||
| 351 | $sumax->{_note} . ' threshtime=' . $sumax->{_threshtime}; | ||
| 352 | $sumax->{_Step} = | ||
| 353 | $sumax->{_Step} . ' threshtime=' . $sumax->{_threshtime}; | ||
| 354 | |||
| 355 | } | ||
| 356 | else { | ||
| 357 | print("sumax, threshtime, missing threshtime,\n"); | ||
| 358 | } | ||
| 359 | } | ||
| 360 | |||
| 361 | =head2 sub verbose | ||
| 362 | |||
| 363 | |||
| 364 | =cut | ||
| 365 | |||
| 366 | sub verbose { | ||
| 367 | |||
| 368 | my ( $self, $verbose ) = @_; | ||
| 369 | if ( $verbose ne $empty_string ) { | ||
| 370 | |||
| 371 | $sumax->{_verbose} = $verbose; | ||
| 372 | $sumax->{_note} = $sumax->{_note} . ' verbose=' . $sumax->{_verbose}; | ||
| 373 | $sumax->{_Step} = $sumax->{_Step} . ' verbose=' . $sumax->{_verbose}; | ||
| 374 | |||
| 375 | } | ||
| 376 | else { | ||
| 377 | print("sumax, verbose, missing verbose,\n"); | ||
| 378 | } | ||
| 379 | } | ||
| 380 | |||
| 381 | =head2 sub get_max_index | ||
| 382 | |||
| 383 | max index = number of input variables -1 | ||
| 384 | |||
| 385 | =cut | ||
| 386 | |||
| 387 | sub get_max_index { | ||
| 388 | my ($self) = @_; | ||
| 389 | my $max_index = 7; | ||
| 390 | |||
| 391 | return ($max_index); | ||
| 392 | } | ||
| 393 | |||
| 394 | 1; |