DATA ENCAPSULATION USING FORTRAN-77 MODULES-A FIRST STEP TOWARD OBJECT-ORIENTED PROGRAMMING IN WATER RESOURCES
暂无分享,去创建一个
Programming is a costly aspect of numerical modeling. Recognizing the need to increase reusability and maintainability of source codes, programs developed using FORTRAN-77 often conform to a method of program design called top-down structured programming, or procedural programming. This method emphasizes the relation between procedures necessary to solve a particular programming problem. An alternative approach is to consider the relation between data and manipulation of data fundamental to solution of a programming problem. The programming construct arising from this perspective is termed a module. In this report, the module programming construct is denned. Through figures and code examples, it is shown how FORTRAN-77 modules are used to encapsulate fundamental data from other parts of the program. FORTRAN-77 modules provide a level of program structure in addition to that available using procedural practices alone. Construction and use of FORTRAN-77 modules improves program clarity, reduces argument passing, and encapsulates fundamental data at the level where they are manipulated. Introduction FORTRAN-77 (American National Standards Institute, 1978) is a procedural programming language commonly used for numerical solution of mathematical equations describing physical phenomena. The increase in number and sophistication of computer programs written to simulate physical phenomena (numerical models) has progressed to the point where programming concerns, in addition to concerns related to development and solution of governing equations, are of significant importance. Software development, support, and maintenance are costly aspects of numerical modeling. Therefore, programs developed using FORTRAN-77 often conform to a design method called topdown structured programming. This method (Yourdon and Constantine, 1979) is applied by reducing each major task of a programming problem into successively smaller sub-tasks until each sub-task can be solved by a relatively short piece of code, usually one procedure. Because this approach to programming is task-oriented, the top-down structured method is often referred to as the procedural approach, the procedural paradigm, or simply procedural programming. The general rule governing program development using procedural programming may be simply stated: determine which procedures are required and implement the procedures as efficiently as you can (Stroustrup, 1989). In the FORTRAN-77 language, a procedure is a called a subprogram, which can be either a subroutine or a function. Procedural programming results from a particular view of the structure of a computer programthat of the interaction of algorithms required to solve a given problem, usually with little regard for data used by the program. However, programming problems can be viewed from other perspectives that may require a shift of paradigm. One such paradigm is based on the data used by a program and manipulation of data fundamental to solution of a programming problem. This paradigm will be referred to as the data-encapsulation paradigm, or the module paradigm. Divergent meanings are attributed to the term module. In this report, module refers to the composition of data and procedures to manipulate these data (Stroustrup, 1989). Purpose and Scope The purpose of this report is to present a comparison of programming paradigms through the use of two example programs. The first example program is developed using procedural programming principles and the second is developed using data encapsulation in FORTRAN-77 modules. Guidelines for developing modules in the FORTRAN-77 language are presented. FORTRAN-77 modules are shown to provide advantages, including an additional level of program structure, not obtainable using procedural practices alone. Example Programs Analysis of two programs which perform the same task will demonstrate differences between procedural and modular programs. These programs are fully operational and FORTRAN-77 source code for each example is presented in an appendix. Diagrams of flow of program control and flow of data between procedures are presented to illustrate differences between the methods. The example problem used to analyze the two programs is to determine normal depth of flow at specific locations within a network of interconnected channels. Normal depth is defined to be the depth of flow that occurs when the water surface is parallel to both the total energy line and the bottom of the channel for a specific volumetric discharge (Chow 1959). The Manning equation is used to relate normal depth to discharge. The Manning equation is: Q = K(H)Sll2 (1) where: Q = volumetric discharge , (L3/T) H = depth of flow , (L) S = bottom slope, (dimensionless) K(H) = channel conveyance, (L3/T) C n ' P(H ) 2/3 C = 1.486(for English units) = 1.0(for metric units) A = cross-sectional area of flow, (L2 ) P = wetted perimeter, (L) n = Manning flow resistance coefficient^!/1' 6 ) Input data required to solve the problem include the locations and volumetric discharges for which normal depths are requested and a description of geometric and hydraulic properties of each channel in the network. For both programs, all channels are assumed to be rectangular in cross section, and channel width is assumed to vary linearly with channel distance. Therefore, each channel in the network is completely described by eight data: a channel number, flow-resistance coefficient, and for each end of the channel a downstream-distance coordinate, channel width, and elevation of the channel bottom. A number is assigned to each channel (channel number) for use as an index in storing channel properties data. The Manning equation is non-linear in depth of flow. Both programs solve it using a NewtonRaphson iterative scheme. Given discharge, bottom slope, and cross-sectional properties of the channel, an iterative solution of the Manning equations is:
[1] Lewis L. DeLong,et al. Data encapsulation using Fortran 77 modules , 1992, FORF.
[2] Bjarne Stroustrup,et al. C++ Programming Language , 1986, IEEE Softw..
[3] Michael Metcalf,et al. Fortran 90 Explained , 1990 .