« lib/App/SeismicUnixGui/big_streams/iWrite_All_iva_out.pm
↑ Summary
lib/App/SeismicUnixGui/sunix/transform/sufft.pm »
| 1 | package App::SeismicUnixGui::sunix::shapeNcut::susort; | ||
| 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 | SUSORT - sort on any segy header keywords | ||
| 25 | |||
| 26 | |||
| 27 | |||
| 28 | |||
| 29 | |||
| 30 | susort <stdin >stdout [[+-]key1 [+-]key2 ...] | ||
| 31 | |||
| 32 | |||
| 33 | |||
| 34 | Susort supports any number of (secondary) keys with either | ||
| 35 | |||
| 36 | ascending (+, the default) or descending (-) directions for | ||
| 37 | |||
| 38 | each. The default sort key is cdp. | ||
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | Note: Only the following types of input/output are supported | ||
| 43 | |||
| 44 | Disk input --> any output | ||
| 45 | |||
| 46 | Pipe input --> Disk output | ||
| 47 | |||
| 48 | |||
| 49 | |||
| 50 | Caveat: On some Linux systems Pipe input and or output often | ||
| 51 | |||
| 52 | fails | ||
| 53 | |||
| 54 | Disk input ---> Disk output is recommended | ||
| 55 | |||
| 56 | |||
| 57 | |||
| 58 | Note: If the the CWP_TMPDIR environment variable is set use | ||
| 59 | |||
| 60 | its value for the path; else use tmpfile() | ||
| 61 | |||
| 62 | |||
| 63 | |||
| 64 | Example: | ||
| 65 | |||
| 66 | To sort traces by cdp gather and within each gather | ||
| 67 | |||
| 68 | by offset with both sorts in ascending order: | ||
| 69 | |||
| 70 | |||
| 71 | |||
| 72 | key1 = cdp | ||
| 73 | |||
| 74 | key2 = offset | ||
| 75 | |||
| 76 | |||
| 77 | |||
| 78 | susort <INDATA >OUTDATA cdp offset | ||
| 79 | |||
| 80 | |||
| 81 | |||
| 82 | Caveat: In the case of Pipe input a temporary file is made | ||
| 83 | |||
| 84 | to hold the ENTIRE data set. This temporary is | ||
| 85 | |||
| 86 | either an actual disk file (usually in /tmp) or in some | ||
| 87 | |||
| 88 | implementations, a memory buffer. It is left to the | ||
| 89 | |||
| 90 | user to be SENSIBLE about how big a file to pipe into | ||
| 91 | |||
| 92 | susort relative to the user's computer. | ||
| 93 | |||
| 94 | |||
| 95 | |||
| 96 | |||
| 97 | |||
| 98 | Credits: | ||
| 99 | |||
| 100 | SEP: Einar Kjartansson , Stew Levin | ||
| 101 | |||
| 102 | CWP: Shuki Ronen, Jack K. Cohen | ||
| 103 | |||
| 104 | |||
| 105 | |||
| 106 | Caveats: | ||
| 107 | |||
| 108 | Since the algorithm depends on sign reversal of the key value | ||
| 109 | |||
| 110 | to obtain a descending sort, the most significant figure may | ||
| 111 | |||
| 112 | be lost for unsigned data types. The old SEP support for tape | ||
| 113 | |||
| 114 | input was removed in version 1.16---version 1.15 is in the | ||
| 115 | |||
| 116 | Portability directory for those who may want to input SU data | ||
| 117 | |||
| 118 | stored on tape. | ||
| 119 | |||
| 120 | |||
| 121 | |||
| 122 | Trace header fields modified: tracl, tracr | ||
| 123 | |||
| 124 | |||
| 125 | |||
| 126 | =head2 User's notes (Juan Lorenzo) | ||
| 127 | untested | ||
| 128 | |||
| 129 | =cut | ||
| 130 | |||
| 131 | |||
| 132 | =head2 CHANGES and their DATES | ||
| 133 | |||
| 134 | =cut | ||
| 135 | |||
| 136 | use Moose; | ||
| 137 | our $VERSION = '0.0.1'; | ||
| 138 | |||
| 139 | |||
| 140 | =head2 Import packages | ||
| 141 | |||
| 142 | =cut | ||
| 143 | |||
| 144 | use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants'; | ||
| 145 | |||
| 146 | use App::SeismicUnixGui::misc::SeismicUnix qw($go $in $off $on $out $ps $to $suffix_ascii $suffix_bin $suffix_ps $suffix_segy $suffix_su); | ||
| 147 | use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config'; | ||
| 148 | use App::SeismicUnixGui::misc::control '0.0.3'; | ||
| 149 | use aliased 'App::SeismicUnixGui::misc::control'; | ||
| 150 | |||
| 151 | |||
| 152 | =head2 instantiation of packages | ||
| 153 | |||
| 154 | =cut | ||
| 155 | |||
| 156 | my $get = L_SU_global_constants->new(); | ||
| 157 | my $Project = Project_config->new(); | ||
| 158 | my $DATA_SEISMIC_SU = $Project->DATA_SEISMIC_SU(); | ||
| 159 | my $DATA_SEISMIC_BIN = $Project->DATA_SEISMIC_BIN(); | ||
| 160 | my $DATA_SEISMIC_TXT = $Project->DATA_SEISMIC_TXT(); | ||
| 161 | |||
| 162 | my $PS_SEISMIC = $Project->PS_SEISMIC(); | ||
| 163 | |||
| 164 | my $var = $get->var(); | ||
| 165 | my $on = $var->{_on}; | ||
| 166 | my $off = $var->{_off}; | ||
| 167 | my $true = $var->{_true}; | ||
| 168 | my $false = $var->{_false}; | ||
| 169 | my $empty_string = $var->{_empty_string}; | ||
| 170 | |||
| 171 | =head2 Encapsulated | ||
| 172 | hash of private variables | ||
| 173 | |||
| 174 | =cut | ||
| 175 | |||
| 176 | my $susort = { | ||
| 177 | _header_word => '', | ||
| 178 | _key1 => '', | ||
| 179 | _key2 => '', | ||
| 180 | _Step => '', | ||
| 181 | _note => '', | ||
| 182 | |||
| 183 | }; | ||
| 184 | |||
| 185 | =head2 sub Step | ||
| 186 | |||
| 187 | collects switches and assembles bash instructions | ||
| 188 | by adding the program name | ||
| 189 | |||
| 190 | =cut | ||
| 191 | |||
| 192 | sub Step { | ||
| 193 | |||
| 194 | $susort->{_Step} = 'susort'.$susort->{_Step}; | ||
| 195 | return ( $susort->{_Step} ); | ||
| 196 | |||
| 197 | } | ||
| 198 | |||
| 199 | |||
| 200 | =head2 sub note | ||
| 201 | |||
| 202 | collects switches and assembles bash instructions | ||
| 203 | by adding the program name | ||
| 204 | |||
| 205 | =cut | ||
| 206 | |||
| 207 | sub note { | ||
| 208 | |||
| 209 | $susort->{_note} = 'susort'.$susort->{_note}; | ||
| 210 | return ( $susort->{_note} ); | ||
| 211 | |||
| 212 | } | ||
| 213 | |||
| 214 | |||
| 215 | =head2 sub clear | ||
| 216 | |||
| 217 | =cut | ||
| 218 | |||
| 219 | sub clear { | ||
| 220 | $susort->{_header_word} = ''; | ||
| 221 | $susort->{_key1} = ''; | ||
| 222 | $susort->{_key2} = ''; | ||
| 223 | $susort->{_Step} = ''; | ||
| 224 | $susort->{_note} = ''; | ||
| 225 | } | ||
| 226 | |||
| 227 | |||
| 228 | =head2 sub header_word | ||
| 229 | |||
| 230 | |||
| 231 | =cut | ||
| 232 | |||
| 233 | sub header_word { | ||
| 234 | |||
| 235 | my ( $self, $old_header_word ) = @_; | ||
| 236 | |||
| 237 | if ( $old_header_word ne $empty_string ) { | ||
| 238 | |||
| 239 | my ( $new_header_word, $header_no_commas ); | ||
| 240 | |||
| 241 | my $control = control->new(); | ||
| 242 | |||
| 243 | $control->set_commas2space($old_header_word); | ||
| 244 | $header_no_commas = $control->get_commas2space(); | ||
| 245 | |||
| 246 | $control->set_back_slashBgone($header_no_commas); | ||
| 247 | $new_header_word = $control->get_back_slashBgone($header_no_commas); | ||
| 248 | |||
| 249 | # print("susort, new_header_words, $new_header_word \n"); | ||
| 250 | |||
| 251 | $susort->{_header_word} = $new_header_word; | ||
| 252 | |||
| 253 | $susort->{_note} = $susort->{_note} . ' ' . $susort->{_header_word}; | ||
| 254 | $susort->{_Step} = $susort->{_Step} . ' ' . $susort->{_header_word}; | ||
| 255 | |||
| 256 | } | ||
| 257 | else { | ||
| 258 | print("susort, header_words, missing header_word,\n"); | ||
| 259 | } | ||
| 260 | } | ||
| 261 | |||
| 262 | =head2 sub headerword | ||
| 263 | |||
| 264 | legacy Nov 2 2018 | ||
| 265 | selects which headerword on which to sort in the order provided | ||
| 266 | multiple calls to this subroutine | ||
| 267 | will work | ||
| 268 | |||
| 269 | =cut | ||
| 270 | |||
| 271 | sub headerword { | ||
| 272 | |||
| 273 | my ( $self, $header_word ) = @_; | ||
| 274 | if ($header_word) { | ||
| 275 | |||
| 276 | $susort->{_header_word} = $header_word; | ||
| 277 | $susort->{_note} = $susort->{_note} . ' ' . $susort->{_header_word}; | ||
| 278 | $susort->{_Step} = $susort->{_Step} . ' ' . $susort->{_header_word}; | ||
| 279 | |||
| 280 | } | ||
| 281 | else { | ||
| 282 | print("susort, headerword, missing headerword,\n"); | ||
| 283 | } | ||
| 284 | } | ||
| 285 | |||
| 286 | |||
| 287 | |||
| 288 | =head2 sub key1 | ||
| 289 | |||
| 290 | |||
| 291 | =cut | ||
| 292 | |||
| 293 | sub key1 { | ||
| 294 | |||
| 295 | my ( $self,$key1 ) = @_; | ||
| 296 | if ( $key1 ne $empty_string ) { | ||
| 297 | |||
| 298 | $susort->{_key1} = $key1; | ||
| 299 | $susort->{_note} = $susort->{_note}.' key1='.$susort->{_key1}; | ||
| 300 | $susort->{_Step} = $susort->{_Step}.' key1='.$susort->{_key1}; | ||
| 301 | |||
| 302 | } else { | ||
| 303 | print("susort, key1, missing key1,\n"); | ||
| 304 | } | ||
| 305 | } | ||
| 306 | |||
| 307 | |||
| 308 | =head2 sub key2 | ||
| 309 | |||
| 310 | |||
| 311 | =cut | ||
| 312 | |||
| 313 | sub key2 { | ||
| 314 | |||
| 315 | my ( $self,$key2 ) = @_; | ||
| 316 | if ( $key2 ne $empty_string ) { | ||
| 317 | |||
| 318 | $susort->{_key2} = $key2; | ||
| 319 | $susort->{_note} = $susort->{_note}.' key2='.$susort->{_key2}; | ||
| 320 | $susort->{_Step} = $susort->{_Step}.' key2='.$susort->{_key2}; | ||
| 321 | |||
| 322 | } else { | ||
| 323 | print("susort, key2, missing key2,\n"); | ||
| 324 | } | ||
| 325 | } | ||
| 326 | |||
| 327 | |||
| 328 | =head2 sub get_max_index | ||
| 329 | |||
| 330 | max index = number of input variables -1 | ||
| 331 | |||
| 332 | =cut | ||
| 333 | |||
| 334 | sub get_max_index { | ||
| 335 | my ($self) = @_; | ||
| 336 | my $max_index = 0; | ||
| 337 | |||
| 338 | return($max_index); | ||
| 339 | } | ||
| 340 | |||
| 341 | |||
| 342 | 1; |