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

filter: Statementstmt 0.0% 0 / 78 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 11 totaltotal 0.0% 0 / 132 CC 9 SCAR 17.4
CC
9
Cov
0%
data
12.0
file
6.0
out_1_col
6.0
CRAP 5.7
1 package App::SeismicUnixGui::misc::writefiles;
2  
3 use Moose;
4 our $VERSION = '0.0.1';
5  
6 =pod
7  
8 =head1 DOCUMENTATION
9  
10 =head2 SYNOPSIS
11  
12 PERL PROGRAM NAME: writefiles
13 AUTHOR: Juan Lorenzo
14 DATE: Oct 29 2012
15 DESCRIPTION write file operations
16 Version 1
17  
18 STEPS ARE:
19 =cut
20  
21 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
22  
23 my $get = L_SU_global_constants->new();
24  
25 my $var = $get->var();
26 my $empty_string = $var->{_empty_string};
27  
28 my ( @col1, @col2 );
29 my ( $num_rows, $file_out, $fmt );
30  
31 my $newline = '
32 ';
33  
34 my $writefiles = {
35 _format => '',
36 _file_name => '',
37 _path => '',
38 };
39  
40 =pod
41  
42 sub clear
43 clear global variables from the memory
44  
45 =cut
46  
47 sub clear {
48 $writefiles->{_format} = '';
49 }
50  
51 sub cols_2 {
52  
53 #WRITE OUT FILE
54 #open and write 2 cols to output file
55  
56 open( OUT, ">$file_out" );
57 my $j;
58 print("format is: $fmt\n\n");
59 for ( $j = 1 ; $j <= $num_rows ; $j++ ) {
60 printf OUT "$fmt\n", $col1[$j], $col2[$j];
61  
62 #print("$col1[$j] $col2[$j]\n");
63 }
64 close(OUT);
65 }
66  
67 sub data {
68 my ( $variables, $ref_array_data1, $ref_array_data2 ) = @_;
69  
70 @col1 = @$ref_array_data1 if defined($ref_array_data1);
71 @col2 = @$ref_array_data2 if defined($ref_array_data2);
72 $num_rows = scalar(@col1) - 1;
73 print("length of data goes from 1 : $num_rows points\n\n");
74 }
75  
76 sub file {
77 my ( $variables, $ref_filename ) = @_;
78 $file_out = $$ref_filename if defined($ref_filename);
79  
80 #print("filename out is: $file_out\n\n");
81 }
82  
83 =head2 sub out_1_col
84  
85 write 1 col into text file
86
87 =cut
88  
89 sub out_1_col {
90  
91 my ( $self, $ref_X ) = @_;
92  
93 if ( $writefiles->{_file_name} ne $empty_string
94 && $writefiles->{_path} ne $empty_string
95 && $ref_X ne $empty_string )
96 {
97  
98 my $outbound_fh;
99 my $outbound = $writefiles->{_path} . '/' . $writefiles->{_file_name};
100  
101 print("writefiles,cols_7 outbound = $outbound\n");
102  
103 open( $outbound_fh, '>', $outbound )
104 || print(
105 "writefiles,cols_7,Can't open $writefiles->{_file_name}, $!\n");
106  
107 # set the counter
108 my $op_counter = 0;
109 my @output_array = @$ref_X;
110 my $array_length = scalar @output_array;
111  
112 # write contents of file
113 for ( my $j = 0 ; $j <= $array_length ; $j++ ) {
114  
115 print OUT ("$$ref_X[$j]\n");
116  
117 # printf OUT "$$ref_fmt\n", $$ref_X[$j];
118 # print("$$ref_X[$j]\n");
119 #
120 }
121  
122 # close the file of interest
123 close($outbound_fh);
124  
125 return ();
126  
127 }
128 else {
129 print("writefiles,cols_7,missing either ref_X, path or file_name\n");
130 print("file_name = $writefiles->{_file_name}\n");
131 print("path = $writefiles->{_path}\n");
132 return ();
133 }
134  
135 }
136  
137 #=head2 sub config_LSU
138 #
139 #=cut
140 #
141 #sub config_LSU {
142 #
143 # my ( $self, $array_ref ) = @_;
144 #
145 # #my ($self,$array_ref) = @_;
146 # #print ("@$array_ref\n");
147 # #foreach (@$array_ref) {
148 # # print "$_\n";
149 # ##}
150 # print("$self writefiles,config_LSU\n");
151 #
152 # return ();
153 #}
154  
155 sub format {
156 my ( $variables, $format ) = @_;
157 $writefiles->{_format} = $format if defined($format);
158 $fmt = $writefiles->{_format};
159 my @cols = split( /%/, $format );
160 my $num_cols = scalar(@cols) - 1;
161  
162 # only use element =1 through i<=$num_cols
163 # do not use i=0
164 #print("#cols = $num_cols\n\n");
165 print("format is = $writefiles->{_format}\n\n");
166 }
167  
168 sub outcol_1 {
169  
170 #WRITE OUT FILE
171 #open and write 1 cols to output file
172 open( OUT, ">$file_out" );
173 my $j;
174  
175 #print("format is: $fmt\n\n");
176 for ( $j = 1 ; $j <= $num_rows ; $j++ ) {
177 printf OUT "$fmt\n", $col1[$j], $col2[$j];
178  
179 #print("$col1[$j] \n");
180 }
181 close(OUT);
182 }
183  
184 sub setcol_1 {
185 my ( $variables, $ref_array_data1 ) = @_;
186 @col1 = @$ref_array_data1 if defined($ref_array_data1);
187 $num_rows = scalar(@col1) - 1;
188 print("length of data goes from 1 : $num_rows points\n\n");
189 }
190  
191 sub setfile {
192 my ( $variables, $ref_filename ) = @_;
193 $file_out = $ref_filename if defined($ref_filename);
194 print("filename out is: $$file_out\n\n");
195 }
196  
197 =head2 sub set_file_name
198  
199 =cut
200  
201 sub set_file_name {
202 my ( $self, $file_name_ref ) = @_;
203  
204 # print("writefiles,set_file_name,path = $$file_name_ref\n");
205 # my $file_name = $$file_name_ref;
206 # if ($file_name ne $empty_string) {
207 #
208 # $writefiles->{_file_name} = $file_name;
209 # print("writefiles,set_file_name,path = $writefiles->{_file_name}\n");
210 #
211 # } else {
212 # print("writefiles,set_file_name,missing file_name\n");
213 # }
214 }
215  
216 =head2 sub set_path
217  
218 =cut
219  
220 sub set_path {
221 my ( $self, $path ) = @_;
222  
223 if ( $path ne $empty_string ) {
224  
225 $writefiles->{_path} = $path;
226 print("writefiles,set_path,path = $writefiles->{_path} \n");
227  
228 }
229 else {
230 print("writefiles,set_path,missing path\n");
231 }
232  
233 }
234  
235 1;