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

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