lib/App/SeismicUnixGui/sunix/shapeNcut/sukill.pm untested

filter: Statementstmt 0.0% 0 / 161 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 22 Podpod 0.0% 0 / 16 totaltotal 0.0% 0 / 247 CC 18 SCAR 23.6
CC
18
Cov
0%
Step
42.0
_check4inbound_listNkey
6.0
_get_inbound
6.0
CRAP 10.6
1 package App::SeismicUnixGui::sunix::shapeNcut::sukill;
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: 0.0.2 1.30.23
14  
15 =head2 USE
16  
17 Typical usage 1:
18 To kill a single of trace number
19 count=1 (default if omitted)
20  
21 Internal code example
22 $sukill->min('2');
23 $sukill->Step()
24  
25 Usage 2:
26 $sukill->list(list_of_traces_to_kill)
27 $sukill->su_base_file_name(file_in_seismic_unix_format)
28  
29 =head3 NOTES
30  
31 =head4 Examples
32  
33 =head2 SYNOPSIS
34  
35 =head3 SEISMIC UNIX NOTES
36 SUKILL - zero out traces
37  
38 sukill <stdin >stdout [optional parameters]
39  
40 Optional parameters:
41  
42 key=trid header name to select traces to kill
43  
44 a=2 header value identifying traces to kill
45  
46 or
47  
48 min= first trace to kill (one-based)
49  
50 count=1 number of traces to kill
51  
52  
53 Notes:
54  
55 If min= is set it overrides selecting traces by header.
56  
57  
58 Credits:
59  
60 CWP: Chris Liner, Jack K. Cohen
61  
62 header-based trace selection: Florian Bleibinhaus
63  
64  
65 Trace header fields accessed: ns
66  
67  
68 =head2 CHANGES and their DATES
69  
70 JML V0.0.2, 1.30.23
71  
72 Normally, sukill can kill contiguous traces.
73 To kill while skipping traces requires an
74 iteration (i.e., logical for loop) over the same file.
75
76 In V0.0.2 I wrap an extension to process an arbitrary
77 list of trace numbers. I automate the iteration by including
78 two additional parameters: list and su_base_file_name
79
80 The parameter "list" is the name of a text file.
81 The file is automatically bound to the SEIMICS_DATA_TXT
82 directory path.
83
84 "list" is the name of a file containing a numeric list
85 of trace numbers of type "key" that are to be deleted:
86
87 An example list
88 file contains values, one per line.
89 1
90 3
91 5
92  
93 "list" = a file name (in directory path: DATA_SEISMICS_TXT)
94
95 su_base_file_name = e.g., 1001, which by defaults lies
96 in directory path: DATA_SEISMIC_SU.
97 A bare file name: '1001' will automatically be given an suffix
98 The file name on the disk will be '1001.su'
99
100 Notes:
101 If list is used then su_base_file_name and key MUST be used
102 If list is used ONLY su_base_file_name and key CAN be used
103  
104 Within code, the imported "list" includes path and name;
105 hence its name: _inbound_list. User enters a list name in
106 GUI using the mouse <MB3>.
107  
108 =cut
109  
110 use Moose;
111 our $VERSION = '0.0.2';
112  
113 =head2 Import packages
114  
115 =cut
116  
117 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
118 use App::SeismicUnixGui::misc::SeismicUnix
119 qw($in $out $on $go $to $suffix_ascii $off $out $suffix_su $suffix_txt $txt $suffix_bin $to);
120 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
121 use aliased 'App::SeismicUnixGui::misc::control';
122 use aliased 'App::SeismicUnixGui::misc::readfiles';
123  
124 =head2 instantiation of packages
125  
126 =cut
127  
128 my $get = L_SU_global_constants->new();
129 my $Project = Project_config->new();
130 my $control = control->new();
131 my $readfiles = readfiles->new();
132 my $DATA_SEISMIC_SU = $Project->DATA_SEISMIC_SU();
133 my $DATA_SEISMIC_BIN = $Project->DATA_SEISMIC_BIN();
134  
135 my $var = $get->var();
136 my $on = $var->{_on};
137 my $off = $var->{_off};
138 my $true = $var->{_true};
139 my $false = $var->{_false};
140 my $empty_string = $var->{_empty_string};
141 my $default = $txt;
142  
143 =head2 Encapsulated
144 hash of private variables
145  
146 =cut
147  
148 my $sukill = {
149 _a => '',
150 _count => '',
151 _inbound_su_base_file_name => '',
152 _key => '',
153 _inbound_list => '',
154 _min => '',
155 _Step => '',
156 _note => '',
157  
158 };
159  
160 $sukill->{_data_type} = $default;
161  
162 =head2 sub Step
163  
164 collects switches and assembles bash instructions
165 by adding the program name
166  
167 =cut
168  
169 sub Step {
170  
171 my ($self) = @_;
172  
173 if ( length $sukill->{_inbound_list}
174 and length $sukill->{_inbound}
175 )
176 {
177  
178 my $trace_num;
179 my @Step;
180  
181 my ( $array_ref, $num_gathers ) = _get_trace_numbers();
182 my $inbound = _get_inbound();
183  
184 # print("sukill, num_gathers=$num_gathers\n");
185 # print("sukill, values=@$array_ref\n");
186  
187 # All cases when num_traces >=0
188 # for first file
189 $trace_num = @$array_ref[0];
190 my $step =
191 "sukill key=$sukill->{_key} count=1 min=$trace_num < $inbound ";
192  
193 my $last_idx = $num_gathers - 1;
194  
195 if ( $last_idx >= 2 ) {
196  
197 # number of kills >=3
198 for ( my $i = 1 ; $i < $last_idx ; $i++ ) {
199  
200 $trace_num = @$array_ref[$i];
201 $step =
202 $step
203 . $to . "\n"
204 . "sukill key=$sukill->{_key} "
205 . "count=1 min=$trace_num ";
206  
207 }
208  
209 # For last
210 $trace_num = @$array_ref[$last_idx];
211 $step =
212 $step
213 . $to
214 . "sukill key=$sukill->{_key} "
215 . "count=1 min=$trace_num";
216  
217 $sukill->{_Step} = $step;
218  
219 }
220 elsif ( $last_idx == 1 ) {
221  
222 # number of kills = 2
223 # For 2nd-to-last trace
224 # print("sukill, last_idx = 1\n");
225  
226 $step =
227 $step
228 . $to
229 . "sukill key=$sukill->{_key} "
230 . "count=1 min=@$array_ref[$last_idx] ";
231  
232 $sukill->{_Step} = $step;
233  
234 }
235 elsif ( $last_idx == 0 ) {
236  
237 $sukill->{_Step} = $step;
238  
239 }
240 elsif ( not length $sukill->{_inbound_list} ) {
241  
242 $sukill->{_Step} = 'sukill' . $sukill->{_Step};
243 return ( $sukill->{_Step} );
244  
245 }
246 else {
247 print(
248 "sukill, Step, Only key and su_base_file_name must accompany list\n"
249 );
250 print(
251 "sukill, Step,key: $sukill->{_key}, file:$sukill->{inbound_su_base_file_name}\n"
252 );
253 print("sukill, Step,list: $sukill->{_inbound_list}\n");
254 return ();
255 }
256  
257 } else{
258 print("sukill, Step, incorrect parameters\n");
259 }
260 }
261  
262 =head2 sub note
263  
264 collects switches and assembles bash instructions
265 by adding the program name
266  
267 =cut
268  
269 sub note {
270  
271 $sukill->{_note} = 'sukill' . $sukill->{_note};
272 return ( $sukill->{_note} );
273  
274 }
275  
276 =head2 sub clear
277  
278 =cut
279  
280 sub clear {
281  
282 $sukill->{_a} = '';
283 $sukill->{_count} = '';
284 $sukill->{_key} = '';
285 $sukill->{_inbound_list} = '';
286 $sukill->{_min} = '';
287 $sukill->{inbound_su_base_file_name} = '';
288 $sukill->{_Step} = '';
289 $sukill->{_note} = '';
290 }
291  
292 =head2 _check4inbound_listNkey
293  
294 =cut
295  
296 sub _check4inbound_listNkey {
297 my ($self) = @_;
298  
299 if ( $sukill->{_data_type} eq $txt
300 && length $sukill->{_inbound_list}
301 && length $sukill->{_key} )
302 {
303 #NADA, $sukill->{_inbound_list} = $sukill->{_inbound_list};
304 }
305 else {
306 print(
307 "sukill, _check4inbound_listNkey, improper type, missing list or key\n"
308 );
309 }
310 return ();
311 }
312  
313 =head2 sub _get_inbound
314  
315 =cut
316  
317 sub _get_inbound {
318 my ($self) = @_;
319  
320 if ( length $sukill->{_inbound} ) {
321  
322 my $inbound = $sukill->{_inbound};
323  
324 # print("_get_inbound: $inbound\n");
325 return ($inbound);
326  
327 }
328 else {
329 print("sukill,_get_inbound, missing su_base_file_name\n");
330 return ();
331 }
332  
333 }
334  
335 sub _get_inbound_list {
336 my ($self) = @_;
337  
338 if ( length $sukill->{_inbound_list} ) {
339  
340 my $inbound_list = $sukill->{_inbound_list};
341 my ( $array_ref, $num_gathers ) = $readfiles->cols_1p($inbound_list);
342 my $result_a = $array_ref;
343 my $result_b = $num_gathers;
344  
345 print("_get_inbound_list, values=@$array_ref\n");
346 return ( $result_a, $result_b );
347  
348 }
349 else {
350 print("_get_inbound_list, missing inbound\n");
351 return ();
352 }
353  
354 }
355  
356 =head2 sub _get_trace_numbers
357  
358 =cut
359  
360 sub _get_trace_numbers {
361 my ($self) = @_;
362  
363 if ( length $sukill->{_inbound_list} ) {
364  
365 my $inbound_list = $sukill->{_inbound_list};
366 $control->set_back_slashBgone($inbound_list);
367 $inbound_list = $control->get_back_slashBgone();
368  
369 my ( $array_ref, $num_gathers ) = $readfiles->cols_1p($inbound_list);
370 my $result_a = $array_ref;
371 my $result_b = $num_gathers;
372  
373 # print("_get_trace_numbers, values=@$array_ref\n");
374 return ( $result_a, $result_b );
375  
376 }
377 else {
378 print("_get_trace_numbers, missing inbound\n");
379 return ();
380 }
381  
382 }
383  
384 sub _set_inbound {
385 my ($self) = @_;
386  
387 if ( length $sukill->{_inbound_su_base_file_name} ) {
388  
389 my $inbound = $sukill->{_inbound_su_base_file_name};
390  
391 $control->set_back_slashBgone($inbound);
392 $inbound = $control->get_back_slashBgone();
393 $sukill->{_inbound} = $inbound;
394  
395 # print("sukill,_set_inbound, sukill->{_inbound}=$inbound\n");
396  
397 }
398 else {
399 print("_set_inbound, missing su_base_file_name\n");
400 return ();
401 }
402  
403 }
404  
405 =head2 sub _set_inbound_list
406  
407 =cut
408  
409 sub _set_inbound_list {
410 my ($self) = @_;
411  
412 if ( length $sukill->{_inbound_list} ) {
413  
414 my $inbound_list = $sukill->{_inbound_list};
415 $control->set_back_slashBgone($inbound_list);
416 $inbound_list = $control->get_back_slashBgone();
417 $sukill->{_inbound_list} = $inbound_list;
418  
419 }
420 else {
421 print("_set_inbound_list, missing list\n");
422 return ();
423 }
424  
425 }
426  
427 =head2 sub a
428  
429  
430 =cut
431  
432 sub a {
433  
434 my ( $self, $a ) = @_;
435 if ( $a ne $empty_string ) {
436  
437 $sukill->{_a} = $a;
438 $sukill->{_note} = $sukill->{_note} . ' a=' . $sukill->{_a};
439 $sukill->{_Step} = $sukill->{_Step} . ' a=' . $sukill->{_a};
440  
441 }
442 else {
443 print("sukill, a, missing a,\n");
444 }
445 }
446  
447 =head2 sub count
448  
449  
450 =cut
451  
452 sub count {
453  
454 my ( $self, $count ) = @_;
455 if ( $count ne $empty_string ) {
456  
457 $sukill->{_count} = $count;
458 $sukill->{_note} = $sukill->{_note} . ' count=' . $sukill->{_count};
459 $sukill->{_Step} = $sukill->{_Step} . ' count=' . $sukill->{_count};
460  
461 }
462 else {
463 print("sukill, count, missing count,\n");
464 }
465 }
466  
467 =head2 sub key
468  
469  
470 =cut
471  
472 sub key {
473  
474 my ( $self, $key ) = @_;
475 if ( $key ne $empty_string ) {
476 $sukill->{_key} = $key;
477 $sukill->{_note} = $sukill->{_note} . ' key=' . $sukill->{_key};
478 $sukill->{_Step} = $sukill->{_Step} . ' key=' . $sukill->{_key};
479  
480 }
481 else {
482 print("sukill, key, missing key,\n");
483 }
484 }
485  
486 =head2 sub list
487  
488 list array
489  
490 =cut
491  
492 sub list {
493 my ( $self, $list ) = @_;
494  
495 if ( length $list ) {
496  
497 $sukill->{_inbound_list} = $list;
498  
499 # print("$list\n\n");
500 _check4inbound_listNkey();
501 _set_inbound_list();
502  
503 # print("sukill,list is $sukill->{_inbound_list}\n\n");
504  
505 }
506 else {
507 print("sukill, list, missing list,\n");
508 }
509 return ();
510 }
511  
512 =head2 sub min
513  
514  
515 =cut
516  
517 sub min {
518  
519 my ( $self, $min ) = @_;
520 if ( $min ne $empty_string ) {
521  
522 $sukill->{_min} = $min;
523 $sukill->{_note} = $sukill->{_note} . ' min=' . $sukill->{_min};
524 $sukill->{_Step} = $sukill->{_Step} . ' min=' . $sukill->{_min};
525  
526 }
527 else {
528 print("sukill, min, missing min,\n");
529 }
530 }
531  
532 =head2 sub su_base_file_name
533  
534 su_base_file_name
535  
536 =cut
537  
538 sub su_base_file_name {
539 my ( $self, $su_base_file_name ) = @_;
540  
541 if ( length $su_base_file_name ) {
542  
543 $sukill->{_inbound_su_base_file_name} = $su_base_file_name;
544 _check4inbound_listNkey();
545 _set_inbound();
546  
547 # print("sukill,su_base_file_name is $sukill->{inbound_su_base_file_name}\n\n");
548  
549 }
550 else {
551 print("sukill, su_base_file_name, missing \n");
552 }
553 return ();
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 = 5;
565  
566 return ($max_index);
567 }
568  
569 1;