lib/App/SeismicUnixGui/sunix/header/sushw.pm untested

filter: Statementstmt 0.0% 0 / 124 Branchbran 0.0% 0 / 34 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 22 Podpod 0.0% 0 / 20 totaltotal 0.0% 0 / 200 CC 18 SCAR 17.7
CC
18
Cov
0%
sample_interval_s
12.0
a
6.0
b
6.0
CRAP 5.8
1 package App::SeismicUnixGui::sunix::header::sushw;
2  
3 =head1 DOCUMENTATION
4  
5 =head2 SYNOPSIS
6  
7 PERL PROGRAM NAME: SUSHW - Set one or more Header Words using trace number, mod and
8
9 AUTHOR: Juan Lorenzo (Perl module only)
10  
11 DATE:
12
13 DESCRIPTION:
14
15 Version:
16  
17 =head2 USE
18  
19 =head3 NOTES
20  
21 =head4 Examples
22  
23 =head3 SEISMIC UNIX NOTES
24  
25 SUSHW - Set one or more Header Words using trace number, mod and
26 integer divide to compute the header word values or input
27 the header word values from a file
28  
29 ... compute header fields
30 sushw <stdin >stdout key=cdp,.. a=0,.. b=0,.. c=0,.. d=0,.. j=..,..
31  
32 ... or read headers from a binary file
33 sushw <stdin > stdout key=key1,.. infile=binary_file
34  
35  
36 Required Parameters for setting headers from infile:
37 key=key1,key2 ... is the list of header fields as they appear in infile
38 infile= binary file of values for field specified by
39 key1,key2,...
40  
41 Optional parameters ():
42 key=cdp,... header key word(s) to set
43 a=0,... value(s) on first trace
44 b=0,... increment(s) within group
45 c=0,... group increment(s)
46 d=0,... trace number shift(s)
47 j=ULONG_MAX,ULONG_MAX,... number of elements in group
48  
49 Notes:
50 Fields that are getparred must have the same number of entries as key
51 words being set. Any field that is not getparred is set to the default
52 value(s) above. Explicitly setting j=0 will set j to ULONG_MAX.
53  
54 The value of each header word key is computed using the formula:
55 i = itr + d
56 val(key) = a + b * (i % j) + c * (int(i / j))
57 where itr is the trace number (first trace has itr=0, NOT 1)
58  
59 Examples:
60 1. set every dt field to 4ms
61 sushw <indata key=dt a=4000 |...
62 2. set the sx field of the first 32 traces to 6400, the second 32 traces
63 to 6300, decrementing by -100 for each 32 trace groups
64 ...| sushw key=sx a=6400 c=-100 j=32 |...
65 3. set the offset fields of each group of 32 traces to 200,400,...,6400
66 ...| sushw key=offset a=200 b=200 j=32 |...
67 4. perform operations 1., 2., and 3. in one call
68 ..| sushw key=dt,sx,offset a=4000,6400,200 b=0,0,200 c=0,-100,0 j=0,32,32 |
69  
70 In this example, we set every dt field to 4ms. Then we set the first
71 32 shotpoint fields to 6400, the second 32 shotpoint fields to 6300 and
72 so forth. Next we set each group of 32 offset fields to 200, 400, ...,
73 6400.
74  
75 Example of a typical processing sequence using suchw:
76 sushw <indata key=dt a=4000 |
77 sushw key=sx a=6400 c=-100 j=32 |
78 sushw key=offset a=200 b=200 j=32 |
79 suchw key1=gx key2=offset key3=sx b=1 c=1 |
80 suchw key1=cdp key2=gx key3=sx b=1 c=1 d=2 >outdata
81  
82 Again, it is possible to eliminate the multiple calls to both sushw and
83 sushw, as in Example 4.
84  
85 Reading header values from a binary file:
86 If the parameter infile=binary_file is set, then the values that are to
87 be set for the fields specified by key=key1,key2,... are read from that
88 file. The values are read sequentially from the file and assigned trace
89 by trace to the input SU data. The infile consists of C (unformated)
90 binary floats in the form of an array of size (nkeys)*(ntraces) where
91 nkeys is the number of floats in the first (fast) dimension and ntraces
92 is the number of traces.
93  
94 Comment:
95 Users wishing to edit one or more header fields (as in geometry setting)
96 may do this via the following sequence:
97 sugethw < sudata output=geom key=key1,key2 ... > hdrfile
98 Now edit the ASCII file hdrfile with any editor, setting the fields
99 appropriately. Convert hdrfile to a binary format via:
100 a2b < hdrfile n1=nfields > binary_file
101 Then set the header fields via:
102 sushw < sudata infile=binary_file key=key1,key2,... > sudata.edited
103  
104 Caveat:
105 If the (number of traces)*(number of key words) exceeds the number of
106 values in the infile then the user may still set a single header field
107 on the remaining traces via the parameters key=keyword a,b,c,d,j.
108  
109 Example:
110 sushw < sudata=key1,key2 ... infile=binary_file [Optional Parameters]
111  
112 Credits:
113 SEP: Einar Kajartansson
114 CWP: Jack K. Cohen
115 CWP: John Stockwell, added multiple fields and infile= options
116  
117 Caveat:
118 All constants are cast to doubles.
119  
120 =head2 CHANGES and their DATES
121  
122 =cut
123  
124 use Moose;
125 our $VERSION = '0.0.1';
126  
127 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
128  
129 my $get = L_SU_global_constants->new();
130  
131 my $var = $get->var();
132 my $empty_string = $var->{_empty_string};
133  
134 my $sushw = {
135 _a => '',
136 _b => '',
137 _c => '',
138 _d => '',
139 _infile => '',
140 _j => '',
141 _key => '',
142 _Step => '',
143 _note => '',
144 };
145  
146 # define a value
147 my $newline = '
148 ';
149  
150 =head2 sub Step
151  
152 collects switches and assembles bash instructions
153 by adding the program name
154  
155 =cut
156  
157 sub Step {
158  
159 $sushw->{_Step} = 'sushw' . $sushw->{_Step};
160 return ( $sushw->{_Step} );
161  
162 }
163  
164 =head2 sub note
165  
166 collects switches and assembles bash instructions
167 by adding the program name
168  
169 =cut
170  
171 sub note {
172  
173 $sushw->{_note} = 'sushw' . $sushw->{_note};
174 return ( $sushw->{_note} );
175  
176 }
177  
178 =head2 sub clear
179  
180 =cut
181  
182 sub clear {
183  
184 $sushw->{_a} = '';
185 $sushw->{_b} = '';
186 $sushw->{_c} = '';
187 $sushw->{_d} = '';
188 $sushw->{_infile} = '';
189 $sushw->{_j} = '';
190 $sushw->{_key} = '';
191 $sushw->{_Step} = '';
192 $sushw->{_note} = '';
193 }
194  
195 =head2 sub a
196  
197 subs a,first_value
198 handles first value of the trace
199  
200 =cut
201  
202 sub a {
203  
204 my ( $self, $a ) = @_;
205 if ( $a ne $empty_string ) {
206  
207 $sushw->{_a} = $a;
208 $sushw->{_note} = $sushw->{_note} . ' a=' . $sushw->{_a};
209 $sushw->{_Step} = $sushw->{_Step} . ' a=' . $sushw->{_a};
210  
211 }
212 else {
213 print("sushw, a, missing a,\n");
214 }
215 }
216  
217 =head2 sub b
218  
219 Increment between traces within a single
220 gather; this increment is assigned when moving on to
221 a subsequent gather.
222  
223 =cut
224  
225 sub b {
226  
227 my ( $self, $b ) = @_;
228 if ( $b ne $empty_string ) {
229  
230 $sushw->{_b} = $b;
231 $sushw->{_note} = $sushw->{_note} . ' b=' . $sushw->{_b};
232 $sushw->{_Step} = $sushw->{_Step} . ' b=' . $sushw->{_b};
233  
234 }
235 else {
236 print("sushw, b, missing b,\n");
237 }
238 }
239  
240 =head2 sub c
241  
242 Increment assigned to all traces within a single
243 gather; this increment is assigned when moving on to
244 a subsequent gather.
245  
246 =cut
247  
248 sub c {
249  
250 my ( $self, $c ) = @_;
251 if ( $c ne $empty_string ) {
252  
253 $sushw->{_c} = $c;
254 $sushw->{_note} = $sushw->{_note} . ' c=' . $sushw->{_c};
255 $sushw->{_Step} = $sushw->{_Step} . ' c=' . $sushw->{_c};
256  
257 }
258 else {
259 print("sushw, c, missing c,\n");
260 }
261 }
262  
263 =head2 sub d
264  
265 value to add to words
266  
267 =cut
268  
269 sub d {
270  
271 my ( $self, $d ) = @_;
272 if ( $d ne $empty_string ) {
273  
274 $sushw->{_d} = $d;
275 $sushw->{_note} = $sushw->{_note} . ' d=' . $sushw->{_d};
276 $sushw->{_Step} = $sushw->{_Step} . ' d=' . $sushw->{_d};
277  
278 }
279 else {
280 print("sushw, d, missing d,\n");
281 }
282 }
283  
284 #=head4
285 #
286 # sub first_val
287 # handles first value of the trace
288 #
289 #=cut
290 #
291 #sub first_val{
292 # my (@first_val) = @_;
293 # $sushw->{_first_val} = @first_val if @first_val;
294 #
295 # # get possible array length
296 # my $first_val_num = scalar($sushw->{_first_val})-1;
297 #
298 # # first case
299 # $sushw->{_note} = $sushw->{_note}.' a='.$first_val[1];
300 # $sushw->{_Step} = $sushw->{_Step}.' a='.$first_val[1];
301 #
302 # # if there is more than a single key name word
303 # for (my $i=2; $i<=$first_val_num; $i++) {
304 # $sushw->{_note} = $sushw->{_note}.','.$first_val[$i];
305 # $sushw->{_Step} = $sushw->{_Step}.','.$first_val[$i];
306 # }
307 #}
308  
309 =head2 sub first_val
310  
311 subs a,first_value
312 handles first value of the trace
313  
314 =cut
315  
316 sub first_val {
317  
318 my ( $self, $a ) = @_;
319 if ( $a ne $empty_string ) {
320  
321 $sushw->{_a} = $a;
322 $sushw->{_note} = $sushw->{_note} . ' a=' . $sushw->{_a};
323 $sushw->{_Step} = $sushw->{_Step} . ' a=' . $sushw->{_a};
324  
325 }
326 else {
327 print("sushw, first_val, missing first_value,\n");
328 }
329 }
330  
331 =head2 sub first_value
332  
333 subs a,first_value
334 handles first value of the trace
335  
336 =cut
337  
338 sub first_value {
339  
340 my ( $self, $a ) = @_;
341 if ( $a ne $empty_string ) {
342  
343 $sushw->{_a} = $a;
344 $sushw->{_note} = $sushw->{_note} . ' a=' . $sushw->{_a};
345 $sushw->{_Step} = $sushw->{_Step} . ' a=' . $sushw->{_a};
346  
347 }
348 else {
349 print("sushw, first_value, missing first_value,\n");
350 }
351 }
352  
353 =head2 sub gather_size
354  
355 how many traces are in gather
356 or group of traces of interest
357  
358 =cut
359  
360 sub gather_size {
361  
362 my ( $self, $j ) = @_;
363 if ( $j ne $empty_string ) {
364  
365 $sushw->{_j} = $j;
366 $sushw->{_note} = $sushw->{_note} . ' j=' . $sushw->{_j};
367 $sushw->{_Step} = $sushw->{_Step} . ' j=' . $sushw->{_j};
368  
369 }
370 else {
371 print("sushw, gather_size, missing gather_size,\n");
372 }
373 }
374  
375 =head2 sub header_bias
376  
377 value to add to words
378  
379 =cut
380  
381 sub header_bias {
382  
383 my ( $self, $d ) = @_;
384 if ( $d ne $empty_string ) {
385  
386 $sushw->{_d} = $d;
387 $sushw->{_note} = $sushw->{_note} . ' d=' . $sushw->{_d};
388 $sushw->{_Step} = $sushw->{_Step} . ' d=' . $sushw->{_d};
389  
390 }
391 else {
392 print("sushw, header_bias, missing header_bias,\n");
393 }
394 }
395  
396 =head2 sub headerwords
397  
398 subs name, key select the names to change
399  
400 =cut
401  
402 sub headerwords {
403  
404 my ( $self, $key ) = @_;
405 if ( $key ne $empty_string ) {
406  
407 $sushw->{_key} = $key;
408 $sushw->{_note} = $sushw->{_note} . ' key=' . $sushw->{_key};
409 $sushw->{_Step} = $sushw->{_Step} . ' key=' . $sushw->{_key};
410  
411 }
412 else {
413 print("sushw, headerwords, missing headerwords,\n");
414 }
415 }
416  
417 =head2 sub infile
418  
419  
420 =cut
421  
422 sub infile {
423  
424 my ( $self, $infile ) = @_;
425 if ( $infile ne $empty_string ) {
426  
427 $sushw->{_infile} = $infile;
428 $sushw->{_note} = $sushw->{_note} . ' infile=' . $sushw->{_infile};
429 $sushw->{_Step} = $sushw->{_Step} . ' infile=' . $sushw->{_infile};
430  
431 }
432 else {
433 print("sushw, infile, missing infile,\n");
434 }
435 }
436  
437 =head2 sub inter_gather_inc
438  
439 Increment assigned to all traces within a single
440 gather; this increment is assigned when moving on to
441 a subsequent gather.
442  
443 =cut
444  
445 sub inter_gather_inc {
446  
447 my ( $self, $c ) = @_;
448 if ( $c ne $empty_string ) {
449  
450 $sushw->{_c} = $c;
451 $sushw->{_note} = $sushw->{_note} . ' c=' . $sushw->{_c};
452 $sushw->{_Step} = $sushw->{_Step} . ' c=' . $sushw->{_c};
453  
454 }
455 else {
456 print("sushw, inter_gather_inc, missing inter_gather_inc,\n");
457 }
458 }
459  
460 =head2 sub intra_gather_inc
461  
462 Increment between traces within a single
463 gather; this increment is assigned when moving on to
464 a subsequent gather.
465  
466 =cut
467  
468 sub intra_gather_inc {
469  
470 my ( $self, $b ) = @_;
471 if ( $b ne $empty_string ) {
472  
473 $sushw->{_b} = $b;
474 $sushw->{_note} = $sushw->{_note} . ' b=' . $sushw->{_b};
475 $sushw->{_Step} = $sushw->{_Step} . ' b=' . $sushw->{_b};
476  
477 }
478 else {
479 print("sushw, intra_gather_inc, missing intra_gather_inc,\n");
480 }
481 }
482  
483 =head2 sub j
484  
485 how many traces are in gather
486 or group of traces of interest
487  
488 =cut
489  
490 sub j {
491  
492 my ( $self, $j ) = @_;
493 if ( $j ne $empty_string ) {
494  
495 $sushw->{_j} = $j;
496 $sushw->{_note} = $sushw->{_note} . ' j=' . $sushw->{_j};
497 $sushw->{_Step} = $sushw->{_Step} . ' j=' . $sushw->{_j};
498  
499 }
500 else {
501 print("sushw, j, missing j,\n");
502 }
503 }
504  
505 =head2 sub key
506  
507 subs name, key select the names to change
508  
509 =cut
510  
511 sub key {
512  
513 my ( $self, $key ) = @_;
514 if ( $key ne $empty_string ) {
515  
516 $sushw->{_key} = $key;
517 $sushw->{_note} = $sushw->{_note} . ' key=' . $sushw->{_key};
518 $sushw->{_Step} = $sushw->{_Step} . ' key=' . $sushw->{_key};
519  
520 }
521 else {
522 print("sushw, key, missing key,\n");
523 }
524 }
525  
526 #=head2 subroutine name
527 #
528 # select the names to change
529 #
530 #=cut
531 #
532 #sub name {
533 # my (@names) = @_;
534 # $sushw->{_names} = @names if @names;
535 #
536 # #get possible array length
537 # my $hdr_num = scalar($sushw->{_names})-1;
538 #
539 # # first case
540 # $sushw->{_note} = $sushw->{_note}.' key='.$names[1];
541 # $sushw->{_Step} = $sushw->{_Step}.' key='.$names[1];
542 #
543 # # if there is more than a single key name word
544 # for (my $i=2; $i<=$hdr_num; $i++) {
545 # $sushw->{_note} = $sushw->{_note}.','.$names[$i];
546 # $sushw->{_Step} = $sushw->{_Step}.','.$names[$i];
547 # }
548 #}
549  
550 =head2 sub name
551  
552 subs name, key select the names to change
553  
554 =cut
555  
556 sub name {
557  
558 my ( $self, $key ) = @_;
559 if ( $key ne $empty_string ) {
560  
561 $sushw->{_key} = $key;
562 $sushw->{_note} = $sushw->{_note} . ' key=' . $sushw->{_key};
563 $sushw->{_Step} = $sushw->{_Step} . ' key=' . $sushw->{_key};
564  
565 }
566 else {
567 print("sushw, name, missing name,\n");
568 }
569 }
570  
571 =head4 sub sample_interval_s
572  
573 In clase that you only want to
574 change a single value
575 in all the traces
576  
577  
578 =cut
579  
580 =head2 sub sudata
581  
582  
583 =cut
584  
585 sub sample_interval_s {
586 my ( $test, $sample_interval_s ) = @_;
587  
588 if ( $sample_interval_s ne $empty_string ) {
589  
590 #print("num sample interval in s is $sample_interval_s\n\n");
591 #print("test is $test\n\n");
592 # convert to microseconds
593 $sushw->{_sample_interval_s} = ( $sample_interval_s * 1000000 )
594 if defined($sample_interval_s);
595  
596 #print("num sample interval in us is $sushw->{_sample_interval_s}\n\n");
597 $sushw->{_Step} =
598 $sushw->{_Step} . ' key=dt a=' . $sushw->{_sample_interval_s};
599 $sushw->{_note} =
600 $sushw->{_note} . ' key=dt a=' . $sushw->{_sample_interval_s};
601  
602 }
603 else {
604 print("sushw, sample_interval_s, missing sample_interval_s\n");
605 }
606 }
607  
608 =head2 sub get_max_index
609
610 max index = number of input variables -1
611
612 =cut
613  
614 sub get_max_index {
615 my ($self) = @_;
616  
617 # only file_name : index=6
618 my $max_index = 6;
619  
620 return ($max_index);
621 }
622  
623 1;