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

filter: Statementstmt 0.0% 0 / 138 Branchbran 0.0% 0 / 36 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 24 Podpod 0.0% 0 / 22 totaltotal 0.0% 0 / 220 CC 19 SCAR 16.9
CC
19
Cov
0%
a
6.0
add_to_all
6.0
b
6.0
CRAP 5.4
1 package App::SeismicUnixGui::sunix::header::suchw;
2  
3 =head1 DOCUMENTATION
4  
5 =head2 SYNOPSIS
6  
7 PERL PROGRAM NAME: SUCHW - Change Header Word using one or two header word fields
8 AUTHOR: Juan Lorenzo (Perl module only)
9 DATE:
10 DESCRIPTION: Nov 3 2013,
11 Version: 0.1
12  
13 =head2 USE
14 suchw->clear();
15 suchw->();
16 $suchw[1] = suchw->Step();
17  
18 =head3 NOTES
19  
20 This program derives from suchw in Seismic Unix
21 "notes" keeps track of actions for possible use in graphics
22 "steps" keeps track of actions for execution in the system
23  
24 =head4 Examples
25  
26 =head3 SEISMIC UNIX NOTES
27  
28 SUCHW - Change Header Word using one or two header word fields
29  
30 suchw <stdin >stdout [optional parameters]
31  
32 Required parameters:
33 none
34  
35 Optional parameters:
36 key1=cdp,... output key(s)
37 key2=cdp,... input key(s)
38 key3=cdp,... input key(s)
39 a=0,... overall shift(s)
40 b=1,... scale(s) on first input key(s)
41 c=0,... scale on second input key(s)
42 d=1,... overall scale(s)
43 e=1,... exponent on first input key(s)
44 f=1,... exponent on second input key(s)
45  
46 The value of header word key1 is computed from the values of
47 key2 and key3 by:
48  
49 val(key1) = (a + b * val(key2)^e + c * val(key3)^f) / d
50  
51 Examples:
52 Shift cdp numbers by -1:
53 suchw <data >outdata a=-1
54  
55 Add 1000 to tracr value:
56 suchw key1=tracr key2=tracr a=1000 <infile >outfile
57  
58 We set the receiver point (gx) field by summing the offset
59 and shot point (sx) fields and then we set the cdp field by
60 averaging the sx and gx fields (we choose to use the actual
61 locations for the cdp fields instead of the conventional
62 1, 2, 3, ... enumeration):
63  
64 suchw <indata key1=gx key2=offset key3=sx b=1 c=1 |
65 suchw key1=cdp key2=gx key3=sx b=1 c=1 d=2 >outdata
66  
67 Do both operations in one call:
68  
69 suchw<indata key1=gx,cdp key2=offset,gx key3=sx,sx b=1,1 c=1,1 d=1,2 >outdata
70  
71  
72 Credits:
73 SEP: Einar Kjartansson
74 CWP: Jack K. Cohen
75 CWP: John Stockwell, 7 July 1995, added array of keys feature
76 Delphi: Alexander Koek, 6 November 1995, changed calculation so
77 headers of different types can be expressed in each other
78  
79 =head2 CHANGES and their DATES
80  
81 =cut
82  
83 use Moose;
84 our $VERSION = '0.0.1';
85  
86 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
87  
88 my $get = L_SU_global_constants->new();
89  
90 my $var = $get->var();
91 my $empty_string = $var->{_empty_string};
92  
93 my $suchw = {
94 _a => '',
95 _b => '',
96 _c => '',
97 _d => '',
98 _e => '',
99 _f => '',
100 _key1 => '',
101 _key2 => '',
102 _key3 => '',
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 $suchw->{_Step} = 'suchw' . $suchw->{_Step};
117 return ( $suchw->{_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 $suchw->{_note} = 'suchw' . $suchw->{_note};
131 return ( $suchw->{_note} );
132  
133 }
134  
135 =head2 sub clear
136  
137 =cut
138  
139 sub clear {
140  
141 $suchw->{_a} = '';
142 $suchw->{_b} = '';
143 $suchw->{_c} = '';
144 $suchw->{_d} = '';
145 $suchw->{_e} = '';
146 $suchw->{_f} = '';
147 $suchw->{_key1} = '';
148 $suchw->{_key2} = '';
149 $suchw->{_key3} = '';
150 $suchw->{_Step} = '';
151 $suchw->{_note} = '';
152 }
153  
154 # define a value
155 my $newline = '
156 ';
157  
158 =head2 sub a
159  
160  
161 subs a, add_to_all
162 add the following
163 value after
164 all other operations
165 are complete
166  
167 =cut
168  
169 sub a {
170  
171 my ( $self, $a ) = @_;
172 if ($a) {
173  
174 $suchw->{_a} = $a;
175 $suchw->{_note} = $suchw->{_note} . ' a=' . $suchw->{_a};
176 $suchw->{_Step} = $suchw->{_Step} . ' a=' . $suchw->{_a};
177  
178 }
179 else {
180 print("suchw, a, missing a,\n");
181 }
182 }
183  
184 =head2 sub add_to_all
185  
186  
187 subs a, add_to_all
188 add the following
189 value after
190 all other operations
191 are complete
192  
193 =cut
194  
195 sub add_to_all {
196  
197 my ( $self, $a ) = @_;
198 if ( $a ne $empty_string ) {
199  
200 $suchw->{_a} = $a;
201 $suchw->{_note} = $suchw->{_note} . ' a=' . $suchw->{_a};
202 $suchw->{_Step} = $suchw->{_Step} . ' a=' . $suchw->{_a};
203  
204 }
205 else {
206 print("suchw, add_to_all, missing add_to_all,\n");
207 }
208 }
209  
210 =head2 sub b
211  
212 Multiply first header values by
213 this constant
214  
215 =cut
216  
217 sub b {
218  
219 my ( $self, $b ) = @_;
220 if ( $b ne $empty_string ) {
221  
222 $suchw->{_b} = $b;
223 $suchw->{_note} = $suchw->{_note} . ' b=' . $suchw->{_b};
224 $suchw->{_Step} = $suchw->{_Step} . ' b=' . $suchw->{_b};
225  
226 }
227 else {
228 print("suchw, b, missing b,\n");
229 }
230 }
231  
232 =head2 sub c
233  
234 Multiply second header values by
235 this constant
236  
237 =cut
238  
239 sub c {
240  
241 my ( $self, $c ) = @_;
242 if ( $c ne $empty_string ) {
243  
244 $suchw->{_c} = $c;
245 $suchw->{_note} = $suchw->{_note} . ' c=' . $suchw->{_c};
246 $suchw->{_Step} = $suchw->{_Step} . ' c=' . $suchw->{_c};
247  
248 }
249 else {
250 print("suchw, c, missing c,\n");
251 }
252 }
253  
254 =head2 sub d
255  
256 After all calculations are complete
257 divide the result by
258  
259 =cut
260  
261 sub d {
262  
263 my ( $self, $d ) = @_;
264 if ( $d ne $empty_string ) {
265  
266 $suchw->{_d} = $d;
267 $suchw->{_note} = $suchw->{_note} . ' d=' . $suchw->{_d};
268 $suchw->{_Step} = $suchw->{_Step} . ' d=' . $suchw->{_d};
269  
270 }
271 else {
272 print("suchw, d, missing d,\n");
273 }
274 }
275  
276 =head2 sub divide_all_by
277  
278 After all calculations are complete
279 divide the result by
280  
281 =cut
282  
283 sub divide_all_by {
284  
285 my ( $self, $d ) = @_;
286 if ( $d ne $empty_string ) {
287  
288 $suchw->{_d} = $d;
289 $suchw->{_note} = $suchw->{_note} . ' d=' . $suchw->{_d};
290 $suchw->{_Step} = $suchw->{_Step} . ' d=' . $suchw->{_d};
291  
292 }
293 else {
294 print("suchw, divide_all_by, missing divide_all_by,\n");
295 }
296 }
297  
298 =head2 sub e
299  
300 Raise the first header values to
301 a given power
302  
303 =cut
304  
305 sub e {
306  
307 my ( $self, $e ) = @_;
308 if ( $e ne $empty_string ) {
309  
310 $suchw->{_e} = $e;
311 $suchw->{_note} = $suchw->{_note} . ' e=' . $suchw->{_e};
312 $suchw->{_Step} = $suchw->{_Step} . ' e=' . $suchw->{_e};
313  
314 }
315 else {
316 print("suchw, e, missing e,\n");
317 }
318 }
319  
320 =head2 sub f
321  
322 Raise the second header values to
323 a given power
324  
325 =cut
326  
327 sub f {
328  
329 my ( $self, $f ) = @_;
330 if ( $f ne $empty_string ) {
331  
332 $suchw->{_f} = $f;
333 $suchw->{_note} = $suchw->{_note} . ' f=' . $suchw->{_f};
334 $suchw->{_Step} = $suchw->{_Step} . ' f=' . $suchw->{_f};
335  
336 }
337 else {
338 print("suchw, f, missing f,\n");
339 }
340 }
341  
342 =head2 sub first_header
343  
344 select the first header value to use
345  
346 =cut
347  
348 sub first_header {
349  
350 my ( $self, $key2 ) = @_;
351 if ( $key2 ne $empty_string ) {
352  
353 $suchw->{_key2} = $key2;
354 $suchw->{_note} = $suchw->{_note} . ' key2=' . $suchw->{_key2};
355 $suchw->{_Step} = $suchw->{_Step} . ' key2=' . $suchw->{_key2};
356  
357 }
358 else {
359 print("suchw, first_header, missing first_header,\n");
360 }
361 }
362  
363 =head2 sub hdr1_exponent
364  
365 Raise the first header values to
366 a given power
367  
368 =cut
369  
370 sub hdr1_exponent {
371  
372 my ( $self, $e ) = @_;
373 if ( $e ne $empty_string ) {
374  
375 $suchw->{_e} = $e;
376 $suchw->{_note} = $suchw->{_note} . ' e=' . $suchw->{_e};
377 $suchw->{_Step} = $suchw->{_Step} . ' e=' . $suchw->{_e};
378  
379 }
380 else {
381 print("suchw, hdr1_exponent, missing hdr1_exponent,\n");
382 }
383 }
384  
385 =head2 sub hdr2_exponent
386  
387 Raise the second header values to
388 a given power
389  
390 =cut
391  
392 sub hdr2_exponent {
393  
394 my ( $self, $f ) = @_;
395 if ( $f ne $empty_string ) {
396  
397 $suchw->{_f} = $f;
398 $suchw->{_note} = $suchw->{_note} . ' f=' . $suchw->{_f};
399 $suchw->{_Step} = $suchw->{_Step} . ' f=' . $suchw->{_f};
400  
401 }
402 else {
403 print("suchw, hdr2_exponent, missing hdr2_exponent,\n");
404 }
405 }
406  
407 =head2 sub key1
408  
409 select the result header value to use
410  
411 =cut
412  
413 sub key1 {
414  
415 my ( $self, $key1 ) = @_;
416 if ( $key1 ne $empty_string ) {
417  
418 $suchw->{_key1} = $key1;
419 $suchw->{_note} = $suchw->{_note} . ' key1=' . $suchw->{_key1};
420 $suchw->{_Step} = $suchw->{_Step} . ' key1=' . $suchw->{_key1};
421  
422 }
423 else {
424 print("suchw, key1, missing key1,\n");
425 }
426 }
427  
428 =head2 sub key2
429  
430 select the first header value to use
431  
432 =cut
433  
434 sub key2 {
435  
436 my ( $self, $key2 ) = @_;
437 if ( $key2 ne $empty_string ) {
438  
439 $suchw->{_key2} = $key2;
440 $suchw->{_note} = $suchw->{_note} . ' key2=' . $suchw->{_key2};
441 $suchw->{_Step} = $suchw->{_Step} . ' key2=' . $suchw->{_key2};
442  
443 }
444 else {
445 print("suchw, key2, missing key2,\n");
446 }
447 }
448  
449 =head2 sub key3
450  
451 select the second header value to use
452  
453 =cut
454  
455 sub key3 {
456  
457 my ( $self, $key3 ) = @_;
458 if ( $key3 ne $empty_string ) {
459  
460 $suchw->{_key3} = $key3;
461 $suchw->{_note} = $suchw->{_note} . ' key3=' . $suchw->{_key3};
462 $suchw->{_Step} = $suchw->{_Step} . ' key3=' . $suchw->{_key3};
463  
464 }
465 else {
466 print("suchw, key3, missing key3,\n");
467 }
468 }
469  
470 =head2 sub multiply_hdr1_by
471  
472 Multiply first header values by
473 this constant
474  
475 =cut
476  
477 sub multiply_hdr1_by {
478  
479 my ( $self, $b ) = @_;
480 if ( $b ne $empty_string ) {
481  
482 $suchw->{_b} = $b;
483 $suchw->{_note} = $suchw->{_note} . ' b=' . $suchw->{_b};
484 $suchw->{_Step} = $suchw->{_Step} . ' b=' . $suchw->{_b};
485  
486 }
487 else {
488 print("suchw, multiply_hdr1_by, missing multiply_hdr1_by,\n");
489 }
490 }
491  
492 =head2 sub multiply_hdr2_by
493  
494 Multiply second header values by
495 this constant
496  
497 =cut
498  
499 sub multiply_hdr2_by {
500  
501 my ( $self, $c ) = @_;
502 if ( $c ne $empty_string ) {
503  
504 $suchw->{_c} = $c;
505 $suchw->{_note} = $suchw->{_note} . ' c=' . $suchw->{_c};
506 $suchw->{_Step} = $suchw->{_Step} . ' c=' . $suchw->{_c};
507  
508 }
509 else {
510 print("suchw, multiply_hdr2_by, missing multiply_hdr2_by,\n");
511 }
512 }
513  
514 =head2 sub result_header
515  
516 select the result header value to use
517  
518 =cut
519  
520 sub result_header {
521  
522 my ( $self, $key1 ) = @_;
523 if ( $key1 ne $empty_string ) {
524  
525 $suchw->{_key1} = $key1;
526 $suchw->{_note} = $suchw->{_note} . ' key1=' . $suchw->{_key1};
527 $suchw->{_Step} = $suchw->{_Step} . ' key1=' . $suchw->{_key1};
528  
529 }
530 else {
531 print("suchw, result_header, missing result_header,\n");
532 }
533 }
534  
535 =head2 sub second_header
536  
537 select the second header value to use
538  
539 =cut
540  
541 sub second_header {
542  
543 my ( $self, $key3 ) = @_;
544 if ( $key3 ne $empty_string ) {
545  
546 $suchw->{_key3} = $key3;
547 $suchw->{_note} = $suchw->{_note} . ' key3=' . $suchw->{_key3};
548 $suchw->{_Step} = $suchw->{_Step} . ' key3=' . $suchw->{_key3};
549  
550 }
551 else {
552 print("suchw, second_header, missing second_header,\n");
553 }
554 }
555  
556 =head2 sub get_max_index
557
558 max index = number of input variables -1
559
560 =cut
561  
562 sub get_max_index {
563 my ($self) = @_;
564 my $max_index = 8;
565  
566 return ($max_index);
567 }
568  
569 1;