Computers in Engineering - 308-208 Lecture 5
Computers in Engineering - 308-208

# Lesson 5 - Learning Goals

## 5.7 How to debug a program

PROGRAM P22

1.LOGICAL COMPARISONS

!
PROGRAM COMPARISON
!
IMPLICIT NONE
LOGICAL :: COMPAR
INTEGER :: I
PRINT *,2+2 = = 4, 5<=3, 1>=1
PRINT *,-1.4>-1.9, I /= 3, I = = 3.0
PRINT *, 'A' < 'B', 'JOHN ROE' < 'JOHN DOE'
COMPAR='LONG' >= 'LONGEST'
PRINT *,COMPAR
STOP
END PROGRAM COMPARISON
PROGRAM OUTPUT :
T F T
T F T
T F
F

2. FORMAT STATEMENT

The General form is :

label FORMAT ( layout information )

where

label - is a statement number from 1 to 99999

FORMAT - Keyword defining this non­executable statement which can be placed anywhere in the program

layout information - is any combination of a number of conversion types or edit descriptors which specify the kind of variable and constant data and its location on the input record (card) or output record (line).

The most used conversion types can be summarized as follows.

General Conversion

 Form Example Type nIw 3I10 INTEGER nFw.d 4F20.5 REAL Fixed point form nEw.d 4E20.7 REAL Exponent form nGw.d 2G15.0 REAL or INTEGER (General form) nLw 2L5 LOGICAL nAw 2A20 CHARACTER nX 15X Skip a number of columns Tn T30 TAB to a given column `...' `TITLE' Output CHARACTER constant r(...) 3(2X,A4) Repeat section in brackets

44 FORMAT (3I5)
PRINT 44,INTl,INT2,INT3
STOP
/DATA

432 ­333 1

OUTPUT :

432 ­333 1

44 FORMAT (3(' ',I3))
PRINT 44,INTl,INT2,INT3
STOP
/DATA

432 ­333 1

OUTPUT :

432 ­33 10

MISCELLANEOUS FORMATTING

1. Repeats

PRINT 15,2,'ABC',4.4,'DEF',­2.13

15 FORMAT (' ',I3,2(' ',A3,'=',F7.2))
OUTPUT
2 ABC= 4.40 DEF= ­2.13

2. Multiple lines

PRINT 20,444,­2.131

20 FORMAT (' ',I3/' ',F7.2)
OUTPUT
444

­2.13

3. Wrong number of arguments

PRINT 30,'SEP'

PRINT 30

PRINT 30,'OCT',31,'NOV',30

30 FORMAT (' ',A3, '=', I2)

OUTPUT

SEP=

OCT=31

NOV=30

MIXING STRINGS

 Operation Size of Result x y x = y 10 20 Left half of y => x x = y 20 10 y + 10 spaces => x x = 'HELLO' 10 `HELLO' + 5 spaces => x PRINT *,x 10 10 chars printed x == y (>, etc) 20 10 x compared to y + spaces READ 10,X 10 x only gets left 10 FORMAT (Ay) 20 half of input string READ 10,X 20 x gets 10 characters 10 FORMAT (Ay) 10 of input data + 10 spaces READ 10,X 10 10 spaces + x 10 FORMAT (' ',Ay) 20 printed READ 10,X 20 Leftmost 10 characters 10 FORMAT (' ',Ay) 10 of x printed

CARRIAGE CONTROL

 Control Characters Character Coded As Vertical spacing one ' 1 ' New page blank ' ' Single spacing zero ' 0 ' Double spacing plus ' + ' No spacing

DEBUGGING A PROGRAM

1) READ COMPLETE PROGRAM SLOWLY FROM TOP TO BOTTOM

- Properly structured

- Proper syntax

- Variables appropriately declared

- Blocks indented

2) COMPILE PROGRAM

- Any errors

- Any warnings

- Refer to ISN (Internal Statement Numbers)

- Clean compile

3) EXECUTION TIME ERRORS

- No output, add print statement

- ''Stuck in a loop'' = too much output !

DYNAMIC - INTERACTIVE DEBUGGING

1) GENERAL CONCEPT

- Your program is available in source form (e.g. FORTRAN, C,

PASCAL, etc. ) and in BINARY.

- Your program is run under the control of debugger.

- Debugger allows :

- Inspection of data input/output

- Single step execution

- Breakpoints

- Tracing

- Animation

- Full speed execution

- Array subscript checking

2) FORTRAN :

ELF90 - Essential LAHEY FORTRAN 90

3) C language :

A) Turbo C

B) Turbo Pascal version 6

On to the next lecture