lib/App/SeismicUnixGui/sunix/data/data_out.pm untested

filter: Statementstmt 0.0% 0 / 155 Branchbran 0.0% 0 / 68 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 14 totaltotal 0.0% 0 / 276 CC 35 SCAR 45.4
CC
35
Cov
0%
_get_suffix
210.0
_get_DIR
156.0
_get_outbound
12.0
CRAP 93.8
1 package App::SeismicUnixGui::sunix::data::data_out;
2  
3 =head1 DOCUMENTATION
4  
5 =head2 SYNOPSIS
6  
7 PERL PROGRAM NAME: data_out.pm
8 AUTHOR: Juan Lorenzo (Perl module only)
9 DATE: June 22 2017
10
11  
12 DESCRIPTION
13
14  
15 BASED ON:
16 Version 0.0.1 June 22 2017
17  
18 Version 0.0.2 July 26 2018
19
20 Version 0.0.3 August 30 2021
21  
22  
23 =cut
24  
25 =head2 USE
26  
27 Use abbreviations such as
28 bin sgy txt and su to automatically access directories
29 that contain the types of files represented by these suffixes.
30  
31 For example, all segy-type files are placed in the same directory
32 If you want to find one of these files, place the parameter =
33 sgy on the second line (suffix_type)
34  
35 To automatically go to the segy-type directory, click on MB-3 while
36 over the first parameter input (base_file_name)
37  
38 =head3 NOTES
39  
40 =head4 Examples
41  
42  
43 =head2 CHANGES and their DATES
44  
45 Version 0.02 July 22 2018 added subs:
46 suffix_type, inbound _get_inbound
47 _get_suffix, _get_DIR
48  
49 Version 0.03 All file without a suffix
50 in which case the default PATH is the
51 path of PL_SEISMIC
52
53 =cut
54  
55 =head2 Notes from bash
56
57 =cut
58  
59 use Moose;
60 our $VERSION = '0.0.3';
61  
62 my $data_out = {
63 _Step => '',
64 _base_file_name => '',
65 _note => '',
66 _notes_aref => '',
67 _suffix_type => '',
68 };
69  
70 =head2
71  
72 Instantiate packages
73  
74 =cut
75  
76 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
77  
78 my $get = L_SU_global_constants->new();
79  
80 my $var = $get->var();
81 my $empty_string = $var->{_empty_string};
82  
83 =head2 subroutine _get_DIR
84
85 send PATH for suffix_suffix_type
86 suffix_type can be su txt sgy or su
87 or nothing, in which case the file
88 goes to the PL_SEISMIC directory
89 by default
90
91  
92 =cut
93  
94 sub _get_DIR {
95 my ($self) = @_;
96  
97 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
98 my $Project = Project_config->new();
99 my $DIR;
100  
101 if ( length $data_out->{_suffix_type} ) {
102  
103 use App::SeismicUnixGui::misc::SeismicUnix
104 qw($bin $ps $seg2 $segb $segd $sgd $segy $sgy $su $txt );
105  
106 my $suffix_type = $data_out->{_suffix_type};
107  
108 if ( $suffix_type eq $ps ) {
109  
110 my ($PS_SEISMIC) = $Project->PS_SEISMIC();
111 $DIR = $PS_SEISMIC;
112  
113 }
114 elsif ( $suffix_type eq $su ) {
115  
116 my ($DATA_SEISMIC_SU) = $Project->DATA_SEISMIC_SU();
117 $DIR = $DATA_SEISMIC_SU;
118  
119 }
120 elsif ( $suffix_type eq $bin ) {
121  
122 my ($DATA_SEISMIC_BIN) = $Project->DATA_SEISMIC_BIN();
123 $DIR = $DATA_SEISMIC_BIN;
124  
125 }
126 elsif ( $suffix_type eq $txt ) {
127  
128 my ($DATA_SEISMIC_TXT) = $Project->DATA_SEISMIC_TXT();
129 $DIR = $DATA_SEISMIC_TXT;
130  
131 }
132 elsif ( $suffix_type eq $seg2 ) {
133  
134 my ($DATA_SEISMIC_SEG2) = $Project->DATA_SEISMIC_SEG2();
135 $DIR = $DATA_SEISMIC_SEG2;
136  
137 }
138 elsif ( $suffix_type eq $segb ) {
139  
140 my ($DATA_SEISMIC_SEGB) = $Project->DATA_SEISMIC_SEGB();
141 $DIR = $DATA_SEISMIC_SEGB;
142  
143 }
144 elsif ( $suffix_type eq $segd ) {
145  
146 my ($DATA_SEISMIC_SEGD) = $Project->DATA_SEISMIC_SEGD();
147 $DIR = $DATA_SEISMIC_SEGD;
148  
149 }
150  
151 elsif ( $suffix_type eq $sgd ) {
152  
153 my ($DATA_SEISMIC_SEGD) = $Project->DATA_SEISMIC_SEGD();
154 $DIR = $DATA_SEISMIC_SEGD;
155  
156 }
157 elsif ( $suffix_type eq $sgy ) {
158  
159 my ($DATA_SEISMIC_SEGY) = $Project->DATA_SEISMIC_SEGY();
160 $DIR = $DATA_SEISMIC_SEGY;
161  
162 }
163 elsif ( $suffix_type eq $segy ) {
164  
165 my ($DATA_SEISMIC_SEGY) = $Project->DATA_SEISMIC_SEGY();
166 $DIR = $DATA_SEISMIC_SEGY;
167  
168 }
169 else {
170 print("data_out, _get_DIR, unexpected suffix_type\n");
171 return ($empty_string);
172 }
173  
174 return ($DIR);
175  
176 }
177 else {
178 my ($PL_SEISMIC) = $Project->PL_SEISMIC();
179 $DIR = $PL_SEISMIC;
180  
181 # print("data_out, _get_DIR, suffix_type default is PL_SEISMIC \n");
182 return ($DIR);
183 }
184 }
185  
186 =head2 subroutine _get_suffix
187
188 send PATH for suffix_type
189 suffix_type can be su txt sgy or su
190
191  
192 =cut
193  
194 sub _get_suffix {
195 my ($self) = @_;
196  
197 if ( $data_out->{_suffix_type} ) {
198  
199 my $suffix;
200 my $suffix_type = $data_out->{_suffix_type};
201  
202 use App::SeismicUnixGui::misc::SeismicUnix
203 qw($suffix_seg2 $suffix_segb $suffix_segd $suffix_sgd $suffix_sgy $suffix_segy $suffix_su $suffix_bin $suffix_ps $suffix_txt $segy $sgy $su $txt $bin);
204  
205 if ( $suffix_type eq $ps ) {
206  
207 $suffix = $suffix_ps;
208  
209 }
210 elsif ( $suffix_type eq $su ) {
211  
212 $suffix = $suffix_su;
213  
214 }
215 elsif ( $suffix_type eq $seg2 ) {
216  
217 $suffix = $suffix_seg2;
218  
219 }
220 elsif ( $suffix_type eq $segb ) {
221  
222 $suffix = $suffix_segb;
223  
224 }
225 elsif ( $suffix_type eq $segd ) {
226  
227 $suffix = $suffix_segd;
228  
229 }
230 elsif ( $suffix_type eq $sgd ) {
231  
232 $suffix = $suffix_sgd;
233 }
234 elsif ( $suffix_type eq $sgy ) {
235  
236 $suffix = $suffix_sgy;
237  
238 }
239 elsif ( $suffix_type eq $segy ) {
240  
241 $suffix = $suffix_segy;
242  
243 }
244 elsif ( $suffix_type eq $bin ) {
245  
246 $suffix = $suffix_bin;
247  
248 }
249 elsif ( $suffix_type eq $txt ) {
250  
251 $suffix = $suffix_txt;
252  
253 }
254 elsif ( $suffix_type eq $empty_string ) {
255  
256 print(
257 "data_out, suffix_type is not su, bin, seg2, segb, segd, segy or txt\n"
258 );
259 $suffix = $empty_string;
260  
261 }
262 else {
263 print("data_out, unexpected suffix_type\n");
264 }
265  
266 return ($suffix);
267  
268 }
269 elsif ( not( length $data_out->{_suffix_type} ) ) {
270  
271 # print("data_out _get_sufix, suffix_type is blank so assume that it means there is non\n");
272 my $suffix = $empty_string;
273 return ($suffix);
274  
275 }
276 else {
277 print("data_out, _get_suffix, suffix_type unexpected \n");
278 return ();
279 }
280 }
281  
282 =head2 subroutine Step
283
284 adds the program name
285  
286 =cut
287  
288 sub Step {
289 my ($self) = @_;
290 my $note;
291  
292 $data_out->{_note} = _get_outbound();
293 $note = $data_out->{_note};
294  
295 return $note;
296  
297 }
298  
299 =head2 subroutine _get_outbound
300  
301 suffix_type can be su txt sgy or su
302  
303 =cut
304  
305 sub _get_outbound {
306 my ($self) = @_;
307  
308 my $outbound;
309 my $suffix_type;
310 my $DIR;
311 my $file;
312 my $suffix;
313  
314 if ( length $data_out->{_suffix_type}
315 && $data_out->{_base_file_name} )
316 {
317  
318 $file = $data_out->{_base_file_name};
319  
320 $DIR = _get_DIR();
321 $suffix = _get_suffix();
322 $outbound = $DIR . '/' . $file . $suffix;
323  
324 # print ("1. data_out,_get_outbound outbound: $outbound\n");
325 return ($outbound);
326  
327 }
328 elsif ( length $data_out->{_base_file_name}
329 && not( $data_out->{_suffix_type} ) )
330 {
331  
332 $file = $data_out->{_base_file_name};
333  
334 $DIR = _get_DIR();
335 $outbound = $DIR . '/' . $file;
336  
337 # print ("2. data_out,_get_outbound outbound: $outbound\n");
338 return ($outbound);
339  
340 }
341 else {
342 print("data_out, missing: suffix_type, base file name \n");
343 }
344 }
345  
346 =head2 sub base_file_name
347  
348 has no suffix
349
350 =cut
351  
352 sub base_file_name {
353 my ( $variable, $base_file_name ) = @_;
354  
355 if ($base_file_name) {
356  
357 $data_out->{_base_file_name} = $base_file_name;
358  
359 # print ("data_out, base_file_name $data_out->{_base_file_name}\n");
360  
361 }
362 else {
363 print("data_out, base_file_name, name missing \n");
364 }
365 }
366  
367 =head2 sub base_file_name_sref
368  
369 has no suffix
370
371 =cut
372  
373 sub base_file_name_sref {
374 my ( $variable, $base_file_name_sref ) = @_;
375  
376 if ($base_file_name_sref) {
377  
378 $data_out->{_base_file_name} = $$base_file_name_sref;
379  
380 # print ("data_out, base_file_name $data_out->{_base_file_name}\n");
381  
382 }
383 else {
384 print("data_out, base_file_name_sref, name missing \n");
385  
386 }
387 }
388  
389 =head2 subroutine clear
390  
391 sets all variable strings to ''
392  
393 =cut
394  
395 sub clear {
396 $data_out->{_Step} = '';
397 $data_out->{_base_file_name} = '';
398 $data_out->{_note} = '';
399 $data_out->{_notes_aref} = '';
400 $data_out->{_suffix_type} = '';
401 }
402  
403 my @notes;
404  
405 # define a value
406 my $newline = '
407 ';
408  
409 =head2 sub full_file_name
410  
411 hase plus suffix
412
413 =cut
414  
415 sub full_file_name {
416 my ( $self, $full_file_name ) = @_;
417  
418 if ($full_file_name) {
419  
420 $data_out->{_full_file_name} = $full_file_name;
421  
422 }
423 else {
424 print("data_out, full_file_name, name missing \n");
425 }
426 }
427  
428 =head2 subroutine get_inbound
429  
430 suffix_type can be su txt sgy or su
431  
432 =cut
433  
434 sub get_inbound {
435 my ($self) = @_;
436  
437 my $inbound;
438 my $suffix_type;
439 my $DIR;
440 my $file;
441 my $suffix;
442  
443 if ( length $data_out->{_suffix_type}
444 && $data_out->{_base_file_name} )
445 {
446  
447 $file = $data_out->{_base_file_name};
448  
449 $DIR = _get_DIR();
450 $suffix = _get_suffix();
451 $inbound = $DIR . '/' . $file . $suffix;
452  
453 # print ("data_out,get_inbound inbound: $inbound\n");
454 return ($inbound);
455  
456 }
457 elsif ( length $data_out->{_base_file_name}
458 && not( $data_out->{_suffix_type} ) )
459 {
460  
461 print(
462 "data_out, missing: suffix_type, base file name .
463 Assume that the expected output is PL_SEISMIC-- as default\n"
464 );
465 $DIR = _get_DIR();
466 $suffix = _get_suffix();
467 $inbound = $DIR . '/' . $file . $suffix;
468 return ($inbound);
469  
470 }
471 else {
472 print(
473 "data_out, missing: suffix_type, base file name . Assume that is what the user wants NADA\n"
474 );
475 return ($empty_string);
476 }
477 }
478  
479 =head2 sub file_name you need to know how many numbers per line
480 will be in the output file
481  
482 =cut
483  
484 sub file_name {
485 my ( $variable, $file_name ) = @_;
486 if ($file_name) {
487 $data_out->{_file_name} = $file_name;
488 $data_out->{_note} =
489 $data_out->{_note} . ' data_out=' . $data_out->{_file_name};
490 $data_out->{_Step} =
491 $data_out->{_Step} . ' data_out=' . $data_out->{_file_name};
492 }
493 }
494  
495 =head2 sub get_max_index
496  
497 max index = number of input variables -1
498  
499 =cut
500  
501 sub get_max_index {
502 my ($self) = @_;
503  
504 # base_file_name : index=0
505 # suffix_type : index=1
506 my $max_index = 1;
507  
508 return ($max_index);
509 }
510  
511 =pod
512  
513 =head2 subroutine note
514 adds the program name
515  
516 =cut
517  
518 sub notes_aref {
519 my ($self) = @_;
520  
521 $notes[1] = "\t" . '$data_out[1] = ' . $data_out->{_note};
522  
523 $data_out->{_notes_aref} = \@notes;
524  
525 return $data_out->{_notes_aref};
526 }
527  
528 =head2 subroutine suffix_type
529  
530 suffix_type can be su txt sgy or su
531  
532 =cut
533  
534 sub suffix_type {
535 my ( $self, $suffix_type ) = @_;
536  
537 if ($suffix_type) {
538  
539 $data_out->{_suffix_type} = $suffix_type;
540  
541 }
542 else {
543 print("data_out, suffix_type missing \n");
544 }
545 }
546  
547 =head2 subroutine type
548  
549 suffix_type can be:
550 bin
551 sgy
552 su
553 txt
554 legacy: as of Oct 31, 2018
555  
556 =cut
557  
558 sub type {
559 my ( $self, $suffix_type ) = @_;
560  
561 if ($suffix_type) {
562  
563 $data_out->{_suffix_type} = $suffix_type;
564  
565 }
566 else {
567 print("data_out, type missing \n");
568 }
569 }
570  
571 1;