Page 129 - Standard Handbook Of Petroleum & Natural Gas Engineering
P. 129

114   Mathematics

                       With  little  extra effort, code can be written so as  to  minimize  the difficulty
                     a  reader  will  encounter  in  comprehending  the  program  logic.  Several  con-
                     siderations in  improving readability  of  a program  are
                       1. Names  should be  as descriptive as  possible,  e.g., DEPTH  rather than  12.
                       2.  Comments should be  liberally  used  to  describe the data and logic  of  the
                         program; they should be brief, when placed in the body of a program unit,
                         but may be longer and more descriptive at the beginning of a program unit.
                       3.  Indentation, when possible, clarifies conditional and iterative constructions,
                         and spacing improves  the  general readability  of  a  program.
                       4.  The use  of  subprogram units allows separation of  the various  operations
                         of a program into modules, thereby  clearly delineating the program logic.
                         Specific  types  of  calculations,  input, and  output  may  be  done  in  distinct
                         modules;  in  many  cases,  the  main  unit  will  consist  primarily  of  calling
                         statements to  a few  modules.
                       The  proper  handling  of  certain  common  errors  can  improve  the  run-time
                     behavior  of programs. In most cases, awareness of inherent problems  in machine
                     handling of  data  and attention to  program  details can  avoid  program  crashes
                     due  to  error.  The  following  should be  considered  when  the  program  code  is
                     being designed:

                       1. Input  validation  statements should be  used  to  automatically  check  input
                         data,  to  produce  a  clear  message  when  an  error  is  found, and  to  allow
                         reentry of erroneous data. Data input should be echoed for user verification
                         and an opportunity  allowed  for  alteration of  specific  data items.
                       2.  A  method  of  exiting  the  program  in  case  of  a  run-time  error,  which
                         produces a  message  to  the user  as  to  the  type  and location of  the error,
                         should  be  provided.  The  possibility  of  certain  errors  occurring can  be
                         anticipated,  and the use of flags and conditional constructions may provide
                         a  path  to  exit  the  program  gracefully.
                       3.  It is  necessary  to avoid predicting the exact  value  of a real variable, since,
                         after several operations, it may have been rounded off one or more times.
                       4. Side effects  in  subprogram units are unintentional changes in data values
                         defined in other units. These frequently occur when  the scope of a variable
                         is mistakenly considered, because of insufficient  cross-checking, to be local,
                         when  it  is, in  fact,  global.


                                             FORTRAN Language
                       FORTRAN  names  (unit, variable,  array,  etc.) consist  of  an initial letter (see
                     defaults for real and integer types in the following) followed by  letters or digits,
                     the  maximum  length of  which  is  6  characters.
                     Data Types. See the  section “Statements” for forms of  declaration  of  type.
                       Integer-Variable  names  starting with  I-N,  unless  otherwise declared.
                       Real-Variable  names  starting with  A-H  and  0-Z, unless  otherwise declared.
                       Double precision-Must  be declared.
                       Complex-Must  be  declared.
                       Logical-Must  be  declared.
                       Character-Must  be  declared with  length  of  string; default length  is  1.
   124   125   126   127   128   129   130   131   132   133   134