lib/App/SeismicUnixGui/sunix/header/segyclean.pm untested

filter: Statementstmt 0.0% 0 / 100 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 144 CC 10 SCAR 26.6
CC
10
Cov
0%
Step
42.0
_get_inbound4base_file_names
6.0
_get_outbound4base_file_names
6.0
CRAP 14.4
1 package App::SeismicUnixGui::sunix::header::segyclean;
2  
3 =head1 DOCUMENTATION
4  
5 =head2 SYNOPSIS
6  
7 PERL PROGRAM NAME: SEGYCLEAN - zero out unassigned portion of header
8 AUTHOR: Juan Lorenzo (Perl module only)
9 DATE:
10 DESCRIPTION:
11 Version:
12  
13 =head2 USE
14  
15 =head3 NOTES
16  
17 =head4 Examples
18  
19 =head3 SEISMIC UNIX NOTES
20  
21 SEGYCLEAN - zero out unassigned portion of header
22  
23 segyclean <stdin >stdout
24  
25 Since "foreign" SEG-Y tapes may use the unassigned portion
26 of the trace headers and since SU now uses it too, this
27 program zeros out the fields meaningful to SU.
28  
29 Example:
30 segyread trmax=200 | segyclean | suximage
31  
32 Credits:
33 CWP: Jack Cohen
34  
35  
36 =head2 CHANGES and their DATES
37  
38 SUG Version 0.0.02 allows a list of files to be cleaned
39  
40 09.02.2025 - added list and su_base_file_name parameters
41 to allow processing of a list of files
42 (Juan Lorenzo)
43  
44 =cut
45  
46 =head2 NOTES
47  
48 Version 0.0.02
49  
50 Normally, segyclean acts on only one file at a time
51
52 In V0.0.2 wraps an extension to process an arbitrary
53 list of trace numbers. The automatic iteration includes
54 two additional parameters: list and su_base_file_name
55
56 The parameter "list" is the name of a text file.
57 The file is automatically bound to the SEIMICS_DATA_TXT
58 directory path.
59
60 "list" is the name of a file containing a numeric list
61 of trace numbers of type "key" that are to be deleted:
62
63 An example list
64 file contains values, one per line.
65 1
66 3
67 5
68  
69 "list" = a file name (in directory path: DATA_SEISMICS_TXT)
70 "list" carries a ".txt" suffix automatically within the directory path,
71 but the user does not enter it in the GUI.
72  
73 Neither does the user enter the ".su" suffix in the GUI.
74 su_base_file_name = e.g., 1001, which by defaults lies
75 in directory path: DATA_SEISMIC_SU.
76  
77 A bare file name: '1001' will automatically be given an ".su" suffix,
78 that is, file name on the disk will be '1001.su'
79  
80 Within code, the imported "list" includes path and name;
81 hence its name: _inbound_list. User enters a list name in
82 GUI using the mouse <MB3>.
83  
84 =cut
85  
86 use Moose;
87 our $VERSION = '0.0.2';
88  
89  
90 =head2 Import packages
91  
92 =cut
93  
94 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
95  
96 use App::SeismicUnixGui::misc::SeismicUnix qw($_clean $go $in $off $on $out $ps $to $suffix_ascii $suffix_bin $suffix_ps $suffix_segy $suffix_su);
97 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
98 use aliased 'App::SeismicUnixGui::misc::manage_files_by2';
99  
100 =head2 instantiation of packages
101  
102 =cut
103  
104 my $get = L_SU_global_constants->new();
105 my $Project = Project_config->new();
106 my $manage_files_by2 = manage_files_by2->new();
107 my $DATA_SEISMIC_SEGY = $Project->DATA_SEISMIC_SEGY();
108 my $DATA_SEISMIC_SU = $Project->DATA_SEISMIC_SU();
109 my $DATA_SEISMIC_BIN = $Project->DATA_SEISMIC_BIN();
110 my $DATA_SEISMIC_TXT = $Project->DATA_SEISMIC_TXT();
111  
112 my $var = $get->var();
113 my $empty_string = $var->{_empty_string};
114  
115 my $segyclean = {
116  
117 _inbound_list => '',
118 _trmax => '',
119 _Step => '',
120 _note => '',
121 };
122  
123 =head2 sub Step
124  
125 collects switches and assembles bash instructions
126 by adding the program name
127  
128 =cut
129  
130 sub Step {
131
132 my ($self) = @_;
133
134 # simple check
135 if ( length $segyclean->{_inbound_list} ) {
136 my $file_num;
137 my @Step;
138 my $step;
139
140 my ($inbound_aref) = _get_inbound4base_file_names();
141 my ($outbound_aref) = _get_outbound4base_file_names();
142 my @inbound = @$inbound_aref;
143 my @outbound = @$outbound_aref;
144 my $num_of_files = scalar @outbound;
145  
146 # print("Step,inbound: @inbound\n");
147 # print("Step,inbound: @outbound\n");
148  
149 my $last_idx = $num_of_files - 1;
150  
151 # All cases when num_files >=1
152 # for first file
153 $step = " segyclean $segyclean->{_Step} < $inbound[0] > $outbound[0] ";
154  
155 if ( $last_idx >= 2 ) {
156  
157 # CASE: >= 3 operations
158 for ( my $i = 1 ; $i < $last_idx ; $i++ ) {
159
160 $step =
161 $step . "& segyclean $segyclean->{_Step} < $inbound[$i] > $outbound[$i] ";
162  
163 }
164  
165 # for last file
166 $segyclean->{_Step} =
167 $step . "& segyclean $segyclean->{_Step} < $inbound[$last_idx] > $outbound[$last_idx]";
168  
169 }
170 elsif ( $last_idx == 1 ) {
171  
172 # for last file
173 $segyclean->{_Step} =
174 $step . "& segyclean $segyclean->{_Step} < $inbound[$last_idx] > $outbound[$last_idx] ";
175  
176 }
177 elsif ( $last_idx == 0 ) {
178  
179 $segyclean->{_Step} = "$step";
180  
181 }
182 else {
183 print("segyclean,Step,unexpected case\n");
184 return();
185 }
186  
187 return ($segyclean->{_Step});
188
189 }
190 elsif ( not length $segyclean->{_inbound_list} ) {
191
192 $segyclean->{_Step} = 'segyclean'.$segyclean->{_Step};
193 return ( $segyclean->{_Step} );
194 }
195 else {
196 print("segyclean, Step, incorrect parameters\n");
197 }
198 }
199  
200  
201 =head2 sub note
202  
203 collects switches and assembles bash instructions
204 by adding the program name
205  
206 =cut
207  
208 sub note {
209  
210 $segyclean->{_note} = 'segyclean' . $segyclean->{_note};
211 return ( $segyclean->{_note} );
212  
213 }
214  
215 =head2 sub clear
216  
217 =cut
218  
219 sub clear {
220  
221 $segyclean->{_inbound_list} = '',
222 $segyclean->{_trmax} = '';
223 $segyclean->{_Step} = '';
224 $segyclean->{_note} = '';
225 }
226  
227 =head2 sub _get_inbound4base_file_names
228  
229 =cut
230  
231 sub _get_inbound4base_file_names {
232 my ($self) = @_;
233  
234 my ( $array_ref, $num_files ) = $manage_files_by2->get_base_file_name_aref();
235  
236 if ( defined $array_ref && @$array_ref ) {
237  
238 my @base_file_name = @$array_ref;
239 my @inbound;
240  
241 for ( my $i = 0 ; $i < $num_files ; $i++ ) {
242  
243 $inbound[$i] = $DATA_SEISMIC_SU . '/' . $base_file_name[$i].$suffix_su;
244 }
245 return ( \@inbound );
246  
247 }
248 else {
249 print("segyclean,_get_inbound4base_file_names, missing file names\n");
250 return ();
251 }
252  
253 }
254  
255 =head2 sub _get_outbound4base_file_names
256  
257 =cut
258  
259 sub _get_outbound4base_file_names {
260 my ($self) = @_;
261  
262 my ( $array_ref, $num_files ) = $manage_files_by2->get_base_file_name_aref();
263  
264 if ( length $array_ref ) {
265  
266 my @base_file_name = @$array_ref;
267 my @outbound;
268  
269 for ( my $i = 0 ; $i < $num_files ; $i++ ) {
270  
271 $outbound[$i] = $DATA_SEISMIC_SU . '/' . $base_file_name[$i].$_clean.$suffix_su;
272  
273 }
274 return ( \@outbound );
275  
276 }
277 else {
278 print("segyclean,_get_outbound4basefile_names, missing file names\n");
279 return ();
280 }
281  
282 }
283  
284  
285  
286  
287 =head2 sub list
288  
289 list array
290  
291 =cut
292  
293 sub list {
294 my ( $self, $list ) = @_;
295  
296 if ( length $list ) {
297  
298 # clear memory
299 $manage_files_by2->clear();
300
301 $segyclean->{_inbound_list} = $list;
302
303 $manage_files_by2->set_inbound_list($list);
304
305  
306 }
307 else {
308 print("segyclean, list, missing list,\n");
309 }
310 return ();
311 }
312  
313 =head2 sub trmax
314  
315 maximum number of traces that are expected in the file
316  
317 =cut
318  
319 sub trmax {
320  
321 my ( $self, $trmax ) = @_;
322 if ( $trmax ne $empty_string ) {
323  
324 $segyclean->{_trmax} = $trmax;
325 $segyclean->{_note} =
326 $segyclean->{_note} . ' trmax=' . $segyclean->{_trmax};
327 $segyclean->{_Step} =
328 $segyclean->{_Step} . ' trmax=' . $segyclean->{_trmax};
329  
330 }
331 else {
332 print("segyclean, trmax, missing trmax,\n");
333 }
334 }
335  
336 =head2 sub get_max_index
337 max index = number of input variables - 1
338
339 =cut
340  
341 sub get_max_index {
342 my ($self) = @_;
343 my $max_index = 1;
344  
345 return ($max_index);
346 }
347  
348 1;