SlideShare une entreprise Scribd logo
1  sur  328
Télécharger pour lire hors ligne
Errata File "OOP via F90"

This is only the beginning of an errata for the text based on comments
from readers. As of June 2004 I have not yet verified the suggested
errors. I hope to review them when I start the summer break in July
2004. Please feel free to send your comments.    Prof. Akin

The Errata will cite pages in the published book, which will differ
from the PDF drafts here, especially for Chapter 9.

------------------------------- 1 --------------------------------------
One reviewer suggests that the source code line numbers should be
moved from the left margin to the right margin. This will be done in
any future release.

------------------------------- 2 --------------------------------------
Date: Fri, 4 Jul 2003 19:40:51 +0100
From: Alistair Mills
To: akin@rice.edu
Subject: Object oriented Fortran 90

Professor Akin

I have just come across your very interesting book. I think that this is a
book which has been waiting to be written! It is very interesting. I hope
that you will not be offended by what I have to say.   It is intended to be
constructive. Your book is a very readable account of the subject, and is
much more comprehensible than other things which I have read on the same
matter! I do not know how you can find time to be a professor at a major
school of engineering, do research, and write such things also!

I have also found your web site, and I have found that you have indexes to
the figures and the files. This is very helpful, as it was taking me time
to work out which source code files correspond to the text. I found that
the page numbers are not correct, but the figure numbers are approximately
correct. For example, I have changed the page numbers for chapter 7, and a
couple of the figure numbers. I will send you a complete updated index, if
you are interested. That would then agree with the published page numbers.

class_Stack.f90          7.2           160 *** See expanded list below ***
stack_check.f90          7.3           161
class_Queue.f90          7.5           163
queue_check.f90          7.6           165
singly_linked_list.f90   7.10          169
Test_SLL_Integers.f90    7.11          171
Integer_Objects.f90      7.12          172
doubly_linked_list.f90   7.14          173
Test_DLL_Integers.f90    7.15          175
random_access.f90        7.16          176
interface_Queue          Section_7.3
exceptions.f90           none
object_type.f90          none

I have also observed a couple of coding errors.     There is quite a serious
one in chapter 7.

Test_DLL_Integers.f90    7.15          175
Line 156 should read as follows:
  point_to_Obj_3   => Get_Ptr_to_Obj (container, Obj_3)      ! There is also an
error on the printed version on this line [20] and [21]

Rather than:
  point_to_Obj_3     =   Get_Ptr_to_Obj (container, Obj_3)

The program fails at run time when using both DVF 6.6 and Intel 7.0. The
error is a common one. The assignment statement on the original attempts to
copy the contents of the object at the end of the pointer to the contents of
the object at the end of point_to_Obj_3. As there is nothing yet on the end
of point_to_Obj_3, the run time system fails with an access violation.

There is also an error in chapter 4. Line 19 of passing_types.f90 is "call
by value". Fortran only does call by address. If you change line 19 to
eliminate the additional parentheses, then the results are different. The
parentheses force the creation of a temporary location containing a copy of
Input_val. The value in the temporary location is changed, but this is not
copied back to the source ie Input_Val. So the effect is the same, although
the reasons are different.

  ! pass by value
  call No_Change ( Input_Val ) ! Use but do not change
  print *, "After No_Change it is ", Input_Val

If you find what I have to say constructive, then I may have more when I
have completed reading the book!

With best wishes

Alistair Mills
------------------------------- 3 te: Tue, 8 Jul 2003 20:10:48 +0100
From: Alistair Mills
To: 'Ed Akin 221 Cox x4879' <akin@mems.rice.edu>
Subject: RE: Object oriented Fortran 90

Prof Akin

Thanks for pointing out the link, and thank you for including my comments.

Here is my version of the source code index.

Alistair

Source                    Figure        Page
hello.c                   1.3            09
hello.cpp                 1.3            09
hello.f90                 1.3            09
hello.m                   1.3            09

Math_Constants.f90        2.1            29
Fibonacci.f90             2.6            34
create_a_type.f90         Section_2.2    29
use_a_type.f90            Section_2.2    30

Geometric_Classes.f90     3.3,3.4        39
Test_Geometry.f90        3.3,3.4      40
class_Date.f90           3.6          42
Test_Date.f90            3.7          43
class_Person.f90         3.9          44
Test_Date_Person.f90     3.10         45
class_Student.f90        3.12         46
Test_Student.f90         3.13         47
class_Rational.f90       3.15         49
Test_Rational.f90        3.16         52
generic_geometry.f90     none
generic_geometry_2.f90   none

arithmetic.f90           4.1          61
do_for.f90               4.2          65
array_index.f90          4.3          65
more_or_less.f90         4.4          70
if_else.f90              4.5          70
and_or_not.f90           4.6          71
clip.f90                 4.7          79
maximum.f90              4.8          80
cpu_time.f90             4.10         82
exceptions.f90           4.11         83
passing_types.f90        4.12         86
string_use.f90           4.13         89
string_or_integer.f90    4.14         90
upper_lower.f90          4.15,4.16    91
struct_access.f90        4.17         96
fractions.f90            4.18         97
test_overload.f90        4.19         98
pt_expression.f90        4.20        101
linear_fit.f90           4.21        106
sort_reals.f90           4.23        109
sort_string.f90          4.24        110
integer_sort.f90         4.25        111
test_bubble.f90          4.27        113
cases.f90                none
vector_norm.f90          none
array_pointer.f90        none
interp_vs_compil.f90     none

interface               5.2          122
class_Drill.f90         5.3          123
test_Drill.f90          5.4          124
class_Angle.f90         5.6          126
class_Position_Angle.f90   5.8       130
class_Global_Position.f90 5.10       132
class_Great_Arc.f90     5.12         139
GPS_library.f90         5.13         135
non_poly_pos_ang.f90    none

                         6.5         139
                         6.6         140
                         6.7         141
                         6.8         143
                         6.9         143
                         6.10        144
                         6.11        145
6.12          146
                         6.13          147
                         6.14          148
                         6.15          149
                         6.16          150
Test_Is_A_Member.f90     6.17          153
member_1_class.f90       6.18          153
member_2_class.f90       6.19          154
is_a_member_class.f90    6.20          155

class_Stack.f90          7.1           160
stack_check.f90          7.3           161
class_Queue.f90          7.5           163
queue_check.f90          7.6           165
singly_linked_list.f90   7.10          169
Test_SLL_Integers.f90    7.11          171
Integer_Objects.f90      7.12          172
doubly_linked_list.f90   7.14          173
Test_DLL_Integers.f90    7.15          175
random_access.f90        7.16          176
interface_Queue          Section_7.3
exceptions.f90           none
object_type.f90          none

trans_opt.f90            8.1           191
Matrix_Operators.f90     none
array_demo.f90           none
display_real.f90         none

elem_type_data_class.f90   9.1      210
memory_leak.f90         9.2         212
No_Copy_Reallocate.f90 9.4          214
                        9.6         219
System_Constants.f90    none
------------------------------- 4 ---------------------------------
Date: Sun, 20 Jun 2004 03:56:44 -0700 (PDT)
From: Wayne B'Rells
To: akin@rice.edu
Subject: Errata for "OO Programming via Fortran 90/95"?

Dear Dr. Akin:

I recently picked up your book on OO programming with Fortran 90/95. I have
only read up to section 2.4, but have discovered a few errors in the text and
in the sample programs. Specifically, line [19] of the Fibonacci example
(Figure 2.6 ) references 'num%exists', which does not exist in the definition
of the 'Fibonacci_Number' type. This new logical variable is also mentioned
in the text, but not seem to be USED in the code.

Would you, perhaps, have an Errata listing for your book? (Such a listing of
corrections would make it a bit easier to follow some of your examples...)

BTW, I will be converting many of your examples so they can be compiled with
the 'F' compiler. This compiler seems to include all the new F90/95 features,
but leaves out those F77 constructs which are now redundant.

Hoping to hear from you,
Wayne B'Rells
Schenectady, NY
------------------------------- 5 ---------------------------------
Date: Mon, 21 Jun 2004 05:16:37 -0700 (PDT)
From: Wayne B'Rells
To: Ed Akin 221 Cox x4879 <akin@is.rice.edu>
Subject: Re: Errata for "OO Programming via Fortran 90/95"?

Dr. Akin:

I was able able to look at the 'errata', but did not notice my specific
problem. On the other hand, the code on the CD was correct in that it did NOT
include any reference to "num%exists".

FYI, the homepage for the F compiler is: http://www.swcp.com/~walt/

As I see it, the major advantages of the F compiler are:

1) It is free.

2) It is available for both the PC and Unix.

3) It FORCES users to strictly adhere to Fortran 90/95 coding practices and
to explicitly declare all variables, access privileges, etc. This seems
particularly desirable from a pedagogical point of view.

My "conversion" of the Fibonaccci example to F did suggest a few places where
the code could be "cleaned up" a bit:

1) The "implicit none" statements in the contained functions of the
"class_Fibonacci_Number" module were flagged as errors by the F compiler.
According to the Metcalf & Reid book ("Fortran 90/95 Explained"): "...and if
there is an implicit none statement there must be no other implicit statement
in the scoping unit." In other words, the implicit none statement at the
module level is inherited by the contained functions via host association. (I
suspect that many F90 compilers just treat the extra implicit none statements
as redundant and ignore them...)

2) In F, all contained functions must be explicitly given the 'public' or
'private' access attribute. Therefore, I had to add 'new_Fibonacci_Number' to
the list of public module functions.

3) In F, the 'intent' of all dummy arguments must be specified. Therefore, I
had to add "intent(in)" to the list of attributes for the 'max' argument in
the 'new_Fibonacci_Number' function.

These were the major modifications that I found necessary. The minor changes
included:

1) Putting only one statement per line
2) Changing ' to ".
3) Putting output formats directly in the write statements

Best wishes,

Wayne------------------------------- 6 ---------------------------------
Object Oriented Programming
via Fortran 90/95

Ed Akin
Rice University
Mechanical Engineering and Materials Science Department
Houston, Texas




May 29, 2001




                                          ­
                    Draft # 4.2, Copyright c 2001, All rights reserved.
ii
Contents

Preface                                                                                                                                                                  vii

1 Program Design                                                                                                                                                          1
  1.1. Introduction . . . . . . . . . . . . . . .                    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    1
  1.2. Problem Definition . . . . . . . . . . .                       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    3
  1.3. Modular Program Design . . . . . . . .                        .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    6
  1.4. Program Composition . . . . . . . . . .                       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    9
       1.4.1. Comments . . . . . . . . . . .                         .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    9
       1.4.2. Statements . . . . . . . . . . .                       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    9
       1.4.3. Flow Control . . . . . . . . . .                       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   11
       1.4.4. Functions . . . . . . . . . . . .                      .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   13
       1.4.5. Modules . . . . . . . . . . . .                        .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   15
       1.4.6. Dynamic Memory Management                              .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   15
  1.5. Program evaluation and testing . . . . .                      .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   15
  1.6. Program documentation . . . . . . . . .                       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   17
  1.7. Object Oriented Formulations . . . . .                        .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   18
  1.8. Exercises . . . . . . . . . . . . . . . .                     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   21

2 Data Types                                                                                                                                                             23
  2.1. Intrinsic Types . . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   23
  2.2. User Defined Data Types        .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   25
  2.3. Abstract Data Types . . .     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   27
  2.4. Classes . . . . . . . . .     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   29
  2.5. Exercises . . . . . . . .     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   31

3 Object Oriented Programming Concepts                                                                                                                                   33
  3.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . .                                          .   .   .   .   .   .   .   .   .   .   .   .   .   .   33
  3.2. Encapsulation, Inheritance, and Polymorphism . . . . . . .                                                .   .   .   .   .   .   .   .   .   .   .   .   .   .   34
       3.2.1. Example Date, Person, and Student Classes . . . . .                                                .   .   .   .   .   .   .   .   .   .   .   .   .   .   37
  3.3. Object Oriented Numerical Calculations . . . . . . . . . . .                                              .   .   .   .   .   .   .   .   .   .   .   .   .   .   38
       3.3.1. A Rational Number Class and Operator Overloading                                                   .   .   .   .   .   .   .   .   .   .   .   .   .   .   39
  3.4. Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . .                                          .   .   .   .   .   .   .   .   .   .   .   .   .   .   42
  3.5. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . .                                           .   .   .   .   .   .   .   .   .   .   .   .   .   .   48

4 Features of Programming Languages                                                                                                                                      51
  4.1. Comments . . . . . . . . . . . . .                .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   51
  4.2. Statements and Expressions . . . .                .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   52
  4.3. Flow Control . . . . . . . . . . .                .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   57
       4.3.1. Explicit Loops . . . . . .                 .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   58
       4.3.2. Implied Loops . . . . . .                  .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   60
       4.3.3. Conditionals . . . . . . .                 .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   61
  4.4. Subprograms . . . . . . . . . . .                 .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   68

­2001 J.E. Akin
c                                                                                            iii
4.4.1. Functions and Subroutines . . . . . . .                       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   68
         4.4.2. Global Variables . . . . . . . . . . . .                      .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   72
         4.4.3. Bit Functions . . . . . . . . . . . . . .                     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   74
         4.4.4. Exception Controls . . . . . . . . . . .                      .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   74
   4.5. Interface Prototype . . . . . . . . . . . . . . .                     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   75
   4.6. Characters and Strings . . . . . . . . . . . . .                      .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   76
   4.7. User Defined Data Types . . . . . . . . . . . .                        .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   80
         4.7.1. Overloading Operators . . . . . . . . .                       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   84
         4.7.2. User Defined Operators . . . . . . . . .                       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   86
   4.8. Pointers and Targets . . . . . . . . . . . . . . .                    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   86
         4.8.1. Pointer Type Declaration . . . . . . . .                      .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   87
         4.8.2. Pointer Assignment . . . . . . . . . . .                      .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   88
         4.8.3. Using Pointers in Expressions . . . . .                       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   88
         4.8.4. Pointers and Linked Lists . . . . . . . .                     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   88
   4.9. Accessing External Source Files and Functions                         .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   89
   4.10. Procedural Applications . . . . . . . . . . . . .                    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   90
         4.10.1. Fitting Curves to Data . . . . . . . . .                     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   90
         4.10.2. Sorting . . . . . . . . . . . . . . . . .                    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   92
   4.11. Exercises . . . . . . . . . . . . . . . . . . . .                    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   99

5 Object Oriented Methods                                                                                                                                         103
  5.1. Introduction . . . . . . . . . . . . . .           .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   103
  5.2. The Drill Class . . . . . . . . . . . .            .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   103
  5.3. Global Positioning Satellite Distances             .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   106
  5.4. Exercises . . . . . . . . . . . . . . .            .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   118

6 Inheritance and Polymorphism                                                                                                                                    119
  6.1. Introduction . . . . . . . . . . . . . . . . . . . . .                         .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   119
  6.2. Example Applications of Inheritance . . . . . . . .                            .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   121
       6.2.1. The Professor Class . . . . . . . . . . . . .                           .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   121
       6.2.2. The Employee and Manager Classes . . . .                                .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   121
  6.3. Polymorphism . . . . . . . . . . . . . . . . . . . .                           .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   124
       6.3.1. Templates . . . . . . . . . . . . . . . . . .                           .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   125
       6.3.2. Subtyping Objects (Dynamic Dispatching)                                 .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   130
  6.4. Exercises . . . . . . . . . . . . . . . . . . . . . .                          .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   133

7 OO Data Structures                                                                                                                                              135
  7.1. Data Structures . . . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   135
  7.2. Stacks . . . . . . . . . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   135
  7.3. Queues . . . . . . . . . . . .     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   139
  7.4. Linked Lists . . . . . . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   142
       7.4.1. Singly Linked Lists . .     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   142
       7.4.2. Doubly Linked Lists .       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   148
  7.5. Direct (Random) Access Files       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   149
  7.6. Exercises . . . . . . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   153

8 Arrays and Matrices                                                                                                                                             155
  8.1. Subscripted Variables: Arrays . . . . . . . . . . . . .                                .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   155
       8.1.1. Initializing Array Elements . . . . . . . . . . .                               .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   158
       8.1.2. Intrinsic Array Functions . . . . . . . . . . . .                               .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   159
       8.1.3. Colon Operations on Arrays (Subscript Triplet)                                  .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   159
       8.1.4. Array Logical Mask Operators . . . . . . . . .                                  .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   163
       8.1.5. User Defined Operators . . . . . . . . . . . . .                                 .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   165
       8.1.6. Connectivity Lists and Vector Subscripts . . .                                  .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   166

­2001 J.E. Akin
c                                                                                     iv
8.1.7. Component Gather and Scatter        .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   168
    8.2. Matrices . . . . . . . . . . . . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   170
         8.2.1. Matrix Algebra . . . . . . . .      .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   172
         8.2.2. Inversion . . . . . . . . . . .     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   174
         8.2.3. Factorizations . . . . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   174
         8.2.4. Determinant of a Matrix . . .       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   175
         8.2.5. Matrix Calculus . . . . . . . .     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   176
         8.2.6. Computation with Matrices .         .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   176
    8.3. Exercises . . . . . . . . . . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   178

9 Advanced Topics                                                                                                                                           181
  9.1. Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                          181
  9.2. Subtyping Objects (Dynamic Dispatching) . . . . . . . . . . . . . . . . . . . . . . . .                                                              183
  9.3. Non-standard Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                            184

A Bibliography                                                                                                                                              187

B Fortran 90 Overview                                                                                                                                       191
  B.1. List of Language Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                          191
  B.2. Alphabetical Table of Fortran 90 Intrinsic Routines . . . . . . . . . . . . . . . . . . .                                                             17
  B.3. Syntax of Fortran 90 Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                             29

C Selected Exercise Solutions                                                                                                                               47
  C.1. Problem 1.8.1 : Checking trigonometric identities . . . . . . . . . .                                            .   .   .   .   .   .   .   .   .   47
  C.2. Problem 1.8.2 : Newton-Raphson algorithm . . . . . . . . . . . . .                                               .   .   .   .   .   .   .   .   .   47
  C.3. Problem 1.8.3 : Game of life . . . . . . . . . . . . . . . . . . . . .                                           .   .   .   .   .   .   .   .   .   48
  C.4. Problem 2.5.1 : Conversion factors . . . . . . . . . . . . . . . . . .                                           .   .   .   .   .   .   .   .   .   49
  C.5. Problem 3.5.3 : Creating a vector class . . . . . . . . . . . . . . . .                                          .   .   .   .   .   .   .   .   .   50
  C.6. Problem 3.5.4 : Creating a sparse vector class . . . . . . . . . . . .                                           .   .   .   .   .   .   .   .   .   56
  C.7. Problem 4.11.1 : Count the lines in an external file . . . . . . . . . .                                          .   .   .   .   .   .   .   .   .   61
  C.8. Problem 4.11.3 : Computing CPU time useage . . . . . . . . . . . .                                               .   .   .   .   .   .   .   .   .   62
  C.9. Problem 4.11.4 : Converting a string to upper case . . . . . . . . . .                                           .   .   .   .   .   .   .   .   .   62
  C.10. Problem 4.11.8 : Read two values from each line of an external file .                                            .   .   .   .   .   .   .   .   .   63
  C.11. Problem 4.11.14 : Two line least square fits . . . . . . . . . . . . . .                                         .   .   .   .   .   .   .   .   .   63
  C.12. Problem 4.11.15 : Find the next available file unit . . . . . . . . . .                                          .   .   .   .   .   .   .   .   .   65
  C.13. Problem 5.4.4 : Polymorphic interface for the class ‘Position Angle’                                            .   .   .   .   .   .   .   .   .   66
  C.14. Problem 6.4.1 : Using a function with the same name in two classes .                                            .   .   .   .   .   .   .   .   .   67
  C.15. Problem 6.4.3 : Revising the employee-manager classes . . . . . . .                                             .   .   .   .   .   .   .   .   .   67

D Companion C++ Examples                                                                                                                                     69
  D.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                          69

E   Glossary of Object Oriented Terms                                                                                                                        77

F Subject Index                                                                                                                                              0

G Program Index                                                                                                                                              1




­2001 J.E. Akin
c                                                                                   v
Preface

There has been an explosion of interest in, and books on object-oriented programming (OOP). Why have
yet another book on the subject? In the past a basic education was said to master the three r’s: reading,
’riting, and ’rithmetic. Today a sound education in engineering programming leads to producing code that
satisfy the four r’s: readability, reusability, reliability, and really-efficient. While some object-oriented
programming languages have some of these abilities Fortran 90/95 offers all of them for engineering
applications. Thus this book is intended to take a different tack by using the Fortran 90/95 language as its
main OOP tool. With more than one hundred pure and hybrid object-oriented languages available, one
must be selective in deciding which ones merit the effort of learning to utilize them. There are millions
of Fortran programmers, so it is logical to present the hybrid object-oriented features of Fortran 90/95 to
them to update and expand their programming skills. This work provides an introduction to Fortran 90
as well as to object-oriented programming concepts. Even with the current release (Fortran 95) we will
demonstrate that Fortran offers essentially all of the tools recommended for object-oriented programming
techniques. It is expected that Fortran 200X will offer additional object-oriented capabilities, such as
declaring ”extensible” (or virtual) functions. Thus, it is expected that the tools learned here will be of
value far into the future.
     It is commonly agreed that the two decades old F77 standard for the language was missing several
useful and important concepts of computer science that evolved and were made popular after its release,
but it also had a large number of powerful and useful features. The following F90 standard included
a large number of improvements that have often been overlooked by many programmers. It is fully
compatible with all old F77 standard code, but it declared several features of that standard as obsolete.
That was done to encourage programmers to learn better methods, even though the standard still supports
those now obsolete language constructs. The F90 standards committee brought into the language most of
the best features of other more recent languages like Ada, C, C++, Eiffel, etc. Those additions included in
part: structures, dynamic memory management, recursion, pointers (references), and abstract data types
along with their supporting tools of encapsulation, inheritance, and the overloading of operators and
routines. Equally important for those involved in numerical analysis the F90 standard added several new
features for efficient array operations that are very similar to those of the popular M ATLAB environment.
Most of those features include additional options to employ logical filters on arrays. All of the new array
features were intended for use on vector or parallel computers and allow programmers to avoid the bad
habit of writing numerous serial loops. The current standard, F95, went on to add more specific parallel
array tools, provided “pure” routines for general parallel operations, simplified the use of pointers, and
made a few user friendly refinements of some F90 features. Indeed, at this time one can view F90/95 as
the only cross-platform international standard language for parallel computing. Thus Fortran continues
to be an important programming language that richly rewards the effort of learning to take advantage of
its power, clarity, and user friendliness.
     We begin that learning process in Chapter 1 with an overview of general programming techniques.
Primarily the older “procedural” approach is discussed there, but the chapter is closed with an outline of
the newer “object” approach to programming. An experienced programmer may want to skip directly to
the last section of Chapter 1 where we outline some object-oriented methods. In Chapter 2, we introduce
the concept of the abstract data types and their extension to classes. Chapter 3 provides a fairly detailed
introduction to the concepts and terminology of object-oriented programming. A much larger supporting
glossary is provided as an appendix.
     For the sake of completeness Chapter 4 introduces language specific details of the topics discussed in

­2002
c         J.E. Akin                                              i
the first chapter. The Fortran 90/95 syntax is used there, but in several cases cross-references are made to
similar constructs in the C++ language and the M ATLAB environment. While some readers may want to
skip Chapter 4, it will help others learn the Fortran 90/95 syntax and/or to read related publications that
use C++ or M ATLAB. All of the syntax of Fortran 90 is also given in an appendix.
     Since many Fortran applications relate to manipulating arrays or doing numerical matrix analysis,
Chapter 5 presents a very detailed coverage of the powerful intrinsic features Fortran 90 has added to
provide for more efficient operations with arrays. It has been demonstrated in the literature that object-
oriented implementations of scientific projects requiring intensive operations with arrays execute much
faster in Fortran 90 than in C++. Since Fortran 90 was designed for operations on vector and parallel
machines that chapter encourages the programmer to avoid unneeded serial loops and to replace them
with more efficient intrinsic array functions. Readers not needing to use numerical matrix analysis may
skip Chapter 5.
     Chapter 6 returns to object-oriented methods with a more detailed coverage of using object-oriented
analysis and object-oriented design to create classes and demonstrates how to implement them as an OOP
in Fortran 90. Additional Fortran 90 examples of inheritance and polymorphism are given in Chapter
7. Object-oriented programs often require the objects to be stored in some type of “container” or data
structure such as a stack or linked-list. Fortran 90 object-oriented examples of typical containers are
given in Chapter 8. Some specialized topics for more advanced users are given in Chapter 9, so beginning
programmers could skip it.
     To summarize the two optional uses of this text; it is recommended that experienced Fortran program-
mers wishing to learn to use OOP cover Chapters 2, 3, 6, 7, 8, and 9, while persons studying Fortran for
the first time should cover Chapters 1, 2, 3, and. Anyone needing to use numerical matrix analysis should
also include Chapter 5.
     A OO glossary is included in an appendix to aid in reading this text and the current literature on OOP.
Another appendix on Fortran 90 gives an alphabetical listing on its intrinsic routines, a subject based
list of them, a detailed syntax of all the F90 statements, and a set of example uses of every statement.
Selected solutions for most of the assignments are included in another appendix along with comments
on those solutions. The final appendix gives the C++ versions of several of the F90 examples in the
text. They are provided as an aid to understanding other OOP literature. Since F90 and M ATLAB are so
similar the corresponding M ATLAB versions often directly follow the F90 examples in the text.

                                                          Ed Akin, Rice University, 2002


Acknowledgements
We are all indebted to the hundreds of programmers that labor on various standards committees to con-
tinually improve all programming languages. Chapter 1 is a modification of introductory programming
notes developed jointly with Prof. Don Johnson at Rice University. I would like to thank Prof. Tinsley
Oden and the Texas Institute for Computational Mathematics for generously hosting my sabbatical leave
where most of this work was developed, and Rice University for financing the sabbatical. Special thanks
go to my wife, Kimberly, without whose support and infinite patience this book would not have been
completed.


Source Codes
All of the example programs and selected solutions are included on the CD-ROM provide with the book.
To be readable on various platforms they have been written with the ISO9660 standard format. Additional
files are provided to relate the ISO standard short filenames to the full length program names used in the
book. Of course, the source files will have to be processed through a Fortran 90 or 95 or 2000 compiler
to form executables. All of the figures are also provided as encapsulated Postscript (tm) files.




­2002
c         J.E. Akin                                              ii
Index

 , 53, 56                                 allocate, 42
   =, 53                                  ALLOCATE statement, 15, 74, 92, 181, 183
   =, 53                                  ALLOCATED function, 15, 181, 183
Ò, 122                                    allocation status, 74, 181, 258
*, 10, 56                                 AND operand, 42, 63, 104
**, 56                                    AND operator, 53
+, 53, 56                                 ANINT function, 162
/, 10, 56                                 ANY function, 162, 181
::, 25, 53                                any mask element true, 162
=, 10                                     arc cosine, 56
= , 143                                   arc sine, 56
%, 51, 143                                arc tangent, 56
&, 10, 34, 37, 42                         arccosine, 162
/=, 53                                    arcsine, 162
==, 53                                    arctangent, 162
=>, 121                                   arctangent for complex number, 162
                                          area, 34
ABS function, 56, 162, 250
                                          argument, 285
absolute value, 56, 162
                                                inout, 69
abstract class, 285
                                                input, 69
abstract data type, 15, 23, 27, 285
                                                interface, 75
abstraction, 19, 27, 285
                                                none, 69
access, 36
access operation, 142                           number of, 75
access restriction, 19                          optional, 75, 76
accessibility, 19                               order, 75
accessor, 18, 285                               output, 69
ACHAR function, 77, 80                          rank, 75
ACOS function, 56, 162                          returned value, 75
actual argument, 56                             type, 75
Ada, 15, 33                               array, 26, 60, 66, 82, 135, 149, 285
addition, 56                                    allocatable, 156
ADJUSTL function, 77                            assumed shape, 76
ADJUSTR function, 77                            automatic, 89, 156
ADT, see abstract data type                     Boolean, 164
ADVANCE specifier, 42, 102                       constant, 156
agent, 18                                       dummy dimension, 156
AIMAG function, 56, 162                         flip, 166
AINT function, 56, 162                          mask, 164, 179
algorithm, 51                                   of pointers, 135
ALL function, 162, 255                          rank, 76, 155, 157, 166
all mask elements true, 162                     rectangular, 166
allocatable array, 156, 157, 285                reshape, 155
ALLOCATABLE attribute, 183                      shape, 155
ALLOCATABLE statement, 15                       shift, 168

                                      1
size, 155                                     ISHFTC, 74
      total, 162                                    MVBITS, 74
      unknown size, 76                              NOT, 74
      variable rank, 156                            TRANSFER, 74
array operations, 159                          bit manipulation, 74
array pointer, 285                             blanks
array shape vector, 162                             all, 77
ASCII character set, 23, 76, 77, 98, 159            leading, 77
ASIN function, 56, 162                              trailing, 77
assembly language, 15                          Boolean type, 53
assignment operator, 10, 39, 189, 285          Boolean value, 23
assignment statement, 285                      bottom-up, 4
ASSOCIATED function, 15, 75, 88, 130, 132,     boundary condition, 192
            181                                bounds, 155
association, 285                               bubble sort, 92, 94
associative, 172, 173                               ordered, 95
asterisk (*), 58                               bug, 9
ATAN function, 56, 162
ATAN2 function, 13, 56, 162                    C, 1, 33, 52
attribute, 103, 104, 107, 119, 123, 192, 285   C++, 1, 10, 14, 24, 33, 52, 58, 59, 76, 81, 102,
      name, 19                                            121
      private, 27, 123                         call by reference, 286
      public, 27                               call by value, 286
      terminator, 25                           CALL statement, 42, 76, 86, 89, 92, 97, 121,
attribute terminator, 25                                  123, 124, 131, 137, 140, 142, 143,
attributes, 19, 27                                        149
automatic array, 89, 156, 157, 285             CASE DEFAULT statement, 63, 188
automatic deallocation, 29                     CASE statement, 63, 188, 272
                                               cases, 62
BACKSPACE statement, 75                        CEILING function, 56, 162
bad style, 158                                 central processor unit, 72
base 10 logarithm, 56, 162                     CHAR function, 77
base class, 119, 286                           character, 81
behavior, 104, 107                                   case change, 80
binary file, 159                                      control, 76
binary operator, 286                                 from number, 80
binary read, 268                                     functions, 77
binary write, 183                                    non-print, 76, 102
bit                                                  strings, 76
      clear, 74                                      to number, 80
      extract, 74                              character set, 23
      set, 74                                  CHARACTER type, 23, 26, 53
      shift, 74                                chemical element, 25
      test, 74                                 chemical element, 128
bit function                                   circuits, 166
      BIT SIZE, 74                             circular shift, 168
      BTEST, 74                                circular-linked list, 185
      IAND, 74                                 class, 15, 19, 33, 286
      IBCLR, 74                                      base, 18
      IBITS, 74                                      Date, 118, 121
      IBSET, 74                                      derived, 18
      IEOR, 74                                       Drill, 103
      IOR, 74                                        Employee, 123
      ISHFT, 74                                      Geometric, 118

­2002
c        J.E. Akin                                   2
Global Position, 112                        column major order, 177
     Great Arc, 112                              column matrix, 170
     hierarchy, 33                               column order, 158
     instance, 33                                comma, 98
     iterator, 192                               comment, 1, 2, 7, 9, 12, 51, 52
     Manager, 123, 133                           commutative, 100, 172, 173
     Person, 118, 121                            compiler, 10, 15, 90
     polymorphic, 131                            complex, 10, 81, 161
     Position Angle, 107, 112                    complex conjugate, 56
     Professor, 121                              COMPLEX type, 23, 24, 53
     sparse vector, 258                          component
     Student, 118, 121                                assignment, 82
class attribute, 286                                  declaring, 82
class code                                            initializing, 82
     class Angle, 112                                 interpretation, 82
     class Circle, 34                                 referencing, 82
     class Date, 37                                   syntax, 82
     class Employee 1, 122                       component selector, 34, 37, 42
     class Employee 2, 123                       composition, 34, 36, 190, 194
     class Employee 3, 124                       concatanate, 122
     class Fibonacci Number, 29                  conditional, 7–9, 11, 51, 58
     class Manager 1, 123                        conformable, 172
     class Manager 2, 123                        CONJG function, 56, 162
     class Manager 3, 124                        conjugate of complex number, 162
     class Object, 143                           connectivity, 166
     class Person, 37                            constant array, 156
                                                 constructor, 18, 29, 34, 123, 132, 133, 136, 149,
     class Position Angle, 270
                                                            255, 286
     class Professor, 121
                                                      default, 18
     class Queue, 140
                                                      intrinsic, 18, 26, 34, 39
     class Rational, 42
                                                      manual, 36
     class Rectangle, 34
                                                      public, 37
     class sparse Vector, 258
                                                      structure, 26
     class Stack, 137
                                                 container, 135
     class Student, 37
                                                 container class, 286
     class Vector, 257
                                                 CONTAINS statement, 29, 33, 34, 72, 75, 85
     Drill, 104
                                                 continuation marker, 10
     elem type data class, 181                   control key, 78
     Global Position, 112                        conversion factors, 29
     Great Arc, 112                              convert real to complex, 162
     Is A Member Class, 131                      convert to integer, 162
     Member 1 Class, 131                         convert to real, 162
     Member 2 Class, 131                         COS function, 56, 162, 249
     Position Angle, 112                         COSH function, 56, 162
class descriptor, 286                            cosine, 56, 162
class inheritance, 286                           COUNT function, 162, 259, 263
clipping function, 14, 69                        count-controlled DO, 12, 13
CLOSE statement, 74, 92, 97, 271                 CPU, see central processor unit
CMPLX function, 162                              curve fit, 90
Coad/Yourdon method, 18                          CYCLE statement, 65, 66, 260, 263
code reuse, 194
colon operator, 56, 60, 61, 77, 156, 159, 163,   data abstraction, 19
           166, 267                              data hiding, 36, 286
     syntax, 56                                  data structure, 135

­2002
c        J.E. Akin                                     3
data types, 10                         dynamic data structures, 38
      intrinsic, 23                    dynamic dispatching, 130
      user defined, 23                  dynamic memory, 74, 181
date, 99, 265                              allocation, 15
DATE AND TIME intrinsic, 265               de-allocation, 15
deallocate, 18, 42, 181                    management, 15
DEALLOCATE statement, 15, 74, 183      dynamic memory management, 88
deallocation, 287
debugger, 17, 287                      e, 25
debugging, 16                          EBCDIC character set, 23, 76
declaration statement, 287             efficiency, 194
default case, 63                       Eiffel, 18
default constructor, 287               electric drill, 103
default value, 29                      ELSE statement, 42, 63, 66
defined operator, 287                   encapsulate, 15
dereference, 58                        encapsulation, 27, 33, 192, 194, 287
dereferencing, 287                     end off shift, 168
derived class, 119                     end-of-file, 75
derived type, 15, 23, 287              end-of-record, 75
      component, 82                    end-of-transmission, 77
                                       EOF, see end-of-file
      nested, 82
                                       EOR, see end-of-record
      print, 84
                                       EOT, see end of transmission
      read, 84
                                       EPSILON function, 162
destructor, 29, 34, 41, 48, 254, 287
                                       equation
determinant, 175
                                             number, 169
diagonal matrix, 170
                                       EQV operator, 53
dimension
                                       error checking, 18
      constant, 157
                                       exception, 74, 287
      extent, 155
                                       exception handler, 74
      lower bound, 155
                                       exception handling, 18
      upper bound, 155
                                       exercises, 21, 31, 48, 99, 118, 132, 154, 178,
distributive, 173
                                                  195
division, 56                           EXIT statement, 65, 66, 251, 260, 262, 263,
division remainder, 56                            265, 269, 272, 273
DO statement, 29, 58, 61               EXP function, 56, 162, 250
DO WHILE statement, 66                 explicit interface, 288
DO-EXIT pair, 67, 68                   explicit loop, 11
documentation, 17                      exponent range, 24
domain, 19                             exponential, 56, 162
dot product, 162                       exponentiation, 56
dot product, 12                        expression, 10, 51, 52, 88
DOT PRODUCT intrinsic, 12, 162         external
double, 24                                   file, 89
DOUBLE PRECISION type, 23, 24, 53            subprogram, 89
doubly linked list, 149                external file, 288
drop fraction, 56                      external procedure, 288
dummy argument, 57, 72, 287            external subprogram, 76
dummy array, 287
dummy dimension, 157                   factorization, 174, 175, 179
dummy dimension array, 156             FALSE result, 62
dummy pointer, 287                     Fibonacci number, 29
dummy variable, 72                     file, 74
dynamic binding, 18, 287                    access, 151

­2002
c        J.E. Akin                           4
binary, 183                       dot Vector, 255, 259
     column count, 99                  Drill , 104, 106
     direct access, 150                D L new, 149
     I/O, 151                          el by el Mult, 259
     internal, 80                      equality operator point, 188
     line count, 99                    equal to Object, 143
     modify, 151                       gcd, 42, 101
     random, 151                       getEmployee, 123, 124
     random access, 150                getName, 123
     read status, 99                   getNameE, 122, 124
     record number, 150                getNameM, 123, 124
     scratch, 183                      getRate, 122, 124
     unit number, 100                  GetX, 188
FILE= specifier, 271                    GetY, 188
finite difference method, 179           get Arc, 112
finite element, 43                      Get Capacity of Q, 140
finite element analysis, 181            get Denominator, 42
flip, 163, 166                          get element, 260
float, 53                               Get Front of Q, 140
floating point, see real, 23, 24, 179   get item cost, 264
FLOOR function, 56, 162                get item count, 264
flow control, 11, 51, 58                get item delay, 264
forever loop, see infinite loop         get item name, 264
FORM= specifier, 271                    get Latitude, 112
FORMAT statement, 34, 112              Get Length of Q, 140, 142
function, 7, 9, 51, 68                 get Longitude, 112
     argument, 13, 15                  get menu, 273
     extensible, 130                   get mr rate, 104
     generic, 183                      get next io unit, 102, 269
     INTEGER, 140                      Get Next Unit, 98
     LOGICAL, 137, 140                 get Numerator, 42
     recursive, 42, 101                Get Obj at Ptr, 149
     result, 69                        get Person, 37
     return, 13                        get person, 37
     TYPE, 137, 140                    Get Ptr to Obj, 149
     variable, 15                      get torque, 104
function code                          Global Position , 112
     Add, 29                           Great Arc , 112
     add Rational, 42                  initialize item, 264
     add Real to Vector, 253           inputCount, 92, 265
     add Vector, 253                   Int deg, 112
     Angle , 112                       Int deg min, 112
     assign, 253                       Int deg min sec, 112
     circle area, 34                   is equal to, 42, 255, 260
     clip, 69                          is item empty, 264
     convert, 42                       Is Q Empty, 140
     copy Rational, 42                 is Q Empty, 142
     copy Vector, 254                  Is Q Full, 140
     Create Q, 140                     is Q Full, 142
     Date , 37                         is Stack Empty, 137
     Decimal min, 112                  is Stack Full, 137
     Decimal sec, 112                  is S L empty, 143
     Default Angle, 112                largest index, 260

­2002
c         J.E. Akin                     5
length, 260                        values of, 263
  lengthnormalize Vector, 255        Vector , 255
  less than Object, 143              Vector max value, 255, 263
  make Person, 37                    Vector min value, 255, 263
  make Professor, 121                Vector mult real, 255
  make Rational, 42                  Vector To Sparse, 263
  make Rectangle, 36                 zero sparse, 263
  make Stack, 137               function definition, 288
  make Student, 37              FUNCTION statement, 29
  make Vector, 253
  Manager , 123, 124            Game of Life, 4
  maximum, 70                   Gamma, 25
  mid value, 69                 gather-scatter, 168
  mult Fraction, 86             gcd, see greatest common divisor
  mult Rational, 42             generic function, 33, 34, 183, 288
  new Fibonacci Number, 29      generic interface, 132
  next generation, 251          generic linked list, 149
  norm, 262                     generic name, 34
  normalize Vecto, 262          generic object, 42
  pay, 123                      generic operator, 288
  payE, 122, 124                generic routine, 121
  payM, 123, 124                generic subprogram, 76
  Person, 121                   geometric shape, 34
  Person , 37                   global positioning satellite, 106
  pop from Stack, 137           global variable, 14, 72
                                GO TO statement, 64, 65
  print, 121
                                GPS, see global positioning satellite
  Professor, 121
                                Graham method, 18
  Rational, 42
                                graphical representation, 27, 118
  Rational , 42
                                greatest common divisor, 42, 101
  real mult Sparse, 262
                                greatest integer, 162
  real mult Vector, 255
                                grid, 190
  rectangle area, 34
  rows of, 262                  Has-A, 107, 194
  setDataE, 122, 124            header file, 129
  setDataM, 123, 124            heat transfer, 185
  set Date, 37                  Hello world, 7
  set Lat and Long at, 112      hello world, 52, 100
  size of, 262                  hierarchie
  size Vector, 255                   kind of, 18
  Sparse mult real, 262              part of, 18
  Student, 37, 121              High Performance Fortran, 195
  Student , 37                  horizontal tab, 77
  subtract Real, 255            host association, 288
  subtract Vector, 255          Hubbard, J.R., 36
  Sub Sparse Vectors, 263       HUGE function, 162
  Sum Sparse Vectors, 263       hyperbolic cosine, 56, 162
  S L new, 143                  hyperbolic sine, 56, 162
  toc, 72                       hyperbolic tangent, 56, 102, 162
  to Decimal Degrees, 112
  to lower, 80                  I/O, see Input-Output
  to Radians, 112               IACHAR function, 77, 80
  to upper, 80, 100, 266        ICHAR function, 77
  values, 255                   identity matrix, 178

­2002
c       J.E. Akin                     6
IF, 62                                                   Add to Q, 140
      nested, 62                                         assign, 131
if, 12                                                   Create Q, 140
IF ELSE statement, 62                                    display, 131
IF statement, 29, 37, 42, 62                             getName, 124
if-else, 12                                              Get Capacity of Q, 140
IF-ELSE pair, 63                                         Get Front of Q, 140
IF-ELSEIF, 130                                           Get Length of Q, 140
imaginary part, 56, 162                                  Init, 188, 190
IMPLICIT COMPLEX, 53                                     Is Q Empty, 140
IMPLICIT DOUBLE PRECISION, 53                            Is Q Full, 140
IMPLICIT INTEGER, 52                                     is Stack Empty, 136
implicit loop, 12                                        is Stack Full, 136
IMPLICIT NONE, 26, 29                                    make Stack, 136
IMPLICIT REAL, 52                                        MyPrint, 188
implied loop, 60, 61, 156, 166                           new, 131
INCLUDE line, 37, 42, 89                                 orthonormal basis, 257
INDEX function, 77, 80, 266, 273                         pop from Stack, 136
indexed loop, 11                                         Position Angle , 270
infinite loop, 9, 68, 269                                 PrintPay, 123, 124
information hiding, 288                                  push on Stack, 136
inheritance, 18, 33, 34, 72, 119, 190, 193, 194,         Remove from Q, 140
            288                                          Set, 188
      rename, 119                                        swap, 127
      selective, 119                                     testing basis, 257
inherited, 37                                      interface operator, 188, 258
initialize random number, 162                      interface operator ( ), 143
inner loop, 61                                     interface operator (*), 39
INQUIRE intrinsic, 92, 97, 102, 268, 269           interface operator (==), 143
                                                   INTERFACE OPERATOR block, 85, 86
INQUIRE statement, 75
                                                   INTERFACE OPERATOR statement, 166
instance, 33, 122, 288
                                                   interface prototype, 103, 104, 123
INT function, 162
                                                   INTERFACE statement, 34
integer, 10, 81, 161
                                                   internal file, 80, 289
integer nearest to real, 162
                                                   internal sub-programs, 72
INTEGER type, 23, 24, 53
                                                   internal subprogram, 251, 289
intent, 289
                                                   interpreter, 10, 15
      in, 29, 100
                                                   intrinsic, 166
      inout, 29
                                                   intrinsic constructor, 85, 98, 106, 136, 289
      out, 100
                                                   intrinsic function, 12, 68
      statement, 29
                                                   inverse, 178
INTENT attribute, 142
                                                   IOLENGTH result, 268
INTENT statement, 29, 58, 69, 93                   IOSTAT= variable, 74, 75, 271
interface, 2, 6, 9, 13, 15, 27, 34, 75, 92, 104,   Is-A, 106, 107, 124, 194
            107, 121, 136, 189, 258, 289           ISO VARIABLE LENGTH STRING, 23
      general form, 76                             iterator, 143, 149, 191, 192, 289
      human, 18
      input/output, 18                             keyword, 121, 289
      prototype, 18                                KIND intrinsic, 24
interface assignment, 258                          Kind-Of, 107, 123
INTERFACE ASSIGNMENT (=) block, 86
interface block, 34, 76                            largest integer, 56
interface body, 76                                 largest number, 162
interface code                                     latitude, 106

­2002
c         J.E. Akin                                      7
least integer, 162                            abort, 66, 67
least squares, 90, 266, 267                   breakout, 65
LEN function, 77, 80                          counter, 59
LEN intrinsic, 77, 80                         cycle, 65, 66
length                                        exit, 59, 65, 66
      line, 52                                explicit, 58
      name, 52                                implied, 60
LEN TRIM function, 77                         index, 100
LEN TRIM intrinsic, 77                        infinite, 60, 67, 68
lexical operator, 94                          nested, 61, 65
lexically                                     pseudocode, 58
      greater than, 77                        skip, 65
      less than, 77                           until, 66, 67
      less than or equal, 77                  variable, 60
LGE function, 77                              while, 66
LGT function, 77                         loop construct, 59
library function, 16                     loop control, 60, 158
line continuation, 100                   loop index, 100
linear equations, 173, 174, 179, 184     loop variable, 11
linked list, 38, 87, 88, 142, 149, 289   lower triangle, 171, 174
      doubly, 149
                                         manual constructor, 85, 104
linked-list, 191
                                         manual page, 17
linker, 16, 89, 289
                                         mask, 161, 164, 165, 179, 259
list
                                         masks, 61
      circular, 139, 185, 190
                                         Mathematica, 51
      doubly-linked, 88
                                         mathematical constants, 25
      empty, 149                         mathematical functions, 56
      length, 139                        Matlab, 1, 10, 14, 52, 60, 68, 99, 102
      singly-linked, 88                  MATMUL intrinsic, 162, 173
LLE function, 77                         matrix, 155, 170, 289
LLT function, 77                              addition, 172
local name, 119                               algebra, 155
LOG function, 56, 162                         column, 170
LOG10 function, 56, 162                       compatible, 172
logarithm, 68, 91, 162                        determinant, 175
logical, 81                                   diagonal, 170
      AND, 63                                 factorization, 174
      equal to, 63                            flip, 163
      EQV, 63                                 identity, 174
      greater than, 63                        inverse, 89, 174
      less than, 63                           multiplication, 159, 172
      NEQV, 63                                non-singular, 174
      NOT, 63                                 null, 170
      operator, 63                            skew symmetric, 171
      OR, 63                                  solve, 89
logical expression, 11                        sparse, 192
logical mask, 61                              square, 170, 171
LOGICAL type, 23, 42, 137                     symmetric, 171
long, 24                                      Toeplitz, 171
long double, 24                               transpose, 159, 171
long int, 24                                  triangular, 171, 174
longitude, 106                                tridiagonal, 179
loop, 5, 7–9, 11, 51, 58, 179            matrix addition, 177, 178

­2002
c         J.E. Akin                            8
matrix algebra, 155, 172                         Conversion Constants, 252
matrix multiplication, 162, 165, 173, 178        doubly linked list, 149
matrix operator, 38                              elem type data class, 181
matrix transpose, 162, 165                       exceptions, 75, 137
maximum array element location, 162              Fractions, 86
maximum array element value, 162                 Gauss Module, 190
maximum values, 70                               inventory object, 49, 264
MAXLOC function, 70, 162                         inventory system, 270
MAXVAL function, 70, 162, 263                    Is A Member Class, 131
mean, 69                                         Math Constants, 25
member, 119                                      Member 1 Class, 131
memory count, 183, 274                           Member 2 Class, 131
memory leak, 183                                 Memory Status Count, 183, 274
memory management, 181                           object type, 136
message, 27                                      Physical Constants, 252
message passing, 289                             Point Module, 188
method, 192, 289                                 Queue of Objects, 140
methods, 3                                       Queue type, 139
     private, 27                                 record Module, 97
     public, 27                                  singly linked lis, 143
military standards, 74                           singly linked list, 143
minimum array element location, 162              stack type, 136
minimum array element value, 162                 swap library, 127
minimum values, 70                               tic toc, 72, 99
MINLOC function, 70, 162                    module procedure, 289
MINVAL function, 70, 162                    MODULE PROCEDURE statement, 34, 39, 85,
                                                      86, 166
MOD function, 56
                                            MODULE statement, 29
modular design, 6
                                            module variable, 29
module, 15, 25, 33, 68, 289
                                            modulo, 56
module code
                                            MODULO function, 56
     class Angle, 112
                                            modulo function, 56
     class Circle, 34
                                            multiple inheritanc, 119
     class Date, 37
                                            multiplication, 56
     class Employee 1, 122
                                            Myer, B., 18
     class Employee 2, 123
     class Employee 3, 124                  NAG, see National Algorithms Group
     class Fibonacci Number, 29             named
     class Global Position, 112                  CYCLE, 65, 66
     class Great Arc, 112                        DO, 59, 66
     class Manager 1, 123                        EXIT, 65, 66
     class Manager 2, 123                        IF, 63
     class Manager 3, 124                        SELECT CASE, 63
     class Object, 143                      National Algorithms Group, 90
     class Person, 37                       natural logarithm, 56
     class Position Angle, 112, 270         NEQV operator, 53
     class Professor, 121                   nested, 289
     class Queue, 140                            DO, 66
     class Rational, 42                          IF, 62
     class Rectangle, 34                    new line, 78, 102
     class sparse Vector, 258               Newton-Raphson method, 11
     class Stack, 137                       NINT function, 56, 162
     class Student, 37                      node
     class Vector, 253, 256, 257                 current, 142, 149

­2002
c        J.E. Akin                                9
dummy, 149                                user defined, 76, 165
     header, 139, 142, 149                operator overloading, 10, 189, 260, 290
     linked list, 142                     operator precedence, 52
     next, 149                            operator symbol, 165
     null, 142                            optional argument, 29, 37, 75
     previous, 142, 149                   OPTIONAL attribute, 29, 36, 104, 137
     root, 142                            OR operand, 37
     tail, 139                            OR operator, 53
non-advancing I/O, 42                     order vector, 99
normalized sign, 162                      ordering array, 95
NOT operator, 53                          orthonormal basis, 256, 257
NULL function (f95), 88                   outer loop, 61
nullify, 132                              overflow, 290
NULLIFY statement, 15, 88, 132            overloaded member, 121
number                                    overloading, 39, 48, 85, 189, 290
     bit width, 24                             operators, 42
     common range, 24                          testing, 86
     label, 58
     significant digits, 24                package, 15
     truncating, 162                      parallel computer, 43
     type, 24                             PARAMETER attribute, 25, 29, 37, 60, 69, 70,
number of true masks, 162                            75, 82, 104, 112
numberic type, 24                         Part-Of, 107
numeric types, 23                         partial derivative, 176
numerical computation, 38                 partial differential equation, 183
                                          partitioned matrix, 171
object, 15, 19, 33                        pass by reference, 57, 76, 87, 253
object oriented                           pass by value, 57, 58, 76, 253
     analysis, 18, 43, 103, 107, 118      pass-by-value, 290
     approach, 18                         path name, 37
     design, 18, 43, 103, 107, 118, 190   pi, 25
     language, 18                         Platypus, 194
     programming, 18, 103                 pointer, 10, 23, 75, 86, 290
     representation, 18                         address, 150
Object Pascal, 18                               allocatable, 15
ONLY keyword, 119                               allocate, 142
OOA, see object oriented analysis               arithmetic, 87
OOD, see object oriented design                 array, 135
OOP, see object oriented programming            assignment, 88
OPEN statement, 74, 92, 97, 159, 271            association, 87
operator, 27                                    deallocate, 142
     .dot., 258                                 declaration, 87
     .op., 86, 165                              dereference, 58
     .solve., 89, 90                            detrimental effect, 87
     .t., 166                                   in expression, 88
     .x., 166                                   inquiry, 88
     assignment, 39                             nullify, 88
     binary, 86                                 nullifying, 88
     defined, 18, 86                             status, 15, 87
     extended, 86                               target, 87
     overloaded, 18, 143, 149, 189              writting, 150
     overloading, 39, 85, 258             pointer array, 290
     symbol, 86                           pointer assignment, 290
     unary, 86                            pointer object, 131

­2002
c        J.E. Akin                              10
pointer variable, 86                                Newton, 250
polymorphic class, 131                              No Copy Reallocate, 183
polymorphic interface, 118                          operate on strings, 78
polymorphism, 18, 33, 34, 119, 124, 194, 290        Person inherit, 37
pop, 137                                            random access file, 151
portability, 15                                     Rational test, 42
pre-condition checking, 137                         relational operators, 63
pre-processor, 129                                  Revise employee manager, 273
precedence order, 53                                simple loop, 60
precedence rules, 11                                string to numbers, 80
precision, 179, 192                                 structure components, 84
     double, 81                                     Testing a Queue, 142
     kind, 24                                       Testing a Stack, 137
     portable, 81                                   test bubble, 97
     single, 81                                     Test Conversion, 252
     specified, 81                                   Test doubly linked, 149
     underscore, 24                                 test Drill, 106
     user defined, 24                                test Employee 1, 122
precision kind, 24                                  test four classes, 121
PRESENT function, 29, 36, 37, 42, 75, 253           test Fractions, 86
PRINT * statement, 29                               test Great Arc, 112
private, 33, 104, 187, 290                          test inventory system, 272
PRIVATE attribute, 29, 36                           test Manager 2, 123
private attributes, 37                              test Manager 3, 124, 133
PRIVATE statement, 27                               Test Physical, 252
procedural programming, 18                          test singly linked, 143
procedure, 68                                       two line lsq fit, 267
PRODUCT function, 162                               watch, 265
product of array elements, 162                 program keyword, 56
                                               PROGRAM statement, 26, 29
program
                                               projectile, 101
     documentation, 17
                                               prototype, 6, 75
     executable, 17
                                               pseudo-pointer, 95
     scope, 14
                                               pseudo-random numbers, 162
program code
                                               pseudocode, 5, 14, 51, 69, 101, 291
     Another Great Arc, 270
                                                    if, 13
     array indexing, 60
                                                    if-else, 13
     check basis, 257
                                                    indexed loop, 9
     check vector class, 256
                                                    nested if, 13
     clip an array, 69
                                                    post-test loop, 9
     create a type, 26
                                                    pre-test loop, 9
     create Student, 37
                                               public, 33, 123, 136, 187, 291
     Date test, 37
                                               PUBLIC attribute, 29
     declare interface, 76                     public constructor, 37
     Dynamic Dispatching, 131                  public method, 27
     Fibonacci, 29                             PUBLIC statement, 27
     game of life, 251                         push, 137
     geometry, 34
     if else logic, 63                         quadratic equation, 3
     linear fit, 92                             query, 191
     Logical operators, 63                     queue, 88, 135, 139
     maximum, 70
     Memory Leak, 183                          raise to power, 56
     Memory Leak Counted, 274                  random access, 150

­2002
c        J.E. Akin                                   11
RANDOM NUMBER subroutine, 162                              bubble, 92
RANDOM SEED subroutine, 162                                characters, 94
rank, 157, 291                                             object, 96
rational number, 38, 39                                    objects, 94
read error, 102                                            strings, 94
READ statement, 29, 61, 75                           sorting, 42
real, 10, 81, 161                                    sparse matrix, 192
REAL function, 162                                   sparse storage, 263
REAL type, 23, 24, 53                                sparse vector, 49, 149, 258
real whole number, 162                               sparse vector class, 179
reallocate, 183, 195                                 specification, 4, 190
recursive algorithm, 87                              SQRT function, 27, 56, 112, 162
RECURSIVE qualifier, 42, 101                          square root, 27, 56, 68, 162
reference, 10                                        stack, 88, 135, 139, 291
referencing components, 82                           STAT = variable, 74
relational operator, 52, 53, 63, 77, 142, 143, 149   statement, 2, 9
remainder, 56                                        statement block, 12, 58
rename, 119                                          statements, 1
rename modifier, 119                                  status
REPEAT function, 77                                        FILE, 75
reshape, 158                                               IOSTAT=, 75
reshape an array, 162                                      MODE, 75
RESHAPE intrinsic, 162                                     OPENED=, 75
RESULT option, 29                                    status checking, 157
result value, 69                                     STATUS= specifier, 271
return, 157                                          stiffness matrix, 191, 192
RETURN statement, 65
                                                     STOP statement, 37, 70, 151, 181, 188
REWIND statement, 75, 183, 265, 266, 268
                                                     storage
round number, 56
                                                           column wise, 155
sample data, 98                                            row wise, 155
SCAN function, 77                                    string, 23, 56, 150
scatter, 169                                               adjust, 77
scope, 14, 291                                             case change, 80
SELECT CASE statement, 63, 188, 272                        character number, 77
SELECTED INT KIND, 23, 24                                  collating sets, 77
SELECTED REAL KIND, 23, 24                                 colon operator, 77
selector symbol, 26, 29, 34                                concatenate, 77
server, 18                                                 copy, 77
SHAPE function, 162                                        dynamic length, 76
short, 24                                                  from number, 80
side effect, 142, 291                                      functions, 77
SIGN function, 162                                         length, 77
signum, 162                                                logic, 77
SIN function, 56, 162, 249                                 repeat, 77
sine, 56, 162                                              scan, 77
SINH function, 56, 162                                     to number, 80
size, 12                                                   trim, 77
SIZE intrinsic, 69, 89, 92, 155, 162                       verify, 77
smallest integer, 56                                 strings, 76
smallest number, 162                                 strong typing, 53, 291
smallest positive number, 162                        struct, 53
Smalltalk, 18                                        structure, 23, 25, 33, 84
sort, 86, 90, 92, 95, 125                            structure constructor, 26

­2002
c         J.E. Akin                                       12
structured programming, 13              mult Fraction, 86
submatrix, 171                          MyPrint Point, 188
subprogram, 68                          new, 131
     recursive, 101                     new member 1, 131
subroutine, 68, 69                      new member 2, 131
subroutine code                         No Change, 76
     Add to Q, 140, 142                 nullify Is A Member, 131
     allocate type application, 181     orthonormal basis, 257
     Alloc Count Int, 183               out, 104, 106
     assign, 86, 131                    pretty, 262
     assign memb 1, 131                 Print, 29
     assign memb 2, 131                 print, 121
     Change, 76                         PrintPay, 123, 124
     deallocate type application, 181   PrintPayEmployee, 123, 124
     Dealloc Count Int, 183             PrintPayManager, 123, 124
     delete Rational, 42                print Date, 37
     delete Sparse Vector, 258          print DOB, 37
     delete Vector, 255                 print DOD, 37
     destroy D L List, 149              print DOM, 37
     detroy D L List, 149               print D L list, 149
     display all, 271                   print GPA, 37
     display members, 131               print item, 264
     display memb 1, 131                print Name, 37
     display memb 2, 131                print Nationality, 37
     D L insert before, 149             print Sex, 37
     enter entry, 272                   print S L list, 143
     enter item, 264                    push on Stack, 137
     enter update, 272                  readData, 92, 100, 266
     equal Fraction, 86                 read Date, 37
     equal Integer, 42                  Read Position Angle, 112
     equal Real, 255                    read Vector, 255, 262
     equal Vector, 260                  read xy file, 268
     exception, 137, 140                reduce, 42
     exception status, 75, 142          Remove from Q, 142
     file read, 264                      Resize Count Int OneD, 183
     file write, 264                     restore system, 271
     in, 104, 106                       save system, 271
     increase Size, 271                 setData, 123
     initialize, 272                    setSalaried, 123, 124
     Init Point, 188                    set DOB, 37
     Init Point Another, 188            set DOD, 37
     Init Point Vctr, 188               set DOM, 37
     Integer Sort, 95, 97, 98           set element, 262
     invert, 42                         set Latitude, 112
     list, 42, 86, 255                  set Longitude, 112
     List Angle, 112                    Set Point, 188
     List Great Arc, 112                set Size, 271
     List Position, 112                 Set Vec, 188
     List Position Angle, 112           Set X, 188
     List Pt to Pt, 112                 Set XY, 188
     list type alloc status, 181        show, 262
     lsq fit, 92                         show Data, 97
     make Sparse Vector, 258            show r v, 262

­2002
c        J.E. Akin                      13
simple arithmetic, 56        triplet, see colon operator
     Sort Reals, 93               true, 12
     Sort String, 94              TRUE result, 62
     Spy, 251                     truncate to real whole number, 162
     String Sort, 97, 98          truss, 166
     swap objects, 126            type
     swap real, 127                     conversion, 80
     swap type, 128                     default, 52
     S L delete, 143                    implicit, 52
     S L insert, 143              TYPE declaration, 26, 29
     testing basis, 257           TYPE statement, 27, 34
     test Manager 1, 123
     test matrix, 89              unary operator, 292
     tic, 72                      underflow, 292
SUBROUTINE statement, 29          unexpected result, 165
subroutines, 33                   upper triangle, 171, 174
subscript, 26, 59, 155            USE association, 119, 123, 190
     bounds, 155                  USE statement, 29, 33, 34, 37, 85, 89
     range, 177                   USE, ONLY, 119
     vector, 166                  user defined operator, 165
subscript triplet, 291            user interface, 2
subtraction, 56
subtype, 131                      validation, 29
subtyping, 124, 130               variable, 8, 10, 23, 51
sum, 12                                global, 14
SUM function, 12, 69, 162              name, 10
SUM intrinsic, 92, 165                 type, 10
sum of array elements, 162        variable rank array, 156
super class, 119                  vector, 155, 292
syntactic error, 17               vector class, 48, 179, 252, 256
SYSTEM CLOCK intrinsic, 72        vector subscript, 61, 166, 292
                                  VERIFY function, 77
tab, 78, 98, 102                  volume, 48
TAN function, 56, 162
tangent, 56, 162                  weakness, 193
TANH function, 56, 162            WHERE construct, 165
TARGET, 15                        WHERE statement, 61, 66, 165
target, 23, 75, 87, 88, 292       while-true, 67
template, 43, 124, 126, 292       wildcard, 126
tensor, 155                       WRITE statement, 34, 61, 75
testing, 15
time, 265
time of day, 99
TINY function, 162
Toeplitz matrix, 171
top-down, 4
total of elements in array, 162
transformational functions, 165
transpose, 159, 171, 173
TRANSPOSE intrinsic, 162, 166
tree, 292
tree structure, 38, 87, 88
tridiagonal matrix, 179
TRIM function, 77

­2002
c        J.E. Akin                      14
Chapter 1


Program Design

1.1 Introduction
The programming process is similar in approach and creativity to writing a paper. In composition, you
are writing to express ideas; in programming you are expressing a computation. Both the programmer
and the writer must adhere to the syntactic rules (grammar) of a particular language. In prose, the funda-
mental idea-expressing unit is the sentence; in programming, two units statements and comments are
available.
    Standing back, composition from technical prose to fiction should be organized broadly, usually
through an outline. The outline should be expanded as the detail is elaborated, and the whole re-examined
and re-organized when structural or creative flaws arise. Once the outline settles, you begin the actual
composition process, using sentences to weave the fabric your outline expresses. Clarity in writing
occurs when your sentences, both internally and globally, communicate the outline succinctly and clearly.
We stress this approach here, with the aim of developing a programming style that produces efficient
programs that humans can easily understand.
    To a great degree, no matter which language you choose for your composition, the idea can be ex-
pressed with the same degree of clarity. Some subtleties can be better expressed in one language than
another, but the fundamental reason for choosing your language is your audience: People do not know
many languages, and if you want to address the American population, you had better choose English
over Swahili. Similar situations happen in programming languages, but they are not nearly so complex
or diverse. The number of languages is far fewer, and their differences minor. Fortran is the oldest lan-
guage among those in use today. C and C++ differ from it somewhat, but there are more similarities
than not. M ATLAB’s language, written in C and Fortran, was created much later than these two, and its
structure is so similar to the others that it can be easily mastered. The C++ language is an extension of
the C language that places its emphasis on object oriented programming (OOP) methods. Fortran added
object oriented capabilities with its F90 standard, and additional enhancements for parallel machines
were issued with F95. The Fortran 2000 standard is planned to contain more user-friendly constructs for
polymorphism and will, thus, enhance its object-oriented capabilities. This creation of a new language
and its similarity to more established ones are this book’s main points: More computer programming lan-
guages will be created during your career, but these new languages will probably not be much different
than ones you already know. Why should new languages evolve? In MATLAB’s case, it was the desire to
express matrix-like expressions easily that motivated its creation. The difference between M ATLAB and
Fortran 90 is infinitesimally small compare to the gap between English and Swahili.
    An important difference between programming and composition is that in programming you are writ-
ing for two audiences: people and computers. As for the computer audience, what you write is “read” by
interpreters and compilers specific to the language you used. They are very rigid about syntactic rules,
and perform exactly the calculations you say. It is like a document you write being read by the most de-
tailed, picky person you know; every pronoun is questioned, and if the antecedent is not perfectly clear,
then they throw up their hands, rigidly declaring that the entire document cannot be understood. Your
picky friend might interpret the sentence “Pick you up at eight” to mean that you will literally lift him or
her off the ground at precisely 8 o’clock, and then demand to know whether the time is in the morning or

­2001
c         J.E. Akin                                              1
afternoon and what the date is.
    Humans demand even more from programs. This audience consists of two main groups, whose goals
can conflict. The larger of the two groups consists of users. Users care about how the program presents
itself, its user interface, and how quickly the program runs, how efficient it is. To satisfy this audience,
programmers may use statements that are overly terse because they know how to make the program more
readable by the computer’s compiler, enabling the compiler to produce faster, but less human-intelligible
program. This approach causes the other portion of the audience programmers to boo and hiss. The
smaller audience, of which you are also a member, must be able to read the program so that they can
enhance and/or change it. A characteristic of programs, which further distinguishes it from prose, is
that you and others will seek to modify your program in the future. For example, in the 1960s when
the first version of Fortran was created, useful programs by today’s standards (such as matrix inversion)
were written. Back then, the user interface possibilities were quite limited, and the use of visual displays
was limited. Thirty years later, you would (conceivably) want to take an old program, and provide a
modern user interface. If the program is structurally sound (a good outline and organized well) and is
well-written, re-using the “good” portions is easy accomplished.
    The three-audience situation has prompted most languages to support both computer-oriented and
human-oriented “prose”. The program’s meaning is conveyed by statements, and is what the computer
interprets. Humans read this part, which in virtually all languages bears a strong relationship to mathe-
matical equations, and also read comments. Comments are not read by the computer at all, but are there
to help explain what might be expressed in a complicated way by programming language syntax. The
document or program you write today should be understandable tomorrow, not only by you, but also by
others. Sentences and paragraphs should make sense after a day or so of gestation. Paragraphs and larger
conceptual units should not make assumptions or leaps that confuse the reader. Otherwise, the document
you write for yourself or others served no purpose. The same is true with programming; the program’s
organization should be easy to follow and the way you write the program, using both statements and com-
ments, should help you and others understand how the computation proceeds. The existence of comments
permits the writer to directly express the program’s outline in the program to help the reader comprehend
the computation.
    These similarities highlight the parallels between composition and programming. Differences become
evident because programming is, in many ways, more demanding than prose writing. On one hand, the
components and structure of programming languages are far simpler than the grammar and syntax of any
verbal or written language. When reading a document, you can figure out the misspelled words, and not
be bothered about every little imprecision in interpreting what is written. On the other, simple errors, akin
to misspelled words or unclear antecedents, can completely obviate a program, rendering it senseless or
causing it to go wildly wrong during execution. For example, there is no real dictionary when it comes
to programming. You can define variable names containing virtually any combination of letters (upper
and lower case), underscores, and numbers. A typographical error in a variable’s name can therefore
lead to unpredictable program behavior. Furthermore, computer execution speeds are becoming faster
and faster, meaning that increasingly complex programs can run very quickly. For example, the program
(actually groups of programs) that run NASA’s space shuttle might be comparable in size to Hugo’s Les
Mis´ rables, but its complexity and immediate importance to the “user” far exceeds that of the novel.
    e
    As a consequence, program design must be extremely structured, having the ultimate intentions of
performing a specific calculation efficiently with attractive, understandable, efficient programs. Achiev-
ing these general goals means breaking the program into components, writing and testing them separately,
then merging them according to the outline. Toward this end, we stress modular programming. Modules
can be on the scale of chapters or paragraphs, and share many of the same features. They consist of a se-
quence of statements that by themselves express a meaningful computation. They can be merged to form
larger programs by specifying what they do and how they interface to other packages of software. The
analogy in prose is agreeing on the character’s names and what events are to happen in each paragraph
so that events happen to the right people in the right sequence once the whole is formed. Modules can be
re-used in two ways. As with our program from the 1960s, we would “lift” the matrix inversion routine
and put a different user interface around it. We can also re-use a routine within a program several times.
For example, solving the equations of space flight involves the inversion of many matrices. We would

­2001
c         J.E. Akin                                              2
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90

Contenu connexe

Similaire à Errata file oop_via_f90

CCIE Real LAB TS 1.0 CCIEREALLABWORKBOOK.CO0
CCIE Real LAB TS 1.0  CCIEREALLABWORKBOOK.CO0CCIE Real LAB TS 1.0  CCIEREALLABWORKBOOK.CO0
CCIE Real LAB TS 1.0 CCIEREALLABWORKBOOK.CO0cciereallabworkbooks
 
BSOP 330 Entire Course NEW
BSOP 330 Entire Course NEWBSOP 330 Entire Course NEW
BSOP 330 Entire Course NEWshyamuopuop
 
Scripting for infosecs
Scripting for infosecsScripting for infosecs
Scripting for infosecsnancysuemartin
 
Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -LynellBull52
 
DeVry GSP 115 All Assignments latest
DeVry GSP 115 All Assignments latestDeVry GSP 115 All Assignments latest
DeVry GSP 115 All Assignments latestAtifkhilji
 
Upgrading to Rails 3
Upgrading to Rails 3Upgrading to Rails 3
Upgrading to Rails 3juliangiuca
 
Manual 1st
Manual 1st Manual 1st
Manual 1st ya
 
IBM Power Systems Performance Report
IBM Power Systems Performance ReportIBM Power Systems Performance Report
IBM Power Systems Performance ReportthinkASG
 
DeVry GSP 115 Week 3 Assignment latest
DeVry GSP 115 Week 3 Assignment latestDeVry GSP 115 Week 3 Assignment latest
DeVry GSP 115 Week 3 Assignment latestAtifkhilji
 
Ib Msystemsperformancebenchmarks
Ib MsystemsperformancebenchmarksIb Msystemsperformancebenchmarks
Ib Msystemsperformancebenchmarkspineiro
 
All bugfixes are incompatibilities
All bugfixes are incompatibilitiesAll bugfixes are incompatibilities
All bugfixes are incompatibilitiesnagachika t
 
Spoto updated new
Spoto updated newSpoto updated new
Spoto updated newAmolDhoke3
 
Writing Commits for You, Your Friends, and Your Future Self
Writing Commits for You, Your Friends, and Your Future SelfWriting Commits for You, Your Friends, and Your Future Self
Writing Commits for You, Your Friends, and Your Future SelfAll Things Open
 

Similaire à Errata file oop_via_f90 (20)

CCIE Real LAB TS 1.0 CCIEREALLABWORKBOOK.CO0
CCIE Real LAB TS 1.0  CCIEREALLABWORKBOOK.CO0CCIE Real LAB TS 1.0  CCIEREALLABWORKBOOK.CO0
CCIE Real LAB TS 1.0 CCIEREALLABWORKBOOK.CO0
 
BSOP 330 Entire Course NEW
BSOP 330 Entire Course NEWBSOP 330 Entire Course NEW
BSOP 330 Entire Course NEW
 
Scripting for infosecs
Scripting for infosecsScripting for infosecs
Scripting for infosecs
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -
 
DeVry GSP 115 All Assignments latest
DeVry GSP 115 All Assignments latestDeVry GSP 115 All Assignments latest
DeVry GSP 115 All Assignments latest
 
Upgrading to Rails 3
Upgrading to Rails 3Upgrading to Rails 3
Upgrading to Rails 3
 
Manual 1st
Manual 1st Manual 1st
Manual 1st
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
Hidden Gems of Ruby 1.9
Hidden Gems of Ruby 1.9Hidden Gems of Ruby 1.9
Hidden Gems of Ruby 1.9
 
Fastlane - ATC 2016
Fastlane - ATC 2016Fastlane - ATC 2016
Fastlane - ATC 2016
 
IBM Power Systems Performance Report
IBM Power Systems Performance ReportIBM Power Systems Performance Report
IBM Power Systems Performance Report
 
DeVry GSP 115 Week 3 Assignment latest
DeVry GSP 115 Week 3 Assignment latestDeVry GSP 115 Week 3 Assignment latest
DeVry GSP 115 Week 3 Assignment latest
 
Ib Msystemsperformancebenchmarks
Ib MsystemsperformancebenchmarksIb Msystemsperformancebenchmarks
Ib Msystemsperformancebenchmarks
 
All bugfixes are incompatibilities
All bugfixes are incompatibilitiesAll bugfixes are incompatibilities
All bugfixes are incompatibilities
 
Spoto updated new
Spoto updated newSpoto updated new
Spoto updated new
 
20140925 rails pacific
20140925 rails pacific20140925 rails pacific
20140925 rails pacific
 
Writing Commits for You, Your Friends, and Your Future Self
Writing Commits for You, Your Friends, and Your Future SelfWriting Commits for You, Your Friends, and Your Future Self
Writing Commits for You, Your Friends, and Your Future Self
 
P4 2018 io_functions
P4 2018 io_functionsP4 2018 io_functions
P4 2018 io_functions
 
Spring roo-docs
Spring roo-docsSpring roo-docs
Spring roo-docs
 

Dernier

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 

Dernier (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Errata file oop_via_f90

  • 1. Errata File "OOP via F90" This is only the beginning of an errata for the text based on comments from readers. As of June 2004 I have not yet verified the suggested errors. I hope to review them when I start the summer break in July 2004. Please feel free to send your comments. Prof. Akin The Errata will cite pages in the published book, which will differ from the PDF drafts here, especially for Chapter 9. ------------------------------- 1 -------------------------------------- One reviewer suggests that the source code line numbers should be moved from the left margin to the right margin. This will be done in any future release. ------------------------------- 2 -------------------------------------- Date: Fri, 4 Jul 2003 19:40:51 +0100 From: Alistair Mills To: akin@rice.edu Subject: Object oriented Fortran 90 Professor Akin I have just come across your very interesting book. I think that this is a book which has been waiting to be written! It is very interesting. I hope that you will not be offended by what I have to say. It is intended to be constructive. Your book is a very readable account of the subject, and is much more comprehensible than other things which I have read on the same matter! I do not know how you can find time to be a professor at a major school of engineering, do research, and write such things also! I have also found your web site, and I have found that you have indexes to the figures and the files. This is very helpful, as it was taking me time to work out which source code files correspond to the text. I found that the page numbers are not correct, but the figure numbers are approximately correct. For example, I have changed the page numbers for chapter 7, and a couple of the figure numbers. I will send you a complete updated index, if you are interested. That would then agree with the published page numbers. class_Stack.f90 7.2 160 *** See expanded list below *** stack_check.f90 7.3 161 class_Queue.f90 7.5 163 queue_check.f90 7.6 165 singly_linked_list.f90 7.10 169 Test_SLL_Integers.f90 7.11 171 Integer_Objects.f90 7.12 172 doubly_linked_list.f90 7.14 173 Test_DLL_Integers.f90 7.15 175 random_access.f90 7.16 176 interface_Queue Section_7.3 exceptions.f90 none object_type.f90 none I have also observed a couple of coding errors. There is quite a serious one in chapter 7. Test_DLL_Integers.f90 7.15 175
  • 2. Line 156 should read as follows: point_to_Obj_3 => Get_Ptr_to_Obj (container, Obj_3) ! There is also an error on the printed version on this line [20] and [21] Rather than: point_to_Obj_3 = Get_Ptr_to_Obj (container, Obj_3) The program fails at run time when using both DVF 6.6 and Intel 7.0. The error is a common one. The assignment statement on the original attempts to copy the contents of the object at the end of the pointer to the contents of the object at the end of point_to_Obj_3. As there is nothing yet on the end of point_to_Obj_3, the run time system fails with an access violation. There is also an error in chapter 4. Line 19 of passing_types.f90 is "call by value". Fortran only does call by address. If you change line 19 to eliminate the additional parentheses, then the results are different. The parentheses force the creation of a temporary location containing a copy of Input_val. The value in the temporary location is changed, but this is not copied back to the source ie Input_Val. So the effect is the same, although the reasons are different. ! pass by value call No_Change ( Input_Val ) ! Use but do not change print *, "After No_Change it is ", Input_Val If you find what I have to say constructive, then I may have more when I have completed reading the book! With best wishes Alistair Mills ------------------------------- 3 te: Tue, 8 Jul 2003 20:10:48 +0100 From: Alistair Mills To: 'Ed Akin 221 Cox x4879' <akin@mems.rice.edu> Subject: RE: Object oriented Fortran 90 Prof Akin Thanks for pointing out the link, and thank you for including my comments. Here is my version of the source code index. Alistair Source Figure Page hello.c 1.3 09 hello.cpp 1.3 09 hello.f90 1.3 09 hello.m 1.3 09 Math_Constants.f90 2.1 29 Fibonacci.f90 2.6 34 create_a_type.f90 Section_2.2 29 use_a_type.f90 Section_2.2 30 Geometric_Classes.f90 3.3,3.4 39
  • 3. Test_Geometry.f90 3.3,3.4 40 class_Date.f90 3.6 42 Test_Date.f90 3.7 43 class_Person.f90 3.9 44 Test_Date_Person.f90 3.10 45 class_Student.f90 3.12 46 Test_Student.f90 3.13 47 class_Rational.f90 3.15 49 Test_Rational.f90 3.16 52 generic_geometry.f90 none generic_geometry_2.f90 none arithmetic.f90 4.1 61 do_for.f90 4.2 65 array_index.f90 4.3 65 more_or_less.f90 4.4 70 if_else.f90 4.5 70 and_or_not.f90 4.6 71 clip.f90 4.7 79 maximum.f90 4.8 80 cpu_time.f90 4.10 82 exceptions.f90 4.11 83 passing_types.f90 4.12 86 string_use.f90 4.13 89 string_or_integer.f90 4.14 90 upper_lower.f90 4.15,4.16 91 struct_access.f90 4.17 96 fractions.f90 4.18 97 test_overload.f90 4.19 98 pt_expression.f90 4.20 101 linear_fit.f90 4.21 106 sort_reals.f90 4.23 109 sort_string.f90 4.24 110 integer_sort.f90 4.25 111 test_bubble.f90 4.27 113 cases.f90 none vector_norm.f90 none array_pointer.f90 none interp_vs_compil.f90 none interface 5.2 122 class_Drill.f90 5.3 123 test_Drill.f90 5.4 124 class_Angle.f90 5.6 126 class_Position_Angle.f90 5.8 130 class_Global_Position.f90 5.10 132 class_Great_Arc.f90 5.12 139 GPS_library.f90 5.13 135 non_poly_pos_ang.f90 none 6.5 139 6.6 140 6.7 141 6.8 143 6.9 143 6.10 144 6.11 145
  • 4. 6.12 146 6.13 147 6.14 148 6.15 149 6.16 150 Test_Is_A_Member.f90 6.17 153 member_1_class.f90 6.18 153 member_2_class.f90 6.19 154 is_a_member_class.f90 6.20 155 class_Stack.f90 7.1 160 stack_check.f90 7.3 161 class_Queue.f90 7.5 163 queue_check.f90 7.6 165 singly_linked_list.f90 7.10 169 Test_SLL_Integers.f90 7.11 171 Integer_Objects.f90 7.12 172 doubly_linked_list.f90 7.14 173 Test_DLL_Integers.f90 7.15 175 random_access.f90 7.16 176 interface_Queue Section_7.3 exceptions.f90 none object_type.f90 none trans_opt.f90 8.1 191 Matrix_Operators.f90 none array_demo.f90 none display_real.f90 none elem_type_data_class.f90 9.1 210 memory_leak.f90 9.2 212 No_Copy_Reallocate.f90 9.4 214 9.6 219 System_Constants.f90 none ------------------------------- 4 --------------------------------- Date: Sun, 20 Jun 2004 03:56:44 -0700 (PDT) From: Wayne B'Rells To: akin@rice.edu Subject: Errata for "OO Programming via Fortran 90/95"? Dear Dr. Akin: I recently picked up your book on OO programming with Fortran 90/95. I have only read up to section 2.4, but have discovered a few errors in the text and in the sample programs. Specifically, line [19] of the Fibonacci example (Figure 2.6 ) references 'num%exists', which does not exist in the definition of the 'Fibonacci_Number' type. This new logical variable is also mentioned in the text, but not seem to be USED in the code. Would you, perhaps, have an Errata listing for your book? (Such a listing of corrections would make it a bit easier to follow some of your examples...) BTW, I will be converting many of your examples so they can be compiled with the 'F' compiler. This compiler seems to include all the new F90/95 features, but leaves out those F77 constructs which are now redundant. Hoping to hear from you,
  • 5. Wayne B'Rells Schenectady, NY ------------------------------- 5 --------------------------------- Date: Mon, 21 Jun 2004 05:16:37 -0700 (PDT) From: Wayne B'Rells To: Ed Akin 221 Cox x4879 <akin@is.rice.edu> Subject: Re: Errata for "OO Programming via Fortran 90/95"? Dr. Akin: I was able able to look at the 'errata', but did not notice my specific problem. On the other hand, the code on the CD was correct in that it did NOT include any reference to "num%exists". FYI, the homepage for the F compiler is: http://www.swcp.com/~walt/ As I see it, the major advantages of the F compiler are: 1) It is free. 2) It is available for both the PC and Unix. 3) It FORCES users to strictly adhere to Fortran 90/95 coding practices and to explicitly declare all variables, access privileges, etc. This seems particularly desirable from a pedagogical point of view. My "conversion" of the Fibonaccci example to F did suggest a few places where the code could be "cleaned up" a bit: 1) The "implicit none" statements in the contained functions of the "class_Fibonacci_Number" module were flagged as errors by the F compiler. According to the Metcalf & Reid book ("Fortran 90/95 Explained"): "...and if there is an implicit none statement there must be no other implicit statement in the scoping unit." In other words, the implicit none statement at the module level is inherited by the contained functions via host association. (I suspect that many F90 compilers just treat the extra implicit none statements as redundant and ignore them...) 2) In F, all contained functions must be explicitly given the 'public' or 'private' access attribute. Therefore, I had to add 'new_Fibonacci_Number' to the list of public module functions. 3) In F, the 'intent' of all dummy arguments must be specified. Therefore, I had to add "intent(in)" to the list of attributes for the 'max' argument in the 'new_Fibonacci_Number' function. These were the major modifications that I found necessary. The minor changes included: 1) Putting only one statement per line 2) Changing ' to ". 3) Putting output formats directly in the write statements Best wishes, Wayne------------------------------- 6 ---------------------------------
  • 6. Object Oriented Programming via Fortran 90/95 Ed Akin Rice University Mechanical Engineering and Materials Science Department Houston, Texas May 29, 2001 ­ Draft # 4.2, Copyright c 2001, All rights reserved.
  • 7. ii
  • 8. Contents Preface vii 1 Program Design 1 1.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2. Problem Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.3. Modular Program Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.4. Program Composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.4.1. Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.4.2. Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.4.3. Flow Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.4.4. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1.4.5. Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 1.4.6. Dynamic Memory Management . . . . . . . . . . . . . . . . . . . . . . . . . 15 1.5. Program evaluation and testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 1.6. Program documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.7. Object Oriented Formulations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 1.8. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2 Data Types 23 2.1. Intrinsic Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.2. User Defined Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 2.3. Abstract Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 2.4. Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 2.5. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 3 Object Oriented Programming Concepts 33 3.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 3.2. Encapsulation, Inheritance, and Polymorphism . . . . . . . . . . . . . . . . . . . . . 34 3.2.1. Example Date, Person, and Student Classes . . . . . . . . . . . . . . . . . . . 37 3.3. Object Oriented Numerical Calculations . . . . . . . . . . . . . . . . . . . . . . . . . 38 3.3.1. A Rational Number Class and Operator Overloading . . . . . . . . . . . . . . 39 3.4. Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 3.5. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 4 Features of Programming Languages 51 4.1. Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 4.2. Statements and Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 4.3. Flow Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 4.3.1. Explicit Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 4.3.2. Implied Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 4.3.3. Conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 4.4. Subprograms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 ­2001 J.E. Akin c iii
  • 9. 4.4.1. Functions and Subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 4.4.2. Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 4.4.3. Bit Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 4.4.4. Exception Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 4.5. Interface Prototype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 4.6. Characters and Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 4.7. User Defined Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 4.7.1. Overloading Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 4.7.2. User Defined Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 4.8. Pointers and Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 4.8.1. Pointer Type Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 4.8.2. Pointer Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 4.8.3. Using Pointers in Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . 88 4.8.4. Pointers and Linked Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 4.9. Accessing External Source Files and Functions . . . . . . . . . . . . . . . . . . . . . 89 4.10. Procedural Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 4.10.1. Fitting Curves to Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 4.10.2. Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 4.11. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 5 Object Oriented Methods 103 5.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 5.2. The Drill Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 5.3. Global Positioning Satellite Distances . . . . . . . . . . . . . . . . . . . . . . . . . . 106 5.4. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 6 Inheritance and Polymorphism 119 6.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 6.2. Example Applications of Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 6.2.1. The Professor Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 6.2.2. The Employee and Manager Classes . . . . . . . . . . . . . . . . . . . . . . . 121 6.3. Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 6.3.1. Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 6.3.2. Subtyping Objects (Dynamic Dispatching) . . . . . . . . . . . . . . . . . . . 130 6.4. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 7 OO Data Structures 135 7.1. Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 7.2. Stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 7.3. Queues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 7.4. Linked Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 7.4.1. Singly Linked Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 7.4.2. Doubly Linked Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 7.5. Direct (Random) Access Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 7.6. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 8 Arrays and Matrices 155 8.1. Subscripted Variables: Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 8.1.1. Initializing Array Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 8.1.2. Intrinsic Array Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 8.1.3. Colon Operations on Arrays (Subscript Triplet) . . . . . . . . . . . . . . . . . 159 8.1.4. Array Logical Mask Operators . . . . . . . . . . . . . . . . . . . . . . . . . . 163 8.1.5. User Defined Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 8.1.6. Connectivity Lists and Vector Subscripts . . . . . . . . . . . . . . . . . . . . 166 ­2001 J.E. Akin c iv
  • 10. 8.1.7. Component Gather and Scatter . . . . . . . . . . . . . . . . . . . . . . . . . . 168 8.2. Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 8.2.1. Matrix Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 8.2.2. Inversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 8.2.3. Factorizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 8.2.4. Determinant of a Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 8.2.5. Matrix Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 8.2.6. Computation with Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 8.3. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 9 Advanced Topics 181 9.1. Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 9.2. Subtyping Objects (Dynamic Dispatching) . . . . . . . . . . . . . . . . . . . . . . . . 183 9.3. Non-standard Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 A Bibliography 187 B Fortran 90 Overview 191 B.1. List of Language Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 B.2. Alphabetical Table of Fortran 90 Intrinsic Routines . . . . . . . . . . . . . . . . . . . 17 B.3. Syntax of Fortran 90 Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 C Selected Exercise Solutions 47 C.1. Problem 1.8.1 : Checking trigonometric identities . . . . . . . . . . . . . . . . . . . 47 C.2. Problem 1.8.2 : Newton-Raphson algorithm . . . . . . . . . . . . . . . . . . . . . . 47 C.3. Problem 1.8.3 : Game of life . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 C.4. Problem 2.5.1 : Conversion factors . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 C.5. Problem 3.5.3 : Creating a vector class . . . . . . . . . . . . . . . . . . . . . . . . . 50 C.6. Problem 3.5.4 : Creating a sparse vector class . . . . . . . . . . . . . . . . . . . . . 56 C.7. Problem 4.11.1 : Count the lines in an external file . . . . . . . . . . . . . . . . . . . 61 C.8. Problem 4.11.3 : Computing CPU time useage . . . . . . . . . . . . . . . . . . . . . 62 C.9. Problem 4.11.4 : Converting a string to upper case . . . . . . . . . . . . . . . . . . . 62 C.10. Problem 4.11.8 : Read two values from each line of an external file . . . . . . . . . . 63 C.11. Problem 4.11.14 : Two line least square fits . . . . . . . . . . . . . . . . . . . . . . . 63 C.12. Problem 4.11.15 : Find the next available file unit . . . . . . . . . . . . . . . . . . . 65 C.13. Problem 5.4.4 : Polymorphic interface for the class ‘Position Angle’ . . . . . . . . . 66 C.14. Problem 6.4.1 : Using a function with the same name in two classes . . . . . . . . . . 67 C.15. Problem 6.4.3 : Revising the employee-manager classes . . . . . . . . . . . . . . . . 67 D Companion C++ Examples 69 D.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 E Glossary of Object Oriented Terms 77 F Subject Index 0 G Program Index 1 ­2001 J.E. Akin c v
  • 11. Preface There has been an explosion of interest in, and books on object-oriented programming (OOP). Why have yet another book on the subject? In the past a basic education was said to master the three r’s: reading, ’riting, and ’rithmetic. Today a sound education in engineering programming leads to producing code that satisfy the four r’s: readability, reusability, reliability, and really-efficient. While some object-oriented programming languages have some of these abilities Fortran 90/95 offers all of them for engineering applications. Thus this book is intended to take a different tack by using the Fortran 90/95 language as its main OOP tool. With more than one hundred pure and hybrid object-oriented languages available, one must be selective in deciding which ones merit the effort of learning to utilize them. There are millions of Fortran programmers, so it is logical to present the hybrid object-oriented features of Fortran 90/95 to them to update and expand their programming skills. This work provides an introduction to Fortran 90 as well as to object-oriented programming concepts. Even with the current release (Fortran 95) we will demonstrate that Fortran offers essentially all of the tools recommended for object-oriented programming techniques. It is expected that Fortran 200X will offer additional object-oriented capabilities, such as declaring ”extensible” (or virtual) functions. Thus, it is expected that the tools learned here will be of value far into the future. It is commonly agreed that the two decades old F77 standard for the language was missing several useful and important concepts of computer science that evolved and were made popular after its release, but it also had a large number of powerful and useful features. The following F90 standard included a large number of improvements that have often been overlooked by many programmers. It is fully compatible with all old F77 standard code, but it declared several features of that standard as obsolete. That was done to encourage programmers to learn better methods, even though the standard still supports those now obsolete language constructs. The F90 standards committee brought into the language most of the best features of other more recent languages like Ada, C, C++, Eiffel, etc. Those additions included in part: structures, dynamic memory management, recursion, pointers (references), and abstract data types along with their supporting tools of encapsulation, inheritance, and the overloading of operators and routines. Equally important for those involved in numerical analysis the F90 standard added several new features for efficient array operations that are very similar to those of the popular M ATLAB environment. Most of those features include additional options to employ logical filters on arrays. All of the new array features were intended for use on vector or parallel computers and allow programmers to avoid the bad habit of writing numerous serial loops. The current standard, F95, went on to add more specific parallel array tools, provided “pure” routines for general parallel operations, simplified the use of pointers, and made a few user friendly refinements of some F90 features. Indeed, at this time one can view F90/95 as the only cross-platform international standard language for parallel computing. Thus Fortran continues to be an important programming language that richly rewards the effort of learning to take advantage of its power, clarity, and user friendliness. We begin that learning process in Chapter 1 with an overview of general programming techniques. Primarily the older “procedural” approach is discussed there, but the chapter is closed with an outline of the newer “object” approach to programming. An experienced programmer may want to skip directly to the last section of Chapter 1 where we outline some object-oriented methods. In Chapter 2, we introduce the concept of the abstract data types and their extension to classes. Chapter 3 provides a fairly detailed introduction to the concepts and terminology of object-oriented programming. A much larger supporting glossary is provided as an appendix. For the sake of completeness Chapter 4 introduces language specific details of the topics discussed in ­2002 c J.E. Akin i
  • 12. the first chapter. The Fortran 90/95 syntax is used there, but in several cases cross-references are made to similar constructs in the C++ language and the M ATLAB environment. While some readers may want to skip Chapter 4, it will help others learn the Fortran 90/95 syntax and/or to read related publications that use C++ or M ATLAB. All of the syntax of Fortran 90 is also given in an appendix. Since many Fortran applications relate to manipulating arrays or doing numerical matrix analysis, Chapter 5 presents a very detailed coverage of the powerful intrinsic features Fortran 90 has added to provide for more efficient operations with arrays. It has been demonstrated in the literature that object- oriented implementations of scientific projects requiring intensive operations with arrays execute much faster in Fortran 90 than in C++. Since Fortran 90 was designed for operations on vector and parallel machines that chapter encourages the programmer to avoid unneeded serial loops and to replace them with more efficient intrinsic array functions. Readers not needing to use numerical matrix analysis may skip Chapter 5. Chapter 6 returns to object-oriented methods with a more detailed coverage of using object-oriented analysis and object-oriented design to create classes and demonstrates how to implement them as an OOP in Fortran 90. Additional Fortran 90 examples of inheritance and polymorphism are given in Chapter 7. Object-oriented programs often require the objects to be stored in some type of “container” or data structure such as a stack or linked-list. Fortran 90 object-oriented examples of typical containers are given in Chapter 8. Some specialized topics for more advanced users are given in Chapter 9, so beginning programmers could skip it. To summarize the two optional uses of this text; it is recommended that experienced Fortran program- mers wishing to learn to use OOP cover Chapters 2, 3, 6, 7, 8, and 9, while persons studying Fortran for the first time should cover Chapters 1, 2, 3, and. Anyone needing to use numerical matrix analysis should also include Chapter 5. A OO glossary is included in an appendix to aid in reading this text and the current literature on OOP. Another appendix on Fortran 90 gives an alphabetical listing on its intrinsic routines, a subject based list of them, a detailed syntax of all the F90 statements, and a set of example uses of every statement. Selected solutions for most of the assignments are included in another appendix along with comments on those solutions. The final appendix gives the C++ versions of several of the F90 examples in the text. They are provided as an aid to understanding other OOP literature. Since F90 and M ATLAB are so similar the corresponding M ATLAB versions often directly follow the F90 examples in the text. Ed Akin, Rice University, 2002 Acknowledgements We are all indebted to the hundreds of programmers that labor on various standards committees to con- tinually improve all programming languages. Chapter 1 is a modification of introductory programming notes developed jointly with Prof. Don Johnson at Rice University. I would like to thank Prof. Tinsley Oden and the Texas Institute for Computational Mathematics for generously hosting my sabbatical leave where most of this work was developed, and Rice University for financing the sabbatical. Special thanks go to my wife, Kimberly, without whose support and infinite patience this book would not have been completed. Source Codes All of the example programs and selected solutions are included on the CD-ROM provide with the book. To be readable on various platforms they have been written with the ISO9660 standard format. Additional files are provided to relate the ISO standard short filenames to the full length program names used in the book. Of course, the source files will have to be processed through a Fortran 90 or 95 or 2000 compiler to form executables. All of the figures are also provided as encapsulated Postscript (tm) files. ­2002 c J.E. Akin ii
  • 13. Index  , 53, 56 allocate, 42 =, 53 ALLOCATE statement, 15, 74, 92, 181, 183 =, 53 ALLOCATED function, 15, 181, 183 Ò, 122 allocation status, 74, 181, 258 *, 10, 56 AND operand, 42, 63, 104 **, 56 AND operator, 53 +, 53, 56 ANINT function, 162 /, 10, 56 ANY function, 162, 181 ::, 25, 53 any mask element true, 162 =, 10 arc cosine, 56 = , 143 arc sine, 56 %, 51, 143 arc tangent, 56 &, 10, 34, 37, 42 arccosine, 162 /=, 53 arcsine, 162 ==, 53 arctangent, 162 =>, 121 arctangent for complex number, 162 area, 34 ABS function, 56, 162, 250 argument, 285 absolute value, 56, 162 inout, 69 abstract class, 285 input, 69 abstract data type, 15, 23, 27, 285 interface, 75 abstraction, 19, 27, 285 none, 69 access, 36 access operation, 142 number of, 75 access restriction, 19 optional, 75, 76 accessibility, 19 order, 75 accessor, 18, 285 output, 69 ACHAR function, 77, 80 rank, 75 ACOS function, 56, 162 returned value, 75 actual argument, 56 type, 75 Ada, 15, 33 array, 26, 60, 66, 82, 135, 149, 285 addition, 56 allocatable, 156 ADJUSTL function, 77 assumed shape, 76 ADJUSTR function, 77 automatic, 89, 156 ADT, see abstract data type Boolean, 164 ADVANCE specifier, 42, 102 constant, 156 agent, 18 dummy dimension, 156 AIMAG function, 56, 162 flip, 166 AINT function, 56, 162 mask, 164, 179 algorithm, 51 of pointers, 135 ALL function, 162, 255 rank, 76, 155, 157, 166 all mask elements true, 162 rectangular, 166 allocatable array, 156, 157, 285 reshape, 155 ALLOCATABLE attribute, 183 shape, 155 ALLOCATABLE statement, 15 shift, 168 1
  • 14. size, 155 ISHFTC, 74 total, 162 MVBITS, 74 unknown size, 76 NOT, 74 variable rank, 156 TRANSFER, 74 array operations, 159 bit manipulation, 74 array pointer, 285 blanks array shape vector, 162 all, 77 ASCII character set, 23, 76, 77, 98, 159 leading, 77 ASIN function, 56, 162 trailing, 77 assembly language, 15 Boolean type, 53 assignment operator, 10, 39, 189, 285 Boolean value, 23 assignment statement, 285 bottom-up, 4 ASSOCIATED function, 15, 75, 88, 130, 132, boundary condition, 192 181 bounds, 155 association, 285 bubble sort, 92, 94 associative, 172, 173 ordered, 95 asterisk (*), 58 bug, 9 ATAN function, 56, 162 ATAN2 function, 13, 56, 162 C, 1, 33, 52 attribute, 103, 104, 107, 119, 123, 192, 285 C++, 1, 10, 14, 24, 33, 52, 58, 59, 76, 81, 102, name, 19 121 private, 27, 123 call by reference, 286 public, 27 call by value, 286 terminator, 25 CALL statement, 42, 76, 86, 89, 92, 97, 121, attribute terminator, 25 123, 124, 131, 137, 140, 142, 143, attributes, 19, 27 149 automatic array, 89, 156, 157, 285 CASE DEFAULT statement, 63, 188 automatic deallocation, 29 CASE statement, 63, 188, 272 cases, 62 BACKSPACE statement, 75 CEILING function, 56, 162 bad style, 158 central processor unit, 72 base 10 logarithm, 56, 162 CHAR function, 77 base class, 119, 286 character, 81 behavior, 104, 107 case change, 80 binary file, 159 control, 76 binary operator, 286 from number, 80 binary read, 268 functions, 77 binary write, 183 non-print, 76, 102 bit strings, 76 clear, 74 to number, 80 extract, 74 character set, 23 set, 74 CHARACTER type, 23, 26, 53 shift, 74 chemical element, 25 test, 74 chemical element, 128 bit function circuits, 166 BIT SIZE, 74 circular shift, 168 BTEST, 74 circular-linked list, 185 IAND, 74 class, 15, 19, 33, 286 IBCLR, 74 base, 18 IBITS, 74 Date, 118, 121 IBSET, 74 derived, 18 IEOR, 74 Drill, 103 IOR, 74 Employee, 123 ISHFT, 74 Geometric, 118 ­2002 c J.E. Akin 2
  • 15. Global Position, 112 column major order, 177 Great Arc, 112 column matrix, 170 hierarchy, 33 column order, 158 instance, 33 comma, 98 iterator, 192 comment, 1, 2, 7, 9, 12, 51, 52 Manager, 123, 133 commutative, 100, 172, 173 Person, 118, 121 compiler, 10, 15, 90 polymorphic, 131 complex, 10, 81, 161 Position Angle, 107, 112 complex conjugate, 56 Professor, 121 COMPLEX type, 23, 24, 53 sparse vector, 258 component Student, 118, 121 assignment, 82 class attribute, 286 declaring, 82 class code initializing, 82 class Angle, 112 interpretation, 82 class Circle, 34 referencing, 82 class Date, 37 syntax, 82 class Employee 1, 122 component selector, 34, 37, 42 class Employee 2, 123 composition, 34, 36, 190, 194 class Employee 3, 124 concatanate, 122 class Fibonacci Number, 29 conditional, 7–9, 11, 51, 58 class Manager 1, 123 conformable, 172 class Manager 2, 123 CONJG function, 56, 162 class Manager 3, 124 conjugate of complex number, 162 class Object, 143 connectivity, 166 class Person, 37 constant array, 156 constructor, 18, 29, 34, 123, 132, 133, 136, 149, class Position Angle, 270 255, 286 class Professor, 121 default, 18 class Queue, 140 intrinsic, 18, 26, 34, 39 class Rational, 42 manual, 36 class Rectangle, 34 public, 37 class sparse Vector, 258 structure, 26 class Stack, 137 container, 135 class Student, 37 container class, 286 class Vector, 257 CONTAINS statement, 29, 33, 34, 72, 75, 85 Drill, 104 continuation marker, 10 elem type data class, 181 control key, 78 Global Position, 112 conversion factors, 29 Great Arc, 112 convert real to complex, 162 Is A Member Class, 131 convert to integer, 162 Member 1 Class, 131 convert to real, 162 Member 2 Class, 131 COS function, 56, 162, 249 Position Angle, 112 COSH function, 56, 162 class descriptor, 286 cosine, 56, 162 class inheritance, 286 COUNT function, 162, 259, 263 clipping function, 14, 69 count-controlled DO, 12, 13 CLOSE statement, 74, 92, 97, 271 CPU, see central processor unit CMPLX function, 162 curve fit, 90 Coad/Yourdon method, 18 CYCLE statement, 65, 66, 260, 263 code reuse, 194 colon operator, 56, 60, 61, 77, 156, 159, 163, data abstraction, 19 166, 267 data hiding, 36, 286 syntax, 56 data structure, 135 ­2002 c J.E. Akin 3
  • 16. data types, 10 dynamic data structures, 38 intrinsic, 23 dynamic dispatching, 130 user defined, 23 dynamic memory, 74, 181 date, 99, 265 allocation, 15 DATE AND TIME intrinsic, 265 de-allocation, 15 deallocate, 18, 42, 181 management, 15 DEALLOCATE statement, 15, 74, 183 dynamic memory management, 88 deallocation, 287 debugger, 17, 287 e, 25 debugging, 16 EBCDIC character set, 23, 76 declaration statement, 287 efficiency, 194 default case, 63 Eiffel, 18 default constructor, 287 electric drill, 103 default value, 29 ELSE statement, 42, 63, 66 defined operator, 287 encapsulate, 15 dereference, 58 encapsulation, 27, 33, 192, 194, 287 dereferencing, 287 end off shift, 168 derived class, 119 end-of-file, 75 derived type, 15, 23, 287 end-of-record, 75 component, 82 end-of-transmission, 77 EOF, see end-of-file nested, 82 EOR, see end-of-record print, 84 EOT, see end of transmission read, 84 EPSILON function, 162 destructor, 29, 34, 41, 48, 254, 287 equation determinant, 175 number, 169 diagonal matrix, 170 EQV operator, 53 dimension error checking, 18 constant, 157 exception, 74, 287 extent, 155 exception handler, 74 lower bound, 155 exception handling, 18 upper bound, 155 exercises, 21, 31, 48, 99, 118, 132, 154, 178, distributive, 173 195 division, 56 EXIT statement, 65, 66, 251, 260, 262, 263, division remainder, 56 265, 269, 272, 273 DO statement, 29, 58, 61 EXP function, 56, 162, 250 DO WHILE statement, 66 explicit interface, 288 DO-EXIT pair, 67, 68 explicit loop, 11 documentation, 17 exponent range, 24 domain, 19 exponential, 56, 162 dot product, 162 exponentiation, 56 dot product, 12 expression, 10, 51, 52, 88 DOT PRODUCT intrinsic, 12, 162 external double, 24 file, 89 DOUBLE PRECISION type, 23, 24, 53 subprogram, 89 doubly linked list, 149 external file, 288 drop fraction, 56 external procedure, 288 dummy argument, 57, 72, 287 external subprogram, 76 dummy array, 287 dummy dimension, 157 factorization, 174, 175, 179 dummy dimension array, 156 FALSE result, 62 dummy pointer, 287 Fibonacci number, 29 dummy variable, 72 file, 74 dynamic binding, 18, 287 access, 151 ­2002 c J.E. Akin 4
  • 17. binary, 183 dot Vector, 255, 259 column count, 99 Drill , 104, 106 direct access, 150 D L new, 149 I/O, 151 el by el Mult, 259 internal, 80 equality operator point, 188 line count, 99 equal to Object, 143 modify, 151 gcd, 42, 101 random, 151 getEmployee, 123, 124 random access, 150 getName, 123 read status, 99 getNameE, 122, 124 record number, 150 getNameM, 123, 124 scratch, 183 getRate, 122, 124 unit number, 100 GetX, 188 FILE= specifier, 271 GetY, 188 finite difference method, 179 get Arc, 112 finite element, 43 Get Capacity of Q, 140 finite element analysis, 181 get Denominator, 42 flip, 163, 166 get element, 260 float, 53 Get Front of Q, 140 floating point, see real, 23, 24, 179 get item cost, 264 FLOOR function, 56, 162 get item count, 264 flow control, 11, 51, 58 get item delay, 264 forever loop, see infinite loop get item name, 264 FORM= specifier, 271 get Latitude, 112 FORMAT statement, 34, 112 Get Length of Q, 140, 142 function, 7, 9, 51, 68 get Longitude, 112 argument, 13, 15 get menu, 273 extensible, 130 get mr rate, 104 generic, 183 get next io unit, 102, 269 INTEGER, 140 Get Next Unit, 98 LOGICAL, 137, 140 get Numerator, 42 recursive, 42, 101 Get Obj at Ptr, 149 result, 69 get Person, 37 return, 13 get person, 37 TYPE, 137, 140 Get Ptr to Obj, 149 variable, 15 get torque, 104 function code Global Position , 112 Add, 29 Great Arc , 112 add Rational, 42 initialize item, 264 add Real to Vector, 253 inputCount, 92, 265 add Vector, 253 Int deg, 112 Angle , 112 Int deg min, 112 assign, 253 Int deg min sec, 112 circle area, 34 is equal to, 42, 255, 260 clip, 69 is item empty, 264 convert, 42 Is Q Empty, 140 copy Rational, 42 is Q Empty, 142 copy Vector, 254 Is Q Full, 140 Create Q, 140 is Q Full, 142 Date , 37 is Stack Empty, 137 Decimal min, 112 is Stack Full, 137 Decimal sec, 112 is S L empty, 143 Default Angle, 112 largest index, 260 ­2002 c J.E. Akin 5
  • 18. length, 260 values of, 263 lengthnormalize Vector, 255 Vector , 255 less than Object, 143 Vector max value, 255, 263 make Person, 37 Vector min value, 255, 263 make Professor, 121 Vector mult real, 255 make Rational, 42 Vector To Sparse, 263 make Rectangle, 36 zero sparse, 263 make Stack, 137 function definition, 288 make Student, 37 FUNCTION statement, 29 make Vector, 253 Manager , 123, 124 Game of Life, 4 maximum, 70 Gamma, 25 mid value, 69 gather-scatter, 168 mult Fraction, 86 gcd, see greatest common divisor mult Rational, 42 generic function, 33, 34, 183, 288 new Fibonacci Number, 29 generic interface, 132 next generation, 251 generic linked list, 149 norm, 262 generic name, 34 normalize Vecto, 262 generic object, 42 pay, 123 generic operator, 288 payE, 122, 124 generic routine, 121 payM, 123, 124 generic subprogram, 76 Person, 121 geometric shape, 34 Person , 37 global positioning satellite, 106 pop from Stack, 137 global variable, 14, 72 GO TO statement, 64, 65 print, 121 GPS, see global positioning satellite Professor, 121 Graham method, 18 Rational, 42 graphical representation, 27, 118 Rational , 42 greatest common divisor, 42, 101 real mult Sparse, 262 greatest integer, 162 real mult Vector, 255 grid, 190 rectangle area, 34 rows of, 262 Has-A, 107, 194 setDataE, 122, 124 header file, 129 setDataM, 123, 124 heat transfer, 185 set Date, 37 Hello world, 7 set Lat and Long at, 112 hello world, 52, 100 size of, 262 hierarchie size Vector, 255 kind of, 18 Sparse mult real, 262 part of, 18 Student, 37, 121 High Performance Fortran, 195 Student , 37 horizontal tab, 77 subtract Real, 255 host association, 288 subtract Vector, 255 Hubbard, J.R., 36 Sub Sparse Vectors, 263 HUGE function, 162 Sum Sparse Vectors, 263 hyperbolic cosine, 56, 162 S L new, 143 hyperbolic sine, 56, 162 toc, 72 hyperbolic tangent, 56, 102, 162 to Decimal Degrees, 112 to lower, 80 I/O, see Input-Output to Radians, 112 IACHAR function, 77, 80 to upper, 80, 100, 266 ICHAR function, 77 values, 255 identity matrix, 178 ­2002 c J.E. Akin 6
  • 19. IF, 62 Add to Q, 140 nested, 62 assign, 131 if, 12 Create Q, 140 IF ELSE statement, 62 display, 131 IF statement, 29, 37, 42, 62 getName, 124 if-else, 12 Get Capacity of Q, 140 IF-ELSE pair, 63 Get Front of Q, 140 IF-ELSEIF, 130 Get Length of Q, 140 imaginary part, 56, 162 Init, 188, 190 IMPLICIT COMPLEX, 53 Is Q Empty, 140 IMPLICIT DOUBLE PRECISION, 53 Is Q Full, 140 IMPLICIT INTEGER, 52 is Stack Empty, 136 implicit loop, 12 is Stack Full, 136 IMPLICIT NONE, 26, 29 make Stack, 136 IMPLICIT REAL, 52 MyPrint, 188 implied loop, 60, 61, 156, 166 new, 131 INCLUDE line, 37, 42, 89 orthonormal basis, 257 INDEX function, 77, 80, 266, 273 pop from Stack, 136 indexed loop, 11 Position Angle , 270 infinite loop, 9, 68, 269 PrintPay, 123, 124 information hiding, 288 push on Stack, 136 inheritance, 18, 33, 34, 72, 119, 190, 193, 194, Remove from Q, 140 288 Set, 188 rename, 119 swap, 127 selective, 119 testing basis, 257 inherited, 37 interface operator, 188, 258 initialize random number, 162 interface operator ( ), 143 inner loop, 61 interface operator (*), 39 INQUIRE intrinsic, 92, 97, 102, 268, 269 interface operator (==), 143 INTERFACE OPERATOR block, 85, 86 INQUIRE statement, 75 INTERFACE OPERATOR statement, 166 instance, 33, 122, 288 interface prototype, 103, 104, 123 INT function, 162 INTERFACE statement, 34 integer, 10, 81, 161 internal file, 80, 289 integer nearest to real, 162 internal sub-programs, 72 INTEGER type, 23, 24, 53 internal subprogram, 251, 289 intent, 289 interpreter, 10, 15 in, 29, 100 intrinsic, 166 inout, 29 intrinsic constructor, 85, 98, 106, 136, 289 out, 100 intrinsic function, 12, 68 statement, 29 inverse, 178 INTENT attribute, 142 IOLENGTH result, 268 INTENT statement, 29, 58, 69, 93 IOSTAT= variable, 74, 75, 271 interface, 2, 6, 9, 13, 15, 27, 34, 75, 92, 104, Is-A, 106, 107, 124, 194 107, 121, 136, 189, 258, 289 ISO VARIABLE LENGTH STRING, 23 general form, 76 iterator, 143, 149, 191, 192, 289 human, 18 input/output, 18 keyword, 121, 289 prototype, 18 KIND intrinsic, 24 interface assignment, 258 Kind-Of, 107, 123 INTERFACE ASSIGNMENT (=) block, 86 interface block, 34, 76 largest integer, 56 interface body, 76 largest number, 162 interface code latitude, 106 ­2002 c J.E. Akin 7
  • 20. least integer, 162 abort, 66, 67 least squares, 90, 266, 267 breakout, 65 LEN function, 77, 80 counter, 59 LEN intrinsic, 77, 80 cycle, 65, 66 length exit, 59, 65, 66 line, 52 explicit, 58 name, 52 implied, 60 LEN TRIM function, 77 index, 100 LEN TRIM intrinsic, 77 infinite, 60, 67, 68 lexical operator, 94 nested, 61, 65 lexically pseudocode, 58 greater than, 77 skip, 65 less than, 77 until, 66, 67 less than or equal, 77 variable, 60 LGE function, 77 while, 66 LGT function, 77 loop construct, 59 library function, 16 loop control, 60, 158 line continuation, 100 loop index, 100 linear equations, 173, 174, 179, 184 loop variable, 11 linked list, 38, 87, 88, 142, 149, 289 lower triangle, 171, 174 doubly, 149 manual constructor, 85, 104 linked-list, 191 manual page, 17 linker, 16, 89, 289 mask, 161, 164, 165, 179, 259 list masks, 61 circular, 139, 185, 190 Mathematica, 51 doubly-linked, 88 mathematical constants, 25 empty, 149 mathematical functions, 56 length, 139 Matlab, 1, 10, 14, 52, 60, 68, 99, 102 singly-linked, 88 MATMUL intrinsic, 162, 173 LLE function, 77 matrix, 155, 170, 289 LLT function, 77 addition, 172 local name, 119 algebra, 155 LOG function, 56, 162 column, 170 LOG10 function, 56, 162 compatible, 172 logarithm, 68, 91, 162 determinant, 175 logical, 81 diagonal, 170 AND, 63 factorization, 174 equal to, 63 flip, 163 EQV, 63 identity, 174 greater than, 63 inverse, 89, 174 less than, 63 multiplication, 159, 172 NEQV, 63 non-singular, 174 NOT, 63 null, 170 operator, 63 skew symmetric, 171 OR, 63 solve, 89 logical expression, 11 sparse, 192 logical mask, 61 square, 170, 171 LOGICAL type, 23, 42, 137 symmetric, 171 long, 24 Toeplitz, 171 long double, 24 transpose, 159, 171 long int, 24 triangular, 171, 174 longitude, 106 tridiagonal, 179 loop, 5, 7–9, 11, 51, 58, 179 matrix addition, 177, 178 ­2002 c J.E. Akin 8
  • 21. matrix algebra, 155, 172 Conversion Constants, 252 matrix multiplication, 162, 165, 173, 178 doubly linked list, 149 matrix operator, 38 elem type data class, 181 matrix transpose, 162, 165 exceptions, 75, 137 maximum array element location, 162 Fractions, 86 maximum array element value, 162 Gauss Module, 190 maximum values, 70 inventory object, 49, 264 MAXLOC function, 70, 162 inventory system, 270 MAXVAL function, 70, 162, 263 Is A Member Class, 131 mean, 69 Math Constants, 25 member, 119 Member 1 Class, 131 memory count, 183, 274 Member 2 Class, 131 memory leak, 183 Memory Status Count, 183, 274 memory management, 181 object type, 136 message, 27 Physical Constants, 252 message passing, 289 Point Module, 188 method, 192, 289 Queue of Objects, 140 methods, 3 Queue type, 139 private, 27 record Module, 97 public, 27 singly linked lis, 143 military standards, 74 singly linked list, 143 minimum array element location, 162 stack type, 136 minimum array element value, 162 swap library, 127 minimum values, 70 tic toc, 72, 99 MINLOC function, 70, 162 module procedure, 289 MINVAL function, 70, 162 MODULE PROCEDURE statement, 34, 39, 85, 86, 166 MOD function, 56 MODULE statement, 29 modular design, 6 module variable, 29 module, 15, 25, 33, 68, 289 modulo, 56 module code MODULO function, 56 class Angle, 112 modulo function, 56 class Circle, 34 multiple inheritanc, 119 class Date, 37 multiplication, 56 class Employee 1, 122 Myer, B., 18 class Employee 2, 123 class Employee 3, 124 NAG, see National Algorithms Group class Fibonacci Number, 29 named class Global Position, 112 CYCLE, 65, 66 class Great Arc, 112 DO, 59, 66 class Manager 1, 123 EXIT, 65, 66 class Manager 2, 123 IF, 63 class Manager 3, 124 SELECT CASE, 63 class Object, 143 National Algorithms Group, 90 class Person, 37 natural logarithm, 56 class Position Angle, 112, 270 NEQV operator, 53 class Professor, 121 nested, 289 class Queue, 140 DO, 66 class Rational, 42 IF, 62 class Rectangle, 34 new line, 78, 102 class sparse Vector, 258 Newton-Raphson method, 11 class Stack, 137 NINT function, 56, 162 class Student, 37 node class Vector, 253, 256, 257 current, 142, 149 ­2002 c J.E. Akin 9
  • 22. dummy, 149 user defined, 76, 165 header, 139, 142, 149 operator overloading, 10, 189, 260, 290 linked list, 142 operator precedence, 52 next, 149 operator symbol, 165 null, 142 optional argument, 29, 37, 75 previous, 142, 149 OPTIONAL attribute, 29, 36, 104, 137 root, 142 OR operand, 37 tail, 139 OR operator, 53 non-advancing I/O, 42 order vector, 99 normalized sign, 162 ordering array, 95 NOT operator, 53 orthonormal basis, 256, 257 NULL function (f95), 88 outer loop, 61 nullify, 132 overflow, 290 NULLIFY statement, 15, 88, 132 overloaded member, 121 number overloading, 39, 48, 85, 189, 290 bit width, 24 operators, 42 common range, 24 testing, 86 label, 58 significant digits, 24 package, 15 truncating, 162 parallel computer, 43 type, 24 PARAMETER attribute, 25, 29, 37, 60, 69, 70, number of true masks, 162 75, 82, 104, 112 numberic type, 24 Part-Of, 107 numeric types, 23 partial derivative, 176 numerical computation, 38 partial differential equation, 183 partitioned matrix, 171 object, 15, 19, 33 pass by reference, 57, 76, 87, 253 object oriented pass by value, 57, 58, 76, 253 analysis, 18, 43, 103, 107, 118 pass-by-value, 290 approach, 18 path name, 37 design, 18, 43, 103, 107, 118, 190 pi, 25 language, 18 Platypus, 194 programming, 18, 103 pointer, 10, 23, 75, 86, 290 representation, 18 address, 150 Object Pascal, 18 allocatable, 15 ONLY keyword, 119 allocate, 142 OOA, see object oriented analysis arithmetic, 87 OOD, see object oriented design array, 135 OOP, see object oriented programming assignment, 88 OPEN statement, 74, 92, 97, 159, 271 association, 87 operator, 27 deallocate, 142 .dot., 258 declaration, 87 .op., 86, 165 dereference, 58 .solve., 89, 90 detrimental effect, 87 .t., 166 in expression, 88 .x., 166 inquiry, 88 assignment, 39 nullify, 88 binary, 86 nullifying, 88 defined, 18, 86 status, 15, 87 extended, 86 target, 87 overloaded, 18, 143, 149, 189 writting, 150 overloading, 39, 85, 258 pointer array, 290 symbol, 86 pointer assignment, 290 unary, 86 pointer object, 131 ­2002 c J.E. Akin 10
  • 23. pointer variable, 86 Newton, 250 polymorphic class, 131 No Copy Reallocate, 183 polymorphic interface, 118 operate on strings, 78 polymorphism, 18, 33, 34, 119, 124, 194, 290 Person inherit, 37 pop, 137 random access file, 151 portability, 15 Rational test, 42 pre-condition checking, 137 relational operators, 63 pre-processor, 129 Revise employee manager, 273 precedence order, 53 simple loop, 60 precedence rules, 11 string to numbers, 80 precision, 179, 192 structure components, 84 double, 81 Testing a Queue, 142 kind, 24 Testing a Stack, 137 portable, 81 test bubble, 97 single, 81 Test Conversion, 252 specified, 81 Test doubly linked, 149 underscore, 24 test Drill, 106 user defined, 24 test Employee 1, 122 precision kind, 24 test four classes, 121 PRESENT function, 29, 36, 37, 42, 75, 253 test Fractions, 86 PRINT * statement, 29 test Great Arc, 112 private, 33, 104, 187, 290 test inventory system, 272 PRIVATE attribute, 29, 36 test Manager 2, 123 private attributes, 37 test Manager 3, 124, 133 PRIVATE statement, 27 Test Physical, 252 procedural programming, 18 test singly linked, 143 procedure, 68 two line lsq fit, 267 PRODUCT function, 162 watch, 265 product of array elements, 162 program keyword, 56 PROGRAM statement, 26, 29 program projectile, 101 documentation, 17 prototype, 6, 75 executable, 17 pseudo-pointer, 95 scope, 14 pseudo-random numbers, 162 program code pseudocode, 5, 14, 51, 69, 101, 291 Another Great Arc, 270 if, 13 array indexing, 60 if-else, 13 check basis, 257 indexed loop, 9 check vector class, 256 nested if, 13 clip an array, 69 post-test loop, 9 create a type, 26 pre-test loop, 9 create Student, 37 public, 33, 123, 136, 187, 291 Date test, 37 PUBLIC attribute, 29 declare interface, 76 public constructor, 37 Dynamic Dispatching, 131 public method, 27 Fibonacci, 29 PUBLIC statement, 27 game of life, 251 push, 137 geometry, 34 if else logic, 63 quadratic equation, 3 linear fit, 92 query, 191 Logical operators, 63 queue, 88, 135, 139 maximum, 70 Memory Leak, 183 raise to power, 56 Memory Leak Counted, 274 random access, 150 ­2002 c J.E. Akin 11
  • 24. RANDOM NUMBER subroutine, 162 bubble, 92 RANDOM SEED subroutine, 162 characters, 94 rank, 157, 291 object, 96 rational number, 38, 39 objects, 94 read error, 102 strings, 94 READ statement, 29, 61, 75 sorting, 42 real, 10, 81, 161 sparse matrix, 192 REAL function, 162 sparse storage, 263 REAL type, 23, 24, 53 sparse vector, 49, 149, 258 real whole number, 162 sparse vector class, 179 reallocate, 183, 195 specification, 4, 190 recursive algorithm, 87 SQRT function, 27, 56, 112, 162 RECURSIVE qualifier, 42, 101 square root, 27, 56, 68, 162 reference, 10 stack, 88, 135, 139, 291 referencing components, 82 STAT = variable, 74 relational operator, 52, 53, 63, 77, 142, 143, 149 statement, 2, 9 remainder, 56 statement block, 12, 58 rename, 119 statements, 1 rename modifier, 119 status REPEAT function, 77 FILE, 75 reshape, 158 IOSTAT=, 75 reshape an array, 162 MODE, 75 RESHAPE intrinsic, 162 OPENED=, 75 RESULT option, 29 status checking, 157 result value, 69 STATUS= specifier, 271 return, 157 stiffness matrix, 191, 192 RETURN statement, 65 STOP statement, 37, 70, 151, 181, 188 REWIND statement, 75, 183, 265, 266, 268 storage round number, 56 column wise, 155 sample data, 98 row wise, 155 SCAN function, 77 string, 23, 56, 150 scatter, 169 adjust, 77 scope, 14, 291 case change, 80 SELECT CASE statement, 63, 188, 272 character number, 77 SELECTED INT KIND, 23, 24 collating sets, 77 SELECTED REAL KIND, 23, 24 colon operator, 77 selector symbol, 26, 29, 34 concatenate, 77 server, 18 copy, 77 SHAPE function, 162 dynamic length, 76 short, 24 from number, 80 side effect, 142, 291 functions, 77 SIGN function, 162 length, 77 signum, 162 logic, 77 SIN function, 56, 162, 249 repeat, 77 sine, 56, 162 scan, 77 SINH function, 56, 162 to number, 80 size, 12 trim, 77 SIZE intrinsic, 69, 89, 92, 155, 162 verify, 77 smallest integer, 56 strings, 76 smallest number, 162 strong typing, 53, 291 smallest positive number, 162 struct, 53 Smalltalk, 18 structure, 23, 25, 33, 84 sort, 86, 90, 92, 95, 125 structure constructor, 26 ­2002 c J.E. Akin 12
  • 25. structured programming, 13 mult Fraction, 86 submatrix, 171 MyPrint Point, 188 subprogram, 68 new, 131 recursive, 101 new member 1, 131 subroutine, 68, 69 new member 2, 131 subroutine code No Change, 76 Add to Q, 140, 142 nullify Is A Member, 131 allocate type application, 181 orthonormal basis, 257 Alloc Count Int, 183 out, 104, 106 assign, 86, 131 pretty, 262 assign memb 1, 131 Print, 29 assign memb 2, 131 print, 121 Change, 76 PrintPay, 123, 124 deallocate type application, 181 PrintPayEmployee, 123, 124 Dealloc Count Int, 183 PrintPayManager, 123, 124 delete Rational, 42 print Date, 37 delete Sparse Vector, 258 print DOB, 37 delete Vector, 255 print DOD, 37 destroy D L List, 149 print DOM, 37 detroy D L List, 149 print D L list, 149 display all, 271 print GPA, 37 display members, 131 print item, 264 display memb 1, 131 print Name, 37 display memb 2, 131 print Nationality, 37 D L insert before, 149 print Sex, 37 enter entry, 272 print S L list, 143 enter item, 264 push on Stack, 137 enter update, 272 readData, 92, 100, 266 equal Fraction, 86 read Date, 37 equal Integer, 42 Read Position Angle, 112 equal Real, 255 read Vector, 255, 262 equal Vector, 260 read xy file, 268 exception, 137, 140 reduce, 42 exception status, 75, 142 Remove from Q, 142 file read, 264 Resize Count Int OneD, 183 file write, 264 restore system, 271 in, 104, 106 save system, 271 increase Size, 271 setData, 123 initialize, 272 setSalaried, 123, 124 Init Point, 188 set DOB, 37 Init Point Another, 188 set DOD, 37 Init Point Vctr, 188 set DOM, 37 Integer Sort, 95, 97, 98 set element, 262 invert, 42 set Latitude, 112 list, 42, 86, 255 set Longitude, 112 List Angle, 112 Set Point, 188 List Great Arc, 112 set Size, 271 List Position, 112 Set Vec, 188 List Position Angle, 112 Set X, 188 List Pt to Pt, 112 Set XY, 188 list type alloc status, 181 show, 262 lsq fit, 92 show Data, 97 make Sparse Vector, 258 show r v, 262 ­2002 c J.E. Akin 13
  • 26. simple arithmetic, 56 triplet, see colon operator Sort Reals, 93 true, 12 Sort String, 94 TRUE result, 62 Spy, 251 truncate to real whole number, 162 String Sort, 97, 98 truss, 166 swap objects, 126 type swap real, 127 conversion, 80 swap type, 128 default, 52 S L delete, 143 implicit, 52 S L insert, 143 TYPE declaration, 26, 29 testing basis, 257 TYPE statement, 27, 34 test Manager 1, 123 test matrix, 89 unary operator, 292 tic, 72 underflow, 292 SUBROUTINE statement, 29 unexpected result, 165 subroutines, 33 upper triangle, 171, 174 subscript, 26, 59, 155 USE association, 119, 123, 190 bounds, 155 USE statement, 29, 33, 34, 37, 85, 89 range, 177 USE, ONLY, 119 vector, 166 user defined operator, 165 subscript triplet, 291 user interface, 2 subtraction, 56 subtype, 131 validation, 29 subtyping, 124, 130 variable, 8, 10, 23, 51 sum, 12 global, 14 SUM function, 12, 69, 162 name, 10 SUM intrinsic, 92, 165 type, 10 sum of array elements, 162 variable rank array, 156 super class, 119 vector, 155, 292 syntactic error, 17 vector class, 48, 179, 252, 256 SYSTEM CLOCK intrinsic, 72 vector subscript, 61, 166, 292 VERIFY function, 77 tab, 78, 98, 102 volume, 48 TAN function, 56, 162 tangent, 56, 162 weakness, 193 TANH function, 56, 162 WHERE construct, 165 TARGET, 15 WHERE statement, 61, 66, 165 target, 23, 75, 87, 88, 292 while-true, 67 template, 43, 124, 126, 292 wildcard, 126 tensor, 155 WRITE statement, 34, 61, 75 testing, 15 time, 265 time of day, 99 TINY function, 162 Toeplitz matrix, 171 top-down, 4 total of elements in array, 162 transformational functions, 165 transpose, 159, 171, 173 TRANSPOSE intrinsic, 162, 166 tree, 292 tree structure, 38, 87, 88 tridiagonal matrix, 179 TRIM function, 77 ­2002 c J.E. Akin 14
  • 27. Chapter 1 Program Design 1.1 Introduction The programming process is similar in approach and creativity to writing a paper. In composition, you are writing to express ideas; in programming you are expressing a computation. Both the programmer and the writer must adhere to the syntactic rules (grammar) of a particular language. In prose, the funda- mental idea-expressing unit is the sentence; in programming, two units statements and comments are available. Standing back, composition from technical prose to fiction should be organized broadly, usually through an outline. The outline should be expanded as the detail is elaborated, and the whole re-examined and re-organized when structural or creative flaws arise. Once the outline settles, you begin the actual composition process, using sentences to weave the fabric your outline expresses. Clarity in writing occurs when your sentences, both internally and globally, communicate the outline succinctly and clearly. We stress this approach here, with the aim of developing a programming style that produces efficient programs that humans can easily understand. To a great degree, no matter which language you choose for your composition, the idea can be ex- pressed with the same degree of clarity. Some subtleties can be better expressed in one language than another, but the fundamental reason for choosing your language is your audience: People do not know many languages, and if you want to address the American population, you had better choose English over Swahili. Similar situations happen in programming languages, but they are not nearly so complex or diverse. The number of languages is far fewer, and their differences minor. Fortran is the oldest lan- guage among those in use today. C and C++ differ from it somewhat, but there are more similarities than not. M ATLAB’s language, written in C and Fortran, was created much later than these two, and its structure is so similar to the others that it can be easily mastered. The C++ language is an extension of the C language that places its emphasis on object oriented programming (OOP) methods. Fortran added object oriented capabilities with its F90 standard, and additional enhancements for parallel machines were issued with F95. The Fortran 2000 standard is planned to contain more user-friendly constructs for polymorphism and will, thus, enhance its object-oriented capabilities. This creation of a new language and its similarity to more established ones are this book’s main points: More computer programming lan- guages will be created during your career, but these new languages will probably not be much different than ones you already know. Why should new languages evolve? In MATLAB’s case, it was the desire to express matrix-like expressions easily that motivated its creation. The difference between M ATLAB and Fortran 90 is infinitesimally small compare to the gap between English and Swahili. An important difference between programming and composition is that in programming you are writ- ing for two audiences: people and computers. As for the computer audience, what you write is “read” by interpreters and compilers specific to the language you used. They are very rigid about syntactic rules, and perform exactly the calculations you say. It is like a document you write being read by the most de- tailed, picky person you know; every pronoun is questioned, and if the antecedent is not perfectly clear, then they throw up their hands, rigidly declaring that the entire document cannot be understood. Your picky friend might interpret the sentence “Pick you up at eight” to mean that you will literally lift him or her off the ground at precisely 8 o’clock, and then demand to know whether the time is in the morning or ­2001 c J.E. Akin 1
  • 28. afternoon and what the date is. Humans demand even more from programs. This audience consists of two main groups, whose goals can conflict. The larger of the two groups consists of users. Users care about how the program presents itself, its user interface, and how quickly the program runs, how efficient it is. To satisfy this audience, programmers may use statements that are overly terse because they know how to make the program more readable by the computer’s compiler, enabling the compiler to produce faster, but less human-intelligible program. This approach causes the other portion of the audience programmers to boo and hiss. The smaller audience, of which you are also a member, must be able to read the program so that they can enhance and/or change it. A characteristic of programs, which further distinguishes it from prose, is that you and others will seek to modify your program in the future. For example, in the 1960s when the first version of Fortran was created, useful programs by today’s standards (such as matrix inversion) were written. Back then, the user interface possibilities were quite limited, and the use of visual displays was limited. Thirty years later, you would (conceivably) want to take an old program, and provide a modern user interface. If the program is structurally sound (a good outline and organized well) and is well-written, re-using the “good” portions is easy accomplished. The three-audience situation has prompted most languages to support both computer-oriented and human-oriented “prose”. The program’s meaning is conveyed by statements, and is what the computer interprets. Humans read this part, which in virtually all languages bears a strong relationship to mathe- matical equations, and also read comments. Comments are not read by the computer at all, but are there to help explain what might be expressed in a complicated way by programming language syntax. The document or program you write today should be understandable tomorrow, not only by you, but also by others. Sentences and paragraphs should make sense after a day or so of gestation. Paragraphs and larger conceptual units should not make assumptions or leaps that confuse the reader. Otherwise, the document you write for yourself or others served no purpose. The same is true with programming; the program’s organization should be easy to follow and the way you write the program, using both statements and com- ments, should help you and others understand how the computation proceeds. The existence of comments permits the writer to directly express the program’s outline in the program to help the reader comprehend the computation. These similarities highlight the parallels between composition and programming. Differences become evident because programming is, in many ways, more demanding than prose writing. On one hand, the components and structure of programming languages are far simpler than the grammar and syntax of any verbal or written language. When reading a document, you can figure out the misspelled words, and not be bothered about every little imprecision in interpreting what is written. On the other, simple errors, akin to misspelled words or unclear antecedents, can completely obviate a program, rendering it senseless or causing it to go wildly wrong during execution. For example, there is no real dictionary when it comes to programming. You can define variable names containing virtually any combination of letters (upper and lower case), underscores, and numbers. A typographical error in a variable’s name can therefore lead to unpredictable program behavior. Furthermore, computer execution speeds are becoming faster and faster, meaning that increasingly complex programs can run very quickly. For example, the program (actually groups of programs) that run NASA’s space shuttle might be comparable in size to Hugo’s Les Mis´ rables, but its complexity and immediate importance to the “user” far exceeds that of the novel. e As a consequence, program design must be extremely structured, having the ultimate intentions of performing a specific calculation efficiently with attractive, understandable, efficient programs. Achiev- ing these general goals means breaking the program into components, writing and testing them separately, then merging them according to the outline. Toward this end, we stress modular programming. Modules can be on the scale of chapters or paragraphs, and share many of the same features. They consist of a se- quence of statements that by themselves express a meaningful computation. They can be merged to form larger programs by specifying what they do and how they interface to other packages of software. The analogy in prose is agreeing on the character’s names and what events are to happen in each paragraph so that events happen to the right people in the right sequence once the whole is formed. Modules can be re-used in two ways. As with our program from the 1960s, we would “lift” the matrix inversion routine and put a different user interface around it. We can also re-use a routine within a program several times. For example, solving the equations of space flight involves the inversion of many matrices. We would ­2001 c J.E. Akin 2