lib/App/SeismicUnixGui/misc/premmod.pm untested

filter: Statementstmt 0.0% 0 / 103 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 140 CC 4 SCAR 14.8
CC
4
Cov
0%
set_binary_strip
12.0
out_header_values
6.0
clear
2.0
CRAP 4.4
1 package App::SeismicUnixGui::misc::premmod;
2  
3 =head1 DOCUMENTATION
4  
5 =head2 SYNOPSIS
6  
7 PROGRAM NAME: premmod.pm
8 AUTHOR: Juan Lorenzo
9 DATE: June 8 2018
10 DESCRIPTION:
11 Version 0.0.3
12
13 =cut
14  
15 =head2 USE
16  
17 =head3 NOTES
18 This program module is used to read a SU file,
19 creates the file:
20 datammod
21 which is a binary fortran file containing the SU file with no headers, and that
22 can be read by program mmodpg. It also creates the ascii file:
23 parmmod
24 containing
25 basic parameters of the SU file (ntr,ns,dt) also used by mmodpg.
26  
27 =head4
28 Examples
29  
30 =head2 CHANGES and their DATES
31 August, 2001 a Perl version from Emilio Vera
32 Version: 0.0.1 4-22-19
33 Version: 0.0.2 Feb 6 2020 as premmod.pl
34 Version: 0.0.3 turn into module
35
36 =cut
37  
38 # must precede immodpg_config
39  
40 =head2 Define
41 local variables
42  
43 =cut
44  
45 use Moose;
46 our $VERSION = '0.0.3';
47  
48 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
49 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
50 use aliased 'App::SeismicUnixGui::configs::big_streams::immodpg_config';
51 use aliased 'App::SeismicUnixGui::big_streams::immodpg_global_constants';
52 use aliased 'App::SeismicUnixGui::misc::manage_files_by2';
53 use aliased 'App::SeismicUnixGui::misc::message';
54 use aliased 'App::SeismicUnixGui::misc::flow';
55 use aliased 'App::SeismicUnixGui::sunix::header::sustrip';
56  
57 =head2 import variables
58  
59 =cut
60  
61 use App::SeismicUnixGui::misc::SeismicUnix
62 qw($in $out $on $go $to $suffix_bin $off $suffix_su);
63  
64 my $Project = Project_config->new();
65 my $immodpg_config = immodpg_config->new();
66 my $get_immodpg = immodpg_global_constants->new();
67 my $files = manage_files_by2->new();
68 my $get = L_SU_global_constants->new();
69 my $log = message->new();
70 my $run = flow->new();
71 my $sustrip = sustrip->new();
72  
73 =head2 Declare
74 local variables
75  
76 =cut
77  
78 my (@flow);
79 my (@items);
80 my (@sustrip);
81  
82 my $var = $get->var();
83 my $empty_string = $var->{_empty_string};
84 my $var_immodpg = $get_immodpg->var();
85  
86 my $DATA_SEISMIC_SU = $Project->DATA_SEISMIC_SU();
87 my $DATA_SEISMIC_BIN = $Project->DATA_SEISMIC_BIN();
88 my $IMMODPG = $Project->IMMODPG();
89 my $no = $var->{_no};
90 my $yes = $var->{_yes};
91 my @X;
92  
93 =head2 private hash
94  
95 =cut
96  
97 my $premmod = {
98 _base_file_name => '',
99 _outbound_par => '',
100 _inbound_su => '',
101 _outbound_bin => '',
102  
103 };
104  
105 =head2 Get starting configuration
106 parameters
107  
108 =cut
109  
110 my ( $CFG_h, $CFG_aref ) = $immodpg_config->get_values();
111 my $base_file_name = $CFG_h->{immodpg}{1}{base_file_name};
112 my $parmmod = 'parmmod';
113  
114 if ( length $base_file_name ) {
115  
116 # print("premmod,base_file_name:$base_file_name\n");
117  
118 $premmod = {
119 _base_file_name => $base_file_name,
120 _outbound_par => $IMMODPG . '/' . $parmmod,
121 _inbound_su => $DATA_SEISMIC_SU . '/' . $base_file_name . $suffix_su,
122 _outbound_bin => $DATA_SEISMIC_BIN . '/'
123 . $base_file_name
124 . $suffix_bin,
125  
126 };
127  
128 }
129 else {
130 print("premmod, missing base file name\n");
131 }
132  
133 =head2 sub clear
134 private hash variables
135  
136 =cut
137  
138 sub clear {
139  
140 my ($self) = @_;
141 $premmod->{_base_file_name} = '', $premmod->{_outbound_par} = '';
142 $premmod->{_inbound_su} = '';
143 $premmod->{_outbound_bin} = '';
144  
145 }
146  
147 =head2 sub out_header_values to FILE
148  
149 =cut
150  
151 sub out_header_values {
152  
153 my ($self) = @_;
154  
155 if ( $premmod->{_inbound_su} ne $empty_string
156 && $premmod->{_outbound_par} ne $empty_string )
157 {
158  
159  
160 my $size = qx(wc -c $premmod->{_inbound_su} | awk '{print \$1}');
161 my $ns =
162 qx(sugethw key=ns output=geom < $premmod->{_inbound_su} | sed 1q);
163 my $dt =
164 qx(sugethw key=dt output=geom < $premmod->{_inbound_su} | sed 1q);
165 my $ntr = $size / ( $ns * 4 + 240 );
166  
167 # can not print the output to ticks. Do not know why
168 # print("premmod,out_header_values, size=$size number of samples=$ns SI=$dt Traces=$ntr \n\n");
169 # print("premmod,out_header_values, size=$size \n\n");
170  
171 open( OUTFILE, '>', $premmod->{_outbound_par} ) or die $!;
172 printf OUTFILE "%d %d %d\n", $ntr, $ns, $dt;
173 close(OUTFILE);
174  
175 }
176 else {
177 print("premmod, out_header_values missing file name\n");
178 }
179  
180 }
181  
182 =head2 sub set_binary_strip
183  
184 =cut
185  
186 sub set_binary_strip {
187  
188 my ($self) = @_;
189  
190 # print("1. premmod,set_binary_strip _inbound_su=$premmod->{_inbound_su}\n");
191 if ( defined( $premmod->{_inbound_su} )
192 && $premmod->{_inbound_su} ne $empty_string )
193 {
194  
195  
196 =head2 Set up
197 sustrip parameter values
198  
199 =cut
200  
201 $sustrip->clear();
202 $sustrip->ftn( quotemeta(1) ); # fortran binary output
203 $sustrip->head( quotemeta('/dev/null') );
204 $sustrip->outpar( quotemeta('/dev/null') );
205 $sustrip[1] = $sustrip->Step();
206  
207 =head2 DEFINE FLOW(s)
208  
209  
210 =cut
211  
212 @items = (
213 $sustrip[1], $in,
214 $premmod->{_inbound_su},
215 $out, $premmod->{_outbound_bin}
216  
217 );
218 $flow[1] = $run->modules( \@items );
219  
220 =head2 RUN FLOW(s)
221  
222 make lock file before writing
223 and release lock file after writing
224  
225 =cut
226  
227 my $outbound_locked = $premmod->{_outbound_bin} . '_locked';
228 my $test = $no;
229  
230 for ( my $i = 0 ; $test eq $no ; $i++ ) {
231
232 if ( not( $files->does_file_exist( \$outbound_locked ) ) ) {
233
234 # print("premmod,$premmod->{_base_file_name}$suffix_bin is unlocked\n");
235
236 my $format = $var_immodpg->{_format_string};
237 $X[0] = $empty_string;
238 $files->write_1col_aref( \@X, \$outbound_locked, \$format );
239 $run->flow( \$flow[1] );
240  
241 =head2 LOG FLOW(s)
242  
243 to screen and FILE
244  
245 =cut
246 my $time = localtime;
247 # print $flow[1] . "\n";
248 $log->file($time);
249 $log->file( $flow[1] );
250  
251 unlink($outbound_locked);
252 $test = $yes;
253  
254 }
255 else {
256 print("premmod,$premmod->{_base_file_name}$suffix_bin is locked\n");
257 print("premmod,trying again\n");
258 print("\(remove: $outbound_locked\)\n");
259 $test = $yes; # to get out
260 } # if
261  
262 # print("premmod,stuck in for loop\n");
263 } # for
264  
265 }
266 else {
267 print("premmod,set_binary_strip missing variables\n");
268 print("premmod,set_binary_strip _inbound_su=$premmod->{_inbound_su}\n");
269 }
270 }
271  
272 1;