engr2216 fortran programming for engineers

Download ENGR2216 FORTRAN PROGRAMMING FOR ENGINEERS

If you can't read please download the document

Upload: kaoru

Post on 10-Jan-2016

30 views

Category:

Documents


2 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

  • ENGR2216FORTRAN PROGRAMMING FOR ENGINEERS

  • Chapter 1The computerCPUMEMORYINPUT/OUTPUT DEVICESDATA REPRESENTATIONBINARY SYSTEMOCTAL & HEXADECIMALDATA TYPESHISTORY OF FORTRANEVOLUTION OF FORTRAN

  • Computers: are they important?Solving problems in any fieldCan you imagine a computer without software (programmes)?Computers success is tied to programming

  • Where do we find computers?In a grocery store: scanners checking pricesATM (Automatic Teller Machines)MobilesMicrowave ovenCarsDo you believe that the first electronic computer was invented about 60 years ago?

  • Basic Definitions

    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.A program:tells the computer what sequence of calculations are required and on which information to perform the calculations.

  • Examples of ProgrammesA computer at the bank stores customers information.Another programme can check each customers 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 its time to take out their Zakat.Another program: when your phones battery becomes low, it gives you a warning: low battery.

  • Computers vs. HumanAre computers smarter than human?No, they only process programmes faster.They follow the instructions given in a programme.They cant think on their own.They must be told what to do and when to do itA clever programme means a clever programmer

  • The computerCPU = computers heartCPU = Control + ALU + memoryControl: controls all PC partsALU: performs calculationsMemory: temporary storage of results during calculationsControl: Interpret instructionsFetch data from inputSend data from memory to output devices or main memoryE.g. multiply 2 3

    Main memory

    Secondary memory

    Input devices

    Output devices

    InternalMemory(registers)

    ArithmeticLogicunit

    Controlunit

    Central Processing Unit

  • The computerMain memory (e.g. RAM)PrimaryVolatileSemiconductor chipVery fastFetch time 60 nsExpensiveStore currently used programmeSecondary memory (e.g. HDD)Non-volatile explain!Higher capacity (80GB vs. 1GB)SlowerCheaper

    Main memory

    Secondary memory

    Input devices

    Output devices

    InternalMemory(registers)

    ArithmeticLogicunit

    Controlunit

    Central Processing Unit

  • The computerInput devices Purpose: enter data/informationExamples:KeyboardMouseScannerCameramicrophoneOutput devices Purpose: display resultsExamples:Monitors/ LCDsPrintersPlottersspeakers

    Main memory

    Secondary memory

    Input devices

    Output devices

    InternalMemory(registers)

    ArithmeticLogicunit

    Controlunit

    Central Processing Unit

  • The binary number system(725)10 = 7 102 + 2 101 + 5 100Used by human

    (101)2 = 1 22 + 0 21 + 1 20Used by computers

    Examples:Find the following:(111)2 = ()10(011)2 = ()10(00001110)2 = ()10Byte = 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 2n rule.

  • Data representation in a computerWhat is a computer memory composed of ?Millions of ON/OFF switchesHow 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 DigitA bit is either 1 or 0.1 Byte = 8 bits representing a binary numberE.g. memory of 256 MB (megabytes) = 256 million bytesE.g. hard disk drive with storage of 40 gigabytes = 40 billion bytes1 word = 2, 4, (or more) consecutive bytes = 32, 64, bitsHow many possible values can we make with 1 byte?28 = 256 possible values (-128 to 127)

  • Binary (2), Octal (8) and Hexadecimal (16)

  • Types of Data stored in memoryEach type needs a different amount of memoryCharacter Data:UPPER CASE LETTERS (A-Z) = 26Lower case letters (a z) = 26Digits (0 9) = 10Symbols: , ( ) [ ] ! ~ @ # $ % ^ & * .Special letters or symbols (e.g. )Total number < 256 1 byte per character1,000 characters need 1,000 bytesFor non-English languages, more characters are used)Task: read text book for ASCII coding and EBCDIC coding

    Integer DataReal Data (floating point)

  • Types of Data stored in memoryEach type needs a different amount of memoryCharacter DataInteger Data:-ve integers, +ve integers, and zeroNeeds 1, 2, 4, or 8 bytes (differs from one computer type to another)In any computer that uses n-bit integer:Smallest integer = -2n-1Largest integer = 2n-1 1(why -1?)What happens if a larger number is used?Task: read text bookError: Overflow condition Real Data (floating point)

  • Types of Data stored in memoryEach type needs a different amount of memoryCharacter DataInteger DataReal Data (floating point):Used for fractional numbers (e.g. 0.25)Used for very large or very small integersValue = mantissa 2exponentE.g. speed of light in decimal system = 2.998 108 m/sComputers use base 2 system, with 32 bits (4 bytes) of computer memory:24 bits for mantissa8 bits for exponentTask: read text bookPrecisionRangeRound-off error

  • Computer LanguagesMachine languageA 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 codeThe data associated with the op code are called operandsA set of op codes is called machine languageE.g. add 3,41011 0011 0100 store A 0101 0000 1010Machine language is very hard for humanHigh level languages:Easy to write/understandList of instructionsConvert to machine language using compilers and linkersExamples of high level programming languages:BasicC++COBOLFortranJava

  • FORTRAN LanguageGrandfather of all scientific computer languagesFORmula TRANslationTranslate formula into a computer codeFirst FORTRAN: 1954 1957 By IBM for 704 computers

  • FORTRAN LanguageGrandfather of all scientific computer languagesFORmula TRANslationTranslate formula into a computer codeFirst FORTRAN: 1954 By IBM for 704 computersIntegers and real data types onlyNo subroutinesFORTRAN II: 1958FORTRAN IV: 1962 (stayed for 15 Years)FORTRAN IV: 1966 (adopted as ANSI standard, and called FORTRAN 66FORTRAN 77: 1977 (introduced IF statements, and simplified using characters)Fortran 90: 1992 Fortran 95: 1996Text book covers both 90/95Task:Read sections 1.4, and 1.5 of the text book