0% found this document useful (0 votes)
10 views

(Fortran) ... LECTURE No. 2

(Fortran) ... LECTURE No. 2

Uploaded by

Mariam Shereeda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

(Fortran) ... LECTURE No. 2

(Fortran) ... LECTURE No. 2

Uploaded by

Mariam Shereeda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Port Said University - Faculty of Engineering

Naval Architecture & Marine Engineering


Department
1

Lectures on

Computer Applications in Marine Engineering


Field
By

Dr. M. M. Moustafa

for
3rd Year Students (2023 – 2024)
Fortran Statements
2

1. Input Statement:

READ ( I, n ) LIST
Where,

I A logic device code number specifying the card reader.


n An unsigned integer constant. It stands for the format
statement number.
LIST A sequence of one or more variable names separated
by commas.

Example, READ ( 5, 10 ) A, B, C, L
2. Output Statement:
3

WRITE ( I, n ) LIST
Where,

I Stands for the logic device code number specifying the


card printer.
n An unsigned integer constant. It stands for the format
statement number.
LIST A sequence of one or more variable names separated
by commas.

Example, WRITE ( 6, 70 ) I, A, B, C, L
3. Specification Statements
4

The specification statements are accomplished by using FORMAT


statements. These statements accompany the I/O statements , they must
be labeled by a statement number (n) . The general form of the
FORMAT statements is :

n FORMAT (a1, a2 , ……., am)


Where,

n Any unique one to five digit integer. It is the statement


number.
a Stands for one or more FORMAT codes. The most popular
and often used FORMATs are I, F, X, E and T.
a. Integer Specification
5

The general form is :

alw
Where,

a indicates the number of times the field will be used. It must


be an integer.

l Specifies that the data field consists of an integer value.

w Indicates the total field width.


Example :
6

I = 123 J = -15 K = 31 L = 1000 M = -256

READ ( 5, 11 ) I, J, K, L, M
11 FORMAT ( I3, I3, I2, I4, I4)

Input Page

1 2 3 - 1 5 3 1 1 0 0 0 - 2 5 6

Another form: READ ( 5, 11 ) I, J, K, L, M


11 FORMAT ( 2I3, I2, 2I4 )
b. Real (Floating-Point) Specification
7

The general form is :

aFw.d
Where,

a indicates the number of times the field will be repeated. It


must be an integer.

F Specifies that the data field consists of a real value.

w Indicates the total field width.

d Is the number of positions following the decimal point.


Example:
8

A = 16.73 B = -2.15 C = 2100.528 D = -1. 7

WRITE ( 6, 15 ) A, B, C, D
15 FORMAT ( F5.2, F5.2, F8.3, F4.1)

Output Page
1 6 . 7 3 - 2 . 1 5 2 1 0 0 . 5 2 8 - 1 . 7

Another form: WRITE ( 6, 15 ) A, B, C, D


15 FORMAT ( 2F5.2, F8.3, F4.1)
Examples:

9 Value in Computer
FORMAT Output
Storage

1234567.896 F10.2 1234567.89

1234567.896 F9.2 *********

12345.95 F6.0 12345.

123.44 F6.0 123.

-123.45 F4.0 ********

123.45 F6.2 123.45


-123.45
F6.2 ********
c . The X Specification
10

The general form is :

nX
Where,

n It indicates the number of spaces or columns to be skipped.


It must be an integer.

X Indicates the X mode.


Example:
11

X = 16.73 M = -125 Y= 5.19

WRITE ( 6, 20 ) X, M, Y
20 FORMAT ( 2X, F5.2, 3X, I4, 2X, F4.2)

Output Page
1 6 . 7 3 - 1 2 5 5 . 1 9
d. The T Specification
12

The general form is :

Tn
Where,

T Indicates where the reading is to begin ( column number).

n Indicates the starting position to be read in.


Example:
13

X = 16.73 M = -125 Y= 5.19

WRITE ( 6, 20 ) X, M, Y
20 FORMAT ( T3, F5.2, 3X, I5, 2X, F5.2)

Output Page
1 6 . 7 3 - 1 2 5 5 . 1 9
e. The H Specification
14

The general form is :

aHm
Where,

a An integer number indicating the length of the field


occupied by the message to be printed out.

H Indicates that the message under consideration begins with


the next character.

m The output message.


Example No. 1
15

Assume a programmer wishes to instruct the computer to print out


a message containing the literal, FORTRAN IS EASY.

WRITE ( 6, 15 )
15 FORMAT (16H FORTRAN IS EASY)

1 Space for the blank after the H


7 Spaces for FORTRAN
1 Blank space It should be noted that
2 Spaces for IS the 16 spaces include
1 Blank space the following:
4 Spaces for EASY
This example can be written in another form as follows:
16
WRITE ( 6, 15 )
15 FORMAT ( ‘FORTRAN IS EASY’ )

Example No. 2: IF AREA = 16.73 m2

WRITE ( 6, 35 ) AREA
35 FORMAT ( 3X, ‘AREA=’, 1X, F5.2, 1X, ‘m2’)

Output Page

A R E A = 1 6 . 7 3 m 2
f. Skipping Lines and Pages
17

/ Means start a new line

// Means start after two lines


18

Thanks

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy