PROGRAMMING GEOPHYSICS IN C
Dave Nichols foundations inversion
Hector Urdaneta moveout applications
Hyang Im Oh missing data examples
Jon Claerbout outline proofreading
Lisa Laane foundations
Martin Karrenbach moveout document integration
Matt Schwab tutorial and convolution
cAugust
Contents
INTRODUCTION
WHAT IS A SPACE
OPERATORS
SOLVERS
ADJOINTS AND THE DOTPRODUCT TEST
Using and understanding an operator
DIRECTORY STRUCTURE
A PHYSICAL OPERATOR CLASS
THE TEST PROGRAM
THE CONVOLUTION CLASS
SKELETON
STANDARD DOCUMENTATION
Elementary Science Operators
MATRIX MULTIPLICATION
CAUSAL INTEGRATION
FIRST DERIVATIVE
CONVOLUTION
A GENERAL MOVEOUT OPERATOR
Base and Building Block Operators
BASIC OPERATOR HIERARCHY
COMPOSING OPERATORS
UTILITY OPERATORS
Solving leastsquares inverse problems
i
ii
CONTENTS
LEAST SQUARES SOLVERS
USING SOLVER OBJECTS
PRECONDITIONED INVERSE PROBLEMS
THE Process UTILITY
Derived moveout operators
LINEAR MOVEOUT
NORMAL MOVEOUT
ANELLIPTIC MOVEOUT
KIRCHHOFF MOVEOUT
Stacking operators
LINEAR MOVEOUT AND STACKING
NMO AND STACK
KIRCHHOFF OPERATOR
VELOCITY ANALYSIS
SLANT STACK AND PRECONDITIONED INVERSION
Missingdata restoration
INTERPOLATING MISSING DATA WITH A KNOWN FILTER
INTERPOLATING MISSING DATA WITH AN UNKNOWN FILTER
SUMMARY
Appendix Man Pages
CONTENTS
PREFACE
This paper document is an advertisement for an electronic document that lies behind
it We plan to distribute the electronic document on CDROM late September or
early October
To run this version of the electronic document two commercial products are re
quired First is a C compiler This books code was tested using the Sun C
compiler version and the HP C compiler Both compilers are implemen
tations of ATTs C compiler versions and which seems to be a unix
industry standard Hopefully at a later date we will be able to include a freeware
C compiler that will also do the job Secondly our code uses the a commercial
matrix class library M from Dyad as a foundation for some of our C classes
In the future we hope to use a public domain matrix class library to avoid this com
mercial dependence We have no antipathy for commercial products in fact we like
them and appreciate them but experience shows that our work will be accessible to
the greatest number of people if our code depends only on noncommercial software
We are collaborating with Les Dye who is aliated with Berea and Stanfords
petroleum reservoir simulation group SUPRIB which is headed by Khalid Aziz
These groups are involved in research on objectbased mathematical abstractions for
reservoir simulation and nonlinear systems We may base our future library designs
on research that results from this collaboration
A recently introduced C language feature known as templates allows devel
opers to write one code that can be used for multiple data types Since our current
libraries only handle oat data and not complex data we hope to use templates
to create a more general library later this year
At mid August we have only begun to use the results of this C project for
serious seismological research We hope to demonstrate its utility further by summers
end
To test whether your environment will build this C document press this
BUTTON to destroy all the gures in this document Then view the document to
see if all the gures are gone Then press this BUTTON to rebuild all the gures
You could scan the document to see if all the gures have been regenerated or press
this BUTTON to see a statistical analysis of the reproducibility of the illustrations
in this document
CONTENTS
Chapter
INTRODUCTION
Every few years brings a new computer language Yet most scientic and engineering
computing continues to be done in Fortran a language that has hardly changed since
Here we explore the hypothesis that a new language C is a worthwhile
alternative to Fortran
C is based on the C language The C language has made remarkable strides
in the last several years Formerly Fortran was the language that was available on
most machines and it had the fewest variations from one machine to another Today
C replaces Fortran in both universality and uniformity Now more young engineers
and scientists learn C than any other language C overcomes the memoryallocation
limitation of Fortran and oers new features such as data structures and scope C
however was not designed for numerical analysis and it does not handle matrices as
conveniently as does Fortran There has been little mass movement of scientic code
from Fortran to C We and many others have overcome some of Fortrans most
glaring decits by calling Clanguage subroutines and by using our preprocessors for
memory allocation and parameter handling
In the past few years C has become
standardized and new developments are now centered on the C language C
shares the advantages of C but it adds features that permit the addition of new more
complex data types to the language and allows the author to dene all operations
possible on the new data types For instance C can handle the concept of arrays
at least as well as Fortran whereas C cannot
We do not predict that Fortran will die and be replaced by C but there
are some reasons why this might happen the growth of C has been much more
rapid
It already has many more users than Fortran We nd C compilers
on all manner of computers also the free GNU compiler whereas our workstation
manufacturers still do not oer Fortran New parallel architectures present an
opportunity for a malleable language like C and a risk for static languages
C was especially designed to enable concepts to be isolated leading to software
that is better debugged and more reusable A particular problem in geophysical
inversion problems see Processing versus inversion PVI for example Claerbout
has been that the Fortran language leads to programs where the physical
CHAPTER
INTRODUCTION
science is closely interwoven with the numerical analysis in the conjugategradient
solver One person the programmer must handle all the ingredients of both physics
and numerical analysis specializations Such code is challenging to write and even
more challenging to debug Further in complicated cases such as with nonlinear
operations or linear operators of very high order we cannot really be sure the code
is debugged which is disheartening
Our ultimate goals are
Write real code that is clean enough that we can include it in publications where
we now use mathematics and pseudocode
Reduce the overlap expertise required to merge scientic application code
with numerical analysis code
Write linear operators in such a way that they can be used by people other
than the original author and operators written by dierent people can easily
be combined to produce new operators
As a rst step to meeting these goals Nichols Dunbar and Claerbout took a
body of tutorial FortranRatfor code in the geophysical textbook Earth soundings
analysis processing versus inversion PVI by Jon Claerbout and began
converting it to C This summer more usersprogrammers were recruited The
base classes were improved and many new operators were added Some examples
from Claerbouts book Basic Earth Interior BEI were converted to C form
The C language
To ameliorate the problem of many of the readers of this document knowing little of
C and C we recommend following learning pathway Begin from any of the many
dozens of C tutorial books concentrating on learning particularly well the ideas of
pointer structure and typedef Then switch to the book which concerns itself
mainly with the class and inheritance concepts avoiding the full minutia of the
C language
Going beyond Fortran the rst concept needed is that of a structure For exam
ple in Fortran if a single symbol could represent the idea of nxi in then
that symbol would denote something like a structure Another structure might be
nn xii in in A numerical analyst thinking about
solving the multivariate regression y Ax might need to allocate several instances
of the structure representing x Clearly the solver program written by the analyst
should work for all possible structures In Fortran the application programmer ends
out allocating the temporary arrays needed by the numerical analyst leading to long
error prone calling sequences In Fortran the work of the applications programmer
and the numerical analyst are typically brought together by subroutines C also uses
subroutine libraries and additionally it makes heavy use of include les that de
ne structures thus serving to better isolate science from numerical analysis C
WHAT IS A SPACE
extends the structure concept to a class which is a structure containing subroutine
pointers C has elaborate provisions for sharing and hiding data for defaulting
and overriding functions
It also uses include les to implement a new method of
merging the work of the applications programmer to the numerical analyst called
inheritance or derivation whose explanation is beyond the scope of this brief
summary but which should become clearer as you progress through this document
WHAT IS A SPACE
The well known word space can lead to considerable confusion because there are
many entities that are described as spaces these include continuous spaces dis
crete sampled spaces abstract innite vector spaces etc
In our C code the
type space class describes objects that are a discrete sampling of a phys
ical property in some geometric region eg pressure measured on a plane The
word type denes the numerical type of the elements of the space currently
floatspace is the only supported type we hope to implement a complexspace class
soon
An abstract space in a numerical problem is a collection of values that could be a
single physical space a single instance of the type space class or an assemblage
of physical spaces In our C code such assemblages are called type spacearray
ie an array of type space objects In this paper we will use the word space
to refer to the abstract concept and type space or type spacearray when
we wish to refer to a particular representation of a space The type spacearray
can be thought of as a generalization of the single type space in our code a
single type space may be automatically converted to a type spacearray
containing a single element
The oatspace class
An object of class floatspace the class to represent a regulary sampled physical
space has two parts The rst part is a multidimensional array of numbers repre
senting the sampled data or model This array contains oating point values The
second part is a set of axes that describe the physical dimensions of region that the
samples are taken from
Every dimension of a floatspace has an axis associated with it which denes
an origin length and sampling interval delta for the axis as well as a label Thus
a floatspace is meant as a collection of real physical data rather than an abstract
collection of numbers This is ideal for many scientic applications as in geophysics
The publicly accessible member functions that manipulate objects of the class
floatspace are relatively few as operators are the main method of transforming a
space The most important member functions are