previous up next print clean
Next: The C++ language Up: C++ in physical science: Previous: C++ in physical science:

Introduction

Every few years brings a new computer language. Yet most scientific and engineering computing continues to be done in Fortran, a language that has hardly changed since 1977. 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 memory-allocation limitation of Fortran, and offers new features such as data structures and scope. AT&T provides a free program that converts Fortran to C. (There is no known program for the reverse, nor is there ever likely to be.) 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 scientific code from Fortran to C. We (and many others) have overcome some of Fortran's most glaring deficits by calling C-language subroutines (especially for input-output), by using the Ratfor preprocessor to improve syntax, and by using saw and sat preprocessors for memory allocation and parameter handling. In the past few years, C has become standardized, and new developments are centered on the C++ language Stroustrup (1986). 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 define 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.)

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 (1992)) has been that the Fortran language leads to programs where the physical science is closely interwoven with the numerical analysis (NA) in the conjugate-gradient solver. In Fortran a new solver routine must be written for every new problem. One person (the programmer) must handle all the ingredients of both physics and NA 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.

The C++ language should allow us to better isolate numerical analysis from the physical-science code. If this promise can be realized, advanced techniques of numerical analysis should be more accessible to end users in science and engineering. Our ultimate goals are:

1.
Write real code that is clean enough that we can include it in publications where we now use mathematics and pseudocode.
2.
Reduce the ``overlap expertise'' required to merge scientific application code with numerical analysis code.
3.
Write linear operators in such a way that they can be used by people other than the original author, and operators written by different people can easily be combined to produce new operators.

As a first step to meeting these goals, we took a large body of tutorial Fortran-Ratfor code in the geophysical textbook, ``Earth soundings analysis: processing versus inversion'' by Jon Claerbout and began converting it to C++.



 
previous up next print clean
Next: The C++ language Up: C++ in physical science: Previous: C++ in physical science:
Stanford Exploration Project
11/17/1997