Download presentation
Presentation is loading. Please wait.
Published byDelphia Gray Modified over 8 years ago
1
Fundamental of Fortran Part 1 Dr.Entesar Ganash
2
Numerical types: An integer: is a number which do not has any decimal point. In Fortran, the integer number could be from -32768 to +32768. A real : is a number which has a decimal point. It has two form: Positional form or Fixed form E.g. 200.0 and Exponential form or Floating point E.g. 2.0 10 2.. (in Fortran language 2.0 E2 ) What is the difference between (10) (10. ) (10.0 ) then evaluate 10/3 and 10/3. ? 10 is an integer number while 10. or 10.0 are real numbers. They will be represented differently in the memory. 10/3 evaluate a to 3 BUT 10/3. evaluate to 3.3333 Real will range between 10 -38 and 10 +38 with a precision of a bout 7 decimal digits. 2. Basic Data types Numerical types are integer, real and complex. Non-Numerical types are character and logical. (BE CAREFULL)
3
A double precision: like 'real' numbers with more accurate representation. A complex number: A complex number (Z) consists of a real and imaginary parts. So, a is represented by: Where and are of the real type. When a complex constant is input it must be enclose in parentheses(), E.g. z=(1,2) or could be z=1.0+i*2. in Fortran this can be written as i=(0,1) Non-Numerical types Character: used to store text or character strings. Character constants are sequences of characters, known as strings. apostrophes (‘) or quotes (“) are used on both sides of Characters. E.g. ‘ a’, ‘physics’, ‘Entesar’ or any name. Logical: There are two possible values denoted either by.TRUE. Or.FALSE.
4
3.Names, Constants &Variables A name - Must start with a letter. -Must consist of between 1 and 31 alphanumeric characters (e.g.the 26 letters (a-z), the 10 digits (0-9) and the underscore( _ ). - Must there is no any space in one word. -Fortran is insensitive, so the names MYNAME=Myname denote the same thing. Which of these names are right? X, x+y, 2A, A2, a2.0, mybooks, my-books, my_book, my books, books$ X, x+y, 2A, A2, a2.0, mybooks, my-books, my_book, my books, books$
5
A constant is a memory location whose value fixed through program execution. E.g. g=9.8, Pi=3.141593 A variable is a memory location whose value may be changed through program Execution. The rules of the a variable's name are same as given before. A variable has a type which determines the constant type it may hold. Variable names can be declared before the first executable statement of a program, E.g. Character :: name, class, degree Integer :: month, minute Real :: x, height, range Assuming n is integer, and x and y are real find n=10.0 /3 x=10/3 y=10/3. 3 3.33333 (BE CAREFULL)
6
Arithmetic Operations OperatorMeaningExamplePrecedence **Exponentiation2**41 *Multiplication2* a2 /Divisiona/b2 +Additiona+b3 -SubtractionA-b3 The parentheses () always have the highest precedence. If there are more than one parentheses () always start with the internal one. Then the next one and so on…. Finally do the external one. E.g. 1+2*3, (1+2)* 3 ? -3**2, (-3)**2 ? (((2+2)*3)/4)* 3 ? 7, 9 -9, 9 9
7
Relational Operator OperatorMeaningExample.LT. or <Less thanA < 1e-5.LE. or <=Less than or equalB**2.LE. 4*A*C. EQ. or ==EqualB**2 == 4*A*C. NE. or /=Not equalA=/ 0.GT. or >Greater thanB**2 - 4*A*C > 0.GE. or >=Greater than or equalX >= 0
8
Logical Operators E.g. (B**2 == 4*A*C).AND. (A /= 0) (A /= 0).Or. (B /= 0).Or. (C /= 0) We will see these later with logical IF statement. OperatorMeaningPrecedence.NOT.Logical negation1.AND.Logical intersection2. OR.Logical union3. EQV.Logical equivalence4. NEQV.Logical non- equivalence4
9
Exercise 1 Decided which of the following constants are not written in standard Fortran and state why not: (a)9,87 (b).0 (c) 25.82 (d) -356231 (e) 3.57*E2 (f) 3.57E2.1 (g) 3.57E+2 (h) 3,57E-2 Exercise 2 State, giving reason, which of the following are not Fortran variable names: (a)A2 (b) A.2 (c) 2A (d) ‘A’ONE (e) AONE (f) _X_1 (g) MixXedUp (h) U.S.S.R
10
References Hahn, B.D., 1994, Fortran 90 For Scientists and Engineers, Elsevier CH2 Ellis, T.M.R., 1990, Fortran 77 Programming with an introduction to Fortran 90 standard (2nd Ed.), Addison.Wesley Publishing Company http://www2.ph.ed.ac.uk/~playfer/f77_tut.html#intro السيد, ابوبكر احمد,1992, برمجة الحاسب بلغة الفوتران, جامعة الكويت, دار القلم للنشر والتوزيع
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.