Editing
Guide to madagascar API
(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!
==Fortran-90 interface== The Fortran-90 clip function is listed below. <syntaxhighlight lang="fortran"> program Clipit use rsf implicit none type (file) :: in, out integer :: n1, n2, i1, i2 real :: clip real, dimension (:), allocatable :: trace call sf_init() ! initialize RSF in = rsf_input() out = rsf_output() if (sf_float /= gettype(in)) call sf_error("Need float type") call from_par(in,"n1",n1) n2 = filesize(in,1) call from_par("clip",clip) ! command-line parameter allocate (trace (n1)) do i2=1, n2 ! loop over traces call rsf_read(in,trace) where (trace > clip) trace = clip where (trace < -clip) trace = -clip call rsf_write(out,trace) end do deallocate (trace) end program Clipit </syntaxhighlight> Let us examine it in detail. <syntaxhighlight lang="fortran"> use rsf </syntaxhighlight> The program starts with importing the <tt>rsf</tt> module. <syntaxhighlight lang="fortran"> call sf_init() ! initialize RSF </syntaxhighlight> A call to <tt>sf_init</tt> is needed to initialize the command-line interface. <syntaxhighlight lang="fortran"> in = rsf_input() out = rsf_output() </syntaxhighlight> The standard input and output files are initialized with <tt>rsf_input</tt> and <tt>rsf_output</tt> functions. Both functions accept optional arguments. For example, if the command line contains <tt>vel=velocity.rsf</tt>, then both <tt>rsf_input("velocity.rsf")</tt> and <tt>rsf_input("vel")</tt> are acceptable. <syntaxhighlight lang="fortran"> if (sf_float /= gettype(in)) call sf_error("Need float type") </syntaxhighlight> A call to <tt>from_par</tt> extracts the "<tt>n1</tt>" parameter from the input file. Conceptually, the RSF data model is a multidimensional hypercube. The <tt>n1</tt> parameter refers to the fastest axis. If the input dataset is a collection of traces, <tt>n1</tt> corresponds to the trace length. We could proceed in a similar fashion, extracting <tt>n2</tt>, <tt>n3</tt>, etc. If we are interested in the total number of traces, like in the clip example, a shortcut is to use the <tt>filesize</tt> function. Calling <tt>filesize(in)</tt> returns the total number of elements in the hypercube (the product of <tt>n1</tt>, <tt>n2</tt>, etc.), calling <tt>filesize(in,1)</tt> returns the number of traces (the product of <tt>n2</tt>, <tt>n3</tt>, etc.), calling <tt>filesize(in,2)</tt> returns the product of <tt>n3</tt>, <tt>n4</tt>, etc. By calling <tt>filesize</tt>, we avoid the need to extract additional parameters for the hypercube dimensions that we are not interested in. <syntaxhighlight lang="fortran"> n2 = filesize(in,1) </syntaxhighlight> The clip parameter is read from the command line, where it can be specified, for example, as <tt>clip=10</tt>. If we knew a good default value for <tt>clip</tt>, we could specify it with an optional argument, i.e. <tt>call~from_par("clip",clip,default)</tt>. <syntaxhighlight lang="fortran"> allocate (trace (n1)) do i2=1, n2 ! loop over traces call rsf_read(in,trace) where (trace > clip) trace = clip where (trace < -clip) trace = -clip </syntaxhighlight> Finally, we do the actual work: loop over input traces, reading, clipping, and writing out each trace. ===Compiling=== To compile the Fortran-90 program, run <pre> f90 clip.f90 -I$RSFROOT/include -L$RSFROOT/lib -lrsff90 -lrsf -lm </pre> Change <tt>f90</tt> to the Fortran-90 compiler appropriate for your system and include additional compiler flags if necessary. The flags that RSF typically uses are in <tt>$RSFROOT/share/madagasacar/etc/config.py</tt>. The complete specification for the F90 API can be found [[Library_Reference#Fortran_90_API | on the Library Reference page]].
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