COMPUTER PROGRAMMING PRESENTATION
COMPUTER PROGRAMMING
CIVIL ENGINEERING STUDY PROGRAM
PRESIDENT UNIVERSITY
CIKARANG, 2022
1
COMPUTER PROGRAMMING PRESENTATION
COMPUTER
Editing, drawing
A tool for storing and retrieving large data
Number cruncher
Artificial intelligence (AI), decision making
2
COMPUTER PROGRAMMING PRESENTATION
Engineering revolution:
Use of computers
Writing in matrix form
Reformatting engineering problems
3
COMPUTER PROGRAMMING PRESENTATION
HIGH LEVEL COMPUTERS:
Understood only by the programmers
Computers only understand machine language
(ASSEMBLER)
Has to be translated to machine language
(compiled)
Fortran, Pascal, Cobol etc.
4
COMPUTER PROGRAMMING PRESENTATION
EXAMPLE:
By MS –DOS, create program named X.FOR IN FORTRAN
Then, compiled to change to X.OBJ TO ASSEMBLER language
Assembled with MATH.LIB and FORTRAN.LIB to have X.EXE
Prepare data file X.DAT
Run X.EXE, read X.DAT, execute and store the result in X,OUT
X.FOR
5
COMPUTER PROGRAMMING PRESENTATION
SOURCE PROGRAM (X.FOR):
• can be modified
• Can be copied
• Can be compiled
• Can not be run (loaded)
6
COMPUTER PROGRAMMING PRESENTATION
OBJECT CODE (X.OBJ):
• can be copied
• can not be modified
• can not be recompiled
• can not be run (loaded)
7
COMPUTER PROGRAMMING PRESENTATION
IMAGE (X.EXE):
• can be copied
• can not be modified
• can not be recompiled
• can be run (loaded)
8
COMPUTER PROGRAMMING PRESENTATION
FORTRAN HIGH LEVEL LANGUAGE:
• The name: FORmula TRANslation
• Invented in 1956 BY John Backus at IBM
• Improving version: Fortran 66, 77 and 90
9
COMPUTER PROGRAMMING PRESENTATION
FORTRAN HIGH LEVEL LANGUAGE:
• Program written in lower level may run in higher level
• Have several higher level, such as BASIC
• Better use standard form of Fortran, so may be developed
in easier fashion
• Using standard form of Fortran, may run in different
computer brand
• Using Fortran 77 is better
10
COMPUTER PROGRAMMING PRESENTATION
CODING RULES:
At column 1, write C or any number or alphabet that
means comments
Column 2-5: statement label
Coding statements at column 7 - 72
Continuation at column 6 by using + or any other signs
Input lines starting at column 1 and ends at column 72
Output lines from column 1 until column 120
11
COMPUTER PROGRAMMING PRESENTATION
PROGRAM STRUCTURE:
• PROGRAM
• eclaration
• STOP
• END
12
COMPUTER PROGRAMMING PRESENTATION
1234567
PROGRAM COBA:
PROGRAM COBA
REAL*8 A(5,5)
C
OPEN(UNIT=3,FILENAME=‘COBA.DAT’, STATUS=‘OLD’
OPEN(UNIT=4,FILENAME=COBA.OUT’,STATUS=‘UNKNOWN’
C
DO 10 I=1,5
READ(3,1001) (A(I,J),J=1,5)
10 CONTINUE
.
STOP
END
13
COMPUTER PROGRAMMING PRESENTATION
PROGRAM COBA:
Write codes COBA.FOR
Compile to make COBA.OBJ
Link COBA.OBJ with MATH.LIB and FORTRAN.LIB to make
COBA.EXE
Prepare data file COBA.DAT
Run COBA.EXE: Read data, execute and create output file
COBA.OUT
14
COMPUTER PROGRAMMING PRESENTATION
CONSTANTS AND ARRAYS:
Constants: single fixed value
Arrays: coding form of matrix
15
COMPUTER PROGRAMMING PRESENTATION
TYPES:
CHARACTERS: NAME, OPSI
REAL CONSTANTS AND ARRAYS
REAL*8 STIF A(4,4), INDEX
INTEGER NUMBERS AND ARRAYS
INTEGER LOAD(3,3), PLOAD
16
COMPUTER PROGRAMMING PRESENTATION
PROGRAM AND SUBPROGRAM(S):
If program becomes too long, it will be difficult to
compile and debugging
Similar computation may be grouped in a subprogram
A program may be divided into a main program and
several subprograms
Easy to compile and debugging separately
17
COMPUTER PROGRAMMING PRESENTATION
SUBPROGRAMS:
SUBROUTINE
FUNCTION
(COMMON)
(DATA)
18
COMPUTER PROGRAMMING PRESENTATION
SUBROUTINE:
Receive large amount of data from main program
Execute the data
Return the results at once to the main program
19
COMPUTER PROGRAMMING PRESENTATION
SUBROUTINE:
1234567
PROGRAM MAIN
REAL*8 A(10)
C
CALL READIN(A,2,3)
STOP
END
C
SUBROUTINE READIN(X,M,N)
REAL*8 X(M,*)
.
RETURN
END
20
COMPUTER PROGRAMMING PRESENTATION
SUBROUTINE:
The program MAIN agitates the subroutine by issuing CALL statement
The memory A with 10 members long, is passed to the subroutine as X as two
dimension array; M becomes 2 and N becomes 3.
X is a dummy array with has no memory, and the routine is allowed to work on the
memory of array A.
After execution, the routine sends beck the result to the main program at the
RETURN statement
21
COMPUTER PROGRAMMING PRESENTATION
FUNCTION:
The program MAIN agitates the FUNCTION by calling its name
The function executes the task
The result is sent back to the main program by the function through its name
The function returns only a sing le value
22
COMPUTER PROGRAMMING PRESENTATION
1234567
PROGRAM MAIN
REAL*8 ADD
C
SUM = SUM +ADD(2.,3.0)
STOP
END
REAL FUNCTION ADD(X,Y)
REAL*8 ADD
ADD=X+Y
RETURN
END
23
COMPUTER PROGRAMMING PRESENTATION
INPUT/OUTPUT:
Inputting by reading an already input file
Outputting is by writing on an already opened output file
Two kinds of number format:
F format: 10F8.3: -1234.567
E format:10E8.3
24
COMPUTER PROGRAMMING PRESENTATION
FORMATTED/UNFORMATTED INPUT/OUTPUT:
Formatted input/output
READ(3,1001) A(6)
1001 FORMAT(E10.3)
.
READ(3,1002) MM(2)
1001 FORMAT(I5)
.
. WRITE(4,1001) A6)
.
WRITE(4,1001) MM(2)
25
COMPUTER PROGRAMMING PRESENTATION
FORMATTED/UNFORMATTED INPUT/OUTPUT:
Formatted input/output
format precisely
26
COMPUTER PROGRAMMING PRESENTATION
FORMATTED/UNFORMATTED INPUT/OUTPUT:
Unformatted input/output
READ(3,*) A(6)
.
READ(3,*) MM(2)
.
WRITE(4,*) A6)
.
WRITE(4,*) MM(2)
27
COMPUTER PROGRAMMING PRESENTATION
FORMATTED/UNFORMATTED INPUT/OUTPUT:
Unformatted input/output
the value
28
ENGINEERING MECHANICS III PRESENTATION
….. THANK YOU …..
29