Errata File "OOP via F90"This is only the beginning of an errata for the text based on commentsfrom readers. As of June 20...
Line 156 should read as follows:  point_to_Obj_3   => Get_Ptr_to_Obj (container, Obj_3)      ! There is also anerror on th...
Test_Geometry.f90        3.3,3.4      40class_Date.f90           3.6          42Test_Date.f90            3.7          43cl...
6.12          146                         6.13          147                         6.14          148                     ...
Wayne BRellsSchenectady, NY------------------------------- 5 ---------------------------------Date: Mon, 21 Jun 2004 05:16...
Object Oriented Programmingvia Fortran 90/95Ed AkinRice UniversityMechanical Engineering and Materials Science DepartmentH...
ii
ContentsPreface                                                                                                           ...
4.4.1. Functions and Subroutines . . . . . . .                       .   .   .   .   .   .   .   .   .   .   .   .   .   ....
8.1.7. Component Gather and Scatter        .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .  ...
PrefaceThere has been an explosion of interest in, and books on object-oriented programming (OOP). Why haveyet another boo...
the first chapter. The Fortran 90/95 syntax is used there, but in several cases cross-references are made tosimilar constru...
Index , 53, 56                                 allocate, 42   =, 53                                  ALLOCATE statement, 1...
size, 155                                     ISHFTC, 74      total, 162                                    MVBITS, 74    ...
Global Position, 112                        column major order, 177     Great Arc, 112                              column...
data types, 10                         dynamic data structures, 38      intrinsic, 23                    dynamic dispatchi...
binary, 183                       dot Vector, 255, 259     column count, 99                  Drill , 104, 106     direct a...
length, 260                        values of, 263  lengthnormalize Vector, 255        Vector , 255  less than Object, 143 ...
IF, 62                                                   Add to Q, 140      nested, 62                                    ...
least integer, 162                            abort, 66, 67least squares, 90, 266, 267                   breakout, 65LEN f...
matrix algebra, 155, 172                         Conversion Constants, 252matrix multiplication, 162, 165, 173, 178       ...
dummy, 149                                user defined, 76, 165     header, 139, 142, 149                operator overloadi...
pointer variable, 86                                Newton, 250polymorphic class, 131                              No Copy...
RANDOM NUMBER subroutine, 162                              bubble, 92RANDOM SEED subroutine, 162                          ...
structured programming, 13              mult Fraction, 86submatrix, 171                          MyPrint Point, 188subprog...
simple arithmetic, 56        triplet, see colon operator     Sort Reals, 93               true, 12     Sort String, 94    ...
Chapter 1Program Design1.1 IntroductionThe programming process is similar in approach and creativity to writing a paper. I...
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Errata file oop_via_f90
Upcoming SlideShare
Loading in …5
×

Errata file oop_via_f90

2,418 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,418
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Errata file oop_via_f90

  1. 1. Errata File "OOP via F90"This is only the beginning of an errata for the text based on commentsfrom readers. As of June 2004 I have not yet verified the suggestederrors. I hope to review them when I start the summer break in July2004. Please feel free to send your comments. Prof. AkinThe Errata will cite pages in the published book, which will differfrom the PDF drafts here, especially for Chapter 9.------------------------------- 1 --------------------------------------One reviewer suggests that the source code line numbers should bemoved from the left margin to the right margin. This will be done inany future release.------------------------------- 2 --------------------------------------Date: Fri, 4 Jul 2003 19:40:51 +0100From: Alistair MillsTo: akin@rice.eduSubject: Object oriented Fortran 90Professor AkinI have just come across your very interesting book. I think that this is abook which has been waiting to be written! It is very interesting. I hopethat you will not be offended by what I have to say. It is intended to beconstructive. Your book is a very readable account of the subject, and ismuch more comprehensible than other things which I have read on the samematter! I do not know how you can find time to be a professor at a majorschool of engineering, do research, and write such things also!I have also found your web site, and I have found that you have indexes tothe figures and the files. This is very helpful, as it was taking me timeto work out which source code files correspond to the text. I found thatthe page numbers are not correct, but the figure numbers are approximatelycorrect. For example, I have changed the page numbers for chapter 7, and acouple of the figure numbers. I will send you a complete updated index, ifyou 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 161class_Queue.f90 7.5 163queue_check.f90 7.6 165singly_linked_list.f90 7.10 169Test_SLL_Integers.f90 7.11 171Integer_Objects.f90 7.12 172doubly_linked_list.f90 7.14 173Test_DLL_Integers.f90 7.15 175random_access.f90 7.16 176interface_Queue Section_7.3exceptions.f90 noneobject_type.f90 noneI have also observed a couple of coding errors. There is quite a seriousone in chapter 7.Test_DLL_Integers.f90 7.15 175
  2. 2. Line 156 should read as follows: point_to_Obj_3 => Get_Ptr_to_Obj (container, Obj_3) ! There is also anerror 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. Theerror is a common one. The assignment statement on the original attempts tocopy the contents of the object at the end of the pointer to the contents ofthe object at the end of point_to_Obj_3. As there is nothing yet on the endof 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 "callby value". Fortran only does call by address. If you change line 19 toeliminate the additional parentheses, then the results are different. Theparentheses force the creation of a temporary location containing a copy ofInput_val. The value in the temporary location is changed, but this is notcopied back to the source ie Input_Val. So the effect is the same, althoughthe reasons are different. ! pass by value call No_Change ( Input_Val ) ! Use but do not change print *, "After No_Change it is ", Input_ValIf you find what I have to say constructive, then I may have more when Ihave completed reading the book!With best wishesAlistair Mills------------------------------- 3 te: Tue, 8 Jul 2003 20:10:48 +0100From: Alistair MillsTo: Ed Akin 221 Cox x4879 <akin@mems.rice.edu>Subject: RE: Object oriented Fortran 90Prof AkinThanks for pointing out the link, and thank you for including my comments.Here is my version of the source code index.AlistairSource Figure Pagehello.c 1.3 09hello.cpp 1.3 09hello.f90 1.3 09hello.m 1.3 09Math_Constants.f90 2.1 29Fibonacci.f90 2.6 34create_a_type.f90 Section_2.2 29use_a_type.f90 Section_2.2 30Geometric_Classes.f90 3.3,3.4 39
  3. 3. Test_Geometry.f90 3.3,3.4 40class_Date.f90 3.6 42Test_Date.f90 3.7 43class_Person.f90 3.9 44Test_Date_Person.f90 3.10 45class_Student.f90 3.12 46Test_Student.f90 3.13 47class_Rational.f90 3.15 49Test_Rational.f90 3.16 52generic_geometry.f90 nonegeneric_geometry_2.f90 nonearithmetic.f90 4.1 61do_for.f90 4.2 65array_index.f90 4.3 65more_or_less.f90 4.4 70if_else.f90 4.5 70and_or_not.f90 4.6 71clip.f90 4.7 79maximum.f90 4.8 80cpu_time.f90 4.10 82exceptions.f90 4.11 83passing_types.f90 4.12 86string_use.f90 4.13 89string_or_integer.f90 4.14 90upper_lower.f90 4.15,4.16 91struct_access.f90 4.17 96fractions.f90 4.18 97test_overload.f90 4.19 98pt_expression.f90 4.20 101linear_fit.f90 4.21 106sort_reals.f90 4.23 109sort_string.f90 4.24 110integer_sort.f90 4.25 111test_bubble.f90 4.27 113cases.f90 nonevector_norm.f90 nonearray_pointer.f90 noneinterp_vs_compil.f90 noneinterface 5.2 122class_Drill.f90 5.3 123test_Drill.f90 5.4 124class_Angle.f90 5.6 126class_Position_Angle.f90 5.8 130class_Global_Position.f90 5.10 132class_Great_Arc.f90 5.12 139GPS_library.f90 5.13 135non_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. 4. 6.12 146 6.13 147 6.14 148 6.15 149 6.16 150Test_Is_A_Member.f90 6.17 153member_1_class.f90 6.18 153member_2_class.f90 6.19 154is_a_member_class.f90 6.20 155class_Stack.f90 7.1 160stack_check.f90 7.3 161class_Queue.f90 7.5 163queue_check.f90 7.6 165singly_linked_list.f90 7.10 169Test_SLL_Integers.f90 7.11 171Integer_Objects.f90 7.12 172doubly_linked_list.f90 7.14 173Test_DLL_Integers.f90 7.15 175random_access.f90 7.16 176interface_Queue Section_7.3exceptions.f90 noneobject_type.f90 nonetrans_opt.f90 8.1 191Matrix_Operators.f90 nonearray_demo.f90 nonedisplay_real.f90 noneelem_type_data_class.f90 9.1 210memory_leak.f90 9.2 212No_Copy_Reallocate.f90 9.4 214 9.6 219System_Constants.f90 none------------------------------- 4 ---------------------------------Date: Sun, 20 Jun 2004 03:56:44 -0700 (PDT)From: Wayne BRellsTo: akin@rice.eduSubject: 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 haveonly read up to section 2.4, but have discovered a few errors in the text andin the sample programs. Specifically, line [19] of the Fibonacci example(Figure 2.6 ) references num%exists, which does not exist in the definitionof the Fibonacci_Number type. This new logical variable is also mentionedin the text, but not seem to be USED in the code.Would you, perhaps, have an Errata listing for your book? (Such a listing ofcorrections 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 withthe 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. 5. Wayne BRellsSchenectady, NY------------------------------- 5 ---------------------------------Date: Mon, 21 Jun 2004 05:16:37 -0700 (PDT)From: Wayne BRellsTo: 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 specificproblem. On the other hand, the code on the CD was correct in that it did NOTinclude 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 andto explicitly declare all variables, access privileges, etc. This seemsparticularly desirable from a pedagogical point of view.My "conversion" of the Fibonaccci example to F did suggest a few places wherethe 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 ifthere is an implicit none statement there must be no other implicit statementin the scoping unit." In other words, the implicit none statement at themodule level is inherited by the contained functions via host association. (Isuspect that many F90 compilers just treat the extra implicit none statementsas redundant and ignore them...)2) In F, all contained functions must be explicitly given the public orprivate access attribute. Therefore, I had to add new_Fibonacci_Number tothe list of public module functions.3) In F, the intent of all dummy arguments must be specified. Therefore, Ihad to add "intent(in)" to the list of attributes for the max argument inthe new_Fibonacci_Number function.These were the major modifications that I found necessary. The minor changesincluded:1) Putting only one statement per line2) Changing to ".3) Putting output formats directly in the write statementsBest wishes,Wayne------------------------------- 6 ---------------------------------
  6. 6. Object Oriented Programmingvia Fortran 90/95Ed AkinRice UniversityMechanical Engineering and Materials Science DepartmentHouston, TexasMay 29, 2001 ­ Draft # 4.2, Copyright c 2001, All rights reserved.
  7. 7. ii
  8. 8. ContentsPreface vii1 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484 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. Akinc iii
  9. 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 995 Object Oriented Methods 103 5.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 5.2. The Drill Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 5.3. Global Positioning Satellite Distances . . . . . . . . . . . . . . . . . . . . . . . . . . 106 5.4. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1186 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1337 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1538 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. Akinc iv
  10. 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1789 Advanced Topics 181 9.1. Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 9.2. Subtyping Objects (Dynamic Dispatching) . . . . . . . . . . . . . . . . . . . . . . . . 183 9.3. Non-standard Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184A Bibliography 187B 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29C 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 . . . . . . . . . . . . . . . . 67D Companion C++ Examples 69 D.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69E Glossary of Object Oriented Terms 77F Subject Index 0G Program Index 1­2001 J.E. Akinc v
  11. 11. PrefaceThere has been an explosion of interest in, and books on object-oriented programming (OOP). Why haveyet 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 thatsatisfy the four r’s: readability, reusability, reliability, and really-efficient. While some object-orientedprogramming languages have some of these abilities Fortran 90/95 offers all of them for engineeringapplications. Thus this book is intended to take a different tack by using the Fortran 90/95 language as itsmain OOP tool. With more than one hundred pure and hybrid object-oriented languages available, onemust be selective in deciding which ones merit the effort of learning to utilize them. There are millionsof Fortran programmers, so it is logical to present the hybrid object-oriented features of Fortran 90/95 tothem to update and expand their programming skills. This work provides an introduction to Fortran 90as well as to object-oriented programming concepts. Even with the current release (Fortran 95) we willdemonstrate that Fortran offers essentially all of the tools recommended for object-oriented programmingtechniques. It is expected that Fortran 200X will offer additional object-oriented capabilities, such asdeclaring ”extensible” (or virtual) functions. Thus, it is expected that the tools learned here will be ofvalue far into the future. It is commonly agreed that the two decades old F77 standard for the language was missing severaluseful 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 includeda large number of improvements that have often been overlooked by many programmers. It is fullycompatible 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 supportsthose now obsolete language constructs. The F90 standards committee brought into the language most ofthe best features of other more recent languages like Ada, C, C++, Eiffel, etc. Those additions included inpart: structures, dynamic memory management, recursion, pointers (references), and abstract data typesalong with their supporting tools of encapsulation, inheritance, and the overloading of operators androutines. Equally important for those involved in numerical analysis the F90 standard added several newfeatures 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 arrayfeatures were intended for use on vector or parallel computers and allow programmers to avoid the badhabit of writing numerous serial loops. The current standard, F95, went on to add more specific parallelarray tools, provided “pure” routines for general parallel operations, simplified the use of pointers, andmade a few user friendly refinements of some F90 features. Indeed, at this time one can view F90/95 asthe only cross-platform international standard language for parallel computing. Thus Fortran continuesto be an important programming language that richly rewards the effort of learning to take advantage ofits 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 ofthe newer “object” approach to programming. An experienced programmer may want to skip directly tothe last section of Chapter 1 where we outline some object-oriented methods. In Chapter 2, we introducethe concept of the abstract data types and their extension to classes. Chapter 3 provides a fairly detailedintroduction to the concepts and terminology of object-oriented programming. A much larger supportingglossary is provided as an appendix. For the sake of completeness Chapter 4 introduces language specific details of the topics discussed in­2002c J.E. Akin i
  12. 12. the first chapter. The Fortran 90/95 syntax is used there, but in several cases cross-references are made tosimilar constructs in the C++ language and the M ATLAB environment. While some readers may want toskip Chapter 4, it will help others learn the Fortran 90/95 syntax and/or to read related publications thatuse 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 toprovide 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 muchfaster in Fortran 90 than in C++. Since Fortran 90 was designed for operations on vector and parallelmachines that chapter encourages the programmer to avoid unneeded serial loops and to replace themwith more efficient intrinsic array functions. Readers not needing to use numerical matrix analysis mayskip Chapter 5. Chapter 6 returns to object-oriented methods with a more detailed coverage of using object-orientedanalysis and object-oriented design to create classes and demonstrates how to implement them as an OOPin Fortran 90. Additional Fortran 90 examples of inheritance and polymorphism are given in Chapter7. Object-oriented programs often require the objects to be stored in some type of “container” or datastructure such as a stack or linked-list. Fortran 90 object-oriented examples of typical containers aregiven in Chapter 8. Some specialized topics for more advanced users are given in Chapter 9, so beginningprogrammers 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 forthe first time should cover Chapters 1, 2, 3, and. Anyone needing to use numerical matrix analysis shouldalso 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 basedlist 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 commentson those solutions. The final appendix gives the C++ versions of several of the F90 examples in thetext. They are provided as an aid to understanding other OOP literature. Since F90 and M ATLAB are sosimilar the corresponding M ATLAB versions often directly follow the F90 examples in the text. Ed Akin, Rice University, 2002AcknowledgementsWe 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 programmingnotes developed jointly with Prof. Don Johnson at Rice University. I would like to thank Prof. TinsleyOden and the Texas Institute for Computational Mathematics for generously hosting my sabbatical leavewhere most of this work was developed, and Rice University for financing the sabbatical. Special thanksgo to my wife, Kimberly, without whose support and infinite patience this book would not have beencompleted.Source CodesAll 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. Additionalfiles are provided to relate the ISO standard short filenames to the full length program names used in thebook. Of course, the source files will have to be processed through a Fortran 90 or 95 or 2000 compilerto form executables. All of the figures are also provided as encapsulated Postscript (tm) files.­2002c J.E. Akin ii
  13. 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, 34ABS function, 56, 162, 250 argument, 285absolute value, 56, 162 inout, 69abstract class, 285 input, 69abstract data type, 15, 23, 27, 285 interface, 75abstraction, 19, 27, 285 none, 69access, 36access operation, 142 number of, 75access restriction, 19 optional, 75, 76accessibility, 19 order, 75accessor, 18, 285 output, 69ACHAR function, 77, 80 rank, 75ACOS function, 56, 162 returned value, 75actual argument, 56 type, 75Ada, 15, 33 array, 26, 60, 66, 82, 135, 149, 285addition, 56 allocatable, 156ADJUSTL function, 77 assumed shape, 76ADJUSTR function, 77 automatic, 89, 156ADT, see abstract data type Boolean, 164ADVANCE specifier, 42, 102 constant, 156agent, 18 dummy dimension, 156AIMAG function, 56, 162 flip, 166AINT function, 56, 162 mask, 164, 179algorithm, 51 of pointers, 135ALL function, 162, 255 rank, 76, 155, 157, 166all mask elements true, 162 rectangular, 166allocatable array, 156, 157, 285 reshape, 155ALLOCATABLE attribute, 183 shape, 155ALLOCATABLE statement, 15 shift, 168 1
  14. 14. size, 155 ISHFTC, 74 total, 162 MVBITS, 74 unknown size, 76 NOT, 74 variable rank, 156 TRANSFER, 74array operations, 159 bit manipulation, 74array pointer, 285 blanksarray shape vector, 162 all, 77ASCII character set, 23, 76, 77, 98, 159 leading, 77ASIN function, 56, 162 trailing, 77assembly language, 15 Boolean type, 53assignment operator, 10, 39, 189, 285 Boolean value, 23assignment statement, 285 bottom-up, 4ASSOCIATED function, 15, 75, 88, 130, 132, boundary condition, 192 181 bounds, 155association, 285 bubble sort, 92, 94associative, 172, 173 ordered, 95asterisk (*), 58 bug, 9ATAN function, 56, 162ATAN2 function, 13, 56, 162 C, 1, 33, 52attribute, 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 149automatic array, 89, 156, 157, 285 CASE DEFAULT statement, 63, 188automatic deallocation, 29 CASE statement, 63, 188, 272 cases, 62BACKSPACE statement, 75 CEILING function, 56, 162bad style, 158 central processor unit, 72base 10 logarithm, 56, 162 CHAR function, 77base class, 119, 286 character, 81behavior, 104, 107 case change, 80binary file, 159 control, 76binary operator, 286 from number, 80binary read, 268 functions, 77binary write, 183 non-print, 76, 102bit 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, 128bit 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­2002c J.E. Akin 2
  15. 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, 82class attribute, 286 declaring, 82class 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, 162class descriptor, 286 cosine, 56, 162class inheritance, 286 COUNT function, 162, 259, 263clipping function, 14, 69 count-controlled DO, 12, 13CLOSE statement, 74, 92, 97, 271 CPU, see central processor unitCMPLX function, 162 curve fit, 90Coad/Yourdon method, 18 CYCLE statement, 65, 66, 260, 263code reuse, 194colon operator, 56, 60, 61, 77, 156, 159, 163, data abstraction, 19 166, 267 data hiding, 36, 286 syntax, 56 data structure, 135­2002c J.E. Akin 3
  16. 16. data types, 10 dynamic data structures, 38 intrinsic, 23 dynamic dispatching, 130 user defined, 23 dynamic memory, 74, 181date, 99, 265 allocation, 15DATE AND TIME intrinsic, 265 de-allocation, 15deallocate, 18, 42, 181 management, 15DEALLOCATE statement, 15, 74, 183 dynamic memory management, 88deallocation, 287debugger, 17, 287 e, 25debugging, 16 EBCDIC character set, 23, 76declaration statement, 287 efficiency, 194default case, 63 Eiffel, 18default constructor, 287 electric drill, 103default value, 29 ELSE statement, 42, 63, 66defined operator, 287 encapsulate, 15dereference, 58 encapsulation, 27, 33, 192, 194, 287dereferencing, 287 end off shift, 168derived class, 119 end-of-file, 75derived 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, 162destructor, 29, 34, 41, 48, 254, 287 equationdeterminant, 175 number, 169diagonal matrix, 170 EQV operator, 53dimension 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 195division, 56 EXIT statement, 65, 66, 251, 260, 262, 263,division remainder, 56 265, 269, 272, 273DO statement, 29, 58, 61 EXP function, 56, 162, 250DO WHILE statement, 66 explicit interface, 288DO-EXIT pair, 67, 68 explicit loop, 11documentation, 17 exponent range, 24domain, 19 exponential, 56, 162dot product, 162 exponentiation, 56dot product, 12 expression, 10, 51, 52, 88DOT PRODUCT intrinsic, 12, 162 externaldouble, 24 file, 89DOUBLE PRECISION type, 23, 24, 53 subprogram, 89doubly linked list, 149 external file, 288drop fraction, 56 external procedure, 288dummy argument, 57, 72, 287 external subprogram, 76dummy array, 287dummy dimension, 157 factorization, 174, 175, 179dummy dimension array, 156 FALSE result, 62dummy pointer, 287 Fibonacci number, 29dummy variable, 72 file, 74dynamic binding, 18, 287 access, 151­2002c J.E. Akin 4
  17. 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, 188FILE= specifier, 271 GetY, 188finite difference method, 179 get Arc, 112finite element, 43 Get Capacity of Q, 140finite element analysis, 181 get Denominator, 42flip, 163, 166 get element, 260float, 53 Get Front of Q, 140floating point, see real, 23, 24, 179 get item cost, 264FLOOR function, 56, 162 get item count, 264flow control, 11, 51, 58 get item delay, 264forever loop, see infinite loop get item name, 264FORM= specifier, 271 get Latitude, 112FORMAT statement, 34, 112 Get Length of Q, 140, 142function, 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, 104function 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­2002c J.E. Akin 5
  18. 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­2002c J.E. Akin 6
  19. 19. IF, 62 Add to Q, 140 nested, 62 assign, 131if, 12 Create Q, 140IF ELSE statement, 62 display, 131IF statement, 29, 37, 42, 62 getName, 124if-else, 12 Get Capacity of Q, 140IF-ELSE pair, 63 Get Front of Q, 140IF-ELSEIF, 130 Get Length of Q, 140imaginary part, 56, 162 Init, 188, 190IMPLICIT COMPLEX, 53 Is Q Empty, 140IMPLICIT DOUBLE PRECISION, 53 Is Q Full, 140IMPLICIT INTEGER, 52 is Stack Empty, 136implicit loop, 12 is Stack Full, 136IMPLICIT NONE, 26, 29 make Stack, 136IMPLICIT REAL, 52 MyPrint, 188implied loop, 60, 61, 156, 166 new, 131INCLUDE line, 37, 42, 89 orthonormal basis, 257INDEX function, 77, 80, 266, 273 pop from Stack, 136indexed loop, 11 Position Angle , 270infinite loop, 9, 68, 269 PrintPay, 123, 124information hiding, 288 push on Stack, 136inheritance, 18, 33, 34, 72, 119, 190, 193, 194, Remove from Q, 140 288 Set, 188 rename, 119 swap, 127 selective, 119 testing basis, 257inherited, 37 interface operator, 188, 258initialize random number, 162 interface operator ( ), 143inner loop, 61 interface operator (*), 39INQUIRE intrinsic, 92, 97, 102, 268, 269 interface operator (==), 143 INTERFACE OPERATOR block, 85, 86INQUIRE statement, 75 INTERFACE OPERATOR statement, 166instance, 33, 122, 288 interface prototype, 103, 104, 123INT function, 162 INTERFACE statement, 34integer, 10, 81, 161 internal file, 80, 289integer nearest to real, 162 internal sub-programs, 72INTEGER type, 23, 24, 53 internal subprogram, 251, 289intent, 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, 178INTENT attribute, 142 IOLENGTH result, 268INTENT statement, 29, 58, 69, 93 IOSTAT= variable, 74, 75, 271interface, 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, 24interface assignment, 258 Kind-Of, 107, 123INTERFACE ASSIGNMENT (=) block, 86interface block, 34, 76 largest integer, 56interface body, 76 largest number, 162interface code latitude, 106­2002c J.E. Akin 7
  20. 20. least integer, 162 abort, 66, 67least squares, 90, 266, 267 breakout, 65LEN function, 77, 80 counter, 59LEN intrinsic, 77, 80 cycle, 65, 66length exit, 59, 65, 66 line, 52 explicit, 58 name, 52 implied, 60LEN TRIM function, 77 index, 100LEN TRIM intrinsic, 77 infinite, 60, 67, 68lexical operator, 94 nested, 61, 65lexically pseudocode, 58 greater than, 77 skip, 65 less than, 77 until, 66, 67 less than or equal, 77 variable, 60LGE function, 77 while, 66LGT function, 77 loop construct, 59library function, 16 loop control, 60, 158line continuation, 100 loop index, 100linear equations, 173, 174, 179, 184 loop variable, 11linked list, 38, 87, 88, 142, 149, 289 lower triangle, 171, 174 doubly, 149 manual constructor, 85, 104linked-list, 191 manual page, 17linker, 16, 89, 289 mask, 161, 164, 165, 179, 259list 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, 173LLE function, 77 matrix, 155, 170, 289LLT function, 77 addition, 172local name, 119 algebra, 155LOG function, 56, 162 column, 170LOG10 function, 56, 162 compatible, 172logarithm, 68, 91, 162 determinant, 175logical, 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, 89logical expression, 11 sparse, 192logical mask, 61 square, 170, 171LOGICAL type, 23, 42, 137 symmetric, 171long, 24 Toeplitz, 171long double, 24 transpose, 159, 171long int, 24 triangular, 171, 174longitude, 106 tridiagonal, 179loop, 5, 7–9, 11, 51, 58, 179 matrix addition, 177, 178­2002c J.E. Akin 8
  21. 21. matrix algebra, 155, 172 Conversion Constants, 252matrix multiplication, 162, 165, 173, 178 doubly linked list, 149matrix operator, 38 elem type data class, 181matrix transpose, 162, 165 exceptions, 75, 137maximum array element location, 162 Fractions, 86maximum array element value, 162 Gauss Module, 190maximum values, 70 inventory object, 49, 264MAXLOC function, 70, 162 inventory system, 270MAXVAL function, 70, 162, 263 Is A Member Class, 131mean, 69 Math Constants, 25member, 119 Member 1 Class, 131memory count, 183, 274 Member 2 Class, 131memory leak, 183 Memory Status Count, 183, 274memory management, 181 object type, 136message, 27 Physical Constants, 252message passing, 289 Point Module, 188method, 192, 289 Queue of Objects, 140methods, 3 Queue type, 139 private, 27 record Module, 97 public, 27 singly linked lis, 143military standards, 74 singly linked list, 143minimum array element location, 162 stack type, 136minimum array element value, 162 swap library, 127minimum values, 70 tic toc, 72, 99MINLOC function, 70, 162 module procedure, 289MINVAL function, 70, 162 MODULE PROCEDURE statement, 34, 39, 85, 86, 166MOD function, 56 MODULE statement, 29modular design, 6 module variable, 29module, 15, 25, 33, 68, 289 modulo, 56module 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­2002c J.E. Akin 9
  22. 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, 53non-advancing I/O, 42 order vector, 99normalized sign, 162 ordering array, 95NOT operator, 53 orthonormal basis, 256, 257NULL function (f95), 88 outer loop, 61nullify, 132 overflow, 290NULLIFY statement, 15, 88, 132 overloaded member, 121number 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, 112numberic type, 24 Part-Of, 107numeric types, 23 partial derivative, 176numerical computation, 38 partial differential equation, 183 partitioned matrix, 171object, 15, 19, 33 pass by reference, 57, 76, 87, 253object 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, 150Object Pascal, 18 allocatable, 15ONLY keyword, 119 allocate, 142OOA, see object oriented analysis arithmetic, 87OOD, see object oriented design array, 135OOP, see object oriented programming assignment, 88OPEN statement, 74, 92, 97, 159, 271 association, 87operator, 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­2002c J.E. Akin 10
  23. 23. pointer variable, 86 Newton, 250polymorphic class, 131 No Copy Reallocate, 183polymorphic interface, 118 operate on strings, 78polymorphism, 18, 33, 34, 119, 124, 194, 290 Person inherit, 37pop, 137 random access file, 151portability, 15 Rational test, 42pre-condition checking, 137 relational operators, 63pre-processor, 129 Revise employee manager, 273precedence order, 53 simple loop, 60precedence rules, 11 string to numbers, 80precision, 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, 122precision kind, 24 test four classes, 121PRESENT function, 29, 36, 37, 42, 75, 253 test Fractions, 86PRINT * statement, 29 test Great Arc, 112private, 33, 104, 187, 290 test inventory system, 272PRIVATE attribute, 29, 36 test Manager 2, 123private attributes, 37 test Manager 3, 124, 133PRIVATE statement, 27 Test Physical, 252procedural programming, 18 test singly linked, 143procedure, 68 two line lsq fit, 267PRODUCT function, 162 watch, 265product of array elements, 162 program keyword, 56 PROGRAM statement, 26, 29program projectile, 101 documentation, 17 prototype, 6, 75 executable, 17 pseudo-pointer, 95 scope, 14 pseudo-random numbers, 162program 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­2002c J.E. Akin 11
  24. 24. RANDOM NUMBER subroutine, 162 bubble, 92RANDOM SEED subroutine, 162 characters, 94rank, 157, 291 object, 96rational number, 38, 39 objects, 94read error, 102 strings, 94READ statement, 29, 61, 75 sorting, 42real, 10, 81, 161 sparse matrix, 192REAL function, 162 sparse storage, 263REAL type, 23, 24, 53 sparse vector, 49, 149, 258real whole number, 162 sparse vector class, 179reallocate, 183, 195 specification, 4, 190recursive algorithm, 87 SQRT function, 27, 56, 112, 162RECURSIVE qualifier, 42, 101 square root, 27, 56, 68, 162reference, 10 stack, 88, 135, 139, 291referencing components, 82 STAT = variable, 74relational operator, 52, 53, 63, 77, 142, 143, 149 statement, 2, 9remainder, 56 statement block, 12, 58rename, 119 statements, 1rename modifier, 119 statusREPEAT function, 77 FILE, 75reshape, 158 IOSTAT=, 75reshape an array, 162 MODE, 75RESHAPE intrinsic, 162 OPENED=, 75RESULT option, 29 status checking, 157result value, 69 STATUS= specifier, 271return, 157 stiffness matrix, 191, 192RETURN statement, 65 STOP statement, 37, 70, 151, 181, 188REWIND statement, 75, 183, 265, 266, 268 storageround number, 56 column wise, 155sample data, 98 row wise, 155SCAN function, 77 string, 23, 56, 150scatter, 169 adjust, 77scope, 14, 291 case change, 80SELECT CASE statement, 63, 188, 272 character number, 77SELECTED INT KIND, 23, 24 collating sets, 77SELECTED REAL KIND, 23, 24 colon operator, 77selector symbol, 26, 29, 34 concatenate, 77server, 18 copy, 77SHAPE function, 162 dynamic length, 76short, 24 from number, 80side effect, 142, 291 functions, 77SIGN function, 162 length, 77signum, 162 logic, 77SIN function, 56, 162, 249 repeat, 77sine, 56, 162 scan, 77SINH function, 56, 162 to number, 80size, 12 trim, 77SIZE intrinsic, 69, 89, 92, 155, 162 verify, 77smallest integer, 56 strings, 76smallest number, 162 strong typing, 53, 291smallest positive number, 162 struct, 53Smalltalk, 18 structure, 23, 25, 33, 84sort, 86, 90, 92, 95, 125 structure constructor, 26­2002c J.E. Akin 12
  25. 25. structured programming, 13 mult Fraction, 86submatrix, 171 MyPrint Point, 188subprogram, 68 new, 131 recursive, 101 new member 1, 131subroutine, 68, 69 new member 2, 131subroutine 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­2002c J.E. Akin 13
  26. 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, 292SUBROUTINE statement, 29 unexpected result, 165subroutines, 33 upper triangle, 171, 174subscript, 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, 165subscript triplet, 291 user interface, 2subtraction, 56subtype, 131 validation, 29subtyping, 124, 130 variable, 8, 10, 23, 51sum, 12 global, 14SUM function, 12, 69, 162 name, 10SUM intrinsic, 92, 165 type, 10sum of array elements, 162 variable rank array, 156super class, 119 vector, 155, 292syntactic error, 17 vector class, 48, 179, 252, 256SYSTEM CLOCK intrinsic, 72 vector subscript, 61, 166, 292 VERIFY function, 77tab, 78, 98, 102 volume, 48TAN function, 56, 162tangent, 56, 162 weakness, 193TANH function, 56, 162 WHERE construct, 165TARGET, 15 WHERE statement, 61, 66, 165target, 23, 75, 87, 88, 292 while-true, 67template, 43, 124, 126, 292 wildcard, 126tensor, 155 WRITE statement, 34, 61, 75testing, 15time, 265time of day, 99TINY function, 162Toeplitz matrix, 171top-down, 4total of elements in array, 162transformational functions, 165transpose, 159, 171, 173TRANSPOSE intrinsic, 162, 166tree, 292tree structure, 38, 87, 88tridiagonal matrix, 179TRIM function, 77­2002c J.E. Akin 14
  27. 27. Chapter 1Program Design1.1 IntroductionThe programming process is similar in approach and creativity to writing a paper. In composition, youare writing to express ideas; in programming you are expressing a computation. Both the programmerand 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 areavailable. Standing back, composition from technical prose to fiction should be organized broadly, usuallythrough an outline. The outline should be expanded as the detail is elaborated, and the whole re-examinedand re-organized when structural or creative flaws arise. Once the outline settles, you begin the actualcomposition process, using sentences to weave the fabric your outline expresses. Clarity in writingoccurs 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 efficientprograms 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 thananother, but the fundamental reason for choosing your language is your audience: People do not knowmany languages, and if you want to address the American population, you had better choose Englishover Swahili. Similar situations happen in programming languages, but they are not nearly so complexor 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 similaritiesthan not. M ATLAB’s language, written in C and Fortran, was created much later than these two, and itsstructure is so similar to the others that it can be easily mastered. The C++ language is an extension ofthe C language that places its emphasis on object oriented programming (OOP) methods. Fortran addedobject oriented capabilities with its F90 standard, and additional enhancements for parallel machineswere issued with F95. The Fortran 2000 standard is planned to contain more user-friendly constructs forpolymorphism and will, thus, enhance its object-oriented capabilities. This creation of a new languageand 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 differentthan ones you already know. Why should new languages evolve? In MATLAB’s case, it was the desire toexpress matrix-like expressions easily that motivated its creation. The difference between M ATLAB andFortran 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” byinterpreters 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. Yourpicky friend might interpret the sentence “Pick you up at eight” to mean that you will literally lift him orher off the ground at precisely 8 o’clock, and then demand to know whether the time is in the morning or­2001c J.E. Akin 1

×