Computing for scientists: Principles of Programming with fortan 90 and C++
Résumé
Preamble
Basic Concepts
Hardware, software and programs 6
Two languages 7
Inside the box 8
Bits, bytes and words 9
Words and memory 11
Languages and compilers 13
Writing a simple program 15
Writing the source code 15
The program in C++ and Fortran 16
Writing readable programs 18
Program ``convert' 18
Comments in source code 19
Writing usable programs 20
Interacting with the user 20
The environment 22
MS-DOS and the PC environment 22
Unix and Linux environments 23
Future directions of Fortran and of C++ 23
The past, the present and the future of 23
Fortran 90
The future with C++ and C 25
C++ versus Fortran? 25
Interpreters 26
Debuggers 26
The operating system 27
Variables and Operators
Variables 30
Naming variables -- the rules and some 30
guidelines
Declaring variables 31
More about declarations 34
Constants 38
Integers in C++ 39
Literal real constants, standard and 40
double precision
The assignment statement 41
Operators 42
Monadic and dyadic operators 42
Simple arithmetical operators 43
Auto incrementing 44
Exponentiation 44
Bit operators and bit functions 46
Operator precedence 47
Operator associativity 49
Operator ambiguities 49
Type conversion 51
Type casting in C++ 53
A typical program 53
Data Structure
Data type: integer 56
Twos-complement negative integers 56
Long and short integers 57
Integer constants 59
Data type: float and real 59
Higher-precision floating-point numbers 60
Data type: complex 62
Data type: logical 63
Data type: character 65
Data type: pointer 66
User-defined types 67
Defining types in C++ 68
Structures 69
Object classes 70
Arrays 71
One-dimensional arrays (vectors) 71
Multidimensional arrays 74
Array operations in Fortran 75
Array sections in Fortran 76
Control
Logical expressions 78
The Fortran type Logical 79
Logicals in C++ 80
Relational and logical operators 81
De Morgan's laws 82
Conditional statements 83
The simple condition: if statement 84
The compound if---else statement 85
The conditional operator in C++ 88
Multiway choices: case/switch 89
Indefinite iteration and while loops 90
Forever loops 90
Testing at the end of the loop: do---while 91
Indexed iteration 92
Escaping 95
Exception and error handling 96
The goto statement 97
Other ways of thinking 99
State models 99
Concurrency 100
Event-driven code 101
An example in control 102
Subprograms: Functions and subroutines
Subprograms: functions and subroutines 104
The subprogram body 105
Specifying that this is a subprogram 105
The return 106
Invocation 106
The stack 107
Arguments 108
Prototyping and interface blocks 109
Fortran modules 110
Arguments: reference and value 112
Arrays as arguments 114
Checking arguments 116
Optional and keyword arguments 117
Overloading 118
Functions as arguments 119
Other facilities 120
Template functions 120
Inline functions 120
Fortran internal subprograms 120
Sharing data 121
Recursion 122
System functions 123
Libraries 123
Characters and Strings
Characters 126
The source character set and execution 126
character set
Manipulating characters in C++ 127
Manipulating characters in Fortran 128
Gaps and tabulation 129
Control characters; operating system 130
differences
The ASCII code 131
ASCII control characters 131
Character sets, fonts, and styles 132
Strings of several characters 133
String constants 133
String variables 134
Strings, arrays, and pointers in C++ 136
String expressions 137
Arrays of strings 138
String assignments 138
String input and output 140
Substrings 141
The length of a string 142
String comparison: equality and sorting 143
Searching strings 144
An example program 145
Reading the data 146
Analysing the formula string 147
Matching characters in strings 148
Finding digits for a repeat count 149
The final piece 150
Pointers
Pointers at the machine level 152
Pointers in C++ 154
Declaring pointers 154
Pointer operations: * and & 155
Further pointer manipulation 156
Pointers and arrays 157
Pointers and dynamic variables 158
Pointers and multidimensional arrays 159
Casts 161
Pointers to functions 162
Pointers and structures 164
Pointers in Fortran 165
Input and Output
C++: standard I/O and stream I/O 168
Standard I/O in C and C++ 168
Formatting output in Fortran and C++/C 169
standard I/O
The format string and the I/O list 169
Details of the format specifications 170
More detailed features 171
Various other Fortran FORMAT features 173
PRINT and WRITE 173
The stand-alone FORMAT statement 174
Default FORMAT 174
Repeat counts 174
Carriage-control characters 175
Loops in I/O lists 175
Formatted input in Fortran and C++/C 176
standard I/O
C++ stream I/O 178
Formatting output with C++ stream I/O 179
Writing your own manipulators 181
The flush manipulator 181
endl and the alternatives 181
Formatting input with stream I/O 182
Single-character I/O in C++ 182
A comparison of the three methods of I/O 183
Streams and records 186
Files: streams and units 187
Opening a connection 189
Error trapping 190
Reading or writing with old or new files 191
Formatted (text) and unformatted (binary) 192
data
Moving about 193
Moving about with sequential files 193
Random access 194
Closing the connection 195
Graphics 196
Numerical Methods
Exploring floating-point numbers 198
Relative accuracy with floating-point 199
numbers
Theory is all very well-what about my 200
machine?
The IEEE 754 floating-point system 202
Single precision: 32-bit numbers 202
Double precision: 64-bit numbers 203
Single precision versus double precision 204
Multiplication and division 205
Range problems for REAL and float 205
variables
Avoiding unnecessary precision in 207
calculations
Precision loss in addition and subtraction 208
Avoiding cancellation losses: rewriting 208
the algebra
Rewriting the algebra: the exponential 209
series
Avoiding cancellation losses: the false 210
mean
Averaging: the running mean 211
Updating the variance 212
Evaluating polynomials: Horner's method 213
Precision in practice 214
Solving quadratic equations 214
Summing series 216
Example 1: Least-squares fit to a straight 219
line
Example 2: Polynomial fits using Fortran 222
array functions
Object-Oriented Programming
What is an object? 226
Objects in C++ 228
Objects in Fortran 230
Operators for objects 231
Operator definitions in C++ 231
Operator definitions in Fortran 231
Comparison between the two languages 232
Initialisation, constructors and destructors 233
Initialising objects 233
Constructor and destructor functions 234
Public and private data and functions 235
Friend functions 236
Conversions between user-defined objects 237
Inheritance 238
Pointers and objects 240
Templates 242
An example: the list 243
Appendix 1 ANSWERS AND CODE
1.1 Chapter 1 251
1.2 Chapter 2 252
1.3 Chapter 3 254
1.4 Chapter 4 255
1.5 Chapter 5 256
1.6 Chapter 6 257
1.7 Chapter 7 258
1.8 Chapter 8 258
1.9 Chapter 9 259
1.10 Chapter 10 262
Appendix 2 THE ASCII CHARACTER SET
Appendix 3 BIBLIOGRAPHY
Caractéristiques techniques
| PAPIER | |
| Éditeur(s) | Wiley |
| Auteur(s) | R.J Barlow |
| Parution | 01/09/1998 |
| Couverture | Relié |
| Intérieur | Noir et Blanc |
| EAN13 | 9780471951148 |
Avantages Eyrolles.com
Consultez aussi
- Les meilleures ventes en Graphisme & Photo
- Les meilleures ventes en Informatique
- Les meilleures ventes en Construction
- Les meilleures ventes en Entreprise & Droit
- Les meilleures ventes en Sciences
- Les meilleures ventes en Littérature
- Les meilleures ventes en Arts & Loisirs
- Les meilleures ventes en Vie pratique
- Les meilleures ventes en Voyage et Tourisme
- Les meilleures ventes en BD et Jeunesse