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

filter: Statementstmt 0.0% 0 / 494 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 45 MC/DCmcdc 0.0% 0 / 30 Subroutinesub 0.0% 0 / 40 Podpod 0.0% 0 / 39 totaltotal 0.0% 0 / 658 CC 6 SCAR 10.6
CC
6
Cov
0%
is_file_empty
6.0
does_file_exist
6.0
is_one
6.0
CRAP 2.9
1 package App::SeismicUnixGui::misc::manage_files_by;
2  
3 use Moose;
4 our $VERSION = '0.0.1';
5  
6 # manage_files_by class
7 # Contains methods/subroutines/functions to operate on directories
8 # V 1. March 3 2008
9 # Juan M. Lorenzo
10  
11 sub copy_file {
12  
13 # this function/method makes a directory
14 # if it does not exist already
15  
16 #get directory names
17 my ($origin) = shift @_;
18 my ($destination) = shift @_;
19  
20 print("\nCopying $origin to $destination \n");
21  
22 system(
23 " \\
24 cp $origin $destination \\
25 "
26 );
27  
28 }
29  
30 #=head2 sub count_lines
31 #
32 # this function counts the numbers of lines in a text file
33 #
34 #=cut
35 #
36 #sub count_lines {
37 # my ($self, $ref_origin) = @_;
38 #
39 ## print ("\nmanage_files_by,count_lines The input file is called $$ref_origin\n");
40 #
41 # # open the file of interest
42 # open( my $IN, '<', $$ref_origin ) or die "Can't open $$ref_origin, $!\n";
43 # my $cnt;
44 # $cnt++ while <$IN>;
45 # close($IN);
46 #
47 # my $num_lines = $cnt;
48 #
49 # # print ("line number = $num_lines\n");
50 #
51 # return ($num_lines);
52 #}
53  
54 sub delete_file {
55  
56 # this function/method deletes files
57  
58 #get directory names
59 my ($ref_directory_path) = shift @_;
60 my ($ref_filename) = shift @_;
61  
62 print("\nDeleting $$ref_directory_path/$$ref_filename \n");
63  
64 system(
65 " \\
66 rm $$ref_directory_path/$$ref_filename \\
67 "
68 );
69  
70 }
71  
72 sub is_file_empty {
73 my ($ref_file) = shift @_;
74  
75 # default situation is to have a file that is empty
76 my $answer = 1;
77  
78 # find status of file to see whether it is empty
79 #$fsize[1] = (stat($$ref_file))[2];
80 #print("\nfile is: $$ref_file\n");
81  
82 # -s is for size
83 #verified by JL
84 my $j = ( -s $$ref_file );
85  
86 # print ("file: $$ref_file is $j in size\n\n");
87 if ( -s $$ref_file > 0 ) {
88  
89 # print ("file is not empty\n\n") ;
90 $answer = 0;
91 }
92  
93 # print("is file empty 1-yes 0-no---- $answer\n\n");
94 # print("file name for size is $$ref_file \n\n");
95 # answer=1 if empty and =0 if not empty
96  
97 return ($answer);
98 }
99  
100 sub does_file_exist {
101 my ($ref_file) = shift @_;
102  
103 # default situation is to have a file non-existent
104 my $answer = 0;
105  
106 # -e returns 1 or ''
107 #verified by JL
108 # print("file for exist test is $$ref_file\n\n");
109 if ( -e $$ref_file ) {
110  
111 # print ("file existence verified\n\n") ;
112 $answer = 1;
113 }
114  
115 # answer=1 if existent and =0 if non-existent
116 #verified by JL
117 return ($answer);
118 }
119  
120 sub is_one {
121  
122 # find out if a special file's content ==1
123 # thereby verifying the existence of a second file
124 my ($ref_file) = shift @_;
125  
126 # default situation is to have a file that is empty
127 my $answer = 0;
128 my $line;
129  
130 #print ("\nFor is_one the input file is called $$ref_file\n");
131  
132 # open the file of interest
133 open( FILE, $$ref_file ) || print("Can't open file_name, $!\n");
134  
135 # read contents of file
136 while ( $line = <FILE> ) {
137 chomp($line);
138 my ($x) = $line;
139  
140 if ( $x == 1 ) {
141 $answer = 1;
142  
143 #print (" yes, first line is one\n\n");
144 }
145 }
146 close(FILE);
147  
148 # answer=1 if line=1 and =0 if line=0
149 return ($answer);
150 }
151  
152 sub is_zero {
153  
154 # find out if a special file's content ==0
155 # thereby showing a second file does not exist
156 my ($ref_file) = shift @_;
157  
158 # default situation is not to have a file with a zero on the first line
159 my $answer = 0;
160 my $line;
161  
162 #print ("\nFor is_zero the input file is called $$ref_file\n");
163  
164 # open the file of interest
165 open( FILE, $$ref_file ) || print("Can't open file_name, $!\n");
166  
167 # read contents of file
168 while ( $line = <FILE> ) {
169 chomp($line);
170 my ($x) = $line;
171  
172 if ( $x == 0 ) {
173 $answer = 1;
174  
175 #print (" yes, first line is zero\n\n");
176 }
177 }
178 close(FILE);
179  
180 # answer=1 if line=1 =0
181 # answer=0 if line1 Not equal to 0
182 return ($answer);
183 }
184  
185 =head2 sub read_mute_par
186  
187 read parameter file
188  
189 =cut
190  
191 sub read_mute_par {
192  
193 my ($ref_file_name) = shift @_;
194  
195 #print ("\nThe input file is called $$ref_file_name\n");
196  
197 =pod Steps
198  
199 1. open file
200  
201 2. set the counter
202  
203 3. read contents of parameter file
204  
205 4. odd-numbered lines contain tnmo and even contain vnmo
206  
207 =cut
208  
209 open( FILE, $$ref_file_name ) || print("Can't open $$ref_file_name, $!\n");
210  
211 my $row = 0;
212 my ( @Items, @things );
213 my ( $i, $line );
214 my ( @row, @numberOfValues );
215  
216 while ( $line = <FILE> ) {
217  
218 # print("\n$line");
219  
220 =pod
221  
222 1. remove end of line
223 2. calculate number of useful elements
224 2. only leave the numbers
225  
226 =cut
227  
228 chomp($line);
229 @things = split /=/, $line;
230  
231 # print("things= @things\n");
232 $numberOfValues[$row] = scalar(@things) + 1;
233 $Items[$row] = pop @things;
234 $row = $row + 1;
235 }
236 close(FILE);
237  
238 print("\n number of rows is $row\n\n");
239  
240 for ( $i = 0 ; $i < $row ; $i++ ) {
241 print("\n row $i contains $Items[$i]");
242 print(" i.e., $numberOfValues[$i] values\n");
243 }
244  
245 return ( \@Items, \@numberOfValues );
246  
247 }
248  
249 =head2 sub read_par
250  
251 read parameter file
252  
253 =cut
254  
255 sub read_par {
256  
257 my ($self, $ref_file_name) = @_;
258  
259 # print ("\nmanage_files_by,read_par,The input file is called $$ref_file_name\n");
260  
261 =pod Steps
262  
263 1. open file
264  
265 2. set the counter
266  
267 3. read contents of parameter file
268  
269 4. odd-numbered lines contain time and even contain vnmo/xmute etc.
270
271  
272 =cut
273  
274 open( FILE, $$ref_file_name ) || print("Can't open file_name, $!\n");
275  
276 my $row = 0;
277 my ( @Items, @things );
278 my ( $i, $line );
279 my ( @row, @ValuesPerRow );
280  
281 while ( $line = <FILE> ) {
282  
283 # print("manage_files_by,read_par, $line");
284  
285 =pod
286  
287 1. remove end of line
288 2. calculate number of useful elements
289 2. only leave the numbers
290  
291 =cut
292  
293 chomp($line);
294 @things = split /=/, $line;
295 $ValuesPerRow[$row] = scalar(@things) + 1;
296 $Items[$row] = pop @things;
297 $row = $row + 1;
298 }
299 close(FILE);
300  
301 return ( \@Items, \@ValuesPerRow );
302  
303 }
304  
305 sub read_2cols_sugethw {
306  
307 # this function reads cols 1 and 2 in a text file
308  
309 my ($ref_origin) = shift @_;
310  
311 # print ("\nThe input file is called $$ref_origin\n");
312  
313 # open the file of interest
314 open( FILE, $$ref_origin ) || print("Can't open file_name, $!\n");
315  
316 #set the counter
317 my $i = 1;
318 my $line;
319 my ( $t, $x );
320 my @TIME;
321 my @OFFSET;
322  
323 # read contents of shotpoint geometry file
324 while ( $line = <FILE> ) {
325  
326 # print("\n$line");
327 chomp($line);
328 ( $t, $x ) = split( " ", $line );
329 $TIME[$i] = $t;
330 $OFFSET[$i] = $x;
331  
332 # print("\n @TIME[$i] @OFFSET[$i]\n");
333 # print("\n @TIME[$i]\n");
334 $i = $i + 1;
335  
336 }
337  
338 close(FILE);
339  
340 my $num_rows = $i - 1;
341  
342 # print out the number of lines of data for the user
343 # print("\nThis file contains $num_rows row(s) of data\n");
344  
345 # to prevent contaminating outside variables
346 my @TIME_OUT = @TIME;
347 my @OFFSET_OUT = @OFFSET;
348  
349 return ( \@TIME_OUT, \@OFFSET_OUT, $num_rows );
350 }
351  
352 sub read_3colsp {
353  
354 # this function reads 3 cols in a text file
355  
356 my ($file_name) = @_;
357  
358 # print ("\nThe input file is called $file_name\n");
359  
360 # open the file of interest
361 open( FILE, $file_name ) || print("Can't open file name, $!\n");
362  
363 #set the counter
364 my $i = 0;
365 my ( @X, @Y, @Z );
366  
367 # read contents of file
368 while ( my $lines = <FILE> ) {
369  
370 # print("$lines");
371 chomp($lines);
372 my ( $x, $y, $z ) = split( " ", $lines );
373  
374 # print("\n$x \n");
375 $X[$i] = $x;
376 $Y[$i] = $y;
377 $Z[$i] = $z;
378  
379 #print("\n @X[$i] @Y[$i] @Z[$i] \n");
380 $i = $i + 1;
381 }
382  
383 # number of geophones stations in file
384 my $num_rows = $i;
385  
386 #print ("This file contains $num_rows rows\n\n\n");
387 # close the file of interest
388 close(FILE);
389  
390 # make sure arrays do not contaminate outside
391 my @XX = @X;
392 my @YY = @Y;
393 my @ZZ = @Z;
394 return ( \@XX, \@YY, \@ZZ, $num_rows );
395  
396 }
397  
398 sub read_3cols {
399  
400 # this function reads 3 cols in a text file
401  
402 my ($ref_file_name) = shift @_;
403  
404 # print ("\nThe input file is called $$ref_file_name\n");
405  
406 # open the file of interest
407 open( FILE, $$ref_file_name ) || print("Can't open file name, $!\n");
408  
409 #set the counter
410 my $i = 1;
411 my ( @X, @Y, @Z );
412  
413 # read contents of file
414 while ( my $lines = <FILE> ) {
415  
416 # print("$lines");
417 chomp($lines);
418 my ( $x, $y, $z ) = split( " ", $lines );
419  
420 # print("\n$x \n");
421 $X[$i] = $x;
422 $Y[$i] = $y;
423 $Z[$i] = $z;
424  
425 #print("\n @X[$i] @Y[$i] @Z[$i] \n");
426 $i = $i + 1;
427 }
428  
429 # number of geophones stations in file
430 my $num_rows = $i - 1;
431  
432 #print ("This file contains $num_rows rows\n\n\n");
433 # close the file of interest
434 close(FILE);
435  
436 # make sure arrays do not contaminate outside
437 my @XX = @X;
438 my @YY = @Y;
439 my @ZZ = @Z;
440 return ( \@XX, \@YY, \@ZZ, $num_rows );
441  
442 }
443  
444 sub read_4cols {
445  
446 # this function reads 4 cols in a text file
447  
448 my ($ref_file_name) = shift @_;
449  
450 # print ("\nThe input file is called $$ref_file_name\n");
451  
452 # open the file of interest
453 open( FILE, $$ref_file_name ) || print("Can't open file_name, $!\n");
454  
455 #set the counter
456 # start counting at 1, NOT 0
457 my $i = 1;
458 my ( @ID, @X, @Y, @Z );
459 my $lines;
460  
461 # read contents of file
462 while ( $lines = <FILE> ) {
463  
464 #print("$lines");
465 chomp($lines);
466 my ( $ident, $x, $y, $z ) = split( " ", $lines );
467  
468 #print("\n $ident \n");
469 $ID[$i] = $ident;
470 $X[$i] = $x;
471 $Y[$i] = $y;
472 $Z[$i] = $z;
473  
474 #print("\nInside sub:read_4cols @ID[$i] @X[$i] @Y[$i] @Z[$i] \n");
475 $i = $i + 1;
476  
477 }
478  
479 # number of geophones stations in file
480 my $num_rows = $i - 1;
481  
482 #print ("This file contains $num_rows row(s)\n\n\n");
483 # close the file of interest
484 close(FILE);
485  
486 # make sure arrays do not contaminate outside
487 my @XX = @X;
488 my @YY = @Y;
489 my @ZZ = @Z;
490 my @IDD = @ID;
491  
492 return ( \@IDD, \@XX, \@YY, \@ZZ, $num_rows );
493  
494 }
495  
496 sub read_4cols_p {
497  
498 # this function reads 4 cols in a text file
499 my $ref_file_name;
500 my @ref_file_name;
501  
502 $ref_file_name = shift @_;
503  
504 # print ("\nThe input file is called @$ref_file_name\n");
505  
506 # open the file of interest
507 open( FILE, @$ref_file_name[1] ) || print("Can't open file_name, $!\n");
508  
509 # set the counter
510 # start counting at 0, NOT 1
511 my $i = 0;
512 my $lines;
513 my ( @ID, @X, @Y, @Z );
514  
515 # read contents of file
516 while ( $lines = <FILE> ) {
517  
518 #print("$lines");
519 chomp($lines);
520 my ( $ident, $x, $y, $z ) = split( " ", $lines );
521  
522 #print("\n $ident \n");
523 $ID[$i] = $ident;
524 $X[$i] = $x;
525 $Y[$i] = $y;
526 $Z[$i] = $z;
527  
528 #print("\nInside sub:read_4cols @ID[$i] @X[$i] @Y[$i] @Z[$i] \n");
529 $i = $i + 1;
530  
531 }
532  
533 # number of geophones stations in file
534 my $num_rows = $i;
535  
536 #print ("This file contains $num_rows row(s)\n\n\n");
537 # close the file of interest
538 close(FILE);
539  
540 # make sure arrays do not contaminate outside
541 my @XX = @X;
542 my @YY = @Y;
543 my @ZZ = @Z;
544 my @IDD = @ID;
545  
546 return ( \@IDD, \@XX, \@YY, \@ZZ, $num_rows );
547  
548 }
549  
550 sub read_5cols {
551  
552 # this function reads 5 cols in a text file
553  
554 my ($ref_file_name) = shift @_;
555  
556 print("\nThe input file with 5 cols is called @$ref_file_name\n");
557  
558 # open the file of interest
559 open( FILE, @$ref_file_name[1] ) || print("Can't open $!\n");
560  
561 #set the counter
562 # start counting at 0, NOT 1
563 my $i = 0;
564 my ( @ID, @X, @Y, @Z, @W );
565 my $lines;
566  
567 # read contents of file
568 while ( $lines = <FILE> ) {
569  
570 #print("$lines");
571 chomp($lines);
572 my ( $ident, $x, $y, $z, $w ) = split( " ", $lines );
573  
574 #print("\n $ident \n");
575 $ID[$i] = $ident;
576 $X[$i] = $x;
577 $Y[$i] = $y;
578 $Z[$i] = $z;
579 $W[$i] = $w;
580  
581 #print("\nInside sub:read_5cols @ID[$i] @X[$i] @Y[$i] @Z[$i] @W[$i]\n");
582 $i = $i + 1;
583 }
584  
585 # number of geophones stations in file
586 my $num_rows = $i - 1;
587  
588 #print ("This file contains $num_rows row(s)\n\n\n");
589 # close the file of interest
590 close(FILE);
591  
592 # make sure arrays do not contaminate outside
593 my @WW = @W;
594 my @XX = @X;
595 my @YY = @Y;
596 my @ZZ = @Z;
597 my @IDD = @ID;
598  
599 return ( \@IDD, \@XX, \@YY, \@ZZ, \@WW, $num_rows );
600  
601 }
602  
603 sub read_5cols_p {
604  
605 # this function reads 5 cols in a text file
606  
607 my ($ref_file_name) = shift @_;
608 print("\nThe input file with 5 cols is called $$ref_file_name[1]\n");
609  
610 # open the file of interest
611 open( FILE, $$ref_file_name[1] ) || print("Can't open $!\n");
612  
613 #set the counter
614 # start counting at 0
615 my $i = 0;
616 my ( @ID, @X, @Y, @Z, @W );
617 my $lines;
618  
619 # read contents of file
620 while ( $lines = <FILE> ) {
621  
622 #print("$lines");
623 chomp($lines);
624 my ( $ident, $x, $y, $z, $w ) = split( " ", $lines );
625  
626 #print("\n $ident \n");
627 $ID[$i] = $ident;
628 $X[$i] = $x;
629 $Y[$i] = $y;
630 $Z[$i] = $z;
631 $W[$i] = $w;
632  
633 #print("\nInside sub:read_5cols @ID[$i] @X[$i] @Y[$i] @Z[$i] @W[$i]\n");
634 $i = $i + 1;
635 }
636  
637 # number of geophones stations in file
638 my $num_rows = $i;
639  
640 #print ("This file contains $num_rows row(s)\n\n\n");
641 # close the file of interest
642 close(FILE);
643  
644 # make sure arrays do not contaminate outside
645 my @WW = @W;
646 my @XX = @X;
647 my @YY = @Y;
648 my @ZZ = @Z;
649 my @IDD = @ID;
650  
651 return ( \@IDD, \@XX, \@YY, \@ZZ, \@WW, $num_rows );
652  
653 }
654  
655 sub read_6cols {
656  
657 # this function reads 6 cols in a text file
658  
659 my ($ref_file_name) = shift @_;
660  
661 # print ("\nThe input file with 6 cols is called $$ref_file_name\n");
662  
663 # open the file of interest
664 open( FILE, $$ref_file_name ) || print("Can't open $$ref_file_name, $!\n");
665  
666 #set the counter
667 my $i = 0;
668 my ( @A, @B, @C, @D, @E, @F );
669 my $lines;
670  
671 # read contents of file
672 while ( $lines = <FILE> ) {
673  
674 #print("$lines");
675 chomp($lines);
676 my ( $a, $b, $c, $d, $e, $f ) = split( " ", $lines );
677  
678 # print("\n $a \n");
679 $A[$i] = $a;
680 $B[$i] = $b;
681 $C[$i] = $c;
682 $D[$i] = $d;
683 $E[$i] = $e;
684 $F[$i] = $f;
685 $i = $i + 1;
686 }
687  
688 # number of geophones stations in file
689 my $num_rows = $i - 1;
690  
691 #print ("This file contains $num_rows row(s)\n\n\n");
692 # close the file of interest
693 close(FILE);
694  
695 # make sure arrays do not contaminate outside
696 my @AA = @A;
697 my @BB = @B;
698 my @CC = @C;
699 my @DD = @D;
700 my @EE = @E;
701 my @FF = @F;
702  
703 return ( \@AA, \@BB, \@CC, \@DD, \@EE, \@FF, $num_rows );
704  
705 }
706  
707 sub write_1col {
708  
709 # WRITE OUT FILE
710  
711 # open and write to output file
712 my ( $ref_X, $ref_file_name, $num_rows, $fmt ) = @_;
713  
714 #print("\nThe write_1col file is called $$ref_file_name\n");
715  
716 open( OUT, ">$$ref_file_name" );
717  
718 for ( my $j = 0 ; $j < $num_rows ; $j++ ) {
719  
720 printf OUT "$fmt\n", $$ref_X[$j];
721  
722 #print("Number of rows is $j, Value is $$ref_X[$j]\n");
723 }
724  
725 close(OUT);
726  
727 }
728  
729 sub mult_col2 {
730  
731 # this function multiplies column 2 by a user given value
732  
733 my ($origin) = shift @_;
734 my ($scale) = shift @_;
735  
736 # print ("\nThe input file is called $origin\n");
737  
738 # open the file of interest
739 open( FILE, $origin ) || print("Can't open file_name, $!\n");
740  
741 #set the counter
742 my $i = 1;
743 my ( @TIME, @OFFSET );
744 my $line;
745  
746 # read contents of file
747 while ( $line = <FILE> ) {
748  
749 #print("\n$line");
750 chomp($line);
751 my ( $t, $x ) = split( " ", $line );
752 $TIME[$i] = $t;
753 $OFFSET[$i] = $x * $scale;
754  
755 # print("\n @TIME[$i] @OFFSET[$i]\n");
756 $i = $i + 1;
757  
758 }
759  
760 close(FILE);
761  
762 my $num_rows = $i - 1;
763  
764 # print out the number of lines of data for the user
765 # print ("This file contains $num_rows[1] rows of data\n\n\n");
766  
767 return ( \@TIME, \@OFFSET, $num_rows );
768  
769 }
770  
771 sub overwriting {
772  
773 # overwrite old Sunix file
774  
775 #get file names
776 my ($ref_backup_file) = shift @_;
777 my ($ref_old_file) = shift @_;
778 my ($ref_new_file) = shift @_;
779  
780 print("\nReplacing $$ref_old_file with $$ref_new_file \n");
781 print("\nKeeping old name $$ref_old_file \n");
782 print("\nBackup is $$ref_backup_file \n");
783  
784 system(" mv $$ref_old_file $$ref_backup_file");
785 system(" mv $$ref_new_file $$ref_old_file ");
786  
787 }
788  
789 sub read_1col {
790  
791 # this function reads 1 col from a text file
792  
793 my ($ref_origin) = shift @_;
794  
795 #print ("\nThe input file is called $$ref_origin\n");
796  
797 # open the file of interest
798 open( FILE, $$ref_origin ) || print("Can't open file_name, $!\n");
799  
800 #set the counter
801 my $i = 1;
802 my $line;
803 my @OFFSET;
804  
805 # read contents of shotpoint geometry file
806 while ( $line = <FILE> ) {
807  
808 #print("\n$line");
809 chomp($line);
810 my ($x) = $line;
811 $OFFSET[$i] = $x;
812  
813 #print("\n Reading 1 col file:@OFFSET[$i]\n");
814 $i = $i + 1;
815  
816 }
817  
818 close(FILE);
819  
820 my $num_rows = $i - 1;
821  
822 # print out the number of lines of data for the user
823 #print ("This file contains $num_rows rows of data\n\n\n");
824 # make sure arrays do not contaminate outside
825 my @OOFFSET = @OFFSET;
826  
827 return ( \@OOFFSET, $num_rows );
828  
829 }
830  
831 sub read_2cols {
832  
833 # this function reads cols 1 and 2 in a text file
834  
835 my ($self, $ref_origin) = @_;
836  
837 # for names that have '
838 # $$ref_origin =~s/'//g;
839  
840 if ( length $ref_origin ) {
841  
842 print("\nThe input file is called $$ref_origin\n");
843  
844 # open the file of interest
845 open( FILE, $$ref_origin ) || print("Can't open file_name, $!\n");
846  
847 # set the counter
848 my $i = 1;
849 my ( @TIME, @OFFSET );
850 my $line;
851  
852 # read contents of shotpoint geometry file
853 while ( $line = <FILE> ) {
854  
855 #print("\n$line");
856 chomp($line);
857 my ( $t, $x ) = split( " ", $line );
858 $TIME[$i] = $t;
859 $OFFSET[$i] = $x;
860  
861 #print("\n @TIME[$i] @OFFSET[$i]\n");
862 $i = $i + 1;
863  
864 }
865  
866 close(FILE);
867  
868 my $num_rows = $i - 1;
869  
870 # print out the number of lines of data for the user
871 #print ("\nThis file contains $num_rows row(s) of data\n");
872  
873 # to prevent contaminating outside variables
874 my @TIME_OUT = @TIME;
875 my @OFFSET_OUT = @OFFSET;
876  
877 return ( \@TIME_OUT, \@OFFSET_OUT, $num_rows );
878  
879 }else{
880 print("manage_files_by, read_2cols, missing file name\n");
881 }
882  
883 }
884  
885 #sub read_2cols_sugethw{
886 ## this function reads cols 1 and 2 in a text file
887 #
888 # my ($ref_origin) = shift @_;
889 #
890 # print ("\nThe input file is called $$ref_origin\n");
891 #
892 ## open the file of interest
893 # open(FILE,$$ref_origin) || print("Can't open file_name, $!\n");
894 #
895 ##set the counter
896 # $i = 1;
897 #
898 ## read contents of shotpoint geometry file
899 # while ($line = <FILE>) {
900 ## print("\n$line");
901 # chomp($line);
902 # ($t,$x) = split (" ",$line);
903 # $TIME[$i] = $t;
904 # $OFFSET[$i] = $x;
905 # print("\n @TIME[$i] @OFFSET[$i]\n");
906 ## print("\n @TIME[$i]\n");
907 # $i = $i +1;
908 #
909 # }
910 #
911 # close(FILE);
912 #
913 # $num_rows = $i-1;
914 #
915 ## print out the number of lines of data for the user
916 # print ("\nThis file contains $num_rows row(s) of data\n");
917 #
918 ## to prevent contaminating outside variables
919 # my @TIME_OUT = @TIME;
920 # my @OFFSET_OUT = @OFFSET;
921 #
922 #return (\@TIME_OUT,\@OFFSET_OUT,$num_rows);
923 #
924 #}
925  
926 #sub read_2cols_2 {
927 #use String::Scanf; # imports sscanf()
928 #TODO
929 # this function reads cols 1 and 2 in a text file with format
930 # this functiondoes not work ebcause it needs scanf from an
931 # unloaded class and scanf is still not tested
932 # my ($ref_filename,$ref_fmt) = shift @_;
933 # print ("\nThe input file is called $$ref_filename\n");
934 #
935 ## open the file of interest
936 # open(FILE,$$ref_filename) || print("Can't open file_name, $!\n");
937 #
938 ## read contents of shotpoint geometry file
939 # for($j=1; <FILE>; $j++) {
940 # printf OUT "$ref_fmt\n", $$ref_X[$j], $$ref_Y[$j];
941 # sscanf FILE "$$ref_fmt\n",$X[$j],$Y[$j];
942 # print("Number of rows is $j, Value is $X[$j]\n");
943 # }
944 # $num_rows = $j-1;
945 # close(FILE);
946 ## print("\n @X[$i] @Y[$i]\n");
947 #
948 ## to prevent contaminating outside variables
949 # my @X_OUT = @X;
950 # my @Y_OUT = @Y;
951 # my $num_rows_out = $num_rows;
952 #
953 #return (\@X_OUT,\@Y_OUT,$num_rows_out);
954 #
955 #}
956 sub trime {
957  
958 # remove the empty spaces at the end of a string
959 #
960 my ($string_in) = @_;
961 $string_in =~ s/\s+$//; #remove trailing spaces
962 my $string_out = $string_in;
963 return ($string_out);
964 }
965  
966 sub write_zero {
967  
968 # WRITE 0 to OUT FILE
969  
970 # open and write 0 to output file
971 my ($ref_file_name) = @_;
972  
973 #print("\nThe write_zero output file is called $$ref_file_name\n");
974 my $zero = 0;
975 open( OUT, ">$$ref_file_name" );
976 print OUT ("$zero\n");
977 close(OUT);
978 }
979  
980 sub write_one {
981  
982 # WRITE 1 to OUT FILE
983 # open and write 1 to output file
984 my ($ref_file_name) = @_;
985  
986 #print("\nThe write_one output file is called $$ref_file_name\n");
987  
988 my $one = 1;
989 open( OUT, ">$$ref_file_name" );
990 print OUT ("$one\n");
991 close(OUT);
992 }
993  
994 sub write_2cols {
995  
996 # WRITE OUT FILE
997  
998 # open and write to output file
999 my ( $ref_X, $ref_Y, $num_rows, $ref_file_name, $fmt ) = @_;
1000  
1001 #print("\nThe output file is called $$ref_file_name\n");
1002 #print("\nThe output file contains $num_rows rows\n");
1003 #print("\nThe output file uses the following format: $fmt\n");
1004  
1005 open( OUT, ">$$ref_file_name" );
1006  
1007 for ( my $j = 1 ; $j <= $num_rows ; $j++ ) {
1008  
1009 #print OUT ("$$ref_X[$j] $$ref_Y[$j]\n");
1010 printf OUT "$fmt\n", $$ref_X[$j], $$ref_Y[$j];
1011  
1012 #print("$$ref_X[$j] $$ref_Y[$j]\n");
1013 }
1014  
1015 close(OUT);
1016 }
1017  
1018 sub write_2cols_p {
1019  
1020 # perl option where the first file has index=0
1021  
1022 # WRITE OUT FILE
1023  
1024 # open and write to output file
1025 my ( $ref_X, $ref_Y, $num_rows, $ref_file_name, $fmt ) = @_;
1026  
1027 print("\nThe output file is called $$ref_file_name\n");
1028 print("\nThe output file contains $num_rows rows\n");
1029 print("\nThe output file uses the following format: $fmt\n");
1030  
1031 open( OUT, ">$$ref_file_name" );
1032  
1033 for ( my $j = 0 ; $j < $num_rows ; $j++ ) {
1034  
1035 #print OUT ("$$ref_X[$j] $$ref_Y[$j]\n");
1036 printf OUT "$fmt\n", $$ref_X[$j], $$ref_Y[$j];
1037  
1038 #print("$$ref_X[$j] $$ref_Y[$j]\n");
1039 }
1040  
1041 close(OUT);
1042 }
1043  
1044 sub write_2cols_2 {
1045  
1046 # WRITE OUT FILE
1047 # April 9 2009
1048 # V2
1049 # new array statements
1050 # open and write to output file
1051 my ( $ref_X, $ref_Y, $num_rows, $ref_file_name, $ref_fmt ) = @_;
1052  
1053 #print("\nThe output file is called $$ref_file_name\n");
1054 #print("\nThe output file contains $num_rows rows\n");
1055 #print("\nThe output file uses the following format: $$ref_fmt\n");
1056  
1057 open( OUT, ">$$ref_file_name" );
1058  
1059 for ( my $j = 1 ; $j <= $num_rows ; $j++ ) {
1060  
1061 #print OUT ("$$ref_X[$j] $$ref_Y[$j]\n");
1062 printf OUT "$$ref_fmt\n", $$ref_X[$j], $$ref_Y[$j];
1063  
1064 #print("$$ref_X[$j] $$ref_Y[$j]\n");
1065 }
1066  
1067 close(OUT);
1068 }
1069  
1070 sub write_3cols {
1071  
1072 # WRITE OUT FILE
1073  
1074 # open and write to output file
1075 my ( $ref_X, $ref_Y, $ref_Z, $num_rows, $ref_file_name, $fmt ) = @_;
1076  
1077 print("\nThe output file is called $$ref_file_name\n");
1078  
1079 open( OUT, ">$$ref_file_name" );
1080  
1081 for ( my $j = 1 ; $j <= $num_rows ; $j++ ) {
1082  
1083 printf OUT "$fmt\n", $$ref_X[$j], $$ref_Y[$j], $$ref_Z[$j];
1084  
1085 #print ("$$ref_X[$j] $$ref_Y[$j] $$ref_Z[$j]\n");
1086 }
1087  
1088 close(OUT);
1089 }
1090  
1091 sub write_3colsp {
1092  
1093 # WRITE OUT FILE
1094  
1095 # open and write to output file
1096 my ( $ref_X, $ref_Y, $ref_Z, $num_rows, $ref_file_name, $fmt ) = @_;
1097  
1098 print("\nThe output file is called $$ref_file_name\n");
1099  
1100 open( OUT, ">$$ref_file_name" );
1101  
1102 for ( my $j = 0 ; $j < $num_rows ; $j++ ) {
1103  
1104 printf OUT "$fmt\n", $$ref_X[$j], $$ref_Y[$j], $$ref_Z[$j];
1105  
1106 # print("$$ref_X[$j] $$ref_Y[$j] $$ref_Z[$j]\n");
1107 }
1108  
1109 close(OUT);
1110 }
1111  
1112 sub write_4cols {
1113  
1114 # WRITE OUT FILE
1115  
1116 # open and write to output filec
1117 my ( $ref_ID, $ref_X, $ref_Y, $ref_Z, $num_rows, $ref_file_name, $fmt ) =
1118 @_;
1119  
1120 print("\nThe output file is called $$ref_file_name\n");
1121  
1122 open( OUT, ">$$ref_file_name" );
1123  
1124 for ( my $j = 1 ; $j <= $num_rows ; $j++ ) {
1125  
1126 printf OUT "$fmt\n", $$ref_ID[$j], $$ref_X[$j], $$ref_Y[$j],
1127 $$ref_Z[$j];
1128  
1129 #print ("$$ref_ID[$j] $$ref_X[$j] $$ref_Y[$j] $$ref_Z[$j]\n");
1130 }
1131  
1132 close(OUT);
1133 }
1134  
1135 sub write_4cols_2 {
1136  
1137 # WRITE OUT FILE
1138 # using two-dimensional arrays
1139 # open and write to output file
1140 my ( $ref_A, $ref_X, $ref_Y, $ref_Z, $num_rows, $num_cols, $ref_file_name,
1141 $fmt )
1142 = @_;
1143  
1144 print("\nThe output file is called $$ref_file_name\n");
1145  
1146 open( OUT, ">$$ref_file_name" );
1147  
1148 for ( my $j = 1 ; $j <= $num_rows ; $j++ ) {
1149 for ( my $i = 1 ; $i <= $num_cols ; $i++ ) {
1150 printf OUT "$fmt\n", $$ref_A[$j][$i], $$ref_X[$j][$i],
1151 $$ref_Y[$j][$i], $$ref_Z[$j][$i];
1152 }
1153 }
1154 close(OUT);
1155 }
1156  
1157 sub write_5cols {
1158  
1159 # WRITE OUT FILE
1160 # open and write to output file
1161 my ( $ref_X, $ref_Y, $ref_Z, $ref_A, $ref_B, $num_rows, $ref_file_name,
1162 $fmt )
1163 = @_;
1164  
1165 print("\nThe output file is called $$ref_file_name\n");
1166  
1167 open( OUT, ">$$ref_file_name" );
1168  
1169 for ( my $j = 1 ; $j <= $num_rows ; $j++ ) {
1170  
1171 printf OUT "$fmt\n", $$ref_X[$j], $$ref_Y[$j], $$ref_Z[$j],
1172 $$ref_A[$j], $$ref_B[$j];
1173 }
1174 close(OUT);
1175 }
1176  
1177 sub write_5cols_2 {
1178  
1179 # WRITE OUT FILE
1180 # using two-dimensional arrays
1181 # open and write to output file
1182 my (
1183 $ref_A, $ref_X, $ref_Y, $ref_Z, $ref_B,
1184 $num_rows, $num_cols, $ref_file_name, $fmt
1185 ) = @_;
1186  
1187 print("\nThe output file is called $$ref_file_name\n");
1188  
1189 open( OUT, ">$$ref_file_name" );
1190  
1191 for ( my $j = 1 ; $j <= $num_rows ; $j++ ) {
1192 for ( my $i = 1 ; $i <= $num_cols ; $i++ ) {
1193 printf OUT "$fmt\n", $$ref_A[$j][$i], $$ref_X[$j][$i],
1194 $$ref_Y[$j][$i], $$ref_Z[$j][$i], $$ref_B[$j][$i];
1195 }
1196 }
1197 close(OUT);
1198 }
1199  
1200 sub write_6cols {
1201  
1202 # WRITE OUT FILE
1203  
1204 # open and write to output file
1205 my (
1206 $ref_X, $ref_Y, $ref_Z,
1207 $ref_R, $ref_uncert, $ref_arrival,
1208 $num_rows, $ref_file_name, $fmt
1209 ) = @_;
1210  
1211 print("\nThe output file is called $$ref_file_name\n");
1212  
1213 open( OUT, ">$$ref_file_name" );
1214  
1215 for ( my $j = 1 ; $j <= $num_rows ; $j++ ) {
1216  
1217 printf OUT "$fmt\n", $$ref_X[$j], $$ref_Y[$j], $$ref_Z[$j],
1218 $$ref_R[$j], $$ref_uncert[$j], $$ref_arrival[$j];
1219 }
1220  
1221 close(OUT);
1222 }
1223  
1224 =head2 write_mute_par
1225  
1226 write out a par file in the correct
1227 format
1228  
1229 =cut
1230  
1231 sub write_mute_par {
1232  
1233 # WRITE OUT FILE
1234  
1235 # open and write to output file
1236 my ( $ref_trace, $ref_values, $ref_file_name, $gather_header ) = @_;
1237 my ( $i, $number_of_traces, $number_of_lines );
1238  
1239 #print("\nThe output file is called $$ref_file_name\n");
1240 $number_of_traces = scalar @$ref_trace - 1;
1241 $number_of_lines = 2 * $number_of_traces;
1242  
1243 #print("number of cdps is $number_of_traces\n");
1244 #print("number of lines is $number_of_lines\n");
1245  
1246 open( OUT, ">$$ref_file_name" );
1247  
1248 print OUT ("$gather_header=");
1249 print OUT ("$$ref_trace[1]");
1250  
1251 for ( $i = 2 ; $i <= $number_of_traces ; $i++ ) {
1252 print OUT (",$$ref_trace[$i]");
1253 }
1254 print OUT ("\n");
1255  
1256 for ( my $i = 1 ; $i < $number_of_lines ; $i = $i + 2 ) {
1257 print OUT ("tmute=$$ref_values[$i]\n");
1258 print OUT ("xmute=$$ref_values[($i+1)]\n");
1259 }
1260  
1261 close(OUT);
1262 }
1263  
1264 =head2 write_cdp
1265  
1266 Write out only the cdp nos.
1267
1268 cdp=g,h
1269
1270 for the first part of a file that contains
1271 more than one tnmo, vnmo pair.
1272  
1273 =cut
1274  
1275 sub write_cdp {
1276  
1277 # WRITE OUT FILE
1278  
1279 # open and write to output file
1280 my ($self, $cdp_aref, $DIR_OUT ) = @_;
1281  
1282 my ( $i, $number_of_cdps, $number_of_lines );
1283  
1284 $number_of_cdps = scalar @$cdp_aref;
1285  
1286 # print("number of cdps is $number_of_cdps \n");
1287 # print("number of cdps is $number_of_cdps \n");
1288 my $temp = '.cdp';
1289 open( OUT, ">$DIR_OUT/$temp" );
1290  
1291 # print first line
1292 print OUT ("cdp=");
1293 print OUT ("@$cdp_aref[0]");
1294  
1295 for ( $i = 1 ; $i < $number_of_cdps ; $i++ ) {
1296 print OUT (",@$cdp_aref[$i]");
1297 }
1298 print OUT ("\n");
1299  
1300 close(OUT);
1301 }
1302  
1303 =head2 write_gather
1304  
1305 write out only the gather nos.
1306
1307 gather=g,h
1308
1309 for the first part of a file that contains
1310 more than one tnmo, vnmo pair
1311  
1312 =cut
1313  
1314 sub write_gather {
1315  
1316 # WRITE OUT FILE
1317  
1318 # open and write to output file
1319 my ( $self, $gather_aref, $DIR_OUT , $gather_type) = @_;
1320  
1321 my ( $i, $number_of_gathers, $number_of_lines );
1322  
1323 $number_of_gathers = scalar @$gather_aref;
1324  
1325 # print("number of gathers is $number_of_gathers \n");
1326 # print("number of gathers is $number_of_gathers \n");
1327 my $temp = '.gather';
1328 open( OUT, ">$DIR_OUT/$temp" );
1329  
1330 # print first line
1331 print OUT ("$gather_type=");
1332 print OUT ("@$gather_aref[0]");
1333  
1334 for ( $i = 1 ; $i < $number_of_gathers ; $i++ ) {
1335 print OUT (",@$gather_aref[$i]");
1336 }
1337 print OUT ("\n");
1338  
1339 close(OUT);
1340 }
1341  
1342 =head2 write_tmute_xmute
1343  
1344 write out only
1345 tmute= a,b,c
1346 xmute= A,B,C
1347 tmute= d,e,f
1348 xmute= D,E,F
1349
1350 for the second part of a file that contains
1351 more than one tmute-xmute pair
1352  
1353 =cut
1354  
1355 sub write_tmute_xmute {
1356  
1357 # WRITE OUT FILE
1358  
1359 # open and write to output file
1360 my ( $self, $gather_aref, $tmute_aref, $xmute_aref, $DIR_OUT ) = @_;
1361  
1362 my ( $i, $number_of_gathers );
1363 $number_of_gathers = scalar @$gather_aref;
1364  
1365 my $temp = '.tx';
1366 open( OUT, ">$DIR_OUT/$temp" );
1367  
1368 # print out subsequent lines
1369 for ( my $i = 0 ; $i < $number_of_gathers ; $i++ ) {
1370  
1371 # for each CDP
1372 print OUT ("tmute=@$tmute_aref[$i]\n");
1373 print OUT ("xmute=@{$xmute_aref}[$i]\n");
1374  
1375 }
1376  
1377 close(OUT);
1378 }
1379  
1380 =head2 write_tnmo_vnmo
1381  
1382 write out only
1383 tnmo= a,b,c
1384 vnmo= A,B,C
1385 rnmo= d,e,f
1386 vnmo= D,E,F
1387
1388 for the second part of a file that contains
1389 more than one tnmo-vnmo pair
1390  
1391 =cut
1392  
1393 sub write_tnmo_vnmo {
1394  
1395 # WRITE OUT FILE
1396  
1397 # open and write to output file
1398 my ( $self, $cdp_aref, $tnmo_aref, $vnmo_aref, $DIR_OUT ) = @_;
1399  
1400 my ( $i, $number_of_cdps );
1401 $number_of_cdps = scalar @$cdp_aref;
1402  
1403 my $temp = '.tv';
1404 open( OUT, ">$DIR_OUT/$temp" );
1405  
1406 # print out subsequent lines
1407 for ( my $i = 0 ; $i < $number_of_cdps ; $i++ ) {
1408  
1409 # for each CDP
1410 print OUT ("tnmo=@{$tnmo_aref}[$i]\n");
1411 print OUT ("vnmo=@{$vnmo_aref}[$i]\n");
1412  
1413 }
1414  
1415 close(OUT);
1416 }
1417  
1418 1;