Intel fortran-80 manual Final Coding

Models: fortran-80

1 130
Download 130 pages 742 b
Page 87
Image 87
7.1.4 Final Coding

FORTRAN-SO

Programming Guidelines

The next pass is a more formal description of level two, introducing FORTRAN statements for English sentences.

Level Three

CINITIALIZE VARIABLES NEEDED FOR TOTALS DATA TOTEMP, TOTHRS, TOTPAY / 3*0.0/

COPEN INPUT/OUTPUT FILES, READ EMPLOYEE RECORD OPEN (input file)

OPEN (output file)

10READ (unit, 20) EMP, HRS, GRPAY, NETPAY

20FORMAT (flist)

CPRINT TOTALS IF NO MORE RECORDS IF (no more records) TH EN

WRITE (unit, 40) TOTEM P, TOTH RS, TOTPAY

40FORMAT (flist) CLOSE (input file) CLOSE (output file)

COTHERWISE PRINT EMPLOYEE DATA AND UPDATE TOTALS ELSE

WRITE (unit, 60) EMP, HRS, GRPAY, NETPAY

60FORMAT (flist)

TOTEMP = TOTEMP + 1

TOTH RS = TOTH RS + HRS TOTPAY = TOTPAY +GRPAY

CREAD NEXT EMPLOYEE RECORD GOTO 10

ENDIF END

A number of details remain to be specified, but each of these levels is in some sense complete and can be debugged to the extent that it is complete. Thus we can confirm the accuracy of the program's logic, then 110 interfaces and basic calculations, and only at the end concern ourselves with such details as format specification.

7.1.4 Final Coding

At the level of detailed code, a number of steps can be taken to simplify writing and debugging the program, or to simplify the task of another programmer updating the program later.

Take advantage of the built-in debugging aids available in the particular programming language. For example, PAUSE, STOP, and WRITE statements can be interspersed throughout initial FORTRAN code to trace program execution paths. These can be removed in the final version of the program.

Avoid tricky programming. Code conservatively!

Concentrate initially on making the program work. Beautiful printouts can be produced as a last step.

Concentrate especially on getting the statement syntax correct the first time. Syntax details can be particularly annoying to FORTRAN programmers, but initial effort in this area can save a lot of grief in the long run.

Again, use comment lines frequently. Use meaningful labels for variables. Use blanks to improve program listing readability.

7-3

Page 87
Image 87
Intel fortran-80 manual Final Coding