Tài liệu Errata File "OOP via F90" pdf

328 287 0
Tài liệu Errata File "OOP via F90" pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

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 --------------------------------- O bject O riented P rogramming via F ortran 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. FlowControl . 11 1.4.4. Functions . 13 1.4.5. Modules . 15 1.4.6. DynamicMemoryManagement . 15 1.5. Programevaluationandtesting 15 1.6. Programdocumentation 17 1.7. ObjectOrientedFormulations 18 1.8. Exercises . 21 2 Data Types 23 2.1. IntrinsicTypes . 23 2.2. UserDefinedDataTypes . 25 2.3. AbstractDataTypes 27 2.4. Classes 29 2.5. Exercises . 31 3 Object Oriented Programming Concepts 33 3.1. Introduction 33 3.2. Encapsulation,Inheritance,andPolymorphism . 34 3.2.1. ExampleDate,Person,andStudentClasses . 37 3.3. ObjectOrientedNumericalCalculations . 38 3.3.1. ARationalNumberClassandOperatorOverloading 39 3.4. Discussion . 42 3.5. Exercises . 48 4 Features of Programming Languages 51 4.1. Comments . 51 4.2. StatementsandExpressions 52 4.3. FlowControl . 57 4.3.1. Explicit Loops . . 58 4.3.2. Implied Loops . . 60 4.3.3. Conditionals . 61 4.4. Subprograms . . . 68 c ­ 2001 J.E. Akin iii 4.4.1. FunctionsandSubroutines 68 4.4.2. GlobalVariables . 72 4.4.3. BitFunctions . 74 4.4.4. ExceptionControls 74 4.5. InterfacePrototype 75 4.6. CharactersandStrings 76 4.7. UserDefinedDataTypes . 80 4.7.1. OverloadingOperators 84 4.7.2. UserDefinedOperators 86 4.8. PointersandTargets 86 4.8.1. PointerTypeDeclaration . 87 4.8.2. PointerAssignment 88 4.8.3. UsingPointersinExpressions 88 4.8.4. PointersandLinkedLists . 88 4.9. AccessingExternalSourceFilesandFunctions . 89 4.10.ProceduralApplications 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. TheDrillClass 103 5.3. Global Positioning Satellite Distances 106 5.4. Exercises . 118 6 Inheritance and Polymorphism 119 6.1. Introduction . . . . 119 6.2. ExampleApplicationsofInheritance . 121 6.2.1. TheProfessorClass 121 6.2.2. TheEmployeeandManagerClasses . 121 6.3. Polymorphism . 124 6.3.1. Templates . 125 6.3.2. SubtypingObjects(DynamicDispatching) . 130 6.4. Exercises . 133 7 OO Data Structures 135 7.1. DataStructures 135 7.2. Stacks . 135 7.3. Queues 139 7.4. LinkedLists 142 7.4.1. SinglyLinkedLists 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. SubscriptedVariables:Arrays 155 8.1.1. Initializing Array Elements . . 158 8.1.2. IntrinsicArrayFunctions . 159 8.1.3. ColonOperationsonArrays(SubscriptTriplet) . 159 8.1.4. ArrayLogicalMaskOperators 163 8.1.5. UserDefinedOperators 165 8.1.6. ConnectivityListsandVectorSubscripts 166 c ­ 2001 J.E. Akin iv 8.1.7. Component Gather and Scatter . . 168 8.2. Matrices 170 8.2.1. MatrixAlgebra 172 8.2.2. Inversion . 174 8.2.3. Factorizations . 174 8.2.4. DeterminantofaMatrix . 175 8.2.5. MatrixCalculus 176 8.2.6. ComputationwithMatrices . 176 8.3. Exercises . 178 9 Advanced Topics 181 9.1. Templates . 181 9.2. SubtypingObjects(DynamicDispatching) 183 9.3. Non-standardFeatures 184 A Bibliography 187 B Fortran90 Overview 191 B.1. List of Language Tables . . 191 B.2.AlphabeticalTableofFortran90IntrinsicRoutines . 17 B.3.SyntaxofFortran90Statements . 29 C Selected Exercise Solutions 47 C.1. Problem 1.8.1 : Checking trigonometric identities . . . 47 C.2.Problem1.8.2:Newton-Raphsonalgorithm 47 C.3.Problem1.8.3:Gameoflife 48 C.4.Problem2.5.1:Conversionfactors . 49 C.5.Problem3.5.3:Creatingavectorclass . 50 C.6.Problem3.5.4:Creatingasparsevectorclass . 56 C.7. Problem 4.11.1 : Count the lines in an external file . . . 61 C.8.Problem4.11.3:ComputingCPUtimeuseage . 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.Problem4.11.14:Twolineleastsquarefits . 63 C.12.Problem4.11.15:Findthenextavailablefileunit . 65 C.13.Problem 5.4.4 : Polymorphic interface for the class ‘Position Angle’ . 66 C.14.Problem6.4.1:Usingafunctionwiththesamenameintwoclasses 67 C.15.Problem6.4.3:Revisingtheemployee-managerclasses 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 c ­ 2001 J.E. Akin v [...]... access, 151 4 binary, 183 column count, 99 direct access, 150 I/O, 151 internal, 80 line count, 99 modify, 151 random, 151 random access, 150 read status, 99 record number, 150 scratch, 183 unit number, 100 FILE= specifier, 271 finite difference method, 179 finite element, 43 finite element analysis, 181 flip, 163, 166 float, 53 floating point, see real, 23, 24, 179 FLOOR function, 56, 162 flow control, 11, 51, 58... vector class, 179 specification, 4, 190 SQRT function, 27, 56, 112, 162 square root, 27, 56, 68, 162 stack, 88, 135, 139, 291 STAT = variable, 74 statement, 2, 9 statement block, 12, 58 statements, 1 status FILE, 75 IOSTAT=, 75 MODE, 75 OPENED=, 75 status checking, 157 STATUS= specifier, 271 stiffness matrix, 191, 192 STOP statement, 37, 70, 151, 181, 188 storage column wise, 155 row wise, 155 string, 23,... 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 . Errata File "OOP via F90" This is only the beginning of an errata for the text based on comments from. <akin@is.rice.edu> Subject: Re: Errata for "OO Programming via Fortran 90/95"? Dr. Akin: I was able able to look at the &apos ;errata& apos;, but did not

Ngày đăng: 12/12/2013, 21:16

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan