next up previous [pdf]

Next: sfpad: Pad a dataset Up: Main programs Previous: sfmask: Create a mask.

sfmath: Mathematical operations on data files.

sfmath > out.rsf n#= d#=(1,1,...) o#=(0,0,...) label#= unit#= type= label= unit= output=
   
Known functions: 
cos,  sin,  tan,  acos,  asin,  atan, 
cosh, sinh, tanh, acosh, asinh, atanh,
exp,  log,  sqrt, abs,
erf,  erfc (for float data),
arg,  conj, real, imag (for complex data).

sfmath will work on float or complex data, but all the input and output
files must be of the same data type.

An alternative to sfmath is sfadd, which may be more efficient, but is
less versatile.

Examples:

sfmath x=file1.rsf y=file2.rsf power=file3.rsf output='sin((x+2*y)^power)' > out.rsf
sfmath < file1.rsf tau=file2.rsf output='exp(tau*input)' > out.rsf
sfmath n1=100 type=complex output="exp(I*x1)" > out.rsf

Arguments which are not treated as variables in mathematical expressions:
datapath=, type=, out=

See also: sfheadermath.

float d#=(1,1,...) sampling on #-th axis
string label= data label
string label#= label on #-th axis
largeint n#= size of #-th axis
float o#=(0,0,...) origin on #-th axis
string output= Mathematical description of the output
string type= output data type [float,complex]
string unit= data unit
string unit#= unit on #-th axis

sfmath is a versatile program for mathematical operations with RSF files. It can operate with several input file, all of the same dimensions and data type. The data type can be real (floating point) or complex. Here is an example that demonstrates several features of sfmath.

bash$ sfmath n1=629 d1=0.01 o1=0 n2=40 d2=1 o2=5 \
output="x2*(8+sin(6*x1+x2/10))" > rad.rsf
bash$ < rad.rsf sfrtoc | sfmath output="input*exp(I*x1)" > rose.rsf
bash$ < rose.rsf sfgraph title=Rose screenratio=1 wantaxis=n | sfpen

The first line creates a 2-D dataset that consists of 40 traces 629 samples each. The values of the data are computed with the formula "x2*(8+sin(6*x1+x2/10))", where x1 refers to the coordinate on the first axis, and x2 is the coordinate of the second axis. In the second line, we convert the data from real to complex using sfrtoc and produce a complex dataset using formula "input*exp(I*x1)", where input refers to the input file. Finally, we plot the complex data as a collection of parametric curves using sfgraph and display the result using sfpen. The plot appearing on your screen should look similar to Figure 1.

rose
rose
Figure 1.
This figure was created with sfmath.
[pdf] [png] [scons]

One possible alternative to the second line above is

bash$ < rad.rsf sfmath output=x1 > ang.rsf
bash$ sfmath r=rad.rsf a=ang.rsf output="r*cos(a)" > cos.rsf
bash$ sfmath r=rad.rsf a=ang.rsf output="r*sin(a)" > sin.rsf
bash$ sfcmplx cos.rsf sin.rsf > rose.rsf
Here we refer to input files by names (r and a) and combine the names in a formula.


next up previous [pdf]

Next: sfpad: Pad a dataset Up: Main programs Previous: sfmask: Create a mask.

2012-07-19