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!
==sfcmplx== {| class="wikitable" align="center" cellspacing="0" border="1" ! colspan="4" style="background:#ffdead;" | Create a complex dataset from its real and imaginary parts. |- ! colspan="4" | sfcmplx < real.rsf > cmplx.rsf real.rsf imag.rsf |- | colspan="4" | There has to be only two input files specified and no additional parameters. |} <tt>sfcmplx</tt> simply creates a complex dataset from its real and imaginary parts. The reverse operation can be accomplished with <tt>sfreal</tt> and <tt>sfimag</tt>. Example of <tt>sfcmplx</tt>: <pre> bash$ sfspike n1=2 n2=3 > one.rsf bash$ sfin one.rsf one.rsf: in="/tmp/one.rsf@" esize=4 type=float form=native n1=2 d1=0.004 o1=0 label1="Time" unit1="s" n2=3 d2=0.1 o2=0 label2="Distance" unit2="km" 6 elements 24 bytes bash$ sfcmplx one.rsf one.rsf > cmplx.rsf bash$ sfin cmplx.rsf cmplx.rsf: in="/tmp/cmplx.rsf@" esize=8 type=complex form=native n1=2 d1=0.004 o1=0 label1="Time" unit1="s" n2=3 d2=0.1 o2=0 label2="Distance" unit2="km" 6 elements 48 bytes </pre> ====Implementation: [https://github.com/ahay/src/blob/master/system/main/cmplx.c system/main/cmplx.c]==== The program flow is simple. First, get the names of the input files. <syntaxhighlight lang="c"> /* the first two non-parameters are real and imag files */ for (i=1; i< argc; i++) { if (NULL == strchr(argv[i],'=')) { if (NULL == real) { real = sf_input (argv[i]); } else { imag = sf_input (argv[i]); break; } } } if (NULL == imag) { if (NULL == real) sf_error ("not enough input"); /* if only one input, real is in stdin */ imag = real; real = sf_input("in"); } </syntaxhighlight> The main part of the program reads the real and imaginary parts buffer by buffer and assembles and writes out the complex input. <syntaxhighlight lang="c"> for (nleft= (size_t) (rsize*resize); nleft > 0; nleft -= nbuf) { nbuf = (BUFSIZ < nleft)? BUFSIZ: nleft; sf_charread(rbuf,nbuf,real); sf_charread(ibuf,nbuf,imag); for (i=0; i < nbuf; i += resize) { memcpy(cbuf+2*i, rbuf+i,(size_t) resize); memcpy(cbuf+2*i+resize,ibuf+i,(size_t) resize); } sf_charwrite(cbuf,2*nbuf,cmplx); } </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