Manual PDF
Manual PDF
KAUST
Contents 7
Preface 9
1 Introduction 11
3 Data types 25
3.1 Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3
4 CONTENTS
9 Filtering 185
9.1 Frequency-domain filtering (freqfilt.c) . . . . . . . . . . . . . . . . . . . . . 185
9.2 Frequency-domain filtering in 2-D (freqfilt.c) . . . . . . . . . . . . . . . . . 189
9.3 Helical convolution (helicon.c) . . . . . . . . . . . . . . . . . . . . . . . . . . 192
9.4 Helical filter definition and allocation (helix.c) . . . . . . . . . . . . . . . . . 193
9.5 Recursive convolution (polynomial division) (recfilt.c) . . . . . . . . . . . . 195
9.6 Cosine Fourier transform (cosft.c) . . . . . . . . . . . . . . . . . . . . . . . . 197
CONTENTS 5
10 Solvers 201
10.1 Banded matrix solver (banded.c) . . . . . . . . . . . . . . . . . . . . . . . . 201
10.2 Claerbout’s conjugate-gradient iteration (cgstep.c) . . . . . . . . . . . . . . 205
10.3 Conjugate-gradient with shaping regularization (conjgrad.c) . . . . . . . . . 206
10.4 CG with preconditioning (conjprec.c) . . . . . . . . . . . . . . . . . . . . . . 209
10.5 CG iteration (complex data) (cgstep.c) . . . . . . . . . . . . . . . . . . . . . 211
10.6 Conjugate-gradient with shaping regularization for complex numbers (cconj-
grad.c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
10.7 Conjugate-direction iteration (cdstep.c) . . . . . . . . . . . . . . . . . . . . 216
10.8 Linked list for use in conjugate-direction-type methods (llist.c) . . . . . . . 219
10.9 Conjugate-direction iteration for complex numbers (ccdstep.c) . . . . . . . . 223
10.10Linked list for CD-type methods (complex data) (clist.c) . . . . . . . . . . . 227
10.11Solving quadratic equations (quadratic.c) . . . . . . . . . . . . . . . . . . . 231
10.12Zero finder (fzero.c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
10.13Runge-Kutta ODE solvers (runge.c) . . . . . . . . . . . . . . . . . . . . . . 233
10.14Solver function for iterative least-squares optimization (tinysolver.c) . . . . 236
10.15Solver functions for iterative least-squares optimization (bigsolver.c) . . . . 237
10.16Weighting for iteratively-reweighted least squares (irls.c) . . . . . . . . . . . 247
10.17Tridiagonal matrix solver (tridiagonal.c) . . . . . . . . . . . . . . . . . . . . 249
11 Interpolation 255
11.1 1-D interpolation (int1.c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
11.2 2-D interpolation (int2.c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
11.3 3-D interpolation (int3.c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
11.4 Basic interpolation functions (interp.c) . . . . . . . . . . . . . . . . . . . . . 262
11.5 Convert data to B-spline coefficients by fast B-spline transform (prefilter.c) 265
11.6 B-spline interpolation (spline.c) . . . . . . . . . . . . . . . . . . . . . . . . . 267
11.7 Inverse linear interpolation (stretch.c) . . . . . . . . . . . . . . . . . . . . . 271
6 CONTENTS
12 Smoothing 285
12.1 1-D triangle smoothing as a linear operator (triangle1.c) . . . . . . . . . . . 285
12.2 2-D triangle smoothing as a linear operator (triangle2.c) . . . . . . . . . . . 287
12.3 Triangle smoothing (triangle.c) . . . . . . . . . . . . . . . . . . . . . . . . . 289
12.4 Smooth gradient operations (edge.c) . . . . . . . . . . . . . . . . . . . . . . 296
15 Geometry 323
15.1 Construction of points (point.c) . . . . . . . . . . . . . . . . . . . . . . . . . 323
15.2 Construction of vectors (vector.c) . . . . . . . . . . . . . . . . . . . . . . . . 334
15.3 Conversion between line and Cartesian coordinates of a vector (decart.c) . . 342
15.4 Axes (axa.c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
16 Miscellaneous 357
16.1 sharpening (sharpen.c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
16.2 Sharpening inversion added Bregman iteration (sharpinv.c) . . . . . . . . . 359
CONTENTS 7
17 System 363
17.1 Priority queue (heap sorting) (pqueue.c) . . . . . . . . . . . . . . . . . . . . 363
17.2 Simplified system command (system.c) . . . . . . . . . . . . . . . . . . . . . 367
17.3 Generic stack (FILO) structure operations (stack.c) . . . . . . . . . . . . . 368
Index 376
8 CONTENTS
Preface
9
10 CONTENTS
the iterations for the conjugate gradient method for real and complex data. Some other
functions include the root finder and tridagonal matrix solver.
Chapter 11 is for the interpolation subroutines. It has subroutines for 1D, 2D and
3D interpolation. There are functions for B-Spline interpolation, calculation for B-spline
coefficients, ENO and ENO power-p interpolation.
Chapter 12 has the subroutines for of smoothing and edge detection. It has functions
for 1D and 2D triangle smoothing.
Chapter 13 lists the Ray Tracing functions.
Chapter 14 has some general purpose tools like functions for evaluating a mathematical
expression and generating random numbers.
Chapter 15 is concerned with the geometry. It has the functions which define vectors
and points which can be used to define the source and receiver coordinates. It also has the
axa.c file which defines the functions for creating and operating on axes.
Chapter 16 is for the miscellaneous functions.
Chapter 17 lists the function which are system specific for example system.c file defines
functions which can run a given command on the terminal from within the program.
Chapter 1
Introduction
Madagascar provides interfaces for programming in C and optionally in C++ and For-
tran90, etc. The C API is installed automatically during the installation of the Madagascar
package. The other interfaces should be installed separately, if necessary, as explained in
the installation guide.
Programming using a language for which an API (Applications Programming Interface)
is provided by Madagascar allows the user to operate on RSF files and also use some
predefined functions from the RSF library. These library files are located in the directories
api and build/api in the source directory.
A guide to Madagascar programming interface can be found at the Madagascar website
11
12 CHAPTER 1. INTRODUCTION
Chapter 2
An example: Finite-Difference
modeling
To demonstrate the use of the RSF library, a time-domain finite-difference modeling pro-
gram is explained in detail.
2.1 Introduction
This section presents time-domain finite-difference modeling [1] written with the RSF li-
brary. The program is demonstrated with the C, C++ and Fortran 90 interfaces. The
acoustic wave-equation
1 ∂2U
∆U − = f (t)
v 2 ∂t2
can be written as
∂2U
|∆U − f (t)|v 2 = ,
∂t2
where ∆ is the Laplacian symbol, f (t) is the source wavelet, v is the velocity, and U is a
scalar wavefield. A discrete time-step involves the following computations:
where Ui?1 , Ui and Ui+1 represent the propagating wavefield at various time steps. In this
exercise we shall use a discrete Laplacian accurate up to the fourth order and the second
derivative of time is accurate up to the second order.
13
14 CHAPTER 2. AN EXAMPLE: FINITE-DIFFERENCE MODELING
2.2 C program
39 idx = 1/(dx*dx);
40
41 /* read wavelet, velocity & reflectivity */
42 ww = sf_floatalloc(nt); sf_floatread(ww ,nt ,Fw);
43 vv = sf_floatalloc2(nz,nx); sf_floatread(vv[0],nz*nx,Fv);
44 rr = sf_floatalloc2(nz,nx); sf_floatread(rr[0],nz*nx,Fr);
45
46 /* allocate temporary arrays */
47 um = sf_floatalloc2(nz,nx);
48 uo = sf_floatalloc2(nz,nx);
49 up = sf_floatalloc2(nz,nx);
50 ud = sf_floatalloc2(nz,nx);
51
52 for (iz=0; iz<nz; iz++) {
53 for (ix=0; ix<nx; ix++) {
54 um[ix][iz]=0;
55 uo[ix][iz]=0;
56 up[ix][iz]=0;
57 ud[ix][iz]=0;
58 }
59 }
60
61 /* MAIN LOOP */
62 if(verb) fprintf(stderr,"\n");
63 for (it=0; it<nt; it++) {
64 if(verb) fprintf(stderr,"\b\b\b\b\b%d",it);
65
66 /* 4th order laplacian */
67 for (iz=2; iz<nz-2; iz++) {
68 for (ix=2; ix<nx-2; ix++) {
69 ud[ix][iz] =
70 c0* uo[ix ][iz ] * (idx+idz) +
71 c1*(uo[ix-1][iz ] + uo[ix+1][iz ])*idx +
72 c2*(uo[ix-2][iz ] + uo[ix+2][iz ])*idx +
73 c1*(uo[ix ][iz-1] + uo[ix ][iz+1])*idz +
74 c2*(uo[ix ][iz-2] + uo[ix ][iz+2])*idz;
75 }
76 }
77
78 /* inject wavelet */
79 for (iz=0; iz<nz; iz++) {
16 CHAPTER 2. AN EXAMPLE: FINITE-DIFFERENCE MODELING
Line 4 has parameters in the main function. This is to enable the program to take
command line arguments. char* argv[] defines the pointer to the array of type
char and int argc is the length of that array.
Lines 16-17 define pointers to the arrays, which will be used for input (*ww , **vv
, **rr) and for temporary storage (**um,**uo,**up,**ud).
19-20: 19 sf_init(argc,argv);
20 if(! sf_getbool("verb",&verb)) verb=0;
Line 19 initializes the symbol tables used to store the argument from the command
line.
Line 20 tests the verbosity flag specified in the command line arguments. If the
verbosity flag in the command line is set to n, the variable verb (of type bool) is set
to zero. This would allow the verbose output to be printed only if the user set the
verbosity flag to y in the command line.
25 Fv = sf_input ("vel");
26 Fr = sf_input ("ref");
In these lines we use the sf input (see p. 80) and sf output (see p. 80) functions
of the RSF API. These functions take a string as argument and return a variable of
type sf file, we had already defined this type of variables earlier in the program.
28-32: 28 /* Read/Write axes */
29 at = sf_iaxa(Fw,1); nt = sf_n(at); dt = sf_d(at);
30 az = sf_iaxa(Fv,1); nz = sf_n(az); dz = sf_d(az);
31 ax = sf_iaxa(Fv,2); nx = sf_n(ax); dx = sf_d(ax);
Here we input axes (at, az, ax) using sf iaxa (p. 348 of the RSF API. sf iaxa
accepts a variables of type sf file (RSF API) and an integer. The first argument
in sf iaxa is the input file and the second is the axis which we want to input. In the
second column we use sf n (p. 350)from RSF API to get the lengths of the respective
axes.
In the third column we use sf d (p. 351) of the RSF API to get the sampling interval
of the respective axes.
33-35: 33 sf_oaxa(Fo,az,1);
34 sf_oaxa(Fo,ax,2);
35 sf_oaxa(Fo,at,3);
Here we output axes (at, az, ax) using sf oaxa (p. 349) of the RSF API. sf oaxa
accepts variables of type sf file (RSF API), sf axis (RSF API) and an integer.
First argument is the output file, second argument is the name of the axis which we
want to output and the third is the number of the axis in the output file (n1 is the
fastest axis).
37-39: 37 dt2 = dt*dt;
38 idz = 1/(dz*dz);
39 idx = 1/(dx*dx);
These lines define the square of the time sampling interval(dt2) and the inverse
squares of the sampling interval of the spatial axes.
41-44: 41 /* read wavelet, velocity & reflectivity */
42 ww = sf_floatalloc(nt); sf_floatread(ww ,nt ,Fw);
43 vv = sf_floatalloc2(nz,nx); sf_floatread(vv[0],nz*nx,Fv);
44 rr = sf_floatalloc2(nz,nx); sf_floatread(rr[0],nz*nx,Fr);
In the first column we allocate the memory required to hold the input wavelet, veloc-
ity and reflectivity. This is done using sf floatalloc (p. 36) and sf floatalloc2
(p. 42) of the RSF API. sf floatalloc takes integers as arguments and from these in-
tegers it calculates an allocates a block of memory of appropriate size. sf floatalloc2
2.3. EXPLANATION OF THE CODE 19
is the same as sf floatalloc except for the fact that the former allocates an array
of two dimensions, size of the memory block assigned in this case is the product of
the two integers given as arguments (e.g. nz*nx in this case).
Then sf floatread (p. 109) of the RSF API is used to read the data from the
files into the allocated memory blocks (arrays). The sf floatread takes the arrays,
integers and files as arguments and returns arrays filled with the data from the files.
By writing down a similar equation for z and adding the two we get the fourth order
approximation of the Laplacian or as we refer to it here “4th order laplacian”.
Now returning back to the code, the first line is the start of the loop in the z direction.
Within the body of the z loop there is another loop which runs through all the values
of x for one value of z. The second line is start of the for-loop for the x direction.
Then in the body of the loop for x direction we use the 2 × 2 arrays which we defined
earlier. This is just the equation of the Laplacian accurate up to the fourth order, as
2.3. EXPLANATION OF THE CODE 21
discussed above, with the common coefficients factored out. Note that the loops for
x and z start two units after 0 and end two units before nx and nz. This is because
to evaluate the Laplacian at a particular point (x, z) the farthest values which we
are using are two units behind and two units ahead of the current point (x, z) if we
include the points iz=0,1 ; iz=nz-1, nz and ix=0,1;ix=nx-1,nx we will run out
of bounds. To fill these we will need a boundary condition which we will get from
the next loop for inserting the wavelet.
and thus serves the purpose of filling the values at ix,iz=0 and ix-2,ix-1=0 and
iz-2,iz-1=0.
But the source wavelet is not an ideal impulse so it has amplitudes at future times so
for each time the wavelet will be multiplied by the reflectivity at every point (x, z).
Why multiply the wavelet with reflectivity? Well, this model assumes a hypothetical
situation that the source was set off at each and every point in space (x, z) under
consideration and scaled by the reflectivity at that point (x, z). What this means is
that the source was set off at all the points where there is a change in the acoustic
impedance (because reflectivity is the ratio of the difference and sum of the acoustic
impedances across an interface).
The first for-loop is for the z direction and within the body of this loop is another
for-loop for the x direction. up is the array which holds the amplitude of the wave at
the current time in the time loop. uo is the array which contains the amplitude at a
time one unit before the current time and the array um holds the amplitude two units
before. ud is the array we calculated earlier in the program, now it gets multiplied
by ∆t2 (dt2) and included in the final equation. This completes the calculation for
one value of it. Now the arrays need to be updated to represent the next time step.
This is done in the last two: The first one says Ui−1 → Ui and the second one says
Ui → Ui+1 , that is, the array um is updated by uo and then the array uo itself gets
updated by up.
The first line puts the cursor in the new line on the screen after the time loop has
run through all the time values.
The second line uses sf close (p. 113) from RSF API to remove the temporary files.
The third line uses the exit() function in C language to close the streams and
return the control to the host environment. The 0 in the argument indicates normal
termination of the program. The last bracket closes the main function.
24 CHAPTER 2. AN EXAMPLE: FINITE-DIFFERENCE MODELING
Chapter 3
Data types
This chapter contains the descriptions of the data types used in the RSF API.
This section lists the data types for the complex numbers and FFT.
This is a data type, which defines a scalar real value for the data type kiss fft cpx for
complex numbers. It can be either of type short or float. Default is float.
This is a data type (a C structure), which defines a complex number. It has the real and
imaginary parts of the complex numbers defined to be of type kiss fft scalar.
25
26 CHAPTER 3. DATA TYPES
The kiss fft state is a data type which defines the required variables for the Fourier
transform and allocates the required space. For example the variable inverse of type int
indicates whether the transform needs to be an inverse or forward.
The kiss fftr state is a data type which defines the required variables for the Fourier
transform and allocates the required space. This has the same purpose as kiss fft state
but for the Fourier transform of the real signals.
sf complex
This is an object of type kiss fft cfg (which is an object of C data structure).
sf double complex
This is a C data structure for complex numbers. It uses the type double for the real and
imaginary parts of the complex numbers.
3.1.2 Files
This section lists the data types used to define the .rsf file structure.
sf file
This is an object of type sf File. sf File is a data structure which defines the variables
required for creating a .rsf file in Madagascar. It is defined in file.c.
3.1. DATA TYPES 27
sf datatype
This is a C enumeration, which means that it contains new data types, which are not the
fundamental types like int, float, sf file etc. This data type is used in sf File data
structure to set the type of a .rsf file, for example SF CHAR, SF INT etc. It is defined
in file.c.
sf dataform
This is a C enumeration, which means that it contains new data types, which are not the
fundamental types like int, float, sf file etc. This data type is used in sf File data
structure to set the format of an .rsf file, for example SF ASCII, SF XDR and SF NATIVE.
It is defined in file.c.
3.1.3 Operators
This section lists the data types used to define linear operators.
sf triangle
This is an object of an abstract C datatype type sf Triangle. The sf triangle data type
defines the variables of relevant types to store information about the triangle smoothing
filter. It is defined in triangle.c.
sf operator
This is a C data type of type void. It is also a pointer to a function which takes the
input parameters precisely as (bool, bool, int, int, float*, float*). It is defined
in solver.h.
sf solverstep
This is a C data type of type void. It is also a pointer to a function which takes the in-
put parameters precisely as (bool, bool, int, int, float*, const float*, float*,
const float*). It is defined in solver.h.
28 CHAPTER 3. DATA TYPES
sf weight
This is a C data type of type void. It is also a pointer to a function which takes the
input parameters precisely as (int, int, const sf complex*, float*). It is defined in
solver.h.
sf coperator
This is a C data type of type void. It is also a pointer to a function which takes the input
parameters precisely as (bool bool, int, int, sf complex*, sf complex*). It works
just like sf operator but does it for complex numbers. It is defined in solver.h.
sf csolverstep
This is a C data type of type void. It is also a pointer to a function which takes the input pa-
rameters precisely as (bool, bool, int, int, sf complex*, const sf complex*, sf complex*,
const sf complex*). It works just like sf solverstep but does it for complex numbers.
It is defined in solver.h.
sf cweight
This is a C data type of type void. It is also a pointer to a function which takes the
input parameters precisely as (int, int, const sf complex*, float*). It works just
like sf weight but does it for the complex numbers. It is defined in solver.h.
sf eno
This is a C data structure, which contains the required variables for 1D ENO (Essentially
Non Oscillatory) interpolation. It is defined in eno.c.
sf eno2
This is a C data structure, which contains the required variables for 2D ENO (Essentially
Non Oscillatory) interpolation. It is defined in eno2.c.
3.1. DATA TYPES 29
sf bands
This is a C data structure, which contains the required variables for storing a banded
matrix. It is defined in banded.c.
3.1.4 Geometry
This section lists the data types used to define the geometry of the seismic data.
sf axa
This is a C data structure which contains the variables of type int and float to store the
length origin and sampling of the axis. It is defined in axa.c.
pt2d
This is a C data structure which contains the variables of type double and float to store
the location and value of a 2D point. It is defined in point.c.
pt3d
This is a C data structure which contains the variables of type double and float to store
the location and value of a 3D point. It is defined in point.c.
vc2d
This is a C data structure which contains the variables of type double to store the compo-
nents of a 2D vector. It is defined in vector.c.
vc3d
This is a C data structure which contains the variables of type double to store the compo-
nents of a 3D vector. It is defined in vector.c.
3.1.5 Lists
This section describes the data types used to create and operate on lists.
30 CHAPTER 3. DATA TYPES
sf list
This is a C data structure, which contains the required variables for storing the information
about the list, for example . It uses another C data structure Entry. It is defined in llist.c.
Entry
This is a C data structure, which contains the required variables for storing the elements
and moving the pointer in the list. It is defined in llist.c.
3.1.6 sys/types.h
This section describes some of the data types used from the C header file sys/types.h.
off t
This is a data type defined in the sys/types.h header file (of fundamental type unsigned
long) and is used to measure the file offset in bytes from the beginning of the file. It is
defined as a signed, 32-bit integer, but if the programming environment enables large files
off t is defined to be a signed, 64-bit integer.
size t
This is a data type defined in the sys/types.h header (of fundamental type unsigned
int) and is used to measure the file size in units of character. It is used to hold the result
of the sizeof operator in C, for example sizeof(int)=4, sizeof(char)=1, etc.
Chapter 4
4.1.1 sf alloc
Checks whether the requested size for memory allocation is valid and if so it returns a
pointer of void type, pointing to the allocated memory block. It takes the ’number of
elements’ and ’size of one element’ as input arguments. Both arguments have to be of the
of type size t.
Call
Definition
31
32 CHAPTER 4. PREPARING FOR INPUT
Input parameters
Output
4.1.2 sf realloc
The same as sf alloc but it allocates new memory such that it appends the block previ-
ously assigned by sf alloc. It takes three parameters, first one is a void pointer to the old
memory block. Second and third parameters are the same as for sf alloc but are used
to determine the new block, which is to be appended. sf realloc returns a void pointer
pointing to the whole memory block (new + old).
Call
Definition
Input parameters
Output
4.1.3 sf charalloc
Allocates the memory exactly like sf alloc but the size in this one is fixed which is the
size of one character. Therefore sf charalloc allocates the memory for n elements which
must be of character type. Because the size is fixed there is just one input parameter which
is the number of elements (i.e. characters). Output is a void pointer pointing to the block
of memory allocated.
Call
Definition
Input parameters
Output
4.1.4 sf ucharalloc
The same as sf charalloc but it only allocates the memory for the unsigned character
type, that is, the size of the elements is sizeof(unsigned char).
34 CHAPTER 4. PREPARING FOR INPUT
Call
Definition
Input parameters
Output
4.1.5 sf shortalloc
Allocates the memory for the short integer type, that is, the size of the elements is, for
example sizeof(short int).
Call
Definition
Input parameters
Output
4.1.6 sf intalloc
Allocates the memory for the large integer type, that is, the size of the elements is, for
example sizeof(int).
Call
Definition
Input parameters
Output
4.1.7 sf largeintalloc
Allocates the memory for the large integer type, that is, the size of the elements is, for
example sizeof(large int).
36 CHAPTER 4. PREPARING FOR INPUT
Call
Definition
Input parameters
Output
4.1.8 sf floatalloc
Allocates the memory for the floating point type, that is, the size of the elements is, for
example sizeof(float).
Call
Definition
Input parameters
Output
4.1.9 sf complexalloc
Allocates the memory for the sf complex type, that is, the size of the elements is, for
example sizeof(sf complex).
Call
Definition
Input parameters
Output
4.1.10 sf complexalloc2
Allocates a 2D array in the memory for the sf complex type. It works just like sf complexalloc
but does it for two dimensions. This is done by making a pointer point to another pointer,
38 CHAPTER 4. PREPARING FOR INPUT
which in turn points to a particular column (or row) of an allocated 2D block of memory
of size n1*n2. n1 is the fastest dimension.
Call
Definition
Input parameters
Output
4.1.11 sf complexalloc3
Allocates a 3D array in the memory for the sf complex type. It works just like sf complexalloc2
but does it for three dimensions. This is done by extending the same argument as
for sf complexalloc2 this time making a pointer such that Pointer2 -> Pointer1 ->
Pointer. n1 is the fastest dimension.
Call
Definition
Input parameters
Output
4.1.12 sf complexalloc4
Allocates a 4D array in the memory for the sf complex type. It works just like sf complexalloc2
but does it for four dimensions. This is done by extending the same argument as for
sf complexalloc2 but this time making a pointer such that Pointer3 -> Pointer2 ->
Pointer1 -> Pointer. n1 is the fastest dimension.
Call
Definition
Input parameters
Output
4.1.13 sf boolalloc
Allocates the memory for the bool type, that is, the size of the elements is, for example
sizeof(bool).
Call
Definition
Input parameters
Output
4.1.14 sf boolalloc2
Allocates a 2D array in the memory for the bool type. It works just like sf boolalloc
but does it for two dimensions. This is done by making a pointer point to another pointer,
which in turn points to a particular column (or row) of an allocated 2D block of memory
of size n1*n2. n1 is the fastest dimension.
Call
Definition
Input parameters
Output
4.1.15 sf boolalloc3
Allocates a 3D array in the memory for the bool type. It works just like sf boolalloc2
but does it for three dimensions. This is done by extending the same argument as for
42 CHAPTER 4. PREPARING FOR INPUT
sf boolalloc2 but this time making a pointer such that Pointer2 -> Pointer1 ->
Pointer. n1 is the fastest dimension.
Call
Definition
Input parameters
Output
4.1.16 sf floatalloc2
Allocates a 2D array in the memory for the float type. It works just like sf floatalloc
but does it for two dimensions. This is done by making a pointer point to another pointer,
which in turn points to a particular column (or row) of an allocated 2D block of memory
of size n1*n2. n1 is the fastest dimension.
Call
Definition
Input parameters
Output
4.1.17 sf floatalloc3
Allocates a 3D array in the memory for the float type. It works just like sf floatalloc2
but does it for three dimensions. This is done by extending the same argument as for
sf floatalloc2 but this time making a pointer such that Pointer2 -> Pointer1 ->
Pointer. n1 is the fastest dimension.
Call
Definition
Input parameters
Output
4.1.18 sf floatalloc4
Allocates a 4D array in the memory for the float type. It works just like sf floatalloc2
but does it for four dimensions. This is done by extending the same argument as for
sf floatalloc2 but this time making a pointer such that Pointer3 -> Pointer2 ->
Pointer1 -> Pointer. n1 is the fastest dimension.
Call
Definition
Input parameters
Output
4.1.19 sf floatalloc5
Allocates a 5D array in the memory for the float type. It works just like sf floatalloc2
but does it for four dimensions. This is done by extending the same argument as for
sf floatalloc2 but this time making a pointer such that Pointer4 -> Pointer3 ->
Pointer2 -> Pointer1 -> Pointer. n1 is the fastest dimension.
Call
Definition
Input parameters
Output
4.1.20 sf floatalloc6
Allocates a 6D array in the memory for the float type. It works just like sf floatalloc2
but does it for four dimensions. This is done by extending the same argument as for
sf floatalloc2 but this time making a pointer such that Pointer5 -> Pointer4 ->
Pointer3 -> Pointer2 -> Pointer1 -> Pointer. n1 is the fastest dimension.
Call
Definition
Input parameters
Output
4.1.21 sf intalloc2
Allocates a 2D array in the memory for the float type. It works just like sf intalloc but
does it for two dimensions. This is done by making a pointer point to another pointer,
which in turn points to a particular column (or row) of an allocated 2D block of memory
of size n1*n2. n1 is the fastest dimension.
Call
Definition
Input parameters
Output
4.1.22 sf intalloc3
Allocates a 3D array in the memory for the float type. It works just like sf intalloc2
but does it for three dimensions. This is done by extending the same argument as for
48 CHAPTER 4. PREPARING FOR INPUT
sf intalloc2 this time making a pointer such that Pointer2 -> Pointer1 -> Pointer.
n1 is the fastest dimension.
Call
Definition
Input parameters
Output
4.1.23 sf intalloc4
Allocates a 4D array in the memory for the float type. It works just like sf intalloc2
but does it for four dimensions. This is done by extending the same argument as for
sf intalloc2 but this time making a pointer such that Pointer3 -> Pointer2 -> Pointer1
-> Pointer. n1 is the fastest dimension.
Call
Definition
Input parameters
Output
4.1.24 sf charalloc2
Allocates a 2D array in the memory for the float type. It works just like sf charalloc
but does it for two dimensions. This is done by making a pointer point to another pointer,
which in turn points to a particular column (or row) of an allocated 2D block of memory
of size n1*n2. n1 is the fastest dimension.
Call
Definition
Input parameters
Output
4.1.25 sf uncharalloc2
Allocates a 2D array in the memory for the float type. It works just like sf uncharalloc
but does it for two dimensions. This is done by making a pointer point to another pointer,
which in turn points to a particular column (or row) of an allocated 2D block of memory
of size n1*n2. n1 is the fastest dimension.
Call
Definition
Input parameters
Output
4.1.26 sf uncharalloc3
Allocates a 3D array in the memory for the float type. It works just like sf uncharalloc2
but does it for three dimensions. This is done by extending the same argument as for
sf uncharalloc2 but this time making a pointer such that Pointer2 -> Pointer1 ->
Pointer. n1 is the fastest dimension.
Call
Definition
Input parameters
Output
Creates a table to store the parameters input either from command line or a file. It takes
the required size (type int) of the table as input. The output is a pointer to the allocated
table and it is of the defined data type sf simtab.
call
table = sf_simtab_init(size);
Definition
Input parameters
Output
table a pointer of type sf simtab pointing to the allocated block of memory for the
symbol table.
Call
sf_simtab_close(table);
4.2. SIMBOL TABLE FOR PARAMETERS (SIMTAB.C) 53
Definition
Input parameters
table the table whose allocated memory has to be deleted. Must be of type sf simtab.
Enters a value in the table, which was created by sf simtab init. In the input it must
be told which table to enter the value in, this is the first input argument and is of type
sf simtab. The second and the third arguments are the pointers of const char* type.
The first one points to key, which would be the name of the argument from command line
or file. Second argument is the pointer to the value to be input.
Call
Definition
Input parameters
table the table in which the the key value is to be stored. Must be of type sf simtab.
key pointer to the name of the key value to be input (const char*).
val pointer to the key value to be input (const char*).
54 CHAPTER 4. PREPARING FOR INPUT
Extracts the value of the input key from the symbol table. It is used in other functions
such as sf simtab getint.
Call
Input parameters
table the table from which the vale has to be extracted. Must be of type sf simtab.
key the name of the entry which has to be extracted (const char*).
Output
val pointer of type char to the desired key value stored in the table. This is the output
in case there is a match between the required key and a key in the table. If there
is no match between the required key and the key stored in the table, then NULL
is returned.
Extracts an integer from the table. If the extraction is successful returns a boolean true,
otherwise returns a false.
Call
Definition
Input parameters
table the table from which the vale has to be extracted. Must be of type sf simtab.
key the name of the entry which has to be extracted (const char*).
par pointer to the integer variable where the extracted value is to be copied.
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
Extracts a large integer from the table. If the extraction is successful, it returns a boolean
true, otherwise a false.
Call
Definition
Input parameters
table the table from which the vale has to be extracted. Must be of type sf simtab.
key the name of the entry which has to be extracted (const char*).
par pointer to the large integer variable where the extracted value is to be copied.
56 CHAPTER 4. PREPARING FOR INPUT
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
Extracts a float value from the table. If the extraction is successful, it returns a boolean
true, otherwise a false.
Call
Definition
Input parameters
table the table from which the vale has to be extracted. Must be of type sf simtab.
key the name of the entry which has to be extracted (const char*).
par pointer to the float type value variable where the extracted value is to be copied.
Output
success a boolean value. It is true, if the extraction was successful and false otherwise
successfully.
Extracts a double type value from the table. If the extraction is successful, it returns a
boolean true, otherwise a false.
4.2. SIMBOL TABLE FOR PARAMETERS (SIMTAB.C) 57
Call
Definition
Input parameters
table the table from which the vale has to be extracted. Must be of type sf simtab.
key the name of the entry which has to be extracted (const char*).
par pointer to the double type value variable where the extracted value is to be copied.
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
Extracts an array of float values from the table. If the extraction is successful, it returns
a boolean true, otherwise a false.
Call
Definition
Input parameters
table the table from which the vale has to be extracted. Must be of type sf simtab.
key the name of the float array which has to be extracted (const char*).
par pointer to the array of float type value variable where the extracted value id to
be copied.
n size of the array to be extracted (size t).
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
Extracts a string pointed by the input key from the symbol table. If the value is NULL it
will return NULL, otherwise it will allocate a new block of memory of char type and copy the
memory block from the table to the new block and return a pointer to the newly allocated
block of memory.
Call
Definition
Input parameters
table the table from which the string has to be extracted. Must be of type sf simtab.
key the name of the string which has to be extracted (const char*).
Output
Extracts a boolean value from the table. If the extraction is successful, it returns a boolean
true, otherwise a false.
Call
Definition
Input parameters
table the table from which the value has to be extracted. Must be of type sf simtab.
key the name of the entry which has to be extracted (const char*).
par pointer to the bool variable where the extracted value is to be copied.
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
60 CHAPTER 4. PREPARING FOR INPUT
Extracts an array of boolean values from the table. If the extraction is successful, it returns
a boolean true, otherwise a false.
Call
Definition
Input parameters
table the table from which the vale has to be extracted. Must be of type sf simtab.
key the name of the boolean array which has to be extracted. Must be of XXXXXXXXX
pointer to the array of bool type value variable where the extracted value is to
be copied.
n size of the array to be extracted (size t).
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
Extracts an array of integer values from the table. If the extraction is successful, it returns
a boolean true, otherwise a false.
4.2. SIMBOL TABLE FOR PARAMETERS (SIMTAB.C) 61
Call
Definition
Input parameters
table the table from which the vale has to be extracted. Must be of type sf simtab.
key the name of the integer array which has to be extracted (const char*).
par pointer to the array of integer type value variable where the extracted value id
to be copied.
n size of the array to be extracted. Must be of size t.
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
Extracts an array of strings from the table. is successful, it returns a boolean true,
otherwise a false.
Call
Definition
Input parameters
table the table from which the vale has to be extracted. Must be of type sf simtab.
key the name of the string array which has to be extracted (const char*).
par pointer to the pointer to array of integer type value variable where the extracted
value is to be copied.
n size of the array to be extracted. Must be of size t.
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
Writes a new key together with its value to the symbol table. The new entry must be in
the form key=val and must be of the const char* type, that is, this function must be
given a pointer to key=val. Since the type of the pointer is const char* this can be a
direct input from the command line and in that case the pointer will be acgv[n] where n
specifies the position in the command line.
Call
Definition
Input parameters
table the table in which the value has to be entered. Must be of type sf simtab.
keyval pointer to key=val which is to be entered.
Inputs a table from one file and copies it into another and also adds the new entry into the
internal table using sf simtab put.
Call
Definition
Input parameters
table the table in which the value has to be entered. Must be of type sf simtab.
fp pointer to the file from which the parameter is to be read. It must be of
typeFILE*.
out pointer to the file in which the parameter is to be written. It must be of type
FILE*.
64 CHAPTER 4. PREPARING FOR INPUT
Reads the parameters from the internal table and writes them to a file.
Call
Definition
Input parameters
table the table in which the value has to be entered. Must be of type sf simtab.
fp pointer to the file in which the parameter is to be written. It must be of type
FILE*.
4.3.1 sf stdin
Checks whether there is an input in the command line, if not it returns a false. It reads
the first character in the file: if it is an EOF, false is returned and if not, then true is the
return value. It takes no input parameters and returns a boolean value.
Call
hasinp sf_stdin();
4.3. PARAMETER HANDLING (GETPAR.C) 65
Definition
bool sf_stdin(void)
/*< returns true if there is an input in stdin >*/
{
...
}
4.3.2 sf init
Initializes a parameter table which is created using sf simtab init. The input arguments
are same as used in the main function in c when there is some arguments are to be input
from the command line.
Input parameters
Call
sf_init(argc, argv[]);
Definition
Frees the allocated space for the table. It uses sf simtab close to close the table. It does
not take any input parameters but passes a pointer pars defined by sf init.
66 CHAPTER 4. PREPARING FOR INPUT
Call
sf_parclose ();
Definition
4.3.4 sf parout
Reads the parameters from the internal table and writes them to a file. It uses sf simtab output.
It takes a pointer to the file, in which the parameters are to be written.
Call
sf_parout (file);
Definition
Input parameters
4.3.5 sf getprog
Outputs a pointer of char type to the name of the current running program. The pointer
it returns is assigned a value in sf init.
4.3. PARAMETER HANDLING (GETPAR.C) 67
Call
Definition
Output
prog pointer to an array which contains the current program name (char).
4.3.6 sf getuser
Outputs a pointer of char type to the name of the current user. The pointer it returns is
assigned a value in sf init.
Call
Definition
Output
4.3.7 sf gethost
Outputs a pointer of char type to the name of the current host. The pointer it returns is
assigned a value in sf init.
Call
Definition
Output
4.3.8 sf getcdir
Outputs a pointer of char type to the name of the current working directory. The pointer
it returns is assigned a value in sf init.
Call
Definition
Output
cdir pointer to an array which contains the current working directory (char).
4.3.9 sf getint
Extracts an integer from the command line. If the extraction is successful, it returns a
true, otherwise a false. It uses sf simtab getint.
Call
Definition
Input parameters
key the name of the entry which has to be extracted (const char*).
par pointer to the integer variable where the extracted value is to be copied.
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
4.3.10 sf getlargeint
Extracts a large integer from the command line. If the extraction is successful, it returns
a true, otherwise a false. It uses sf simtab getlargeint.
70 CHAPTER 4. PREPARING FOR INPUT
Call
Definition
Input parameters
key the name of the entry which has to be extracted (const char*).
par pointer to the large integer variable where the extracted value is to be copied. Must
be of type off t which is defined in the header <sys/types.h>.
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
4.3.11 sf getints
Extracts an array of integer values from the command line. If the extraction is successful,
it returns a true, otherwise a false.
Call
Definition
...
}
Input parameters
key the name of the integer array which has to be extracted (const char*).
par pointer to the array of integer type value variable where the extracted value id to
be copied.
n size of the array to be extracted. Must be of size t.
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
4.3.12 sf getfloat
Extracts a float value from the command line. If the extraction is successful, it returns a
true, otherwise a false.
Call
Definition
Input parameters
key the name of the entry which has to be extracted (const char*).
par pointer to the float type value variable where the extracted value is to be copied.
72 CHAPTER 4. PREPARING FOR INPUT
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
4.3.13 sf getdouble
Extracts a double type value from the command line. If the extraction is successful, it
returns a true, otherwise a false.
Call
Definition
Input parameters
table the table from which the vale has to be extracted. Must be of type sf simtab.
key the name of the entry which has to be extracted (const char*).
par pointer to the double type value variable where the extracted value is to be copied.
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
4.3.14 sf getfloats
Extracts an array of float values from the command line. If the extraction is successful, it
returns a true, otherwise a false. It uses sf simtab getfloats.
4.3. PARAMETER HANDLING (GETPAR.C) 73
Call
Definition
Input parameters
key the name of the float array which has to be extracted (const char*).
par pointer to the array of float type value variable where the extracted value id to be
copied.
n size of the array to be extracted (size t).
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
4.3.15 sf getstring
Extracts a string pointed by the input key from the command line. If the value is NULL
it will return NULL, otherwise it will allocate a new block of memory of char type and
copy the memory block from the table to the new block and return a pointer to the newly
allocated block of memory. It uses sf simtab getstring.
Call
Definition
Input parameters
key the name of the string which has to be extracted (const char*).
Output
4.3.16 sf getstrings
Extracts an array of strings from the command line. If the extraction is successful, it
returns a true, otherwise a false.
Call
Definition
Input parameters
key the name of the string array which has to be extracted (const char*).
4.3. PARAMETER HANDLING (GETPAR.C) 75
par pointer to the pointer to array of integer type value variable where the extracted
value is to be copied.
n size of the array to be extracted. Must be of size t.
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
4.3.17 sf getbool
Extracts a boolean value from the command line. If the extraction is successful, it returns
a true, otherwise a false.
Call
Definition
Input parameters
key the name of the entry which has to be extracted (const char*).
par pointer to the bool variable where the extracted value is to be copied.
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
76 CHAPTER 4. PREPARING FOR INPUT
4.3.18 sf getbools
Extracts an array of bool values from the command line. If the extraction is successful, it
returns a true, otherwise a false. It uses sf simtab getbools.
Call
Definition
Input parameters
key the name of the bool array which has to be extracted (const char*).
par pointer to the array of bool type value variable where the extracted value id to be
copied.
n size of the array to be extracted. Must be of size t.
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
4.3.19 sf getpars
This function returns a pointer to the parameter table which must have been initialized
earlier in the program using sf init.
Call
Definition
Output
Sets an error on opening files. It sets the value of error (a static variable of type bool).
This variable is used in the sf input error as an if-condition.
Call
sf_file_error(err);
Definition
Input parameters
err value of type bool which is to be assigned to the static variable error.
79
80 CHAPTER 5. OPERATIONS WITH RSF FILES
5.1.2 sf error
Outputs an error message to the stderr (usually the screen) if the file cannot be opened.
The ’:’ after the format specifiers in the call to sf error ensures that any system errors
are also included in the output.
Call
Definition
static void sf_input_error(sf_file file, const char* message, const char* name)
{
...
}
Input parameters
5.1.3 sf input
Creates an input file structure and returns a pointer to that file structure. It will create
the symbol table, input parameters to the table and write them in a temporary file and
check for any errors in the input of the parameters. It will also set the format of the file
and then return a pointer to the file structure.
Call
file = sf_input(tag);
5.1. MAIN OPERATIONS WITH RSF FILES (FILE.C) 81
Definition
Input parameters
Output
5.1.4 sf output
Creates an output file structure and returns a pointer to that file structure. It will create
the symbol table, a header file and put the path of the data file in the header with the key
”in”.
Call
file = sf_output(tag);
Definition
Input parameters
Output
5.1.5 sf gettype
Returns the type of the file, e.g. SF INT, SF FLOAT, SF COMPLEX etc.
Call
Definition
Input parameters
file a pointer to the file structure whose type is required (sf file).
Output
5.1.6 sf getform
Call
Definition
Input parameters
file a pointer to the file structure whose type is required (sf file).
Output
5.1.7 sf esize
Returns the size of the element type of the file, e.g. SF INT, SF FLOAT, SF COMPLEX etc.
Call
size = sf_esize(file);
Definition
Input parameters
file a pointer to the file structure whose type is required (sf file).
Output
5.1.8 sf settype
Sets the type of the file, e.g. SF INT, SF FLOAT, SF COMPLEX etc.
Call
sf_settype (file,type);
Definition
Input parameters
file a pointer to the file structure whose type is to be set (sf file).
type the type to be set. Must be of type sf datatype, e.g. SF INT.
5.1.9 sf setpars
Changes the parameter table from that of the file to the one which has parameters from
the command line.
Call
sf_setpars (file);
5.1. MAIN OPERATIONS WITH RSF FILES (FILE.C) 85
Definition
Input parameters
file a pointer to the file structure whose parameter table is to be closed (sf file).
5.1.10 sf bufsiz
Returns the size of the buffer associated with the file. It gets the buffer size using the file
descriptor of the file and the predefined structure stat. This provides control over the I/O
operations, making them more efficient.
Call
bufsiz = sf_bufsiz(file);
Definition
Input parameters
file a pointer to the file structure whose buffer size is required (sf file).
Output
5.1.11 sf setform
Call
Definition
Input parameters
file a pointer to the file structure whose form is to be set (sf file).
form the type to be set. Must be of type sf datatype, e.g. SF ASCII.
5.1.12 sf setformat
Sets the format of the file, e.g. SF INT, SF FLOAT, SF COMPLEX etc. Format is the combina-
tion of file form and its type, e.g. ASCII INT.
Call
Definition
{
...
}
Input parameters
file a pointer to the file structure whose format is to be set (sf file).
format the type to be set (const char*).
5.1.13 sf getfilename
Returns a boolean value (true or false), depending on whether it was able to find the
filename of an open file or not. The search is based on finding the file descriptor of an open
file, if it is found the return value is true, otherwise false. Once the file name is found
it is copied to the value pointed by the pointer filename which is given as input and is
already defined in the sf input.
Call
Definition
Input parameters
Output
success a boolean value which is true if the filename is found otherwise false.
5.1.14 sf gettmpdatapath
Returns the path of temporary data. It takes no input parameters. The places it looks for
the temporary data path are listed in the function definition comment.
Call
Definition
Datapath rules:
1. check tmpdatapath= on the command line
2. check TMPDATAPATH environmental variable
3. check .tmpdatapath file in the current directory
4. check .tmpdatapath in the home directory
5. return NULL
*/
{
...
}
Output
5.1.15 sf getdatapath
Returns the path of the data. It takes no input parameters. The places it looks for the
temporary data path are listed in the function definition comment.
5.1. MAIN OPERATIONS WITH RSF FILES (FILE.C) 89
Call
path = getdatapath();
Definition
Datapath rules:
1. check datapath= on the command line
2. check DATAPATH environmental variable
3. check .datapath file in the current directory
4. check .datapath in the home directory
5. use ’.’ (not a SEPlib behavior)
*/
{
...
}
Output
5.1.16 sf readpathfile
Returns a boolean value (true or false), depending on whether it was able to find the data
path in an open file or not. Once the datapath is found it is copied to the value pointed
by the pointer datapath which is given as input and is already defined in the sf input.
Call
Definition
{
...
}
Input parameters
filename a pointer to the file name in which datapath is to be found (const char).
datapath pointer to the parameter which is being looked for.
Output
success a boolean value which is true if the filename is found otherwise false.
5.1.17 sf fileclose
Closes the file and frees any allocated space, like the temporary file and buffer.
Call
sf_fileclose (file);
Definition
Input parameters
5.1.18 sf histint
Extracts an integer from the file. If the extraction is successful, it returns a true, otherwise
a false. It uses sf simtab getint.
5.1. MAIN OPERATIONS WITH RSF FILES (FILE.C) 91
Call
Definition
Input parameters
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
5.1.19 sf histints
Extracts an array of integer values from the file. If the extraction is successful, it returns
a true, otherwise a false.
Call
Definition
{
...
}
Input parameters
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
5.1.20 sf histlargeint
Extracts a large integer from the file. If the extraction is successful, it returns a true,
otherwise a false. It uses sf simtab getlargeint.
Call
Definition
Input parameters
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
5.1.21 sf histfloat
Extracts a float value from the file. If the extraction is successful, it returns a true,
otherwise a false.
Call
Definition
Input parameters
file file from which a floating point number is to be extracted (sf file).
key the name of the entry which has to be extracted (const char*).
par pointer to the float type value variable where the extracted value is to be copied.
94 CHAPTER 5. OPERATIONS WITH RSF FILES
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
5.1.22 sf histdouble
Extracts a double type value from the file. If the extraction is successful, it returns a true,
otherwise a false.
Call
Definition
Input parameters
file file from which a double type value is to be extracted (sf file).
table the table from which the vale has to be extracted. Must be of type sf simtab.
key the name of the entry which has to be extracted (const char*).
par pointer to the double type value variable where the extracted value is to be copied.
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
5.1. MAIN OPERATIONS WITH RSF FILES (FILE.C) 95
5.1.23 sf histfloats
Extracts an array of float values from the file. If the extraction is successful returns a true.
It uses sf simtab getfloats.
Call
Definition
Input parameters
file file from which a float type array is to be extracted (sf file).
key the name of the float array which has to be extracted (const char*).
par pointer to the array of float type value variable where the extracted value is to be
copied.
n size of the array to be extracted (size t).
5.1.24 sf histbool
Extracts a boolean value from the file. If the extraction is successful, it returns a true,
otherwise a false.
Call
Definition
Input parameters
file file from which a bool type value is to be extracted (sf file).
key the name of the entry which has to be extracted (const char*).
par pointer to the bool variable where the extracted value is to be copied.
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
5.1.25 sf histtbools
Extracts an array of bool values from the file. If the extraction is successful, it returns a
true, otherwise a false.It uses sf simtab getbools.
Call
Definition
Input parameters
file file from which an array of bool value is to be extracted (sf file).
key the name of the bool array which has to be extracted (const char*).
par pointer to the array of bool type value variable where the extracted value is to be
copied.
n size of the array to be extracted. Must be of size t.
Output
success a boolean value. It is true, if the extraction was successful and false other-
wise.
5.1.26 sf histstring
Extracts a string pointed by the input key from the file. If the value is NULL it will return
NULL, otherwise it will allocate a new block of memory of char type and copy the memory
block from the table to the new block and return a pointer to the newly allocated block of
memory. It uses sf simtab getstring.
Call
Definition
Input parameters
Output
5.1.27 sf fileflush
Outputs the parameters from source file to the output file. It sets the data format in the
output file and prepares the file for writing binary data.
Call
Definition
Input parameters
5.1.28 sf putint
Call
Definition
Input parameters
file the file in which the the key value is to be stored (sf file).
key pointer to the name of the key value to be input (const char*).
par integer parameter which is to be written.
5.1.29 sf putints
Call
Definition
void sf_putints (sf_file file, const char* key, const int* par, size_t n)
/*< put an int array of size n parameter to a file >*/
{
...
}
Input parameters
file the file in which the the key value is to be stored (sf file).
key pointer to the name of the key value to be input (const char*).
par pointer to integer parameter array which is to be written.
n size of the array to be written (size t).
100 CHAPTER 5. OPERATIONS WITH RSF FILES
5.1.30 sf putlargeint
Call
Definition
Input parameters
file the file in which the the key value is to be stored (sf file).
key pointer to the name of the key value to be input (const char*).
par integer parameter which is to be written.
5.1.31 sf putfloat
Call
Definition
Input parameters
file the file in which the the key value is to be stored (sf file).
key pointer to the name of the key value to be input (const char*).
par floating point parameter which is to be written.
Definition
5.1.32 sf putstring
Call
Definition
Input parameters
file the file in which the key value is to be stored (sf file).
key pointer to the name of the key value to be input (const char*).
par pointer to the string parameter which is to be written.
102 CHAPTER 5. OPERATIONS WITH RSF FILES
5.1.33 sf putline
Call
Definition
Input parameters
file the file in which the string line is to be stored (sf file).
line pointer to the which is to be written.
5.1.34 sf setaformat
Sets number format specifiers for ASCII output. This can be used in sf complexwrite,
for example.
Call
Definition
void sf_setaformat (const char* format /* number format (.i.e "%5g") */,
int line /* numbers in line */ )
/*< Set format for ascii output >*/
{
...
5.1. MAIN OPERATIONS WITH RSF FILES (FILE.C) 103
Input parameters
5.1.35 sf complexwrite
Writes a complex array to the file, according to the value of the form of the file, i.e. SF ASCII,
SF XDR or SF NATIVE.
Call
Definition
Input parameters
5.1.36 sf complexread
Reads a complex array from the file, according to the value of the form of the file,
i.e. SF ASCII, SF XDR or SF NATIVE.
104 CHAPTER 5. OPERATIONS WITH RSF FILES
Call
Definition
Input parameters
arr a pointer to the array to which the array from the file is to be copied (sf complex).
size size of the array (size t).
file a file in which the array is to be written (sf file).
5.1.37 sf charwrite
Writes a character array to the file, according to the value of the form of the file, i.e. SF ASCII,
SF XDR or SF NATIVE.
Call
Definition
Input parameters
5.1.38 sf uncharwrite
Writes a unsigned character array to the file, according to the value of the form of the file,
i.e. SF ASCII, SF XDR or SF NATIVE.
Call
Definition
Input parameters
5.1.39 sf charread
Reads a character array from the file, according to the value of the form of the file,
i.e. SF ASCII, SF XDR or SF NATIVE.
Call
Definition
Input parameters
arr a pointer to the array to which the array from the file is to be copied (sf complex).
size size of the array (size t).
file a file in which the array is to be written (sf file).
5.1.40 sf uncharread
Reads an unsigned character array from the file, according to the value of the form of the
file, i.e. SF ASCII, SF XDR or SF NATIVE.
Call
Definition
void sf_ucharread (/*@out@*/ unsigned char* arr, size_t size, sf_file file)
/*< read a uchar array arr[size] from file >*/
{
...
}
Input parameters
arr a pointer to the array to which the array from the file is to be copied (sf complex).
size size of the array (size t).
file a file in which the array is to be written (sf file).
5.1. MAIN OPERATIONS WITH RSF FILES (FILE.C) 107
5.1.41 sf intwrite
Writes an integer array to the file, according to the value of the form of the file, i.e. SF ASCII,
SF XDR or SF NATIVE.
Call
Input parameters
5.1.42 sf intread
Reads an integer array from the file, according to the value of the form of the file,
i.e. SF ASCII, SF XDR or SF NATIVE.
Call
Definition
Input parameters
arr a pointer to the array to which the array from the file is to be copied (sf complex).
size size of the array (size t).
file a file in which the array is to be written (sf file).
108 CHAPTER 5. OPERATIONS WITH RSF FILES
5.1.43 sf shortread
Reads an short array from the file, according to the value of the form of the file, i.e. SF ASCII,
SF XDR or SF NATIVE.
Call
Definition
Input parameters
arr a pointer to the array to which the array from the file is to be copied (sf complex).
size size of the array (size t).
file a file in which the array is to be written (sf file).
5.1.44 sf shortwrite
Writes an short array to the file, according to the value of the form of the file, i.e. SF ASCII,
SF XDR or SF NATIVE.
Call
Definition
{
...
}
Input parameters
5.1.45 sf floatwrite
Writes an float array to the file, according to the value of the form of the file, i.e. SF ASCII,
SF XDR or SF NATIVE.
Call
Definition
Input parameters
5.1.46 sf floatread
Reads a float array from the file, according to the value of the form of the file, i.e. SF ASCII,
SF XDR or SF NATIVE.
110 CHAPTER 5. OPERATIONS WITH RSF FILES
Call
Definition
Input parameters
arr a pointer to the array to which the array from the file is to be copied (sf complex).
size size of the array (size t).
file a file in which the array is to be written (sf file).
5.1.47 sf bytes
Call
Definition
Input parameters
file a pointer to the file structure whose size is required (sf file).
5.1. MAIN OPERATIONS WITH RSF FILES (FILE.C) 111
Output
5.1.48 sf tell
Call
Definition
Input parameters
file a pointer to the file structure the value of whose position indicator required
(sf file).
Output
5.1.49 sf tempfile
Call
Definition
Input parameters
dataname a pointer to the value of the name of the temporary file (char**).
mode mode of the file to be created, e.g. w+.
Output
5.1.50 sf seek
Call
Definition
5.1.51 sf unpipe
Call
Definition
Input parameters
5.1.52 sf close
Call
sf_close();
Definition
void sf_close(void)
/*< Remove temporary files >*/
{
...
}
5.2.1 sf filedims
Call
Definition
Input parameters
file a pointer to the file structure whose dimensions are required (sf file).
n an array where the dimensions will be stored (int).
Output
5.2.2 sf largefiledims
Returns the dimensions of the file. It is exactly like sf filedims but n in the input is the
offset in bytes in the input file (type off t) rather than just an integer.
Call
Definition
Input parameters
file a pointer to the file structure whose dimensions are required (sf file).
n an array where the dimensions will be stored (off t).
Output
5.2.3 sf memsize
Returns the memory size defined in the environment variable RSFMEMSIZE. If there is an
invalid value the function will print an error message an assign a default value of 100
Mbytes.
Call
memsize = sf_memsize();
Definition
int sf_memsize()
/*< Returns memory size by:
1. checking RSFMEMSIZE environmental variable
2. using hard-coded "def" constant
>*/
{
...
116 CHAPTER 5. OPERATIONS WITH RSF FILES
return memsize;
}
5.2.4 sf filesize
Returns the size of the file, that is, the product of the dimensions. It uses the function
sf leftsize.
Call
Definition
Input parameters
file a pointer to the file structure whose size is required (sf file).
Output
5.2.5 sf leftsize
Returns the size of the file, that is, the product of the dimensions but only for the dimen-
sions greater than the input integer dim. It uses the function sf leftsize.
Call
Definition
Input parameters
Output
size product of dimensions greater than dim in the file (off t).
5.2.6 sf cp
Call
Definition
Input parameters
5.2.7 sf rm
Removes the RSF file. There are options to force removal (files are deleted even if pro-
tected), to inquire before removing a file and whether or to require verbose output.
Call
Definition
void sf_rm(const char* filename, bool force, bool verb, bool inquire)
/*< Remove an RSF file.
---
force, verb, and inquire flags should behave similar to the corresponding flags
in the Unix "rm" command. >*/
{
...
}
Input parameters
5.2.8 sf shiftdim
Shifts the grid by one dimension after the axis defined in the input parameters (axis).
Call
Definition
Input parameters
Output
n3 the file size (product of dimensions) after the shift (off t).
5.2.9 sf unshiftdim
Shifts the grid backward by one dimension after the axis defined in the input parameters
(axis).
Call
Definition
Input parameters
Output
n3 the file size (product of dimensions) after the backward shift (off t).
5.2.10 sf endian
Definition
Definition
Output
little endian a boolean parameter which is true if the machine is little endian.
5.3.1 creal
Call
r = sf_creal(c);
Definition
double sf_creal(sf_double_complex c)
/*< real part >*/
{
...
}
Input parameters
Output
5.3.2 cimag
Call
im = sf_cimag(c);
Definition
double sf_cimag(sf_double_complex c)
/*< imaginary part >*/
{
...
}
122 CHAPTER 5. OPERATIONS WITH RSF FILES
Input parameters
Output
5.3.3 dcneg
Call
n = sf_dcneg(a);
Definition
sf_double_complex sf_dcneg(sf_double_complex a)
/*< unary minus >*/
{
...
}
Input parameters
Output
5.3.4 dcadd
Call
c = sf_dcadd(a, b);
Definition
Input parameters
Output
5.3.5 dcsub
Call
c = sf_dcsub(a, b);
Definition
Input parameters
Output
5.3.6 dcmul
Call
c = sf_dcmul(a, b);
Definition
Input parameters
Output
5.3.7 dccmul
Multiplies two complex number. Its output type and one of the input parameters is of type
kiss fft cpx.
Call
c = sf_dccmul(a, b);
Definition
Input parameters
Output
5.3.8 dcdmul
Multiplies two complex number. One of the input parameters is kiss fft cpx. This means
that it should only be used if complex.h header is not used.
Call
c = sf_dcdmul(a, b);
126 CHAPTER 5. OPERATIONS WITH RSF FILES
Definition
Input parameters
Output
5.3.9 dcrmul
Call
c = sf_dcrmul(a, b);
Definition
Input parameters
Output
c product of the complex number a and the real number b. It is of type sf double complex.
5.3.10 dcdiv
Call
c = sf_dcdiv(a, b);
Definition
Input parameters
Output
a
c b. It is of type sf double complex.
5.3.11 cabs
Returns the absolute value (magnitude) of a complex number. It uses the hypot function
from the C library.
Call
a = sf_cabs(z);
128 CHAPTER 5. OPERATIONS WITH RSF FILES
Definition
double sf_cabs(sf_double_complex z)
/*< replacement for cabsf >*/
{
...
}
Input parameters
Output
5.3.12 cabs
Returns the argument of a complex number. It uses the atan2 function from the C library.
Call
u = sf_carg(z);
Definition
double sf_carg(sf_double_complex z)
/*< replacement for cargf >*/
{
...
}
Input parameters
Output
5.3.13 crealf
Call
r = sf_crealf(c);
Definition
float sf_crealf(kiss_fft_cpx c)
/*< real part >*/
{
...
}
Input parameters
Output
5.3.14 cimagf
Call
im = sf_cimagf(c);
130 CHAPTER 5. OPERATIONS WITH RSF FILES
Definition
float sf_cimagf(kiss_fft_cpx c)
/*< imaginary part >*/
{
...
}
Input parameters
Output
5.3.15 cprint
Prints the complex number on the screen. This is done using the sf warning.
Call
cprint(c);
Definition
Input parameters
5.3.16 cadd
Adds two complex numbers. The output is of type kiss fft cpx.
Call
c = sf_cadd(a, b);
Definition
Input parameters
Output
c the sum a + b of the two complex numbers a, b. It is of type kiss fft cpx.
5.3.17 csub
Subtracts two complex numbers. The output is of type kiss fft cpx.
Call
c = sf_csub(a, b);
132 CHAPTER 5. OPERATIONS WITH RSF FILES
Definition
Input parameters
Output
5.3.18 csqrtf
Returns the square root of a complex number. The output is of type kiss fft cpx.
Call
c = sf_csqrtf (c);
Definition
Input parameters
Output
5.3.19 cdiv
Divides two complex numbers. The output is of type kiss fft cpx.
Call
c = sf_cdiv(a, b);
Definition
Input parameters
Output
a
c b. It is of type kiss fft cpx.
5.3.20 cmul
Multiplies two complex numbers. The output is of type kiss fft cpx.
Call
c = sf_cmul(a, b);
134 CHAPTER 5. OPERATIONS WITH RSF FILES
Definition
Input parameters
Output
c product of the two complex numbers a and b. It is of type kiss fft cpx.
5.3.21 crmul
Multiplies a complex number with a real number. The output is of type kiss fft cpx.
Call
c = sf_crmul(a, b);
Definition
Input parameters
Output
c the product ab of a complex number a and real number b. It is of type kiss fft cpx.
5.3.22 cneg
Returns negative of a complex number. The output is of type kiss fft cpx.
Call
b = sf_cneg(a);
Definition
kiss_fft_cpx sf_cneg(kiss_fft_cpx a)
/*< unary minus >*/
{
...
}
Input parameters
Output
5.3.23 conjf
Returns complex conjugate of a complex number. The output is of type kiss fft cpx.
Call
z1 = sf_conjf(z);
136 CHAPTER 5. OPERATIONS WITH RSF FILES
Definition
kiss_fft_cpx sf_conjf(kiss_fft_cpx z)
/*< complex conjugate >*/
{
...
}
Input parameters
Output
5.3.24 cabsf
Returns the magnitude of a complex number. It uses a function hypotf from c99.h, which
calls the hypot function from math.h in the C library.
Call
w = sf_cabsf(kiss_fft_cpx z);
Definition
float sf_cabsf(kiss_fft_cpx z)
/*< replacement for cabsf >*/
{
...
}
Input parameters
Output
5.3.25 cargf
Returns the argument of a complex number. It uses a function atan2f from c99.h, which
calls the atan2 function from math.h in the C library.
Call
u = sf_cargf(z);
Definition
float sf_cargf(kiss_fft_cpx z)
/*< replacement for cargf >*/
{
...
}
Input parameters
Output
5.3.26 ctanhf
Returns hyperbolic tangent of a complex number. It uses a function like coshf and sinhf
from c99.h, which call cosh and sinh functions from math.h in the C library.
Call
th = sf_ctanhf(z);
138 CHAPTER 5. OPERATIONS WITH RSF FILES
Definition
kiss_fft_cpx sf_ctanhf(kiss_fft_cpx z)
/*< complex hyperbolic tangent >*/
{
...
}
Input parameters
Output
5.3.27 ccosf
Returns cosine of a complex number. It uses the functions like coshf and sinhf from
c99.h, which call cosh and sinh functions from math.h in the C library.
Call
w = sf_ccosf (z);
Definition
kiss_fft_cpx sf_ccosf(kiss_fft_cpx z)
/*< complex cosine >*/
{
...
}
Input parameters
Output
5.3.28 ccoshf
Returns hyperbolic cosine of a complex number. It uses the functions like coshf and sinhf
from c99.h, which call cosh and sinh functions from math.h in the C library.
Call
w = sf_ccoshf(z);
Definition
kiss_fft_cpx sf_ccoshf(kiss_fft_cpx z)
/*< complex hyperbolic cosine >*/
{
...
}
Input parameters
Output
5.3.29 ccosf
Returns sine of a complex number. It uses the functions like coshf and sinhf from c99.h,
which call cosh and sinh functions from math.h in the C library.
Call
w = sf_csinf(z);
140 CHAPTER 5. OPERATIONS WITH RSF FILES
Definition
kiss_fft_cpx sf_csinf(kiss_fft_cpx z)
/*< complex sine >*/
{
...
}
Input parameters
Output
5.3.30 csinhf
Returns hyperbolic cosine of a complex number. It uses the functions like coshf and sinhf
from c99.h, which call cosh and sinh functions from math.h in the C library.
Call
w = sf_csinhf(z);
Definition
kiss_fft_cpx sf_csinhf(kiss_fft_cpx z)
/*< complex hyperbolic sine >*/
{
...
}
Input parameters
Output
5.3.31 clogf
Returns natural logarithm of a complex number. It uses the functions like logf and hypotf
from c99.h, which call log and hypot functions from math.h in the C library.
Call
w = sf_clogf(z);
Definition
kiss_fft_cpx sf_clogf(kiss_fft_cpx z)
/*< complex natural logarithm >*/
{
...
}
Input parameters
Output
5.3.32 cexpf
Returns exponential of a complex number. It uses the functions like expf and cosf from
c99.h, which call exp and cos functions from math.h in the C library.
Call
w = sf_cexpf(z);
142 CHAPTER 5. OPERATIONS WITH RSF FILES
Definition
kiss_fft_cpx sf_cexpf(kiss_fft_cpx z)
/*< complex exponential >*/
{
...
}
Input parameters
Output
5.3.33 ctanf
Returns tangent of a complex number. It uses the functions like sinf and cosf from
c99.h, which call sin and cos functions from math.h in the C library.
Call
w = sf_ctanf(z);
Definition
kiss_fft_cpx sf_ctanf(kiss_fft_cpx z)
/*< complex tangent >*/
{
...
}
Input parameters
Output
5.3.34 casinf
Returns hyperbolic arcsine of a complex number. It uses the function asinf from c99.h,
which calls the asin function from math.h in the C library.
Call
w = sf_casinf(z);
Definition
kiss_fft_cpx sf_casinf(kiss_fft_cpx z)
/*< complex hyperbolic arcsine >*/
{
...
}
Input parameters
Output
5.3.35 cacosf
Call
w = sf_cacosf(z);
144 CHAPTER 5. OPERATIONS WITH RSF FILES
Definition
kiss_fft_cpx sf_cacosf(kiss_fft_cpx z)
/*< complex hyperbolic arccosine >*/
{
...
}
Input parameters
Output
5.3.36 catanf
Call
w = sf_catanf(z);
Definition
kiss_fft_cpx sf_catanf(kiss_fft_cpx z)
/*< complex arctangent >*/
{
...
}
Input parameters
Output
5.3.37 catanhf
Call
w =_cpx sf_catanhf(z);
Definition
kiss_fft_cpx sf_catanhf(kiss_fft_cpx z)
/*< complex hyperbolic arctangent >*/
{
...
}
Input parameters
Output
5.3.38 casinhf
Call
w = sf_casinhf(z);
146 CHAPTER 5. OPERATIONS WITH RSF FILES
Definition
kiss_fft_cpx sf_casinhf(kiss_fft_cpx z)
/*< complex hyperbolic sine >*/
{
...
}
Input parameters
Output
5.3.39 cacoshf
Call
w = sf_cacoshf(z);
Definition
kiss_fft_cpx sf_cacoshf(kiss_fft_cpx z)
/*< complex hyperbolic cosine >*/
{
...
}
Input parameters
Output
5.3.40 cpowf
Call
c = sf_cpowf(a, b);
Definition
Input parameters
Output
Error handling
6.1.1 sf error
Outputs an error message to stderr, which is usually the screen. It uses sf getprog to
get the name of the program which is causing the error and print it on the screen. Uses
vfprintf, which can take a variable number of arguments initialized by va list. This
gives the user flexibility in choosing the number of arguments.
If there is a ’:’ at the end of format, information about the system errors is printed,
this is done by using strerror to interpret the last error number errno in the system.
Also, if there is a ’;’ at the end of a format the command prompt will not go to the next
line.
Call
Definition
149
150 CHAPTER 6. ERROR HANDLING
{
...
}
Input parameters
format a string of type const char* containing the format specifiers for the arguments
to be input from the next commands.
... variable number of arguments, which are to replace the format specifiers in the
format.
Output
6.1.2 sf warning
Outputs a warning message to stderr which is usually the screen. It uses sf getprog to
get the name of the program which is causing the error and print it on the screen. Uses
vfprintf, which can take a variable number of arguments initialized by va list. This
gives the user flexibility in choosing the number of arguments. If there is a ’:’ at the end
of format, information about the system errors is printed, this is done by using strerror
to interpret the last error number errno in the system. Also, if there is a ’;’ at the end of
a format the command prompt will not go to the next line.
Call
Definition
...
}
Input parameters
format a string of type const char* containing the format specifiers for the arguments
to be input from the next commands.
... variable number of arguments, which are to replace the format specifiers in the
format.
Output
Linear operators
7.1 Introduction
This section contains a bunch of programs that implement operators. Therefore a short
introduction on operators is in order.
153
154 CHAPTER 7. LINEAR OPERATORS
pose). Padding this vector with m zeros, produces another vector y with
x1
x2
..
.
x
y= xn = 0 ,
0
..
.
0
Note that as in the case of functions, the domains of x and y are different: x ∈ Rn (or
more generally x ∈ Cn ), while y ∈ Rn+m (or Cn+m ).
Similarly, one can define convolution of x with a = [a1 a2 . . . am ]T as the multiplication
of x with
a1 0 0 · · · 0 0
a2 a1 0 · · · 0 0
a3 a2 a1 · · · 0 0
A = ... .. .. . . .. .. .
. . . . .
0 0 0 · · · am−1 am−2
0 0 0 ··· am am−1
0 0 0 ··· 0 am
and many other operations as matrix multiplications. Other operators are the identity
operator is the identity matrix I and is implemented by copy.c and ccopy.c and the
null operator (or zero matrix O), which is implemented by adjnull.c. For the rest of
this introduction, the boldface notation will imply specifically discrete operators, while the
normal fonts will imply operators on either continuous or discrete mathematical entities.
then we can define L1 L2 as L1 L2 [x] = L1 [L2 [x]], provided that L1 [L2 [x]] makes sense
mathematically. This is called the composition of the operators L1 and L2 . Because in
the discrete case the composition of operators is in fact the multiplication L1 L2 of the two
matrices L1 , L2 the operator composition is usually referred to as operator product and
denoted by L1 L2 is used. The composition of operators can be naturally extended to any
finite product L1 · · · Ln−1 Ln . The product of up to 3 operators is implemented in chain.c.
yn
..
.
yn+m
We conclude that the adjoint of data zero-padding is data truncation. It is also easy (but
tedious) to verify that the adjoint operation of the convolution between a and x is the
crosscorrelation of a with yH . One may also notice that for the specific zero-padding
operator, L∗ Lx = x, i.e. in this case the adjoint neutralizes the effect of the operator. It
is tempting to say that the adjoint operation is the inverse operation, however this is not
the case: it is not always the case that L∗ L = LL∗ . In fact such an equality is meaningless
mathematically if L is not a square matrix (if L is a n × m matrix, then LL∗ is n × n,
while L∗ L is m × m). L∗ is not even the left inverse of L: notice that in the case of the
zero padding operator, (L∗ )∗ L∗ y = LL∗ y = ỹ 6= y (the last m elements of ỹ are zero).
However it is often the case that the adjoint is an adequate. It is the case though quite
often that the adjoint is adequate approximation to the inverse (sometimes within a scaling
factor) and it is also quite probable that the adjoint will do a better job than the inverse in
inverse problems. This is because the adjoint operator tolerates data imperfections, which
the inverse does not.
1
The adjoint operator should not be confused with the (classical) adjoint or adjucate or adjunct matrix
of a square matrix. The adjugate matrix of an invertible matrix is the inverse multiplied by its determinant.
156 CHAPTER 7. LINEAR OPERATORS
From the definition of the adjoint operation as the left multiplication the complex
conjugate matrix, it follows that the adjoint of the product of two linear operators equals
the product of the adjoints in reverse order, i.e. (L1 L2 )∗ = L∗2 L∗1 . This is naturally extended
to the product of any finite product of operators, i.e. (L1 L2 · · · Ln )∗ = L∗n L∗n−1 · · · L∗1 . The
adjoint of the product is also implemented in chain.c.
The dot-product test is a valuable checkpoint, which can tell us whether the implementation
of the adjoint operator is wrong (however it cannot guarantee that it is indeed correct).
The concept is the following: Assuming that we have coded an operator L and its adjoint
L∗ . Then for any two vectors or functions a and b,
where h , i denotes the dot product. Remember that the dot product of two functions
f, g ∈ L2 is f g ∗ dt while the dot product of two vectors x and y is xH y. Notice that for
R
vectors eq. (7.1) becomes xH Ly = (LH y)H y which is obviously true. The lhs of eq. (7.1)
is computed using L, while the rhs is computed using the adjoint L∗ . For the dot-product
test, one just needs to load the vectors x and y with random numbers and perform the
two computations. If the two results are not equal (within machine precision), then the
computation of either L or L∗ is erroneous. Note that truncation errors have identical
effects on both operators, so the two results should be almost equal. The dot-product test
(for real operators only) is implemented by sf dot test.
It should be evident by now that the implementation of an operator L should have at least
four arguments: a variable x from which the operand (entity on which L is applied) x is
read along with its length nx, and the variable y in which the result y = Lx is stored and
its length ny .
Also, since every operator comes along with its adjoint, the implementation of the linear
operators described later in this chapter, gives also the possibility to compute the adjoint
operator. This is done through the boolean adj input argument. When adj is true, the
adjoint operator L∗ computed. As discussed before, the domains of x and Lx are in general
different, therefore L∗ cannot be applied on x. However it can always be applied on Lx or
some y, which has the same domain as Lx. For this reason, when adj is true, the operand
is y and the result is x and thus, y is used as input and the result is stored in x. As an
example if sf copy lop (the identity operator) is called, then the result is that y ← x.
7.2. ADJOINT ZEROING (ADJNULL.C) 157
However if additionally adj is true, then the result will be x ← y. If adjnull (the null
operator) is called, then the result is that y ← 0. However if additionally adj is true, then
the result will be x ← 0.
Finally, it is often the case that we need to compute y ← Lx but y ← y + Lx. For this
reason another boolean argument, namely add is defined. If add is true, then y ← y + Lx.
Considering the same example with the identity operator, if sf copy lop is called with
add being true, then y ← y +x. If additionally adj is true, then x ← y +x. Or if adjnull
is called with add being true, if adj is false, y ← y and if adj is true, then x ← x (so
in essence, if add is true, no matter what the value of adj, nothing happens).
As a conclusion, the linear operators described in this chapter have all the following
form:
where adj and add are boolean, nx and ny are integers and x and y are pointers of various
but the same data type. Table 7.1 summarizes the effect of the adj and add variables.
Its adjoint is
x = 0∗ y = 0, with xt ← 0.
7.2.1 sf adjnull
Call
Definition
Input parameters
adj adjoint flag (bool). If true, then the adjoint is computed, i.e. x ← 0∗ y or x ←
x + 0∗ y.
add addition flag (bool). If true, then y ← y + 0x or x ← x + 0∗ y.
nx size of x (int).
ny size of y (int).
x input data or output (float*).
y output or input data (float*).
7.2.2 sf cadjnull
Call
Definition
Input parameters
adj adjoint flag (bool). If true, then the adjoint is computed, i.e. x ← 0∗ y or x ←
x + 0∗ y.
add addition flag (bool). If true, then y ← y + 0x or x ← x + 0∗ y.
nx size of x (int).
ny size of y (int).
x input data or output (sf complex*).
y output or input data (sf complex*).
y = 1x = x, with yt ← xt .
Its adjoint is
x = 1∗ y = y, with xt ← yt .
Call
Definition
void sf_copy_lop (bool adj, bool add, int nx, int ny, float* xx, float* yy)
/*< linear operator >*/
{
...
}
Input parameters
adj adjoint flag (bool). If true, then the adjoint is computed, i.e. x ← 1∗ y or x ←
x + 1∗ y.
add addition flag (bool). If true, then y ← y + 1x or x ← x + 1∗ y.
nx size of x (int). nx must equal ny.
ny size of y (int). ny must equal nx.
x input data or output (float*).
y output or input data (float*).
This is the same operator as sf copy lop but for complex data. In particular, the identity
operator is defined by
y = 1x = x, with yt ← xt .
Its adjoint is
x = 1∗ y = y, with xt ← yt .
Call
Definition
void sf_ccopy_lop (bool adj, bool add, int nx, int ny,
sf_complex* xx, sf_complex* yy)
/*< linear operator >*/
{
...
}
Input parameters
adj adjoint flag (bool). If true, then the adjoint is computed, i.e. x ← 1∗ y or x ←
x + 1∗ y.
add addition flag (bool). If true, then y ← y + 1x or x ← x + 1∗ y.
nx size of x (int). nx must equal ny.
ny size of y (int). ny must equal nx.
x input data or output (sf complex*).
y output or input data (sf complex*).
y = Lm x = mx, with yt ← mt xt ,
Initializes the static variable m with boolean values, to be used in the sf mask lop or
sf cmask lop.
Call
sf_mask_init (m);
162 CHAPTER 7. LINEAR OPERATORS
Definition
Input parameters
Call
Definition
void sf_mask_lop(bool adj, bool add, int nx, int ny, float *x, float *y)
/*< linear operator >*/
{
...
}
Input parameters
adj adjoint flag (bool). If true, then the adjoint is computed, i.e. x ← L∗m y or x ←
x + L∗m y.
add addition flag (bool). If true, then y ← y + Lm x or x ← x + L∗m y.
nx size of x (int). nx must equal ny.
ny size of y (int). ny must equal nx.
x input data or output (float*).
y output or input data (float*).
7.6. SIMPLE WEIGHT OPERATOR (WEIGHT.C) 163
Call
Definition
Input parameters
adj adjoint flag (bool). If true, then the adjoint is computed, i.e. x ← L∗m y or x ←
x + L∗m y.
add addition flag (bool). If true, then y ← y + Lm x or x ← x + L∗m y.
nx size of x (int). nx must equal ny.
ny size of y (int). ny must equal nx.
x input data or output (sf complex*).
y output or input data (sf complex*).
y = Lw x = wx, with yt ← wt xt .
Its adjoint is
Note that for complex data the weight w must still be real.
There is also an in-place (x ← Lw x) version of the operator, which multiplies the input
data with the square of w i.e.
x = Lw x = w2 x, with xt ← wt2 xt .
Call
sf_weight_init(w);
Definition
Input parameters
Applies the linear operator with the weights initialized by sf weight init.
Call
Definition
void sf_weight_lop (bool adj, bool add, int nx, int ny, float* xx, float* yy)
/*< linear operator >*/
{
...
}
Input parameters
adj adjoint flag (bool). If true, then the adjoint is computed, i.e. x ← L∗w y or x ←
x + L∗w y.
add addition flag (bool). If true, then y ← y + Lw x or x ← x + L∗w y.
nx size of x (int). nx must equal ny.
ny size of y (int). ny must equal nx.
x input data or output (float*).
y output or input data (float*).
Call
Definition
void sf_cweight_lop (bool adj, bool add, int nx, int ny,
sf_complex* xx, sf_complex* yy)
/*< linear operator >*/
{
...
}
166 CHAPTER 7. LINEAR OPERATORS
Input parameters
adj adjoint flag (bool). If true, then the adjoint is computed, i.e. x ← L∗w y or x ←
x + L∗w y.
add addition flag (bool). If true, then y ← y + Lw x or x ← x + L∗w y.
nx size of x (int). nx must equal ny.
ny size of y (int). ny must equal nx.
x input data or output (sf complex*).
y output or input data (sf complex*).
Call
Definition
Input parameters
nx size of x (int).
x input data and output (float*).
The same as the sf weight apply but for the complex numbers.
7.7. 1-D FINITE DIFFERENCE (IGRAD1.C) 167
Call
Definition
Input parameters
nx size of x (int).
x input data and output (sf complex*).
Its adjoint is
Call
Definition
Input parameters
adj adjoint flag (bool). If true, then the adjoint is computed, i.e. x ← D∗ y or x ←
x + D∗ y.
add addition flag (bool). If true, then y ← y + Dx or x ← x + D∗ y.
nx size of x (int).
ny size of y (int).
x input data or output (float*).
y output or input data (float*).
t
X
y = Lx, with yt ← xτ .
τ =0
Its adjoint is
T
X −1
x = L∗ y, with xt ← yτ ,
τ =t
Call
Defintion
Input parameters
adj adjoint flag (bool). If true, then the adjoint is computed, i.e. x ← L∗ y or x ←
x + L∗ y.
add addition flag (bool). If true, then y ← y + Lx or x ← x + L∗ y.
nx size of x (int).
ny size of y (int).
x input data or output (float*).
y output or input data (float*).
7.9.1 sf chain
d = (L2 L1 )m.
Its adjoint is
Call
Definition
Input parameters
7.9.2 sf cchain
Call
Definition
Input parameters
7.9.3 sf array
d = Lm,
or its adjoint
m = L∗ d,
where
L d
L= 1 and d = 1
L2 d2
Call
Definition
Input parameters
7.9.4 sf normal
d = LL∗ m.
Call
Definition
Input parameters
7.9.5 sf chain3
d = (L3 L2 L1 )m.
Its adjoint is
Call
Definition
Input parameters
Performs the dot product test (see p. 156), to check whether the adjoint of the operator is
coded incorrectly. Coding is incorrect if any of
hLm1 , d2 i = hm1 , L∗ d2 i or hd1 + Lm1 , d2 i = hm1 , m2 + L∗ d2 i
does not hold (within machine precision). m1 and d2 are random vectors.
dot1[0] must equal dot1[1] and dot2[0] must equal dot2[1] for the test to pass.
176 CHAPTER 7. LINEAR OPERATORS
Call
Definition
Input parameters
Data analysis
Allocates the memory for the FFT and returns an object of type kiss fftr cfg.
Call
Definition
Input parameters
177
178 CHAPTER 8. DATA ANALYSIS
Input parameters
Performs the forward FFT on the input timedata which is real, and stores the transformed
complex freqdata in the location specified in the input.
Call
Definition
...
}
Input parameters
Performs the inverse FFT on the input timedata which is real, and stores the transformed
complex freqdata in the location specified in the input.
Call
Definition
Input parameters
8.2.1 sf tent2
Sets the weights for the windows defined for each dimension.
Call
Definition
Input parameters
Initializes the required variables and allocates the required space for the anisotropic diffu-
sion.
Call
Definition
Input parameters
Definition
sf_impl2_close ();
Definition
Call
sf_impl2_set(x);
Definition
void sf_impl2_set(float ** x)
/*< compute weighting function >*/
{
...
}
Input parameters
x data (float**).
Call
Definition
Input parameters
x data (float*).
set whether the weighting function needs to be computed (bool).
adj whether the weighting function needs to be applied (bool).
Call
Definition
void sf_impl2_lop (bool adj, bool add, int nx, int ny, float* x, float* y)
/*< linear operator >*/
{
...
}
Input parameters
Filtering
Initializes the required variables and allocates the required space for frequency filtering.
Call
sf_freqfilt_init(nfft1, nw1);
Definition
Input parameters
185
186 CHAPTER 9. FILTERING
Call
sf_freqfilt_set(filt);
Definition
Input parameters
Call
sf_freqfilt_cset (filt);
Definition
Input parameters
Call
sf_freqfilt_close();
Definition
void sf_freqfilt_close(void)
/*< Free allocated storage >*/
{
...
}
9.1.5 sf freqfilt
Call
sf_freqfilt(nx, x);
Definition
Input parameters
Applies the frequency filtering to either y or x, depending on whether adj is true of false
and then applies the result to x or y as a linear operator.
Call
Definition
void sf_freqfilt_lop (bool adj, bool add, int nx, int ny, float* x, float* y)
/*< Filtering as linear operator >*/
{
...
}
Input parameters
Initializes the required variables and allocates the required space for frequency filtering for
2D data.
Call
Definition
Input parameters
Call
sf_freqfilt2_set (filt);
Input parameters
Definition
Call
sf_freqfilt2_close();
Definition
void sf_freqfilt2_close(void)
/*< free allocated storage >*/
{
...
}
Call
Definition
...
}
Input parameters
Applies the frequency filtering to either y or x, depending on whether adj is true of false
and then applies the result to x or y as a linear operator.
Call
Definition
void sf_freqfilt2_lop (bool adj, bool add, int nx, int ny, float* x, float* y)
/*< linear filtering operator >*/
{
...
}
Input parameters
Call
sf_helicon_init(bb);
Definition
Input parameters
Does the helical convolution. It applies the filter to either yy or xx, depending on whether
adj is true of false and then applies the result to xx or yy as a linear operator.
Call
Definition
Input parameters
9.4.1 sf allocatehelix
Call
aa = sf_allocatehelix(nh);
Definition
Input parameters
Output
9.4.2 sf deallocatehelix
Definition
sf_deallocatehelix (aa);
Call
Input parameters
9.4.3 sf displayhelix
Call
sf_displayhelix(aa);
Definition
{
...
}
Input parameters
Initializes the linear filter by allocating the required space and initializing the required
variables.
Call
Definition
Input parameters
Applies the linear operator to xx (or yy) and the result is applied to yy (or xx), depending
on whether adj is false or true, with the operator initialized by sf recfilt init.
Call
Definition
void sf_recfilt_lop( bool adj, bool add, int nx, int ny, float* xx, float*yy)
/*< linear operator >*/
{
...
}
Input parameters
Call
sf_recfilt_close ();
9.6. COSINE FOURIER TRANSFORM (COSFT.C) 197
Definition
9.6.1 sf cosft
Makes preparations for the cosine Fourier transform, by allocating the required spaces.
Call
sf_cosft_init(n1);
Definition
Input parameters
Call
sf_cosft_close();
198 CHAPTER 9. FILTERING
Definition
void sf_cosft_close(void)
/*< free allocated storage >*/
{
...
}
Call
Definition
Input parameters
Call
Definition
Input parameters
Solvers
Initializes an object of type sf bands for the banded matrix, that is, it allocates the
required spaces and defines initializes the variables.
Call
Definition
Input parameters
201
202 CHAPTER 10. SOLVERS
Output
Call
Input parameters
Definition
Call
Definition
Input parameters
Defines the banded matrix with constant diagonal values for the reflecting boundary con-
ditions.
Call
Definition
Input parameters
Call
Definition
Input parameters
Call
sf_banded_close (slv);
10.2. CLAERBOUT’S CONJUGATE-GRADIENT ITERATION (CGSTEP.C) 205
Definition
Input parameters
10.2.1 sf cgstep
Call
Definition
Input parameters
Output
Frees the space allocated for the conjugate gradient step calculation.
Call
sf_cgstep_close ();
Definition
Initializes the conjugate gradient solver by initializing the required variables and allocating
the required space.
Call
Definition
Input parameters
Frees the space allocated for the conjugate gradient solver by sf conjgrad init.
Definition
sf_conjgrad_close();
208 CHAPTER 10. SOLVERS
Definition
void sf_conjgrad_close(void)
/*< Free allocated space >*/
{
...
}
10.3.3 sf conjgrad
Applies the conjugate gradient solver with the shaping filter to the input data.
Definition
Definition
Input parameters
Initializes the conjugate gradient solver, that is, it sets the required variables and allocates
the required memory.
Call
Definition
Input parameters
Call
sf_conjprec_close();
Definition
void sf_conjprec_close(void)
/*< Free allocated space >*/
{
...
}
10.4.3 sf conjprec
Applies the conjugate gradient method after preconditioning to the input data.
Call
Definition
Input parameters
10.5.1 sf ccgstep
Evaluates one step of the Claerbout’s conjugate-gradient iteration for complex numbers.
Call
Definition
Input parameters
Call
sf_ccgstep_close();
Definition
10.5.3 dotprod
Returns the dot product of two complex numbers or the sum of the dot products if the are
two arrays of complex numbers.
Call
Definition
Input parameters
Output
prod dot product of the complex numbers. It is of type static sf double complex.
10.6.1 norm
Returns the L2 norm of the complex number with double-precision, or the sum of L2 norms,
if there is an array of complex numbers.
Call
Definition
Input parameters
Output
Initializes the complex conjugate gradient solver by initializing the required variables and
allocating the required space.
Definition
Definition
Input parameters
Frees the space allocated for the complex conjugate gradient solver by sf cconjgrad init.
Definition
sf_cconjgrad_close();
Definition
void sf_cconjgrad_close(void)
/*< Free allocated space >*/
{
...
}
10.6.4 sf cconjgrad
Applies the complex conjugate gradient solver with the shaping filter to the input data.
Definition
Definition
Input parameters
Call
sf_cdstep_init();
10.7. CONJUGATE-DIRECTION ITERATION (CDSTEP.C) 217
Definition
void sf_cdstep_init(void)
/*< initialize internal storage >*/
{
...
}
Call
sf_cdstep_close();
Definition
void sf_cdstep_close(void)
/*< free internal storage >*/
{
...
}
10.7.3 sf cdstep
Calculates one step for the conjugate direction iteration, that is, it calculates the new
conjugate gradient for the new line search direction.
Call
Definition
Input parameters
Call
sf_cdstep_diag(nx, res);
Definition
Input parameters
Call
Definition
Input parameters
Call
l = sf_llist_init();
220 CHAPTER 10. SOLVERS
Definition
sf_list sf_llist_init(void)
/*< create an empty list >*/
{
...
}
Output
Rewinds the list, that is, it makes the pointer to the current position equal to the first
entry position.
Call
sf_llist_rewind(l);
Definition
void sf_llist_rewind(sf_list l)
/*< return to the start >*/
{
...
}
Input parameters
Call
d = sf_llist_depth(l);
Definition
int sf_llist_depth(sf_list l)
/*< return list depth >*/
{
...
}
Input parameters
Output
Call
sf_llist_add(l, g, gn);
Definition
Input parameters
Call
sf_llist_down(l, g, gn);
Definition
Input parameters
Call
sf_llist_close(l);
10.9. CONJUGATE-DIRECTION ITERATION FOR COMPLEX NUMBERS (CCDSTEP.C)223
Definition
void sf_llist_close(sf_list l)
/*< free allocated storage >*/
{
...
}
Input parameters
Call
sf_llist_chop(l);
Definition
void sf_llist_chop(sf_list l)
/*< free the top entry from the list >*/
{
...
}
Input parameters
Call
sf_ccdstep_init();
Definition
void sf_ccdstep_init(void)
/*< initialize internal storage >*/
{
...
}
Call
sf_ccdstep_close();
Definition
void sf_ccdstep_close(void)
/*< free internal storage >*/
{
...
}
10.9.3 sf ccdstep
Calculates one step for the conjugate direction iteration, that is, it calculates the new
conjugate gradient for the new line search direction. It works like sf cdstep but for
complex numbers.
Call
Definition
Input parameters
10.9.4 saxpy
Multiplies a given complex number with an array of complex numbers and stores the
cumulative products in another array.
Call
Definition
Input parameters
10.9.5 dsdot
Returns the Hermitian dot product of two complex numbers or the sum of the dot products
if the are two arrays of complex numbers.
Call
Definition
Input parameters
Output
prod dot product of the complex numbers. It is of type static sf double complex.
Creates an empty list for complex numbers. It returns a pointer to the list.
Call
sf_clist_init();
Definition
sf_clist sf_clist_init(void)
/*< create an empty list >*/
{
...
}
Output
Rewinds the list, that is, it makes the pointer to the current position equal to the first
entry position.
Call
sf_clist_rewind(l);
228 CHAPTER 10. SOLVERS
Definition
void sf_clist_rewind(sf_clist l)
/*< return to the start >*/
{
...
}
Input parameters
Input parameters
Output
Call
sf_clist_depth(l);
Definition
int sf_clist_depth(sf_clist l)
/*< return list depth >*/
{
10.10. LINKED LIST FOR CD-TYPE METHODS (COMPLEX DATA) (CLIST.C) 229
...
}
Call
sf_clist_add(l, g, gn);
Definition
Input parameters
Call
sf_clist_down(l, g, gn);
Definition
Input parameters
Call
sf_clist_close(l);
Definition
void sf_clist_close(sf_clist l)
/*< free allocated storage >*/
{
...
}
Input parameters
Call
sf_clist_chop(l);
10.11. SOLVING QUADRATIC EQUATIONS (QUADRATIC.C) 231
Definition
void sf_clist_chop(sf_clist l)
/*< free the top entry from the list >*/
{
...
}
Input parameters
Solves the equation ax2 + 2bx + c = 0 and returns the smallest positive root.
Call
Definition
Input parameters
a coefficient of x2 (float).
b coefficient of x (float).
c constant term (float).
232 CHAPTER 10. SOLVERS
Output
10.12.1 sf zero
Returns the zero (root) of the input function, f (x) in a specified interval [a, b].
Call
Definition
...
return b;
}
Input parameters
(*func)(float) function, the root of which is required. Must be of type sf double complex.
a lower limit of the interval (float).
b upper limit of the interval (float).
fa function value at the lower limit (float).
10.13. RUNGE-KUTTA ODE SOLVERS (RUNGE.C) 233
Output
Initializes the required variables and allocates the required space for the ODE solver for
raytracing.
Call
Definition
\subsubsection*{Input parameters}
\begin{desclist}{\tt }{\quad}[\tt dim1]
\setlength\itemsep{0pt}
\item[dim1] dimension of the ODE (\texttt{int}).
\item[n1] number of steps for performing the raytracing (\texttt{int}).
\item[d1] number of time steps for performing the raytracing (\texttt{int}).
\end{desclist}
234 CHAPTER 10. SOLVERS
\subsection{{sf\_runge\_close\_init}}
Frees all allocated memory.
\subsubsection*{Call}
\begin{verbatim}sf_runge_close();
Definition
void sf_runge_close(void)
/*< free allocated storage >*/
{
...
}
10.13.2 sf ode23
This function solves a first order ODE to calculate the travel time by raytracing.
Call
Definition
...
}
Input parameters
Output
Call
Definition
Input parameters
Output
10.14.1 sf tinysolver
Performs the linear inversion for equations of the type Lx = y to compute the model x.
10.15. SOLVER FUNCTIONS FOR ITERATIVE LEAST-SQUARES OPTIMIZATION (BIGSOLVER.C)237
Call
Definition
Input parameters
Call
Definition
Input parameters
Applies solves generic linear equations for complex data after preconditioning the data.
Call
Definition
Input parameters
Call
Definition
Input parameters
10.15.4 sf solver
Call
sf_solver (oper, solv, nx, ny, x, dat, niter, "x0",x0, ..., "end");
Definition
---
The last parameter in the call to this function should be "end".
Example:
---
sf_solver (oper_lop,sf_cgstep,nx,ny,x,y,100,"x0",x0,"end");
---
Parameters in ...:
---
"wt": float*: weight
"wght": sf_weight wght: weighting function
"x0": float*: initial model
"nloper": sf_operator: nonlinear operator
"mwt": float*: model weight
"verb": bool: verbosity flag
"known": bool*: known model mask
"nmem": int: iteration memory
"nfreq": int: periodic restart
"xmov": float**: model iteration
"rmov": float**: residual iteration
"err": float*: final error
"res": float*: final residual
>*/
{
...
}
Input parameters
Call
Definition
Input parameters
10.15.6 sf csolver
Call
sf_csolver (oper, solv, nx, ny, x, dat, niter, "x0",x0, ..., "end");
Definition
Input parameters
Allocates the space equal to the data size for iteratively-reweighted least squares.
Call
sf_irls_init(n);
Definition
void sf_irls_init(int n)
/*< Initialize with data size >*/
{
...
}
Input parameters
Frees the space allocated for the iteratively-reweighted least squares by sf irls init.
Call
sf_irls_close();
248 CHAPTER 10. SOLVERS
Definition
void sf_irls_close(void)
/*< free allocated storage >*/
{
...
}
10.16.3 sf l1
Call
Definition
Input parameters
10.16.4 sf cauchy
Call
Definition
Input parameters
Initializes the object of the abstract data of type sf tris, which contains a matrix of size
n with separate variables for the diagonal and off-diagonal entries and also for the solution
to the matrix equation which it will be used to solve.
Call
Definition
Input parameters
Output
Fills in the diagonal and off-diagonal entries in the tridiagonal solver based on the input
entries diag and offd.
Call
Definition
Input parameters
Fills in the diagonal and off diagonal entries in the tridiagonal solver based on the input
entries diag and offd. It works like sf tridiagonal define but for the special case where
the matrix is Toeplitz.
10.17. TRIDIAGONAL MATRIX SOLVER (TRIDIAGONAL.C) 251
Call
Definition
Input parameters
Solves the matrix equation (like La = b, where b is the input for the solve function, a is the
output and L is the matrix defined by sf tridiagonal define) and stores the solution in
the space allocated by the variable x in the slv object.
Call
Definition
{
...
}
Input parameters
Definition
This function frees the allocated space for the slv object.
Call
sf_tridiagonal_close (slv);
Definition
Input parameters
Interpolation
Initializes the required variables and allocates the required space for 1D interpolation.
Call
Definition
255
256 CHAPTER 11. INTERPOLATION
Input parameters
Call
Definition
void sf_int1_lop (bool adj, bool add, int nm, int ny, float* x, float* ord)
/*< linear operator >*/
{
...
}
Input parameters
Call
Definition
void sf_cint1_lop (bool adj, bool add, int nm, int ny, sf_complex* x, sf_comple
x* ord)
/*< linear operator for complex numbers >*/
{
...
}
Input parameters
Call
sf_int1_close ();
258 CHAPTER 11. INTERPOLATION
Definition
Initializes the required variables and allocates the required space for 2D interpolation.
Call
sf_int2_init (coord, o1, o2, d1, d2, n1, n2, interp, nf_in, nd_in);
Definition
Input parameters
Call
Definition
void sf_int2_lop (bool adj, bool add, int nm, int ny, float* x, float* ord)
/*< linear operator >*/
{
...
}
Input parameters
Call
sf_int2_close();
Definition
Initializes the required variables and allocates the required space for 3D interpolation.
Call
Definition
{
...
}
Input parameters
Call
Definition
void sf_int3_lop (bool adj, bool add, int nm, int ny, float* mm, float* dd)
/*< linear operator >*/
{
...
}
262 CHAPTER 11. INTERPOLATION
Input parameters
Call
int3_close ();
Definition
Call
Definition
Input parameters
x data (float).
n number of interpolation points (int).
w interpolation coefficients (float*).
Call
Definition
Input parameters
x data (float).
n number of interpolation points (int).
w interpolation coefficients (float*).
264 CHAPTER 11. INTERPOLATION
11.4.3 sf lg int
Call
Definition
Input parameters
x data (float).
n number of interpolation points (int).
w interpolation coefficients (float*).
Call
Definition
Input parameters
x data (float).
n number of interpolation points (int).
w interpolation coefficients (float*).
Initializes the pre-filter for spline interpolation by initializing the required variables and
allocating the required space.
Call
Definition
Input parameters
Applies the pre-filter to the input 1D data to convert it to the spline coefficients.
266 CHAPTER 11. INTERPOLATION
Call
Definition
Input parameters
11.5.3 sf prefilter
Applies the pre-filter to the input N dimensional data to convert it to the spline coefficients.
Call
Definition
Input parameters
Call
sf_prefilter_close();
Definition
Call
Definition
Input parameters
Output
Call
slv = sf_spline4_init(nd);
Definition
Input parameters
Output
Call
Definition
Input parameters
Call
Definition
Input parameters
11.6.5 sf spline2
call
Definition
Input parameters
Initializes the object of the abstract data of type sf map, which will be used to define and
transform (stretch) coordinates.
Call
Definition
sf_map sf_stretch_init (int n1, float o1, float d1 /* regular axis */,
int nd /* data length */,
float eps /* regularization */,
bool narrow /* if zero boundary */)
/*< initialize >*/
{
...
}
Input parameters
n1 axis (int).
o1 first sample on the axis (int).
d1 step length to access the sample on the same axis (int).
272 CHAPTER 11. INTERPOLATION
Output
Defines the coordinates for mapping (which in this case is stretching. That is, it fills the
required variables in the sf map object to map the input coordinates.
Call
Definition
Input parameters
Converts the ordinates (ord) defined in the input to model (mod). It uses the sf tridiagonal solve
function.
11.7. INVERSE LINEAR INTERPOLATION (STRETCH.C) 273
Call
Definition
Input parameters
Converts model (mod) to ordinates by linear interpolation. It is the inverse of sf stretch apply.
Call
Definition
Input parameters
This function frees the allocated space for the sf map object.
Call
sf_stretch_close (str);
Definition
Input parameters
Call
Definition
Input parameters
Output
Frees the space allocated for the internal storage by sf eno init.
Call
sf_eno_close (ent);
Definition
Call
Definition
Input parameters
Call
Definition
Input parameters
Call
Definition
...
return pnt;
}
Input parameters
Output
Call
Definition
Input parameters
Sets the interpolation table for the 2D data in a 1D array, which is of size n1*n2.
Call
Definition
Input parameters
Frees the space allocated for the internal storage by sf eno2 init.
Call
sf_eno2_close (pnt);
Definition
Call
Definition
Input parameters
Call
Definition
Input parameters
Output
Frees the space allocated for the sf pweno object by sf pweno init.
Call
sf_pweno_close (ent);
Definition
Input parameters
11.10.3 powerpeno
Calculates the Power-p limiter for eno method using the input numbers x and y.
Call
Definition
Input parameters
Output
Call
void sf_pweno_set (sf_pweno ent, float* c /* data [n] */, int p);
11.10. 1-D ENO POWER-P INTERPOLATION (PWENO.C) 283
Definition
void sf_pweno_set (sf_pweno ent, float* c /* data [n] */, int p /* power order */)
/*< Set the interpolation undivided difference table. c can be changed or freed
afterwards >*/
{
...
}
Input parameters
Call
Definition
Input parameters
Smoothing
Call
Definition
Input parameters
285
286 CHAPTER 12. SMOOTHING
Applies the triangle smoothing to one of the input data and applies the smoothed data to
the unsmoothed one as a linear operator.
Call
Definition
void sf_triangle1_lop (bool adj, bool add, int nx, int ny, float* x, float* y)
/*< linear operator >*/
{
...
}
Input parameters
Output
Call
sf_triangle1_close();
Definition
void sf_triangle1_close(void)
/*< free allocated storage >*/
{
...
}
Call
Definition
Input parameters
Applies the triangle smoothing to one of the input data and applies the smoothed data to
the unsmoothed one as a linear operator. This is just like sf triangle1 lop but with two
triangle filters instead of one.
Call
Definition
void sf_triangle2_lop (bool adj, bool add, int nx, int ny, float* x, float* y)
/*< linear operator >*/
{
...
}
Input parameters
Output
Call
sf_triangle2_close();
Definition
void sf_triangle2_close(void)
/*< free allocated storage >*/
{
...
}
Call
Definition
Input parameters
Output
12.3.2 fold
Folds the edges of the smoothed data, because when the data is convolved with the data,
the length of the data increases and in most cases it is required that the smoothed data is
of the same length as the input data.
Call
Definition
static void fold (int o, int d, int nx, int nb, int np,
const float *x, float* tmp)
{
...
}
Input parameters
12.3.3 fold2
Is the same as fold except for the fact that it copies from tmp to data, unlike the fold
which does it the other way round.
Call
Definition
static void fold2 (int o, int d, int nx, int nb, int np,
float *x, const float* tmp)
{
...
}
Input parameters
12.3.4 doubint
Integrates the input data first in the backward direction and then if the input variable der
is true it integrates the result forward.
Call
Definition
Input parameters
12.3.5 doubint2
Unlike the doubint function this function integrates the input data first in the forward
direction and then if the input variable der is true it integrates the result backward direc-
tion.
Call
Definition
Input parameters
12.3.6 triple
Call
Definition
static void triple (int o, int d, int nx, int nb, float* x,
const float* tmp, bool box)
{
...
}
Input parameters
12.3.7 triple2
Call
Definition
Input parameters
12.3.8 sf smooth
Smoothes the input data by first applying the fold function then doubint and then triple.
Call
Definition
...
}
Input parameters
tr an object (filter) used for smoothing, box or triangle. Must be of type sf triangle.
o first indices of the input data (int).
d step size (int).
der a parameter to specify whether forward integration in doubint is required or not
(const float).
x a pointer to the input data (float).
box a parameter to specify whether a box filter is required (bool).
12.3.9 sf smooth2
Smoothes the input data by first applying the triple2 function then doubint2 and then
fold2.
Call
Definition
Input parameters
tr an object (filter) used for smoothing, box or triangle. Must be of type sf triangle.
o first indices of the input data (int).
d step size (int).
der a parameter to specify whether forward integration in doubint is required or not
(const float).
x a pointer to the input data (float).
box a parameter to specify whether a box filter is required (bool).
Call
sf_triangle_close(tr);
Definition
Input parameters
12.4.1 sf grad2
Calculates the gradient squared of the input with the centered finite-difference formula.
12.4. SMOOTH GRADIENT OPERATIONS (EDGE.C) 297
Call
Definition
Input parameters
12.4.2 sf sobel
Call
Definition
Input parameters
12.4.3 sf sobel2
Calculates the Sobel’s gradient squared for a 2D image. It works like sf sobel but outputs
the gradient squared.
Call
Definition
Input parameters
12.4.4 sf sobel32
Calculates the Sobel’s gradient squared for a 3D image. It works like sf sobel but outputs
the gradient squared for 3D data.
Call
Definition
void sf_sobel32 (int n1, int n2, int n3 /* data size */,
float ***x /* input data [n3][n2][n1] */,
float ***w /* output gradient squared */)
/*< Sobel’s gradient squared in 3-D>*/
{
...
}
Input parameters
Ray tracing
Initializes the object sf celltrace for ray tracing by initializing the required variables
and allocating the required space.
Call
ct = sf_celltrace_init (order, nt, nz, nx, dz, dx, z0, x0, slow);
Definition
301
302 CHAPTER 13. RAY TRACING
...
}
Input parameters
Output
Frees the space allocated for the sf celltrace object by sf celltrace init.
Call
sf_celltrace_close (ct);
Definition
Traces the ray with the ray parameter specified in the input.
Call
Definition
Input parameters
Output
Call
Definition
Input parameters
Performs the first step of the first order symplectic method for ray tracing.
Call
Definition
float sf_cell1_update1 (int dim, float s, float v, float *p, const float *g)
/*< symplectic first-order: step 1 >*/
{
13.2. CELL RAY TRACING (CELL.C) 305
...
}
Input parameters
Output
Performs the second step of the first order symplectic method for ray tracing.
Call
Definition
float sf_cell1_update2 (int dim, float s, float v, float *p, const float *g)
/*< symplectic first-order: step 2 >*/
{
...
}
Input parameters
Output
Call
Definition
Input parameters
Performs the first step of the first order non-symplectic method for ray tracing.
Call
Definition
float sf_cell11_update1 (int dim, float s, float v, float *p, const float *g)
/*< nonsymplectic first-order: step 1 >*/
{
...
}
Input parameters
Output
Performs the second step of the first order non-symplectic method for ray tracing.
Call
Definition
float sf_cell11_update2 (int dim, float s, float v, float *p, const float *g)
/*< nonsymplectic first-order: step 2 >*/
{
...
}
Input parameters
Output
Call
Definition
Input parameters
Definition
Definition
Input parameters
z position (float*).
iz sampling (int*).
eps tolerance. It is of type float.
Output
Performs the first step of the second order symplectic method for ray tracing.
Call
Definition
float sf_cell_update1 (int dim, float s, float v, float *p, const float *g)
/*< symplectic second-order: step 1 >*/
{
...
}
Input parameters
Output
Performs the second step of the second order symplectic method for ray tracing.
Call
Definition
Input parameters
Output
Call
a = sf_cell_p2a (p);
Definition
{
...
}
Input parameters
Output
General tools
Initializes the derivative calculation of the input trace, that is, it sets the required param-
eters and allocates the required space.
Call
Definition
Input parameters
313
314 CHAPTER 14. GENERAL TOOLS
Call
sf_deriv_free ();
Definition
void sf_deriv_free(void)
{
...
}
14.1.3 sf deriv
Calculates the derivative of the input trace (trace) and outputs it to trace2.
Definition
Definition
Input parameters
14.2.1 sf quantile
Returns the quantile - which is specified in the input - for the input array.
Call
k = sf_quantile(q, n, a);
Definition
Input parameters
Output
14.3.1 sf randn1
Call
Definition
Output
14.3.2 sf randn
Call
Definition
Input parameters
nr size of the array where the random numbers are to be stored (int).
r the array where the random numbers are to be stored (float*).
14.3.3 sf random
Call
sf_random (nr, r)
Definition
Input parameters
nr size of the array where the random numbers are to be stored (int).
nr the array where the random numbers are to be stored (float*).
14.4.1 myabs
Returns a complex number with zero imaginary value and the real non-zero real part is
the absolute value of the input complex number.
Call
c = sf_complex myabs(c);
318 CHAPTER 14. GENERAL TOOLS
Definition
Input parameters
Output
c a complex number with real part = absolute value of the input complex number and
imaginary part = zero. It is of type static sf complex.
14.4.2 myconj
Call
c = myconj(sf_complex c);
Definition
Input parameters
Output
14.4.3 myarg
Call
c = myarg(c);
Definition
Input parameters
Output
Applies a mathematical function to the input stack. For example it could evaluate the
exponents of the samples in the stack.
Call
Definition
Input parameters
Applies a mathematical function to the input stack. For example it could evaluate the
exponents of the samples in the stack, It works like sf math evaluate but does it for
complex numbers.
Call
Definition
Call
Definition
Input parameters
call
Definition
...
}
Input parameters
Output
Call
check();
Definition
Geometry
15.1.1 printpt2d
Call
printpt2d(pt2d P);
Definition
void printpt2d(pt2d P)
/*< print point2d info >*/
{
...
}
Input parameters
323
324 CHAPTER 15. GEOMETRY
15.1.2 printpt3d
Call
printpt3d(P);
Definition
void printpt3d(pt3d P)
/*< print point3d info >*/
{
...
}
Input parameters
15.1.3 pt2dwrite1
Outputs a 1D array of 2D points to a file. It can be used to define the source or receiver
arrays, for example.
Call
Definition
Input parameters
15.1.4 pt2dwrite2
Outputs a 2D array of 2D points to a file. It can be used to define the source or receiver
arrays, for example.
Call
Definition
Input parameters
15.1.5 pt3dwrite1
Outputs a 1D array of 3D points to a file. It can be used to define the source or receiver
arrays, for example.
Call
Definition
Input parameters
15.1.6 pt3dwrite2
Outputs a 2D array of 3D points to a file. It can be used to define the source or receiver
arrays, for example.
Call
Definition
Input parameters
15.1.7 pt2dread1
Reads a 1D array of 2D points from a file. It can be used to define the source or receiver
arrays, for example.
Call
Definition
Input parameters
File a file from which the 1D array of 2D points is to be read (sf file).
328 CHAPTER 15. GEOMETRY
15.1.8 pt2dread2
Reads a 2D array of 2D points from a file. It can be used to define the source or receiver
arrays, for example.
Call
Definition
Input parameters
File a file from which the 2D array of 2D points is to be read (sf file).
v an array of 2D points which is to be read (pt2d).
n1 size of one axis of the 2D array (size t).
n2 size of the other axis of the 2D array (size t).
k a number, which if equal to 3, indicates that the value of the 2D points must also
be included (int).
15.1.9 pt3dread1
Reads a 1D array of 3D points from a file. It can be used to define the source or receiver
arrays, for example.
15.1. CONSTRUCTION OF POINTS (POINT.C) 329
Call
Definition
Input parameters
File a file from which the 1D array of 3D points is to be read (sf file).
v an array of 1D points which is to be read (pt3d).
n1 size of one axis of the 3D array (size t).
k a number, which if equal to 4, indicates that the value of the 3D points must also
be included (int).
15.1.10 pt3dread2
Reads a 2D array of 3D points from a file. It can be used to define the source or receiver
arrays, for example.
Call
Definition
Input parameters
File a file from which the 2D array of 3D points is to be read (sf file).
v an array of 2D points which is to be read (pt3d).
n1 size of one axis of the 2D array (size t).
n2 size of the other axis of the 2D array (size t).
k a number, which if equal to 4, indicates that the value of the 3D points must also
be included (int).
15.1.11 pt2dalloc1
Call
ptr = pt2dalloc1(n1);
Definition
Input parameters
Output
15.1.12 pt2dalloc2
Call
ptr = pt2dalloc2(n1,n2);
Definition
Input parameters
Output
15.1.13 pt2dalloc3
Call
Definition
Input parameters
Output
15.1.14 pt3dalloc1
Call
ptr = pt3dalloc1(n1);
Definition
Input parameters
Output
15.1.15 pt3dalloc2
Call
ptr = pt3dalloc2(n1,n2);
Definition
Input parameters
Output
15.1.16 pt3dalloc3
Call
Definition
Input parameters
Output
15.2.1 det3
Call
d = det3(m);
Definition
Input parameters
m a 3 × 3 matrix (double).
Output
15.2.2 det2
Call
d = det2(m);
Definition
Input parameters
m a 2 × 2 matrix (double).
Output
15.2.3 jac3d
Returns a 3D jacobian.
Call
r = jac3d(C, T, P, Q);
Definition
...
}
Input parameters
Output
15.2.4 vec3d
Builds a 3D vector. The components of the vector returned are the difference of the
respective components of the two input points (position vectors). The first input vector is
the origin.
Call
V = vec3d(O, A);
Definition
Input parameters
Output
15.2.5 axa3d
Builds a 3D unit vector. The components of the vector returned are zero except for the
one indicated in the input argument n, which is equal to one. If n=1 the z axis is 1, if n=2
the x axis is 1 and if n=3 the y axis is 1.
Call
V = axa3d (n);
Definition
Input parameters
Output
15.2.6 scp3d
Call
p = scp3d(U, V);
338 CHAPTER 15. GEOMETRY
Definition
Input parameters
U a 3D vector (vc3d).
V a 3D vector (vc3d).
Output
15.2.7 vcp3d
Call
W = vcp3d(U, V);
Definition
Input parameters
U a 3D vector (vc3d).
V a 3D vector (vc3d).
15.2. CONSTRUCTION OF VECTORS (VECTOR.C) 339
Output
15.2.8 len3d
Call
l = len3d(V);
Definition
double len3d(vc3d* V)
/*< 3D vector length >*/
{
...
}
Input parameters
V a 3D vector (vc3d).
Output
15.2.9 nor3d
Normalizes a 3D vector. The components of the 3D input vector are divided by its length.
Call
W = nor3d(V);
340 CHAPTER 15. GEOMETRY
Definition
vc3d nor3d(vc3d* V)
/*< normalize 3D vector >*/
{
...
}
Input parameters
Output
15.2.10 ang3d
Call
a = ang3d(U, V);
Definition
Input parameters
Output
15.2.11 tip3d
Returns the tip of a 3D vector. The components of the vector returned are the sum of
the respective components of the two input points (position vectors). Unlike the sf vc3d
where the first input vector was the origin, in sf tip3d the origin is zero. This means that
the vector returned is a position vector or simply a point, which is of type pt3d.
Call
A = tip3d(O, V);
Definition
Input parameters
O a 3D point (pt3d).
V a 3D point (pt3d).
Output
15.2.12 scl3d
Scales a 3D vector, that is, it multiplies it by a scalar. The components of the vector
returned are the product of the components of the input vector and the input scalar.
342 CHAPTER 15. GEOMETRY
Call
W = scl3d(V, s);
Definition
Input parameters
V a 3D point (pt3d).
s a scalar which is to be multiplied by every component of the input vector (float).
Output
15.3.1 sf line2cart
Call
Definition
Input parameters
15.3.2 sf cart2line
Call
Definition
Input parameters
Output
Call
Definition
Input parameters
Output
Converts the line coordinate to Cartesian coordinates. It works exactly like sf line2cart
but in this one the line and Cartesian coordinates are of type off t, which means that
they are given in terms of the offset in bytes in the data file.
Call
Definition
Input parameters
Converts the Cartesian coordinates to line coordinate. It works exactly like sf line2cart
but in this one the line and Cartesian coordinates are of type off t, which means that
they are given in terms of the offset in bytes in the data file.
Call
Definition
Input parameters
Output
Returns the first index for a particular dimension. It works exactly like sf first index
but in this one the line coordinate, box size, step size and the first index are of type off t,
which means that they are given in terms of the offset in bytes in the data file.
Call
Definition
Input parameters
Output
15.4.1 sf maxa
Call
AA = sf_maxa(n, o, d);
Definition
Input parameters
Output
15.4.2 sf iaxa
Call
AA = sf_iaxa(FF, i);
Definition
Input parameters
Output
15.4.3 sf oaxa
Writes an axis, from the input location, to the file, which is also given in the input.
Call
Definition
Input parameters
15.4.4 sf raxa
Call
sf_raxa(AA);
Definition
Input parameters
AA the axis about which the information is required. Must be of type const sf axis.
15.4.5 sf n
Call
AA->n = sf_n(AA);
Definition
Input parameters
Output
15.4.6 sf o
Call
AA->o = sf_o(AA);
15.4. AXES (AXA.C) 351
Definition
Input parameters
Output
15.4.7 sf d
Call
AA->d = sf_d(AA);
Definition
Input parameters
Output
15.4.8 sf nod
Copies the length, origin and sampling of the input axis to another place which is also an
object of type sf axis.
Call
BB = sf_nod(AA);
Definition
Input parameters
AA the axis whose length, origin and sampling is to be accessed. Must be of type const
sf axis.
Output
BB the location where the length, origin and sampling are copied. It is of type sf axis.
15.4.9 sf setn
Call
Definition
Input parameters
15.4.10 sf seto
Call
Definition
Input parameters
15.4.11 sf setd
Call
Definition
Input parameters
15.4.12 sf setlabel
Call
sf_setlabel(AA, label);
Definition
Input parameters
15.4.13 sf setunit
Call
sf_setunit(AA, unit);
Definition
Input parameters
Miscellaneous
Initializes the sharpening operator by allocating the required and initializing the required
operators.
Call
sf_sharpen_init(n1, perc);
Definition
Input parameters
357
358 CHAPTER 16. MISCELLANEOUS
Call
sf_sharpen_close();
Definition
void sf_sharpen_close(void)
/*< free allocated storage >*/
{
...
}
16.1.3 sf sharpen
Call
wp = sf_sharpen(pp);
Definition
Input parameters
Output
16.1.4 sf csharpen
Computes the weights for the sharpening regularization for complex numbers.
Call
sf_csharpen(pp);
Definition
Input parameters
16.2.1 sf csharpinv
Performs the sharp inversion to estimate the model from the data, for complex numbers.
Call
sf_csharpinv(oper, scale, niter, ncycle, perc, verb, nq, np, qq, pp);
360 CHAPTER 16. MISCELLANEOUS
Definition
Input parameters
16.2.2 sf sharpinv
Performs the sharp inversion to estimate the model from the data.
Call
void sf_sharpinv(oper, scale, niter, ncycle, perc, verb, nq, np, qq, pp);
16.2. SHARPENING INVERSION ADDED BREGMAN ITERATION (SHARPINV.C)361
Definition
Input parameters
System
Initializes the heap with the maximum size given in the input.
Call
sf_pqueue_init (n);
Definition
Input parameters
363
364 CHAPTER 17. SYSTEM
Call
sf_pqueue_start ();
Definition
Call
sf_pqueue_close();
Definition
Call
sf_pqueue_insert (v);
Definition
Input parameters
Call
sf_pqueue_insert2 (v);
Definition
Input parameters
Call
v = sf_pqueue_extract();
Definition
Output
Call
v = sf_pqueue_extract2();
Definition
Output
Call
sf_pqueue_update (v);
Definition
Input parameters
17.2.1 sf system
Call
sf_system(command);
368 CHAPTER 17. SYSTEM
Definition
Input parameters
Initializes the object of type sf stack, that is, it allocates the required memory for the
data and also sets the size of the stack.
Call
Definition
Input parameters
Output
Prints the information about the stack on the screen. This may be used for debugging.
Call
sf_stack_print(s);
Definition
Input parameters
Call
l = sf_stack_get(s);
Definition
{
...
}
Call
sf_stack_set(s, pos);
Definition
Input parameters
Output
Sets the position of the pointer in the stack to the specified in the input pos.
Input parameters
17.3.5 sf push
Call
Definition
Input parameters
17.3.6 sf pop
Call
dat = sf_pop(s);
372 CHAPTER 17. SYSTEM
Definition
void* sf_pop(sf_stack s)
/*< pop data from stack >*/
{
...
}
Input parameters
Output
17.3.7 sf full
Call
isfull = sf_full(s);
Definition
Input parameters
Output
s->top >= s->entry true, if the stack is full, false otherwise. It is of type bool.
17.3.8 sf top
Call
typ = sf_top(s);
Definition
int sf_top(sf_stack s)
/*< return the top type >*/
{
...
}
Input parameters
Output
Call
sf_stack_close(s);
374 CHAPTER 17. SYSTEM
Definition
void sf_stack_close(sf_stack s)
/*< free allocated memory >*/
{
...
}
Input parameters
dot product
Hermitian, 222
filtering
frequency domain, 181, 185
operator
adjoint, 151
convolution, 150
crosscorrelation, 151
identity, 150
linear, 149
null, 150
product, 151
375
376 INDEX