lib/App/SeismicUnixGui/big_streams/Sucat.pl untested

filter: Statementstmt 0.0% 0 / 127 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 0.0% 0 / 13 Podpod n/a totaltotal 0.0% 0 / 200 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1  
2 =head1 DOCUMENTATION
3  
4 =head2 SYNOPSIS
5  
6 PROGRAM NAME: Sucat.pl
7 Purpose: Concatenate a series files
8 AUTHOR: Juan M. Lorenzo DEPENDS: on cat from bash
9 DATE: May 25 2018
10
11 Includes access to a simple configuration file
12 Simple file is called Sucat.config
13 Access to simple file is via Sucat2_config.pl
14 Sucat2_config.pl uses Config::Simple (jdhedden)
15 as well as SeismicUnix and SystemVariables
16 packages V 2.10
17
18 April 9 2018
19 removed dependency on Config::Simple (CPAN)
20
21 V0.1.5 Now uses sucat.pm instead of bash commands
22  
23 DESCRIPTION:
24  
25 =head2 USAGE
26
27 Sucat
28 Needs a local configuration file Sucat.config
29 GUI will generate a new one if needed one, but will
30 prefer to use the contents of an existant configuration file.
31  
32 =head2 Example Cases
33  
34 Square brackets show abbreviations of default directories.
35 [$DATA_SEISMIC_TXT]: is at: ~/txt/"subUser"/
36  
37 CASE 1A
38  
39 Use a list of complete file names (include suffixes if they have them
40 but exclude the directory paths)
41 for concatenating iVelan "pick files" (Vrms,time pairs)
42 into the correct format.
43  
44 A "list.txt", which is found in the $DATA_SEISMIC_TXT directory contains,
45 e.g.,:
46 ivpicks_sorted_par_L28Hz_Ibeam_geom4_cdp1
47 ivpicks_sorted_par_L28Hz_Ibeam_geom4_cdp11
48  
49 The starting input format in "par" format is as follows:
50  
51 (for ivpicks_sorted_par_L28Hz_Ibeam_geom4_cdp1)
52 tnmo=0.0189974,0.113193,0.153562,0.231926
53 vnmo=59.4778,160.806,195.689,273.761
54  
55 (for ivpicks_sorted_par_L28Hz_Ibeam_geom4_cdp11)
56 tnmo=0.0316623,0.0759894,0.129815
57 vnmo=101.006,130.906,263.794
58  
59 The final output format is:
60  
61 cdp=3,5
62 tnmo=0.0189974,0.113193,0.153562,0.231926
63 vnmo=59.4778,160.806,195.689,273.761
64 tnmo=0.0316623,0.0759894,0.129815
65 vnmo=101.006,130.906,263.794
66
67 (See ~sunix/shell/sucat.pm)
68 If "data_type" = "velan" then the concatenated output file
69 will automatically be reformatted for input into sunmo.
70  
71 CASE 1B
72  
73 Use a list of complete file names (include suffixes if they have them
74 but exclude the directory paths),
75 for concatenating picked "mute files" (time, x-coordinate pairs)
76 into the correct format.
77  
78 For example, a "list" called ""ute_list.txt"" [in $DATA_SEISMIC_TXT] contains:
79  
80 itop_mute_par_All_SH_geom3_ep3
81 itop_mute_par_All_SH_geom3_ep4
82  
83 The starting input format in each in "par" format:
84 tmute=0.0122645,0.0122645,0.00947713,0.0133795,0.0462707,0.0819493,0.134352,0.20
85 5152
86 xmute=1.18683,0.58898,2.75617,4.21343,10.9766,19.8322,36.9455,60.1121
87  
88 tmute=0.0328725,0.0223064,0.0540049,0.105662,0.207214
89 xmute=0.397959,4.11054,13.7934,28.7942,60.7526
90  
91 For the final output format:
92 Data_type is determined by parsing the file names and normally contains:
93 "itop_mute", "ibot_mute" etc." '
94
95 (See ~sunix/shell/sucat.pm)
96 If "data_type" = "itop_mute" or "ibot_mute" then the concatenated
97 output file will automatically be reformatted for input into
98 "sumute".
99  
100 GUI EXAMPLE:
101
102 Note that a list can only be used when the values of the prior
103 6 parameters are BLANK, i.e., be sure to
104 exclude values for first 6 parameters in GUI.
105  
106 The input name should have an suffix= ".txt"
107 SUG will recognize the extension but will not show the suffix
108 in the GUI.
109 An output name is also required. The suffix ".su"
110 will be added automatically to whatever name you choose.
111 Alternative directories are optional.
112  
113 first_file_number_in =
114 last_file_number_in =
115 number_of_files_in =
116 input_suffix =
117 input_name_prefix =
118 input_name_extension =
119 list = list [$DATA_SEISMIC_TXT]
120 output_base_file_name = base_file_name
121 alternative_inbound_directory =
122 alternative_outbound_directory =
123
124
125 An example of what can be inside the file: "list.txt":
126
127 25.su
128 26.su
129 27.su
130  
131 ---------------------------------------------------------------------------
132  
133 CASE 2
134 General concatenation of files with patterns in their names
135  
136 DO NOT use a list.
137 Instead, include values for at least the first 3
138 parameters in the GUI,
139 and up to and including values for all the remaining parametfile nameers,
140 except the list name. A
141  
142 An output name is possible but not required. Note that it is assumed
143 that the suffix and therefore directory of the output file has the
144 same origin directory as the input files. The input suffix is used
145 to determine the origin directory. For example an su input suffix will
146 point to a $DATA_SEISMIC_SU directory.
147
148 Example:
149
150 first_file_number_in = 1000
151 last_file_number_in = 1001
152 number_of_files_in = 2
153 input_suffix = su
154 input_name_prefix = cdp
155 input_name_extension = _clean
156 list =
157 output_base_file_name = 1000_01
158 alternative_inbound_directory =
159 alternative_outbound_directory =
160
161 The above case will produce carries out the following instruction:
162
163 cat DIR1/cdp1000_clean.su DIR1/cdp1001_clean.su > DIR2/1000_01.su
164
165
166 A list CAN NOT be in use when
167 values exist for any of the following parameters:
168
169 first_file_number_in = 1000
170 last_file_number_in = 1010
171 number_of_files_in = 11
172 input_suffix = su
173 input_name_prefix = cdp
174 input_name_extension = _clean
175
176
177 CASE 3
178
179 If you want to use a list, the list
180 is a file that contains one
181 or more file names
182  
183  
184 first_file_number_in =
185 last_file_number_in =
186 number_of_files_in =
187 input_suffix =
188 input_name_prefix =
189 input_name_extension =
190 list = cat_list_good_sp [$DATA_SEISMIC_TXT]
191 output_base_file_name = All_good_sp [$DATA_SEISMIC_SU]
192 alternative_inbound_directory =
193 alternative_outbound_directory =
194  
195  
196 CASE 4:
197
198 first_file_number_in = 1000 [$DATA_SEISMIC_SU]
199 last_file_number_in = 1010 [$DATA_SEISMIC_SU]
200 number_of_files_in = 11 [$DATA_SEISMIC_SU]
201 input_suffix = _clean.su [$DATA_SEISMIC_SU]
202 input_name_prefix =
203 input_name_extension =
204 output_base_file_name = 1000_10 [$DATA_SEISMIC_SU]
205 alternative_inbound_directory =
206 alternative_outbound_directory =
207  
208 =head2 NOTES
209  
210 The input and output default directories are
211 but these can be overridden by the values of the
212 alternative directories
213
214
215 =head2 CHANGES
216
217 V 0.1.2 considers empty file_names May 30, 2019; NM
218 V 0.1.3 includes additional concatenation for:
219 (1) sorted ivpicks
220 V 0.1.4 update NOTES 9.9.21
221 V 0.1.5 improved USAGE 11.8.22
222 V 0.1.6 requires lists to have a ".txt" suffix
223 The Input directories for a generic
224 "list.txt" is [$DATA_SEISMIC_TXT] May, 2023, NM
225  
226 =cut
227  
228 use Moose;
229 our $VERSION = '0.1.6';
230 use App::SeismicUnixGui::misc::control '0.0.3';
231 use aliased 'App::SeismicUnixGui::misc::control';
232 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
233 use aliased 'App::SeismicUnixGui::misc::readfiles';
234 use aliased 'App::SeismicUnixGui::misc::flow';
235 use aliased 'App::SeismicUnixGui::misc::message';
236 use aliased 'App::SeismicUnixGui::sunix::shell::sucat';
237 use aliased 'App::SeismicUnixGui::misc::manage_files_by';
238 use App::SeismicUnixGui::misc::SeismicUnix
239 qw($_cdp $_mute $in $itop_mute_par_ $ivpicks_sorted_par_ $out $on $go $to $suffix_ascii $off $suffix_su $suffix_txt);
240 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
241 use aliased 'App::SeismicUnixGui::configs::big_streams::Sucat_config';
242 use aliased 'App::SeismicUnixGui::specs::big_streams::Sucat_specB';
243  
244 =head2 Declare variables
245  
246 in local memory space
247  
248 =cut
249  
250 my ( @file_out, @flow, @items, @cat, @sufile_out );
251 my $outbound_directory;
252 my $inbound_directory;
253 my ( @ref_array, @sucat );
254 my $ref_array;
255 my $num_cdps;
256 my $outbound;
257  
258 =head2 2. Instantiate classes:
259  
260 Create a new version of the package with a unique name
261  
262 =cut
263  
264 my $Project = Project_config->new();
265 my $control = control->new();
266 my $log = message->new();
267 my $run = flow->new();
268 my $sucat = sucat->new();
269 my $read = readfiles->new();
270 my $Sucat_specB = Sucat_specB->new();
271  
272 my $get = L_SU_global_constants->new->new();
273 my $Sucat_config = Sucat_config->new();
274  
275 =head2 Get configuration information
276  
277 Establish default variables using a *_spec file
278 and defaults defined hereinf or the location of the list file;
279 in DATA_SEISMIC_TXT
280  
281 =cut
282  
283 my ( $CFG_h, $CFG_aref ) = $Sucat_config->get_values();
284 my $Sucat_spec_variables = $Sucat_specB->variables();
285  
286 # defaults are for su-type data
287 my $DATA_DIR_IN_default = $Sucat_spec_variables->{_DATA_DIR_IN};
288 my $DATA_DIR_OUT_default = $Sucat_spec_variables->{_DATA_DIR_OUT};
289 my $DATA_SEISMIC_TXT = $Project->DATA_SEISMIC_TXT;
290  
291 my $inbound_directory_default = $DATA_DIR_IN_default;
292 my $outbound_directory_default = $DATA_DIR_OUT_default;
293 my $list_directory_default = $DATA_SEISMIC_TXT;
294  
295 $inbound_directory = $inbound_directory_default;
296 $outbound_directory = $outbound_directory_default;
297 my $list_directory = $list_directory_default;
298  
299 $sucat->list_directory($list_directory);
300  
301 =head2 set global imported variables
302  
303 =cut
304  
305 my $var = $get->var();
306 my $empty_string = $var->{_empty_string};
307 my $literal_empty_string = $var->{_literal_empty_string};
308  
309 # print("Sucat.pl, literal_empty_string: ->$literal_empty_string<- \n");
310  
311 =head2 set the different parameters
312  
313 includes variables
314  
315 =cut
316  
317 my $alternative_outbound_directory = '';
318 my $alternative_inbound_directory = '';
319  
320 my $first_file_number_in = $CFG_h->{sucat}{1}{first_file_number_in};
321 my $last_file_number_in = $CFG_h->{sucat}{1}{last_file_number_in};
322 my $number_of_files_in = $CFG_h->{sucat}{1}{number_of_files_in};
323 my $output_base_file_name = $CFG_h->{sucat}{1}{output_base_file_name};
324 my $input_suffix = $CFG_h->{sucat}{1}{input_suffix};
325 my $input_name_prefix = $CFG_h->{sucat}{1}{input_name_prefix};
326 my $input_name_extension = $CFG_h->{sucat}{1}{input_name_extension};
327 my $list = $CFG_h->{sucat}{1}{list};
328 $alternative_inbound_directory =
329 $CFG_h->{sucat}{1}{alternative_inbound_directory};
330 $alternative_outbound_directory =
331 $CFG_h->{sucat}{1}{alternative_outbound_directory};
332  
333 # print("0. Sucat.pl, selected inbound_directory=$inbound_directory \n");
334  
335 =head2 correct input format values
336  
337 =cut
338  
339 $list = $control->get_no_quotes($list);
340  
341 # print("Sucat.pl, list: $list\n\n");
342 # print("Sucat.pl, output_base_file_name: $output_base_file_name\n\n");
343 # print("Sucat.pl, outbound_directory: $outbound_directory\n\n");
344  
345 =head2 3. Consider compatible
346  
347 parameter inputs with and without
348 a list
349  
350 =cut
351  
352 # CASE 1: new inbound and or/outbound directories replace defaults
353 if ( $alternative_outbound_directory ne $empty_string ) {
354  
355 $outbound_directory = $alternative_outbound_directory;
356  
357 # print("1. Sucat.pl, selected alternative_outbound_directory $outbound_directory\n");
358  
359 }
360 elsif ( $alternative_outbound_directory eq $empty_string ) {
361  
362 if ( $list ne $empty_string ) {
363  
364 $outbound_directory = $DATA_DIR_OUT_default;
365  
366 }
367 else {
368 $outbound_directory = $DATA_DIR_OUT_default;
369 }
370  
371 # print("2. Sucat.pl, selected outbound_directory $outbound_directory \n");
372 }
373 else {
374 # print("Sucat.pl, unexpected alternative_outbound_directory \n");
375 }
376  
377 if ( $alternative_inbound_directory ne $empty_string ) {
378  
379 $inbound_directory = $alternative_inbound_directory;
380  
381 # print("3A. Sucat.pl, selected inbound_directory=$inbound_directory \n");
382 # print("3B. Sucat.pl, selected alternative inbound_directory=$alternative_inbound_directory \n");
383  
384 }
385 elsif ( $alternative_inbound_directory eq $empty_string ) {
386  
387 if ( $list ne $empty_string ) {
388  
389 $inbound_directory = $list_directory_default;
390  
391 }
392 else {
393 #NADA $inbound_directory = $DATA_DIR_IN_default;
394 }
395  
396 # print("4. Sucat.pl, selected inbound_directory=$inbound_directory \n");
397 }
398 else {
399 print("Sucat.pl, unexpected alternative_inbound_directory \n");
400 }
401  
402 # print("Sucat.pl,inbound_directory:---$inbound_directory--\n");
403 # print("Sucat.pl,outbound_directory:---$outbound_directory--\n");
404  
405 =head2 3. Declare output file names and their paths
406  
407 inbound and outbound directories
408 are defaulted but can be different
409  
410 =cut
411  
412 $file_out[1] = $output_base_file_name; # always needed
413  
414 if ( length $output_base_file_name ) {
415
416 if ( $input_suffix ne $empty_string ) {
417  
418 $outbound =
419 $outbound_directory . '/' . $file_out[1] . '.' . $input_suffix;
420  
421 }
422 elsif ( $input_suffix eq $empty_string ) {
423  
424 $outbound = $outbound_directory . '/' . $file_out[1];
425  
426 }
427 else {
428 print("Sucat.pl,unexpected empty string\n");
429 }
430
431 print("Sucat.pl,outbound=$outbound\n");
432 }
433 else {
434 print("Sucat.pl, missing output filename\n");
435 }
436  
437 =header set up sucat
438  
439 =cut
440  
441 $sucat->clear();
442 $sucat->first_file_number_in($first_file_number_in);
443 $sucat->last_file_number_in($last_file_number_in);
444 $sucat->number_of_files_in($number_of_files_in);
445 $sucat->input_suffix($input_suffix);
446 $sucat->input_name_prefix($input_name_prefix);
447 $sucat->input_name_extension($input_name_extension);
448 $sucat->output_base_file_name($output_base_file_name);
449 $sucat->list($list);
450 $sucat->list_directory($list_directory);
451 $sucat->inbound_directory($inbound_directory);
452 $sucat->outbound_directory($outbound_directory);
453  
454 =head2 4. create script to concatenate files
455  
456 files may use either a default directory
457 or an alternative directory provided by the user
458 Also consider incompatible as well as compatible
459 parameter inputs
460  
461 =cut
462  
463 # CASE 1 If there is a list, we do not need numbers or
464 # other forms of names
465 if ( $list ne $empty_string
466 and $first_file_number_in eq $empty_string
467 and $last_file_number_in eq $empty_string
468 and $number_of_files_in eq $empty_string
469 and $input_suffix eq $empty_string
470 and $input_name_prefix eq $empty_string
471 and $input_name_extension eq $empty_string )
472 {
473  
474 # print("2. Sucat.pl, list:---$list---\n");
475 # print("2. Sucat.pl, list_directory:---$list_directory---\n");
476 # print("2. Sucat.pl, list:---0:@$ref_array[0], 1:@$ref_array[1]\n");
477 # my $ans =scalar @$ref_array;
478 # print("2. Sucat.pl, num_rows---$ans\n");
479 my $inbound_list = $list_directory . '/' . $list . $suffix_txt;
480  
481 # print("1. Sucat.pl, inbound_list:---$inbound_list---\n");
482 ( $ref_array, $num_cdps ) = $read->cols_1p($inbound_list);
483 $sucat->set_list_aref($ref_array);
484 $sucat->data_type();
485  
486 # print("ref_array is num_cdps is $num_cdps\n\n");
487 }
488  
489 # CASE 2 If there is no list but at least the first 3 file parameters exist
490 elsif ( $list eq $empty_string
491 and $first_file_number_in ne $empty_string
492 and $last_file_number_in ne $empty_string
493 and $number_of_files_in ne $empty_string )
494 {
495  
496 # print("3. Sucat.pl, OK, NADA\n");
497  
498 }
499 else {
500 print(
501 "Warning: Incorrect settings. Either:
502 \t 1) Use a list without values for first 6 parameters. Include the output
503 \t name (the alternative directories are optional).
504 \t That is, a list can only be used when the values of the prior
505 \t 6 parameters are blank
506 \t 2) Do not use a list. Instead include values for at least the first 3
507 \t parameters and up to and including values for all the remaining parameters,
508 \t except the list\n"
509 );
510 }
511  
512 $sucat[1] = $sucat->Step();
513  
514 # outbound includes a suffix if su data is detected
515 # outbound also chooses DATA_SEISMIC_TXT path if
516 # data_type = $txt
517  
518 $sucat->set_outbound($outbound);
519 my $new_outbound = $sucat->get_outbound();
520  
521 =head2 A. DEFINE FLOW(S)
522  
523 =cut
524  
525 @items = ( $sucat[1], $out, $new_outbound, $go );
526  
527 $flow[1] = $run->modules( \@items );
528  
529 =head2 B. RUN FLOW(S)
530  
531 =cut
532  
533 $run->flow( \$flow[1] );
534  
535 =head2 C. LOG FLOW(S)TO SCREEN AND FILE
536  
537 =cut
538  
539 $log->screen( $flow[1] );
540  
541 #my $time = localtime;
542 #$log->time;
543 #$log->file( $flow[1] );