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

filter: Statementstmt 0.0% 0 / 188 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 45 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 0.0% 0 / 24 Podpod 0.0% 0 / 17 totaltotal 0.0% 0 / 336 CC 22 SCAR 30.9
CC
22
Cov
0%
Step
90.0
_check4inbound_listNdata
6.0
_get_file_names
6.0
CRAP 21.9
1 package App::SeismicUnixGui::sunix::shapeNcut::susplit;
2  
3 =head2 SYNOPSIS
4  
5 PERL PROGRAM NAME: susplit.pm
6  
7 AUTHOR: Juan Lorenzo (Perl module only)
8  
9 DATE:
10 V0.2 6.19.23
11  
12 DESCRIPTION:
13  
14 Version:
15  
16 =head2 USE
17  
18 =head3 NOTES
19  
20 There are now four cases that susplit can handle:
21
22 1. As in the traditional case, the split files are written to
23 the directory in which perl thinks the code is running.
24  
25 2. If a list of su_base_file_names is given (in $DATA_SEISMIC_TXT)
26 split files are written to $DATA_SEISMIC_SU.
27  
28 3. If an su_base_file_name is given then the split files are written
29 to $DATA_SEISMIC_SU.
30  
31 4. Cases 2 and 3 are mutually exclusive and a warning message is given.
32  
33 =head4 Examples
34  
35 =head2 SYNOPSIS
36  
37 =head3 SEISMIC UNIX NOTES
38 SUSPLIT - Split traces into different output files by keyword value
39  
40 susplit <stdin >stdout [options]
41  
42 Required Parameters:
43  
44 none
45  
46 Optional Parameters:
47  
48 key=cdp Key header word to split on (see segy.h)
49  
50 stem=split_ Stem name for output files
51  
52 middle=key middle of name of output files
53  
54 suffix=.su Suffix for output files
55  
56 numlength=7 Length of numeric part of filename
57  
58 verbose=0 =1 to echo filenames, etc.
59  
60 close=1 =1 to close files before opening new ones
61  
62  
63 Notes:
64  
65 The most efficient way to use this program is to presort the input data
66  
67 into common keyword gathers, prior to using susplit. "
68  
69  
70 Use "suputgthr" to put SU data into SU data directory format.
71  
72  
73 Credits:
74  
75 Geocon: Garry Perratt hacked together from various other codes
76  
77 =head2 CHANGES and their DATES
78  
79 V0.0.2 06.13.23
80  
81 Normally susplit writes divided files into the local directory.
82 Now, split files are automatically moved into $the DATA_SEISMICS_SU
83 directory.
84  
85 Normally, susplit input consists of a single file. Now, user can
86 enter the name of a list containing more than one file. Now,
87 susplit will iterate over each file with the same general instructions.
88  
89 Now, there is no need to use a data_in or data_out module. Now, susplit
90 handles input and output internally.
91  
92 =cut
93  
94 use Moose;
95 our $VERSION = '0.0.1';
96  
97 =head2 Import packages
98  
99 =cut
100  
101 use App::SeismicUnixGui::misc::L_SU_global_constants;
102 use App::SeismicUnixGui::misc::SeismicUnix qw($in $out $on $go $to
103 $suffix_ascii $off $suffix_su $suffix_txt $txt $suffix_bin);
104 use aliased 'App::SeismicUnixGui::misc::control';
105 use aliased 'App::SeismicUnixGui::misc::readfiles';
106 use App::SeismicUnixGui::configs::big_streams::Project_config;
107 use Cwd;
108  
109 =head2 instantiation of packages
110  
111 =cut
112  
113 my $get = App::SeismicUnixGui::misc::L_SU_global_constants->new();
114 my $control = control->new();
115 my $Project = App::SeismicUnixGui::configs::big_streams::Project_config->new();
116 my $readfiles = readfiles->new();
117  
118 my $DATA_SEISMIC_SU = $Project->DATA_SEISMIC_SU();
119 my $DATA_SEISMIC_BIN = $Project->DATA_SEISMIC_BIN();
120  
121 #my $DATA_SEISMIC_TXT = $Project->DATA_SEISMIC_TXT();
122  
123 my $var = $get->var();
124 my $on = $var->{_on};
125 my $off = $var->{_off};
126 my $true = $var->{_true};
127 my $false = $var->{_false};
128 my $empty_string = $var->{_empty_string};
129 my $default = $txt;
130  
131 =head2 Encapsulated
132 hash of private variables
133  
134 =cut
135  
136 my $susplit = {
137 _close => '',
138 _data_type => '',
139 _inbound_list => '',
140 _inbound_su_base_file_name => '',
141 _key => '',
142 _middle => '',
143 _numlength => '',
144 _stem => '',
145 _suffix => '',
146 _verbose => '',
147 _Step => '',
148 _note => '',
149  
150 };
151  
152 $susplit->{_data_type} = $default;
153  
154 =head2 sub Step
155  
156 collects switches and assembles bash instructions
157 by adding the program name
158 move output data into the DATA_SEISMIC_UNIX directory
159  
160 =cut
161  
162 sub Step {
163  
164 my ($self) = @_;
165  
166 if ( length $susplit->{_inbound_list}
167 and not length $susplit->{_inbound_su_base_file_name}
168 and length $susplit->{_close}
169 and length $susplit->{_key}
170 and length $susplit->{_numlength}
171 and length $susplit->{_stem}
172 and length $susplit->{_suffix}
173 and length $susplit->{_verbose} )
174 {
175 my $file_num;
176 my @step;
177 my @inbound;
178 my $first_step;
179 my $last_step;
180 my $step;
181  
182 my ( $array_ref, $num_files ) = _get_file_names();
183 my @file = @$array_ref;
184 my $penultimate_idx = $num_files - 2;
185 my $last_idx = $num_files - 1;
186  
187 # print("susplit, Step, num_files=$num_files\n");
188 # print("susplit, Step, names=@file\n");
189  
190 my $close = $susplit->{_close};
191 my $key = $susplit->{_key};
192 my $stem = $susplit->{_stem};
193 my $middle = $susplit->{_middle};
194 my $numlength = $susplit->{_numlength};
195 my $suffix = $susplit->{_suffix};
196 my $verbose = $susplit->{_verbose};
197  
198 # All cases when num_files >=0
199 if ( $num_files >= 1 ) {
200  
201 $inbound[0] = $DATA_SEISMIC_SU . '/' . $file[0]. $suffix_su;
202 print("susplit,Step,first_file=$inbound[0]\n");
203  
204 $first_step =
205 " susplit close=$close "
206 . "key=$key stem=$stem middle=$middle numlength=$numlength "
207 . "suffix=$suffix verbose=$verbose < $inbound[0] ";
208 }
209  
210 if ($num_files == 2) {
211
212 $inbound[1] = $DATA_SEISMIC_SU . '/' . $file[1].$suffix_su;
213 # print(" last name = $inbound[1]\n");
214
215 $last_step =
216 " susplit close=$close "
217 . "key=$key stem=$stem middle=$middle numlength=$numlength "
218 . "suffix=$suffix verbose=$verbose < $inbound[1]";
219
220 $step = $first_step . ";" . $last_step;
221
222 }
223
224 if ( $num_files > 2 ) {
225
226 my $temp_step;
227
228 $inbound[$last_idx] = $DATA_SEISMIC_SU . '/' . $file[$last_idx].$suffix_su;
229 # print(" last name = $inbound[$last_idx]\n");
230
231 $last_step =
232 " susplit close=$close "
233 . "key=$key stem=$stem middle=$middle numlength=$numlength "
234 . "suffix=$suffix verbose=$verbose < $inbound[$last_idx]";
235  
236 for ( my $i = 1, ; $i <= $penultimate_idx ; $i++ ) {
237 $inbound[$i] =
238 $DATA_SEISMIC_SU . '/' . $file[$i]. $suffix_su;
239 # print("Step, num_files>1;$inbound[$i]\n");
240
241 # for the remaining files
242 $temp_step =
243 $temp_step . ";"
244 . " susplit close=$close "
245 . "key=$key stem=$stem middle=$middle numlength=$numlength "
246 . "suffix=$suffix verbose=$verbose < $inbound[$i]";
247 }
248  
249 $step = $first_step . $temp_step . ";" . $last_step;
250 }
251  
252 if ($num_files == 1) {
253
254 $step = $first_step . ";" . "mv *$stem$middle* $DATA_SEISMIC_SU ";
255
256 } else{
257 $step = $step . ";" . "mv *$stem$middle* $DATA_SEISMIC_SU ";
258 }
259  
260 $susplit->{_Step} = $step;
261  
262 return ( $susplit->{_Step} );
263  
264 }
265 elsif ( not length $susplit->{_inbound_list}
266 and length $susplit->{_inbound_su_base_file_name}
267 and length $susplit->{_key} )
268 {
269  
270 my $name = $susplit->{_inbound_su_base_file_name};
271  
272 # CASE of a single data file without a list, and without
273 # use of data_in module
274 # print("CASE without data_in module\n");
275 $susplit->{_Step} = 'susplit' . $susplit->{_Step} . " < $name";
276  
277 $susplit->{_Step} = $susplit->{_Step} . ";"
278 . "mv *$susplit->{_stem}$susplit->{_middle}* $DATA_SEISMIC_SU ";
279  
280 return ( $susplit->{_Step} );
281 }
282 elsif ( not length $susplit->{_inbound_list}
283 and not length $susplit->{_inbound_su_base_file_name}
284 and length $susplit->{_key} )
285 {
286  
287 # traditional use, with data_in module, and outputs
288 # to the current directory in perl space
289 $susplit->{_Step} = 'susplit' . $susplit->{_Step};
290 $susplit->{_Step} = $susplit->{_Step};
291  
292 return ( $susplit->{_Step} );
293  
294 }
295 elsif ( length $susplit->{_inbound_list}
296 and length $susplit->{_inbound_su_base_file_name}
297 and length $susplit->{_key} )
298 {
299  
300 print(
301 "susplit, Step, either list or su_base_file_name are redundant \n");
302  
303 }
304 else {
305 print(
306 "susplit, Step, missing parameter(s) e.g., list,su_base_file_name,key,suffix\n"
307 );
308 }
309 }
310  
311 =head2 sub note
312  
313 collects switches and assembles bash instructions
314 by adding the program name
315  
316 =cut
317  
318 sub note {
319  
320 $susplit->{_note} = 'susplit' . $susplit->{_note};
321 return ( $susplit->{_note} );
322  
323 }
324  
325 =head2 sub clear
326  
327 =cut
328  
329 sub clear {
330  
331 $susplit->{_close} = '';
332 $susplit->{_key} = '';
333 $susplit->{_inbound_list} = '',
334 $susplit->{_inbound_su_base_file_name} = '',
335 $susplit->{_middle} = '';
336 $susplit->{_numlength} = '';
337 $susplit->{_stem} = '';
338 $susplit->{_suffix} = '';
339 $susplit->{_verbose} = '';
340 $susplit->{_Step} = '';
341 $susplit->{_note} = '';
342 }
343  
344 =head2 _check4inbound_listNkey
345  
346 =cut
347  
348 sub _check4inbound_listNdata {
349 my ($self) = @_;
350  
351 if ( $susplit->{_data_type} eq $txt
352 && length $susplit->{_inbound_list}
353 && length $susplit->{_inbound_su_base_file_name} )
354 {
355 #NADA,
356 print(
357 "susplit,$susplit->{_inbound_list} = $susplit->{_inbound_list}\n");
358 }
359 else {
360 print(
361 "susplit, _check4inbound_list, missing list or su_base_file_name\n"
362 );
363 }
364 return ();
365 }
366  
367 sub _get_file_names {
368 my ($self) = @_;
369  
370 if ( length $susplit->{_inbound_list} ) {
371  
372 my $inbound_list = $susplit->{_inbound_list};
373  
374 # $control->set_back_slashBgone($inbound_list);
375 # $inbound_list = $control->get_back_slashBgone();
376  
377 my ( $array_ref, $num_files ) = $readfiles->cols_1p($inbound_list);
378 my $result_a = $array_ref;
379 my $result_b = $num_files;
380  
381 # print("_get_file_names, names=@$array_ref\n");
382 return ( $result_a, $result_b );
383  
384 }
385 else {
386 print("_get_file_names, missing inbound\n");
387 return ();
388 }
389  
390 }
391  
392 sub _set_inbound {
393 my ($self) = @_;
394  
395 if ( length $susplit->{_inbound_su_base_file_name} ) {
396  
397 my $inbound = $susplit->{_inbound_su_base_file_name};
398  
399 $control->set_back_slashBgone($inbound);
400 $inbound = $control->get_back_slashBgone();
401 $susplit->{_inbound} = $inbound;
402  
403 # print("susplit,_set_inbound, susplit->{_inbound}=$inbound\n");
404  
405 }
406 else {
407 print("_set_inbound, missing su_base_file_name\n");
408 return ();
409 }
410  
411 }
412  
413 sub _set_inbound_list {
414 my ($self) = @_;
415  
416 if ( length $susplit->{_inbound_list} ) {
417  
418 my $inbound_list = $susplit->{_inbound_list};
419 $control->set_back_slashBgone($inbound_list);
420 $inbound_list = $control->get_back_slashBgone();
421 $susplit->{_inbound_list} = $inbound_list;
422  
423 }
424 else {
425 print("_set_inbound_list, missing list\n");
426 return ();
427 }
428  
429 }
430  
431 =head2 sub close
432  
433  
434 =cut
435  
436 sub close {
437  
438 my ( $self, $close ) = @_;
439 if ( $close ne $empty_string ) {
440  
441 $susplit->{_close} = $close;
442 $susplit->{_note} = $susplit->{_note} . ' close=' . $susplit->{_close};
443 $susplit->{_Step} = $susplit->{_Step} . ' close=' . $susplit->{_close};
444  
445 }
446 else {
447 print("susplit, close, missing close,\n");
448 }
449 }
450  
451 =head2 sub key
452  
453  
454 =cut
455  
456 sub key {
457  
458 my ( $self, $key ) = @_;
459 if ( $key ne $empty_string ) {
460  
461 $susplit->{_key} = $key;
462 $susplit->{_note} = $susplit->{_note} . ' key=' . $susplit->{_key};
463 $susplit->{_Step} = $susplit->{_Step} . ' key=' . $susplit->{_key};
464  
465 }
466 else {
467 print("susplit, key, missing key,\n");
468 }
469 }
470  
471 =head2 sub list
472  
473 list array
474  
475 =cut
476  
477 sub list {
478 my ( $self, $list ) = @_;
479  
480 if ( length $list ) {
481  
482 $susplit->{_inbound_list} = $list;
483  
484 # _check4inbound_list();
485 _set_inbound_list();
486  
487 # print("susplit,list; inbound list is $susplit->{_inbound_list}\n\n");
488  
489 }
490 else {
491 print("susplit, list, missing list,\n");
492 }
493 return ();
494 }
495  
496 =head2 sub middle
497  
498  
499 =cut
500  
501 sub middle {
502  
503 my ( $self, $middle ) = @_;
504 if ( $middle ne $empty_string ) {
505  
506 $susplit->{_middle} = $middle;
507 $susplit->{_note} =
508 $susplit->{_note} . ' middle=' . $susplit->{_middle};
509 $susplit->{_Step} =
510 $susplit->{_Step} . ' middle=' . $susplit->{_middle};
511  
512 }
513 else {
514 print("susplit, middle, missing middle,\n");
515 }
516 }
517  
518 =head2 sub numlength
519  
520  
521 =cut
522  
523 sub numlength {
524  
525 my ( $self, $numlength ) = @_;
526 if ( $numlength ne $empty_string ) {
527  
528 $susplit->{_numlength} = $numlength;
529 $susplit->{_note} =
530 $susplit->{_note} . ' numlength=' . $susplit->{_numlength};
531 $susplit->{_Step} =
532 $susplit->{_Step} . ' numlength=' . $susplit->{_numlength};
533  
534 }
535 else {
536 print("susplit, numlength, missing numlength,\n");
537 }
538 }
539  
540 =head2 sub stem
541  
542  
543 =cut
544  
545 sub stem {
546  
547 my ( $self, $stem ) = @_;
548 if ( $stem ne $empty_string ) {
549  
550 $susplit->{_stem} = $stem;
551 $susplit->{_note} = $susplit->{_note} . ' stem=' . $susplit->{_stem};
552 $susplit->{_Step} = $susplit->{_Step} . ' stem=' . $susplit->{_stem};
553  
554 }
555 else {
556 print("susplit, stem, missing stem,\n");
557 }
558 }
559  
560 =head2 sub su_base_file_name
561  
562 su_base_file_name
563  
564 =cut
565  
566 sub su_base_file_name {
567 my ( $self, $su_base_file_name ) = @_;
568  
569 if ( length $su_base_file_name ) {
570  
571 $susplit->{_su_base_file_name} = $su_base_file_name;
572 $susplit->{_note} =
573 $susplit->{_note}
574 . ' su_base_file_name='
575 . $susplit->{_su_base_file_name};
576  
577 $susplit->{_inbound_su_base_file_name} = $su_base_file_name;
578  
579 # _check4inbound_listNkey();
580 # _set_inbound();
581  
582 # print("susplit,su_base_file_name is $susplit->{_su_base_file_name}\n\n");
583  
584 }
585 else {
586 print("susplit, su_base_file_name, missing \n");
587 }
588 return ();
589 }
590  
591 =head2 sub suffix
592  
593  
594 =cut
595  
596 sub suffix {
597  
598 my ( $self, $suffix ) = @_;
599 if ( $suffix ne $empty_string ) {
600  
601 $susplit->{_suffix} = $suffix;
602 $susplit->{_note} =
603 $susplit->{_note} . ' suffix=' . $susplit->{_suffix};
604 $susplit->{_Step} =
605 $susplit->{_Step} . ' suffix=' . $susplit->{_suffix};
606  
607 }
608 else {
609 print("susplit, suffix, missing suffix,\n");
610 }
611 }
612  
613 =head2 sub verbose
614  
615  
616 =cut
617  
618 sub verbose {
619  
620 my ( $self, $verbose ) = @_;
621 if ( $verbose ne $empty_string ) {
622  
623 $susplit->{_verbose} = $verbose;
624 $susplit->{_note} =
625 $susplit->{_note} . ' verbose=' . $susplit->{_verbose};
626 $susplit->{_Step} =
627 $susplit->{_Step} . ' verbose=' . $susplit->{_verbose};
628  
629 }
630 else {
631 print("susplit, verbose, missing verbose,\n");
632 }
633 }
634  
635 =head2 sub get_max_index
636  
637 max index = number of input variables -1
638
639 =cut
640  
641 sub get_max_index {
642 my ($self) = @_;
643 my $max_index = 8;
644  
645 return ($max_index);
646 }
647  
648 1;