lib/App/SeismicUnixGui/big_streams/iVrms2Vint.pm untested

filter: Statementstmt 0.0% 0 / 174 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 215 CC 9 SCAR 16.3
CC
9
Cov
0%
calcNdisplay
12.0
cdp_num
6.0
file_in
6.0
CRAP 5.1
1 package App::SeismicUnixGui::big_streams::iVrms2Vint;
2  
3 use Moose;
4 our $VERSION = '1.0.0';
5 use aliased 'App::SeismicUnixGui::misc::message';
6 use aliased 'App::SeismicUnixGui::misc::flow';
7 use aliased 'App::SeismicUnixGui::sunix::par::a2b';
8 use aliased 'App::SeismicUnixGui::sunix::plot::xgraph';
9 use aliased 'App::SeismicUnixGui::misc::manage_files_by2';
10 use aliased 'App::SeismicUnixGui::misc::seismics';
11 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
12  
13 =head1 DOCUMENTATION
14 $Time[$i] = $$ref_T[$i];
15 =head2 SYNOPSIS
16  
17 PACKAGE NAME
18 iVrms2Vint.pm
19 Purpose: Convert Vrms to Vinterval
20 Juan M. Lorenzo
21 April 7 2009
22 Nov. 19 2013
23  
24 =head2 USE
25  
26 =head2 NOTES
27  
28 =head4
29  
30 Examples
31  
32 =head2 SEISMIC UNIX NOTES
33  
34 =head4 CHANGES and their DATES
35  
36 =cut
37  
38 =head2 STEPS
39  
40 1. define the types of variables you are using
41 these would be the values you enter into
42 each of the Seismic Unix programs each of the$Time[$i] = $$ref_T[$i];
43 Seismic Unix programs
44  
45 2. build a list or hash with all the possible variable
46 names you may use and you can even change them
47  
48 =cut
49  
50 =head2 instantiate programs
51  
52  
53 =cut
54  
55 my $log = message->new();
56 my $run = flow->new();
57 my $a2b = a2b->new();
58 my $xgraph = xgraph->new();
59 my $files = manage_files_by2->new();
60 my $seismics = seismics->new();
61 my $Project = Project_config->new();
62  
63 =head2 set defaults
64  
65 VELAN DATA
66 m/s
67  
68
69 =cut
70  
71 my $iVrms2Vint = {
72 _cdp_num => '',
73 _first_velocity => '',
74 _number_of_velocities => '',
75 _tmax_s => '',
76 _velocity_increment => '',
77 };
78  
79 =head2 subroutine clear
80  
81 sets all variable strings to ''
82  
83 =cut
84  
85 sub clear {
86 my ( $variable) = @_;
87 $iVrms2Vint->{_cdp_num} = '';
88 $iVrms2Vint->{_first_velocity} = '';
89 $iVrms2Vint->{_number_of_velocities} = '';
90 $iVrms2Vint->{_tmax_s} = '';
91 $iVrms2Vint->{_velocity_increment} = '';
92 }
93  
94 =head2 subroutine cdp
95  
96 sets cdp number to consider
97  
98 =cut
99  
100 sub cdp_num {
101 my ( $variable, $cdp_num ) = @_;
102 $iVrms2Vint->{_cdp_num} = $cdp_num if defined($cdp_num);
103 $iVrms2Vint->{_cdp_num_suffix} = '_cdp' . $iVrms2Vint->{_cdp_num};
104 }
105  
106 sub calcNdisplay {
107  
108 =head2 variables of local scope
109  
110  
111 =cut
112  
113 my ( @cdp_num, @items, @format );
114 my ( @num_samples_file, @num_sample_cols );
115 my ( $ref_T, $ref_Vrms, $num_points_Vrms, $ref_Tnew );
116 my ($ref_Vint);
117 my ( @ref_Vint, @ref_Tnew );
118 my ( $wbox, $hbox, $xbox, $ybox );
119 my ( $xgraph_first_vel, $xgraph_last_vel );
120 my ( @sorted_suffix, @plot_prefix );
121 my (@suffix);
122 my ( @vpicks_stdin, @vint_std );
123 my ( @sortfile_in, @sortfile_out );
124 my ( @write_fileout, @Vint_outbound );
125 my ( @Vint_plot, @Time_plot );
126 my ( @flow, @xgraph, @a2b, @sort );
127 my (@geometry);
128 my ( $Time_plot, $Vint_plot, $num_points_Vint_plot );
129 my ( $i, $j );
130 my (@inbound);
131 my (@sufile_in);
132 my ( @Vrmsfile_in, @Vrms_read_file );
133 my (@Vint_plot_outbound);
134 my ($num_points_Vint);
135 my ( @mkparfile, @parfile_out );
136 my (@outbound);
137  
138 my ($PL_SEISMIC) = $Project->PL_SEISMIC();
139 my ($date) = $Project->date();
140 use App::SeismicUnixGui::misc::SeismicUnix qw($on $off $in $out $to $go);
141  
142 =head2 some SUB-STEPS in Vrms2Vint:
143  
144  
145 1. sort i/p 'ivpicks_old'.'_'.$sufile_in[1].$suffix[3]
146 o/p ivpicks_old'.'_'.'sorted'.'_'.$sufile_in[1].$suffix[3]
147  
148 2. convert rms to int
149 i/p 'ivpicks_old'.'_'.'sorted'
150 o/p 'ivint_old'.'_'.$sufile_in[1].$suffix[3];
151  
152 3. generate a data file for plotting
153 o/p 'plot'.'_'.'ivint_old'.'_'.$sufile_in[1].$suffix[3];
154  
155 =cut
156  
157 $cdp_num[1] = $iVrms2Vint->{_cdp_num};
158  
159 #print("CDP in iVrms2Vint=$iVrms2Vint->{_cdp_num}\n\n");
160 # suffixes
161 $plot_prefix[1] = '.plot';
162 $suffix[3] = '_cdp' . $iVrms2Vint->{_cdp_num};
163  
164 # su file names
165 $sufile_in[1] = $iVrms2Vint->{_file_in};
166  
167 #V file names
168 $vpicks_stdin[1] = 'ivpicks_old';
169 $vint_std[1] = 'ivint_old';
170  
171 # sort file names
172 $sortfile_in[1] = 'ivpicks_old';
173 $sortfile_out[1] = 'ivpicks_old' . '_' . 'sorted';
174 $inbound[1] =
175 $PL_SEISMIC . '/' . 'ivpicks_old' . '_' . $sufile_in[1] . $suffix[3];
176 $outbound[1] =
177 $PL_SEISMIC . '/'
178 . 'ivpicks_old' . '_'
179 . 'sorted' . '_'
180 . $sufile_in[1]
181 . $suffix[3];
182  
183 # RMS Velocity file names
184 $Vrmsfile_in[1] = 'ivpicks_old' . '_' . 'sorted';
185 $Vrms_read_file[1] =
186 $PL_SEISMIC . '/' . $Vrmsfile_in[1] . '_' . $sufile_in[1] . $suffix[3];
187  
188 # a2b file names
189 $num_samples_file[1] = '.num_samples_Vrms_Vint';
190 $num_sample_cols[1] = 2;
191  
192 # Interval Velocity write file names
193 $Vint_outbound[1] =
194 $PL_SEISMIC . '/' . 'ivint_old' . '_' . $sufile_in[1] . $suffix[3];
195  
196 # plot file names
197 $Vint_plot_outbound[1] =
198 $PL_SEISMIC . '/' . 'plot' . '_'
199 . 'ivint_old' . '_'
200 . $sufile_in[1]
201 . $suffix[3];
202  
203 =head2 SORT a TEXT FILE
204  
205
206 =cut
207  
208 $sort[1] = (
209 " sort \\
210 -n \\
211 "
212 );
213 @items = ( $sort[1], $in, $inbound[1], $out, $outbound[1] );
214  
215 $flow[1] = $run->modules( \@items );
216  
217 =head2 RUN FLOW(S)
218  
219 Must run this flow BEFORE converting Vrms to Vint
220 TOD create an individual sort package
221  
222 =cut
223  
224 $run->flow( \$flow[1] );
225  
226 =head2 LOG FLOW(S)TO SCREEN AND FILE
227  
228 =cut
229  
230 # print "$flow[1]\n";
231 #$log->file($flow[1]);
232  
233 =head2 TEXT to BINARY CONVERSION
234  
235  
236 =cut
237  
238 $a2b->clear();
239 $a2b->outpar( quotemeta( $num_samples_file[1] ) );
240 $a2b->floats_per_line( quotemeta( $num_sample_cols[1] ) );
241 $a2b[1] = $a2b->Step();
242  
243 # print("iVrms2Vint first a2b is $a2b[1]\n\n");
244  
245 =head2
246  
247 read Vrms file
248 i/p
249 'ivpicks_old'.'_'.'sorted'.'_'.$sufile_in[1].$suffix[3];
250  
251 =cut
252  
253 # print("iVrms2Vint reading $Vrms_read_file[1] \n");
254 ( $ref_T, $ref_Vrms, $num_points_Vrms ) =
255 $files->read_2cols( \$Vrms_read_file[1] );
256  
257 #print("iVrms2Vint \ntime=$$ref_T[1]\nVrms=$$ref_Vrms[1]\nn=$num_points_Vrms \n");
258  
259 =head2 CONVERT VRMS to VINT FILE
260  
261  
262 =cut
263  
264 ( $ref_Vint, $ref_Tnew, $num_points_Vint ) =
265 $seismics->Vrms2Vint( $ref_T, $ref_Vrms, $num_points_Vrms );
266  
267 print("Vint num points out is $num_points_Vint\n");
268 #for ($i=1; $i<=$num_points_Vint; $i++) {
269 # print("\n$$ref_Vint[$i]\n");
270 # print("\n$$ref_Tnew[$i]\n");
271 #}
272  
273 =head2 CREATE PLOTTING VALUES
274  
275 normally, first time i value is >0
276  
277 =cut
278  
279 if ( $$ref_Tnew[1] > 0. ) {
280 $Time_plot[1] = 0;
281 $Vint_plot[1] = $$ref_Vint[1];
282 for ( $i = 1 ; $i < $num_points_Vint ; $i++ ) {
283 $j = 2 * $i;
284 $Time_plot[$j] = $$ref_Tnew[$i];
285 $Time_plot[ $j + 1 ] = $$ref_Tnew[$i];
286 $Vint_plot[$j] = $$ref_Vint[$i];
287 $Vint_plot[ $j + 1 ] = $$ref_Vint[ $i + 1 ];
288 }
289 $num_points_Vint_plot = $j + 1;
290 }
291  
292 if ( $$ref_Tnew[1] == 0. ) {
293 $Time_plot[1] = 0;
294 $Vint_plot[1] = $$ref_Vint[1];
295 for ( $i = 2 ; $i <= $num_points_Vint ; $i++ ) {
296 $j = 2 * $i;
297 $Time_plot[$j] = $$ref_Tnew[$i];
298 $Time_plot[ $j + 1 ] = $$ref_Tnew[$i];
299 $Vint_plot[$j] = $$ref_Vint[$i];
300 $Vint_plot[ $j + 1 ] = $$ref_Vint[$i];
301 }
302 $num_points_Vint_plot = $j + 1;
303 }
304  
305 =head2 write Vint
306
307 file for plotting
308  
309 =cut
310  
311 $format[1] = '%10.3f %10.3f';# FORMAT TODO
312  
313 print("num points in Vint plot are/is $num_points_Vint_plot\n\n");
314 $files->write_2cols( \@Time_plot, \@Vint_plot, $num_points_Vint_plot,
315 \$Vint_plot_outbound[1],
316 \$format[1] );
317  
318 =head2 XGRAPH FILE(s)
319  
320  
321 =cut
322  
323 $wbox = 550;
324 $hbox = 450;
325 $xbox = 600;
326 $ybox = 600;
327  
328 $geometry[1] = $wbox . 'x' . $hbox . '+' . $xbox . '+' . $ybox;
329  
330 # print(" geometry is $geometry[1])\n\n");
331  
332 $xgraph_first_vel = $iVrms2Vint->{_first_velocity};
333 $xgraph_last_vel =
334 $iVrms2Vint->{_first_velocity} +
335 $iVrms2Vint->{_number_of_velocities} * $iVrms2Vint->{_velocity_increment};
336  
337 my $num_points_per_plot = $num_points_Vrms . ',' . $num_points_Vint_plot;
338 $xgraph->clear();
339 # $xgraph->d1(quotemeta (.05));
340 $xgraph->geometry( quotemeta( $geometry[1] ) );
341 # $xgraph->grid1_type( quotemeta('dash') );
342 # $xgraph->grid2_type( quotemeta('dash') );
343 $xgraph->num_points( quotemeta($num_points_per_plot) );
344 $xgraph->num_points( quotemeta($num_points_per_plot) );
345 $xgraph->x1_min( quotemeta(0) );
346 $xgraph->x1_max( quotemeta( $iVrms2Vint->{_tmax_s} ) );
347 $xgraph->x2_min( quotemeta($xgraph_first_vel) );
348 $xgraph->x2_min(0);
349 $xgraph->x2_max( quotemeta($xgraph_last_vel) );
350 $xgraph->windowtitle(
351 quotemeta( $sufile_in[1] . ' ' . $date . ' ' . $suffix[3] ) );
352 $xgraph->title( quotemeta( $Vrmsfile_in[1] . ' Vrms(green) Vint(red)' ) );
353 $xgraph->format( quotemeta('2,2') );
354 $xgraph->mark_indices( quotemeta('0,8') );
355 $xgraph->mark_size_pix( quotemeta('12,8') );
356 $xgraph->box_width( quotemeta($wbox) );
357 $xgraph->box_height( quotemeta($hbox) );
358 $xgraph->geometry( quotemeta( $geometry[1] ) );
359 $xgraph->label1( quotemeta('Time (s)') );
360 $xgraph->label2( quotemeta('Velocity (m/s)') );
361 $xgraph->line_widths( quotemeta('2,2') );
362 $xgraph->line_color( quotemeta('3,2') );
363 $xgraph->axes_style( quotemeta('seismic') );
364  
365 $xgraph[1] = $xgraph->Step();
366  
367 =head2 DEFINE FLOW(S)
368
369  
370 =cut
371  
372 @items = (
373 "cat", " ", $Vrms_read_file[1], " ",
374 $Vint_plot_outbound[1], $to, $a2b[1], $to,
375 $xgraph[1], $go
376 );
377 $flow[2] = $run->modules( \@items );
378  
379 =head2 RUN FLOW(S)
380  
381  
382 =cut
383  
384 $run->flow( \$flow[2] );
385  
386 =head2 LOG FLOW(S)
387  
388 TO SCREEN AND FILE
389  
390 =cut
391  
392 print "$flow[2]\n";
393 #$log->file($flow[2]);
394  
395 =head2 WRITE OUTPUT FILE
396  
397 write Vint file
398  
399 =cut
400  
401 $files->write_2cols( $ref_T, $ref_Vint, $num_points_Vint,
402 \$Vint_outbound[1], \$format[1] );
403 }
404  
405 # END calcNdisplay
406  
407 =head2 subroutine file_in
408  
409 Required file name
410 on which to perform velocity analyses
411  
412 =cut
413  
414 sub file_in {
415 my ( $variable, $file_in ) = @_;
416 $iVrms2Vint->{_file_in} = $file_in if defined($file_in);
417  
418 #print("file name is $iVrms2Vint->{_file_in} \n\n");
419 }
420  
421 =head2 subroutine first_velocity
422  
423  
424 =cut
425  
426 sub first_velocity {
427 my ( $variable, $first_velocity ) = @_;
428 $iVrms2Vint->{_first_velocity} = $first_velocity
429 if defined($first_velocity);
430  
431 #print("first velocity is $iVrms2Vint->{_first_velocity} \n\n");
432 }
433  
434 =head2 subroutine number_of_velocities
435  
436  
437 =cut
438  
439 sub number_of_velocities {
440 my ( $variable, $number_of_velocities ) = @_;
441 $iVrms2Vint->{_number_of_velocities} = $number_of_velocities
442 if defined $number_of_velocities;
443  
444 #print(" number_of_velocities is $iVrms2Vint->{_number_of_velocities} \n\n");
445 }
446  
447 =head2 subroutine tmax_s
448  
449  
450 =cut
451  
452 sub tmax_s {
453 my ( $self, $tmax_s ) = @_;
454 if ($tmax_s) {
455 $iVrms2Vint->{_tmax_s} = $tmax_s;
456 }
457 }
458  
459 =head2 subroutine velocity increment
460  
461  
462 =cut
463  
464 sub velocity_increment {
465 my ( $variable, $velocity_increment ) = @_;
466 $iVrms2Vint->{_velocity_increment} = $velocity_increment
467 if defined($velocity_increment);
468  
469 #print("velocity_increment is $iVrms2Vint->{_velocity_increment} \n\n");
470 }
471  
472 1;