lib/App/SeismicUnixGui/sunix/statsMath/farith.pm untested

filter: Statementstmt 0.0% 0 / 91 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 135 CC 9 SCAR 15.4
CC
9
Cov
0%
bias
6.0
in
6.0
in2
6.0
CRAP 4.7
1 package App::SeismicUnixGui::sunix::statsMath::farith;
2  
3 =head2 SYNOPSIS
4  
5 PERL PROGRAM NAME:
6  
7 AUTHOR: Juan Lorenzo (Perl module only)
8  
9 DATE:
10  
11 DESCRIPTION:
12  
13 Version:
14  
15 =head2 USE
16  
17 =head3 NOTES
18  
19 =head4 Examples
20  
21 =head2 SYNOPSIS
22  
23 =head3 SEISMIC UNIX NOTES
24 FARITH - File ARITHmetic -- perform simple arithmetic with binary files
25  
26  
27  
28 farith <infile >outfile [optional parameters]
29  
30  
31  
32 Optional Parameters:
33  
34 in=stdin input file
35  
36 out=stdout output file
37  
38 in2= second input file (required for binary operations)
39  
40 if it can't be opened as a file, it might be a scalar
41  
42 n=size_of_in, fastest dimension (used only for op=cartprod is set)
43  
44 isig= index at which signum function acts (used only for
45  
46 op=signum)
47  
48 scale= value to scale in by, used only for op=scale)
49  
50 bias= value to bias in by, used only for op=bias)
51  
52  
53  
54 op=noop noop for out = in
55  
56 neg for out = -in
57  
58 abs for out = abs(in)
59  
60 scale for out = in *scale
61  
62 bias for out = in + bias
63  
64 exp for out = exp(in)
65  
66 sin for out = sin(in)
67  
68 cos for out = cos(in)
69  
70 log for out = log(in)
71  
72 sqrt for out = (signed) sqrt(in)
73  
74 sqr for out = in*in
75  
76 degrad for out = in*PI/180
77  
78 raddeg for out = in*180/PI
79  
80 pinv for out = (punctuated) 1 / in
81  
82 pinvsqr for out = (punctuated) 1 /in*in
83  
84 pinvsqrt for out = (punctuated signed) 1 /sqrt(in)
85  
86 add for out = in + in2
87  
88 sub for out = in - in2
89  
90 mul for out = in * in2
91  
92 div for out = in / in2
93  
94 cartprod for out = in x in2
95  
96 requires: n=size_of_in, fastest dimension in output
97  
98 signum for out[i] = in[i] for i< isig and
99  
100 = -in[i] for i>= isig
101  
102 requires: isig=point where signum function acts
103  
104 Seismic operations:
105  
106 slowp for out = 1/in - 1/in2 Slowness perturbation
107  
108 slothp for out = 1/in^2 - 1/in2^2 Sloth perturbation
109  
110  
111  
112 Notes:
113  
114 op=sqrt takes sqrt(x) for x>=0 and -sqrt(ABS(x)) for x<0 (signed sqrt)
115  
116  
117  
118 op=pinv takes y=1/x for x!=0, if x=0 then y=0. (punctuated inverse)
119  
120  
121  
122 The seismic operations assume that in and in2 are wavespeed profiles.
123  
124 "Slowness" is 1/wavespeed and "sloth" is 1/wavespeed^2.
125  
126 Use "suop" and "suop2" to perform unary and binary operations on
127  
128 data in the SU (SEGY trace) format.
129  
130  
131  
132 The options "pinvsq" and "pinvsqrt" are also useful for seismic
133  
134 computations involving converting velocity to sloth and vice versa.
135  
136  
137  
138 The option "cartprod" (cartesian product) requires also that the
139  
140 parameter n=size_of_in be set. This will be the fastest dimension
141  
142 of the rectangular array that is output.
143  
144  
145  
146 The option "signum" causes a flip in sign for all values with index
147  
148 greater than "isig" (really -1*signum(index)).
149  
150  
151  
152 For file operations on SU format files, please use: suop, suop2
153  
154  
155  
156  
157  
158  
159  
160 Author: Dave Hale, Colorado School of Mines, 07/07/89
161  
162 Zhaobo Meng added scale and cartprod, 10/01/96
163  
164 Zhaobo Meng added signum, 9 May 1997
165  
166 Tony Kocurko added scalar operations, August 1997
167  
168 John Stockwell added bias option 4 August 2004
169  
170  
171  
172 =head2 User's notes (Juan Lorenzo)
173 untested
174  
175 =cut
176  
177  
178 =head2 CHANGES and their DATES
179  
180 =cut
181  
182 use Moose;
183 our $VERSION = '0.0.1';
184  
185  
186 =head2 Import packages
187  
188 =cut
189  
190 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
191  
192 use App::SeismicUnixGui::misc::SeismicUnix qw($go $in $off $on $out $ps $to $suffix_ascii $suffix_bin $suffix_ps $suffix_segy $suffix_su);
193 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
194  
195  
196 =head2 instantiation of packages
197  
198 =cut
199  
200 my $get = L_SU_global_constants->new();
201 my $Project = Project_config->new();
202 my $DATA_SEISMIC_SU = $Project->DATA_SEISMIC_SU();
203 my $DATA_SEISMIC_BIN = $Project->DATA_SEISMIC_BIN();
204 my $DATA_SEISMIC_TXT = $Project->DATA_SEISMIC_TXT();
205  
206 my $PS_SEISMIC = $Project->PS_SEISMIC();
207  
208 my $var = $get->var();
209 my $on = $var->{_on};
210 my $off = $var->{_off};
211 my $true = $var->{_true};
212 my $false = $var->{_false};
213 my $empty_string = $var->{_empty_string};
214  
215 =head2 Encapsulated
216 hash of private variables
217  
218 =cut
219  
220 my $farith = {
221 _bias => '',
222 _in => '',
223 _in2 => '',
224 _isig => '',
225 _n => '',
226 _op => '',
227 _out => '',
228 _scale => '',
229 _Step => '',
230 _note => '',
231  
232 };
233  
234 =head2 sub Step
235  
236 collects switches and assembles bash instructions
237 by adding the program name
238  
239 =cut
240  
241 sub Step {
242  
243 $farith->{_Step} = 'farith'.$farith->{_Step};
244 return ( $farith->{_Step} );
245  
246 }
247  
248  
249 =head2 sub note
250  
251 collects switches and assembles bash instructions
252 by adding the program name
253  
254 =cut
255  
256 sub note {
257  
258 $farith->{_note} = 'farith'.$farith->{_note};
259 return ( $farith->{_note} );
260  
261 }
262  
263  
264  
265 =head2 sub clear
266  
267 =cut
268  
269 sub clear {
270  
271 $farith->{_bias} = '';
272 $farith->{_in} = '';
273 $farith->{_in2} = '';
274 $farith->{_isig} = '';
275 $farith->{_n} = '';
276 $farith->{_op} = '';
277 $farith->{_out} = '';
278 $farith->{_scale} = '';
279 $farith->{_Step} = '';
280 $farith->{_note} = '';
281 }
282  
283  
284 =head2 sub bias
285  
286  
287 =cut
288  
289 sub bias {
290  
291 my ( $self,$bias ) = @_;
292 if ( $bias ne $empty_string ) {
293  
294 $farith->{_bias} = $bias;
295 $farith->{_note} = $farith->{_note}.' bias='.$farith->{_bias};
296 $farith->{_Step} = $farith->{_Step}.' bias='.$farith->{_bias};
297  
298 } else {
299 print("farith, bias, missing bias,\n");
300 }
301 }
302  
303  
304 =head2 sub in
305  
306  
307 =cut
308  
309 sub in {
310  
311 my ( $self,$in ) = @_;
312 if ( $in ne $empty_string ) {
313  
314 $farith->{_in} = $in;
315 $farith->{_note} = $farith->{_note}.' in='.$farith->{_in};
316 $farith->{_Step} = $farith->{_Step}.' in='.$farith->{_in};
317  
318 } else {
319 print("farith, in, missing in,\n");
320 }
321 }
322  
323  
324 =head2 sub in2
325  
326  
327 =cut
328  
329 sub in2 {
330  
331 my ( $self,$in2 ) = @_;
332 if ( $in2 ne $empty_string ) {
333  
334 $farith->{_in2} = $in2;
335 $farith->{_note} = $farith->{_note}.' in2='.$farith->{_in2};
336 $farith->{_Step} = $farith->{_Step}.' in2='.$farith->{_in2};
337  
338 } else {
339 print("farith, in2, missing in2,\n");
340 }
341 }
342  
343  
344 =head2 sub isig
345  
346  
347 =cut
348  
349 sub isig {
350  
351 my ( $self,$isig ) = @_;
352 if ( $isig ne $empty_string ) {
353  
354 $farith->{_isig} = $isig;
355 $farith->{_note} = $farith->{_note}.' isig='.$farith->{_isig};
356 $farith->{_Step} = $farith->{_Step}.' isig='.$farith->{_isig};
357  
358 } else {
359 print("farith, isig, missing isig,\n");
360 }
361 }
362  
363  
364 =head2 sub n
365  
366  
367 =cut
368  
369 sub n {
370  
371 my ( $self,$n ) = @_;
372 if ( $n ne $empty_string ) {
373  
374 $farith->{_n} = $n;
375 $farith->{_note} = $farith->{_note}.' n='.$farith->{_n};
376 $farith->{_Step} = $farith->{_Step}.' n='.$farith->{_n};
377  
378 } else {
379 print("farith, n, missing n,\n");
380 }
381 }
382  
383  
384 =head2 sub op
385  
386  
387 =cut
388  
389 sub op {
390  
391 my ( $self,$op ) = @_;
392 if ( $op ne $empty_string ) {
393  
394 $farith->{_op} = $op;
395 $farith->{_note} = $farith->{_note}.' op='.$farith->{_op};
396 $farith->{_Step} = $farith->{_Step}.' op='.$farith->{_op};
397  
398 } else {
399 print("farith, op, missing op,\n");
400 }
401 }
402  
403  
404 =head2 sub out
405  
406  
407 =cut
408  
409 sub out {
410  
411 my ( $self,$out ) = @_;
412 if ( $out ne $empty_string ) {
413  
414 $farith->{_out} = $out;
415 $farith->{_note} = $farith->{_note}.' out='.$farith->{_out};
416 $farith->{_Step} = $farith->{_Step}.' out='.$farith->{_out};
417  
418 } else {
419 print("farith, out, missing out,\n");
420 }
421 }
422  
423  
424 =head2 sub scale
425  
426  
427 =cut
428  
429 sub scale {
430  
431 my ( $self,$scale ) = @_;
432 if ( $scale ne $empty_string ) {
433  
434 $farith->{_scale} = $scale;
435 $farith->{_note} = $farith->{_note}.' scale='.$farith->{_scale};
436 $farith->{_Step} = $farith->{_Step}.' scale='.$farith->{_scale};
437  
438 } else {
439 print("farith, scale, missing scale,\n");
440 }
441 }
442  
443  
444 =head2 sub get_max_index
445  
446 max index = number of input variables -1
447
448 =cut
449
450 sub get_max_index {
451 my ($self) = @_;
452 my $max_index = 7;
453  
454 return($max_index);
455 }
456
457
458 1;