Language:EN
Pages: 4
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
fortran overviewinput output syntax read

Fortran overviewinput output syntax read

MECH1004 COMPUTING / 2. Fortran Overview

Type Declaration:-

[Generalised Syntax]
REAL :: list of names
INTEGER :: list of names

[Generalised Syntax] name = value
name = expression

[Examples]
age = 21
years_to_go = 65 – age

Program Naming:-
PROGRAM name IMPLICIT NONE

Block of FORTRAN
code goes here

• May contain only A to Z (or a to z), the digits 0 to 9, and the underscore character _

• Maximum of 32 characters!

[Generalised Syntax]
READ *, list of names
PRINT *, list of names

[Examples]
READ *, first, second, x1, y1, x2, y2
PRINT *, “Your age now is ”, age
PRINT *, “Your age next birthday will be ”, age + 1

Different types of variables have different storage requirements in a computer.

INTEGER

LOGICAL

user derived type

2.4 Executable and Non Executable and Non--Executable Statements

END PROGRAM age_next_year

MECH1004 COMPUTING / 2. Fortran Overview

In order to be able to run older Fortran programs using modern and more efficient compilers, implicit
declaration remains active unless “switched off” by the IMPLICIT NONE statement.

MECH1004 COMPUTING / 2. Fortran Overview 2.3 From Source Code to ““Executable

USER SALFORD FORTRAN DEVELOPMENT
SOFTWARE
.exe file
COMPILER
Binary File
“Object Code”(unlinked)

.obj file

LINKER link

Binary File
“Executable
Code” (fully
linked)

Non--Executable Executable / / Executable

PROGRAM age_next_year
IMPLICIT NONE
! This program works out the user’s age ! after his/her next birthday

So...

3. Handling Numbers

MECH1004 COMPUTING / 3. Handling Numbers

4 1 3 7 0 2 0 3
6 8 4 9 1 5 4 9 represents -0.315085 x 1049 (or -0.315085E49)
4 1 3 7 0 2 9 7 represents 0.413702 x 10-3 (or 0.413702E-3) = 0.000413702
6 8 4 9 1 5 5 0 represents -0.315085 x 10-50(or -0.315085E-50)
0 0 0 0 0 0 0 0

represents 0.0 x 100 = 0.000000

N.B. in a real computer the digits would be binary digits, so you would need lots more digits to represent these sorts of numbers.

REAL :: a1, a2
INTEGER :: total
...

...

PROGRAM demo_2
IMPLICIT NONE
...

REAL :: a1, total
INTEGER :: a2
...

Within the assignment
expression for total, a2 would effectively be converted to REAL before calculation.

MECH1004 COMPUTING / 3. Handling Numbers 3.1 How Numbers are Stored
Storage of INTEGERS using 8 digits (in a hypothetical computer):-

might represent +49 999 999
N.B. in a real computer the digits would be binary digits, so you would need lots more digits to represent these sorts of numbers.

MECH1004 COMPUTING / 3. Handling Numbers

On the same typical 32-bit machine default REALs can range between about -1038and +1038, with 7 or 8 significant decimal digits. But note that they may vary slightly from theoretically“true” values due to rounding rounding or truncation truncation processes that occur within the CPU.

Default REALs in Fortran normally use twice the amount of space as default INTEGERs.

Operator Meaning Priority
+ addition low
- subtraction low
* multiplication medium
/ division medium
** exponentiation high

Within the same level of priority, evaluation proceeds from left to right. a = b + c * d / e – f ** g / h + i * j + k

more readable

a = b + (c * d / e) – (f ** g) / h + i * (j + k)

Other useful intrinsic functions for exercises 3:-FRACTION (X)
MOD (A, P)
INT (A)
NINT (A)
AINT (A)
ANINT (A)

MECH1004 COMPUTING / 3. Handling Numbers

MECH1004 COMPUTING / 3. Handling Numbers 3.4 Intrinsic Functions Available
See list provided in hardcopy.

[Generalised Syntax]
function (name)
function (expression)

“angle” in degrees

MECH1004 COMPUTING / 3. Handling Numbers

MECH1004 COMPUTING / 3. Handling Numbers

Remember that type declaration statements are non-executable – i.e. they don’t do anything once the program has started to run.

You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File
img

Uploaded by : Margaret Campbell

PageId: DOC081E394