Editing
Guide to madagascar programs
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==sfmath== {| class="wikitable" align="center" cellspacing="0" border="1" ! colspan="4" style="background:#ffdead;" | Mathematical operations on data files. |- ! colspan="4" | sfmath > out.rsf nostdin=n n#= d#=(1,1,...) o#=(0,0,...) label#= unit#= type= label= unit= output= |- | colspan="4" | <br>Known functions: <br>cos, sin, tan, acos, asin, atan, <br>cosh, sinh, tanh, acosh, asinh, atanh,<br>exp, log, sqrt, abs,<br>erf, erfc, sign (for float data),<br>arg, conj, real, imag (for complex data).<br><br>sfmath will work on float or complex data, but all the input and output<br>files must be of the same data type.<br><br>An alternative to sfmath is sfadd, which may be more efficient, but is<br>less versatile.<br><br>Examples:<br><br>sfmath x=file1.rsf y=file2.rsf power=file3.rsf output='sin((x+2*y)^power)' > out.rsf<br>sfmath < file1.rsf tau=file2.rsf output='exp(tau*input)' > out.rsf<br>sfmath n1=100 type=complex output="exp(I*x1)" > out.rsf<br><br>Arguments which are not treated as variables in mathematical expressions:<br>datapath=, type=, out=<br><br>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 |- | ''bool '' || '''nostdin=n''' || [y/n] || y - ignore stdin |- | ''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 |} <tt>sfmath</tt> is a versatile program for mathematical operations with RSF files. It can operate with several input files with the same dimensions and data type. The data type can be real (floating point) or complex. The following example demonstrates several features of <tt>sfmath</tt>. <pre> 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 </pre> 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 <font color="#cd4b19">"x2*(8+sin(6*x1+x2/10))"</font>, where <tt>x1</tt> refers to the coordinate on the first axis, and <tt>x2</tt> is the coordinate of the second axis. In the second line, we convert the data from real to complex using <tt>sfrtoc</tt> and produce a complex dataset using formula <font color="#cd4b19">"input*exp(I*x1)"</font>, where <tt>input</tt> refers to the input file. Finally, we plot the complex data as a collection of parametric curves using <tt>sfgraph</tt> and display the result using <tt>sfpen</tt>. The plot appearing on your screen should look similar to the figure. [[Image:rose.png|frame|center|This figure was created with <tt>sfmath</tt>.]] One possible alternative to the second line above is <pre> 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 </pre> Here we refer to input files by names (<tt>r</tt> and <tt>a</tt>) and combine the names in a formula. Functions can be nested and combined, and variable names, as well as the <tt>input</tt> keyword, may be combined with the axes keywords <tt>x1</tt>, <tt>x2</tt>, etc. Here is an example that shifts a wavelet -0.4s to t=0, computes the frequency-domain complex square root (equivalent to the convolutional square root in time), and shifts the result back to t=0.4s: <syntaxhighlight lang="bash"> pi=3.14159265 tshift=0.4 sfspike n1=256 k1=101 |\ sfbandpass flo=4 fhi=30 |\ sffft1 opt=n sym=y |\ sfmath output="sqrt(input*exp(2*$pi*$tshift*x1*I))*exp(-2*$pi*$tshift*x1*I)" |\ sffft1 opt=n sym=y inv=y |\ sfgraph |\ sfpen </syntaxhighlight>
Summary:
Please note that all contributions to Madagascar are considered to be released under the GNU Free Documentation License 1.3 or later (see
My wiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
English
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Getting Madagascar
download
Installation
GitHub repository
SEGTeX
Introduction
Package overview
Tutorial
Hands-on tour
Reproducible documents
Hall of Fame
User Documentation
List of programs
Common programs
Popular programs
The RSF file format
Reproducibility with SCons
Developer documentation
Adding programs
Contributing programs
API demo: clipping data
API demo: explicit finite differences
Community
Conferences
User mailing list
Developer mailing list
GitHub organization
LinkedIn group
Development blog
Twitter
Slack
Tools
What links here
Related changes
Special pages
Page information