ENGR2216 FORTRAN PROGRAMMING FOR ENGINEERS
Chapter 1 The computer CPU MEMORY INPUT/OUTPUT DEVICES DATA REPRESENTATION BINARY SYSTEM OCTAL & HEXADECIMAL DATA TYPES HISTORY OF FORTRAN EVOLUTION OF FORTRAN
Computers: are they important? Solving problems in any field Solving problems in any field Can you imagine a computer without software (programmes)? Can you imagine a computer without software (programmes)? Computer’s success is tied to programming Computer’s success is tied to programming
Where do we find computers? In a grocery store: scanners checking prices ATM (Automatic Teller Machines) Mobiles Microwave oven Cars Do you believe that the first electronic computer was invented about 60 years ago?
Basic Definitions A computer: A computer: is a special type of machine that stores information and can perform mathematical calculations on that information at speeds much faster than human beings can think. is a special type of machine that stores information and can perform mathematical calculations on that information at speeds much faster than human beings can think. A program: A program: tells the computer what sequence of calculations are required and on which information to perform the calculations. tells the computer what sequence of calculations are required and on which information to perform the calculations.
Examples of Programmes A computer at the bank stores customers’ information. Another programme can check each customer’s account daily. Once it goes below 100 Rials, the customer gets charged 1 Rial. Another programme can monitor the customers’ account, and send an sms message to the customers informing them that it’s time to take out their Zakat. Another program: when your phone’s battery becomes low, it gives you a warning: ”low battery”.
Computers vs. Human Are computers smarter than human? No, they only process programmes faster. They follow the instructions given in a programme. They can’t think on their own. They must be told what to do and when to do it A clever programme means a clever programmer
CPU = computer’s heart CPU = Control + ALU + memory Control: controls all PC parts ALU: performs calculations Memory: temporary storage of results during calculations Control: Interpret instructions Fetch data from input Send data from memory to output devices or main memory E.g. multiply 2 × 3 The computer
Main memory (e.g. RAM) Primary Volatile Semiconductor chip Very fast Fetch time 60 ns Expensive Store currently used programme Secondary memory (e.g. HDD) Non-volatile … explain! Higher capacity (80GB vs. 1GB) Slower Cheaper
The computer Input devices Purpose: enter data/information Examples: Keyboard Mouse Scanner Camera microphone Output devices Purpose: display results Examples: Monitors/ LCDs Printers Plotters speakers
The binary number system (725) 10 = 7 × × × 10 0 Used by human (101) 2 = 1 × × × 2 0 Used by computers Examples: Find the following: (111) 2 = (……) 10 (011) 2 = (……) 10 ( ) 2 = (……) 10 Byte = 8 bits How many possible values can we make with a 3-bit binary number? Hint: (000) to (111) HOW TO CONVERT FROM BASE 10 TO BASE 2? The 2 n rule.
Data representation in a computer What is a computer memory composed of ? Millions of ON/OFF switches How does a PC store data in memory? A switch is either ON (1) or OFF (0) A single switch can represent only 1 or 0. What does bit mean? BIT stands for Binary Digit A bit is either 1 or 0. 1 Byte = 8 bits representing a binary number E.g. memory of 256 MB (megabytes) = 256 million bytes E.g. hard disk drive with storage of 40 gigabytes = 40 billion bytes 1 word = 2, 4, (or more) consecutive bytes = 32, 64, bits How many possible values can we make with 1 byte? 2 8 = 256 possible values (-128 to 127)
Binary (2), Octal (8) and Hexadecimal (16) HexadecimalOctalBinaryDecimal A B C D E F
Types of Data stored in memory Each type needs a different amount of memory Character Data: UPPER CASE LETTERS (A-Z) = 26 Lower case letters (a – z) = 26 Digits (0 – 9) = 10 Symbols: “, ( ) [ ] ! # $ % ^ & *. Special letters or symbols (e.g. é ) Total number < 256 1 byte per character 1,000 characters need 1,000 bytes For non-English languages, more characters are used) Task: read text book for ASCII coding and EBCDIC coding Integer Data Real Data (floating point)
Types of Data stored in memory Each type needs a different amount of memory Character Data Integer Data: -ve integers, +ve integers, and zero Needs 1, 2, 4, or 8 bytes (differs from one computer type to another) In any computer that uses n-bit integer: Smallest integer = 2 n 1 Largest integer = 2 n 1 – 1(why 1?) What happens if a larger number is used? Task: read text book Error: Overflow condition Real Data (floating point)
Types of Data stored in memory Each type needs a different amount of memory Character Data Integer Data Real Data (floating point): Used for fractional numbers (e.g. 0.25) Used for very large or very small integers Value = mantissa × 2 exponent E.g. speed of light in decimal system = × 10 8 m/s Computers use base 2 system, with 32 bits (4 bytes) of computer memory: 24 bits for mantissa 8 bits for exponent Task: read text book Precision Range Round-off error
Computer Languages Machine language A program is a list of operations to be executed by a computer: E.g. load, store, add, subtract, etc. Each operation has a binary pattern (e.g. add = 1011) called op code The data associated with the op code are called operands A set of op codes is called machine language E.g. add 3, store A Machine language is very hard for human High level languages: Easy to write/understand List of instructions Convert to machine language using compilers and linkers Examples of high level programming languages: Basic C++ COBOL Fortran Java
FORTRAN Language Grandfather of all scientific computer languages FORmula TRANslation Translate formula into a computer code First FORTRAN: 1954 – 1957 By IBM for 704 computers
FORTRAN Language Grandfather of all scientific computer languages FORmula TRANslation Translate formula into a computer code First FORTRAN: 1954 By IBM for 704 computers Integers and real data types only No subroutines FORTRAN II: 1958 FORTRAN IV: 1962 (stayed for 15 Years) FORTRAN IV: 1966 (adopted as ANSI standard, and called FORTRAN 66 FORTRAN 77: 1977 (introduced IF statements, and simplified using characters) Fortran 90: 1992 Fortran 95: 1996 Text book covers both 90/95 Task: Read sections 1.4, and 1.5 of the text book