?? : ??? ????401A 3366-3062 - PowerPoint PPT Presentation

1 / 38
About This Presentation
Title:

?? : ??? ????401A 3366-3062

Description:

mantissa. exponent. The real numbers in a computer are similar to the scien ... puter memory, divided into two components: a 24-bit. mantissa and an 8-bit exponent. ... – PowerPoint PPT presentation

Number of Views:15
Avg rating:3.0/5.0
Slides: 39
Provided by: yjsh
Category:
Tags: 401a | mantissa

less

Transcript and Presenter's Notes

Title: ?? : ??? ????401A 3366-3062


1
? ? ? ? ?
???? ??? ?? ??? ????401A 3366-3062 ????
1. Fortran 90/95 for Scientists and Engineers
Stephen J. Chapman 2. Fortran 90 for Engineers
and Scientists Larry R. Nyhoff and Sanford C.
Leestma 3. Fortran 90 Programming T. M.
Ellis Ivor R. Philips and Thomas M. Lahey
2
Chapter 1
Introduction to Computers and the Fortran
Language
3
  • The computer is the most important invention of
    the 20th
  • century. It affects our lives profoundly in very
    many ways.
  • Computers control our telephone and electric
    power
  • systems, run our microwave ovens and other
    appliances,
  • and even control the engines in our cars. Almost
    any
  • business in the developed world would collapse
    over-
  • night if it were suddenly deprived of its
    computers.
  • Considering their importance in our lives, it is
    almost im-
  • possible to believe that the first electronic
    computers
  • were invented just over 50 to 60 years ago.

4
  • A computer is a special type of machine that
    stores
  • information and performs mathematical
    calculations
  • on that information at speeds much faster than
    human
  • beings can think.
  • A program, which stored in the computers memory,
  • tells the computer what sequence of calculations
    are
  • required and which information to perform the
    calcu-
  • lations on.
  • Users mean that people who use computers to
    accom-
  • plish certain tasks and programmers indicate
    people
  • who program computers so that things can be done
    by
  • the users.

5
  • It is important to realize that computers do not
    think as
  • we understand thinking they merely follow the
    steps
  • contained in their programs.
  • When a computer appears to be doing something
    clever,
  • it is because a clever person has written the
    program that
  • it is executing.
  • The collective creativity of humans allows the
    computer
  • to perform its miracles.
  • This class will help you learn how to write
    programs of
  • your own so the computer will do what you want
    it to do.

6
The Computer
The major components of the computer are the
central processing unit (CPU), main memory,
secondary memory, and input and output devices.
7
A block diagram of a typical computer
8
The CPU
  • The central processing unit is the heart of any
    computer.
  • It is divided into a control unit, an
    arithmetic-logic unit
  • (ALU), and internal memory.
  • The control unit within the CPU controls all the
    other
  • parts of the computer, and the ALU performs the
    actual
  • mathematical calculations.
  • The internal memory within a CPU consists of a
    series
  • of memory registers used for the temporary
    storage of
  • intermediate results during calculations.

9
  • The control unit of the CPU interprets the
    instructions of
  • the computer program. It also fetches data
    values from
  • input devices or main memory, stores them in the
    me-
  • mory registers, and sends data values from
    memory
  • registers to output devices or main memory.
  • For example, if a program says to multiply two
    numbers
  • together and save the result, the control unit
    will fetch
  • the two numbers from main memory and store them
    in
  • registers. Then it will present the numbers in
    the regis-
  • ters to the ALU along with directions to
    multiply them
  • and store the results in another register.
    Finally, after the
  • ALU multiplies the numbers, the control unit
    will take the
  • result from the destination register and store
    it back into
  • main memory.

10
Main and Secondary Memory
  • A computer has two major types of memory main or
  • primary memory, and secondary memory.
  • Main memory usually consists of semiconductor
    chips.
  • It is very fast and relatively expensive. Data
    that is stored
  • in main memory can be fetched for use in 100
    nanose-
  • conds or less on a modern computer.
  • Because it is so fast, main memory is used to
    temporarily
  • store the program currently being executed by
    the com-
  • puter, as well as the data that the program
    requires.

11
  • Main memory is not used for the permanent storage
    of
  • programs or data. Most main memory is volatile,
    meaning
  • that it is erased whenever the computers power
    is turned
  • off.
  • Secondary memory consists of devices that are
    slower
  • and less expensive than main memory. They can
    store
  • much more information for much less money than
    main
  • memory can.
  • Most secondary memory devices are nonvolatile.
    They
  • retain the programs and data stored in them
    whenever
  • the computers power is turned off.

12
  • Typical secondary memory devices are hard disks,
  • floppy disks, and tape drives.
  • Secondry storage devices are normally used to
  • store programs and data that are not needed at
    the
  • moment, but which may be needed some time in
  • the future.

13
Input and Output Devices
  • Data is entered into a computer through an input
    device
  • and is output through an output device.
  • The input devices are keyboards, scanners, and
    micro-
  • phones, .
  • Output devices permit us to use the data stored
    in a
  • computer. The output devices are monitors,
    printers,
  • plotters and speakers, etc.

14
Data Representation in a Computer
  • Computer memories are composed of millions of
    indivi-
  • dual switches, each of which can be ON or OFF,
    but not
  • at a state in between.
  • Each switch represents one binary digit (also
    called a bit)
  • the ON state is interpreted as a binary 1, and
    the OFF
  • state is interpreted as a binary 0.
  • A single switch can represent only the numbers 0
    and 1.
  • Since we obviously need to work with numbers
    other than
  • 0 and 1, a number of bits are grouped together
    to repre-
  • sent each number used in a computer.

15
  • When several bits are grouped together, they can
    be
  • used to represent numbers in the binary (base 2)
  • number system.
  • The smallest common grouping of bits is called a
    byte.
  • A byte is a group of 8 bits that are used
    together to re-
  • present a binary number.
  • The byte is the fundamental unit used to measure
    the
  • capacity of a computers memory.
  • The next larger grouping of bits in a computer is
    a word.
  • A word consists of 2, 4 or more consecutive
    bytes that
  • are used to represent a single number in memory.
    The
  • size of a word varies from computer to computer.

16
The Binary Number System
In the familiar base 10 number system, the
number 12210 is
In the binary number system
17
Note that three binary digits can be used to
represent 8 possible values 0 (0002) to 7
(1112). In general, if n bits are grouped
together to form a binary number, then they can
represent 2n possible values.
Typically, half of all possible values are
reserved for re- presenting negative numbers,
and half of the values are reserved for
representing positive numbers.
18
Computer Languages
  • When a computer executes a program, it executes a
  • string of very simple operations such as load,
    store, add,
  • substract, and multiply.
  • Each operation has a unique binary pattern called
    an
  • operation code (op code) to specify it.
  • The program that a computer executes is just a
    string of
  • op codes ( and the data associated with the op
    codes) in
  • the order necessary to achieve a purpose.
  • Op codes are collectively called machine
    language,
  • since they are the actual language that a
    computer
  • recognizes and executes.

19
  • Unfortunately, we humans find machine language
    very
  • hard to work with.
  • We prefer to work with English-like statements
    and alge-
  • braic equations that are expressed in forms
    familiar to us,
  • instead of arbitrary patterns of zeros and ones.
  • We like to program computers with high-level
    languages.
  • We write out our instructions in a high-level
    language and
  • then use special programs called compilers and
    linkers
  • to convert the instructions into the machine
    language that
  • the computer understands.

20
  • Programmers use many different high-level
    languages,
  • with different characteristics.
  • Some of them are designed to work well for
    business
  • problems, while others are designed for general
    scientific
  • use. Still others are especially suited for
    applications like
  • operating-systems programming.
  • It is important to pick a proper language to
    match the pro-
  • blem that you are trying to solve.
  • Some of the high-level computer languages in use
    today
  • are Basic, C, COBOL, Fortran and Pascal.

21
  • Fortran is the preeminent language for general
    scientific
  • computers.
  • It has been around in one form or another for
    more than
  • 50 years and has been used to implement
    everything
  • from computer models of nuclear power plants to
    aircraft
  • design programs etc.
  • The language is especially useful for numerical
    analysis
  • and technical calculations.
  • In addition, Fortran is the dominant language in
    the world
  • of supercomputers and massively parallel
    computers.

22
A Brief History of Fortran
  • One of the first high-level languages to gain
    widespread
  • acceptance was FORTRAN (FORmula TRANslation),
  • which was developed for the IBM 704 computer by
    John
  • Backus and a team of 13 other programmers at IBM
    over
  • a 3-year period (1954-1957).
  • In the years that followed, other computer
    manufacturers
  • developed FORTRAN compilers for their machines.
  • Several of these provided extensions and
    variations of
  • FORTRAN that were specific to their particular
    computers.

23
  • Programs written for one machine could not be
    used on a
  • different machine without modification.
  • Over time, users developed large collections of
    FORTRAN
  • programs, and the cost of converting all these
    programs
  • whenever a new computer was installed became
    prohibi-
  • tive.
  • To remedy these problems, efforts were made to
    standize
  • FORTRAN so that programs were portable, which
    means
  • they can be processed on several different
    machines with
  • little or no alteration.
  • One of the earliest standard versions appeared in
    1966,
  • and in 1977 another revision appeared, known as
  • FORTRAN 77.

24
  • While the changes introduced in FORTRAN 77 were
  • significant, it did not solve all of the
    problems in earlier
  • versions, nor did it include many of the new
    features
  • that were appearing in newer programming
    languages.
  • Consequently, work began almost immediately on a
  • new standard version in 1991, an extensive
    revision
  • known as Fortran 90 appeared, and compilers to
    support
  • this new version of Fortran have been developed.
  • The American National Standards Institute (ANSI),
    which
  • establishes standards for programming languages,
  • decided that during the transition period there
    should be
  • two American standards for Fortran, FORTRAN 77
    and
  • Fortran 90.

25
  • However, International Standards Organization
    (ISO)
  • groups decided that Fortran 90 will be the only
    inter-
  • national Fortran standard.
  • Fortran 90 has standardized earlier versions and
  • provides a base from which newer versions of the
    lan-
  • guage will be developed.
  • In fact, another ANSI committee is already at
    work
  • preparing a new version that will make it
    possible to
  • design Fortran programs that will execute
    efficiently on
  • massively parallel computers and that
    incorporate
  • modern programming techniques such as object-
  • oriented programming.

26
Programming with FORTRAN
  • FORTRAN a combination of the words FORmula
  • TRANslator
  • (1) high-level
  • (2) English-like language
  • (3) Engineering-oriented
  • It is very easy to read and understand a Fortran
  • program.

27
An example program example ! This program
is to calculate the summation ! and average of
two variables, a and b. real a, b, sum,
avg read (,) a, b sum ab avg
(ab)/2. write(,) a, b, sum, avg end
program example
28
Program Format
  • Earlier versions of FORTRAN have rather strict
    rules
  • about where statements and comments can be
    placed.
  • However, Fortran 90 allows considerably more
    flexibility
  • in the program format.
  • The main rules that must be followed are
  • (1)A line may have a maximum of 132 characters.
  • (2)A line may contain more than one statement,
    provided
  • the statements are separated by semicolons
    ().
  • program example
  • real a,b,sum,avg read , a,b
  • sumab avg(ab)/2.0 print ,a,b,sum,avg
  • end program example

29
(3)An ampersand () must be placed at the end of
each line that is to be continued to the next
line. At most 39 continuation lines are
permitted. For example
avg (ab)/2. ???
avg
(ab)/2. ??
avg
(ab) /2.
30
(4)Any characters following an exclamation (!)
and running to the end of the line form a
comment. program example ! This program
is to calculate the summation ! and average
of two variables, a and b. real
a,b,sum,avg read , a,b sumab
avg(ab)/2. print , a,b,sum,avg end
program example
  • Comments may also be attached to statements.
  • sumab ! Calculate the summation of a and b

31
(5)If a statement requires a statement label,
this label must precede the statement and be
separated from it by at least one blank.
Statement labels must be integers in the
range 1 to 99999. .
. goto 1000 .
. 1000 sumab
avg(ab)/2. . .
32
Types of Data Stored in Memory
  • Three common types of data are stored in a
    computers
  • memory character data, integer data, and real
    data.
  • Each type of data has different characteristics
    and takes
  • up a different amount of memory in the computer.

Character data
  • The character data type consists of characters
    and
  • symbols. A typical system for representing
    character
  • data in a non-Oriental language must include the
  • following symbols

33
  • The 26 uppercase letters A through Z.
  • The 26 lowercase a through z.
  • The 10 digits 0 through 9.
  • Miscellaneous common symbols, such as ,()
  • !_at_
  • Any special letters or symbols required by the
  • language, such as áçñ?.

Since the total number of characters and symbols
required to write non-Oriental languages is less
than 256, it is cus- tomary to use 1 byte of
memory to store each character.
34
Integer data
  • The integer data type consists of the positive
    integers,
  • the negative integers, and zero. The amount of
    memory
  • devoted to storing an integer will vary from
    computer to
  • computer, but it will usually be 1, 2, 4, or 8
    bytes. The
  • most common type of integers in modern computers
  • are 4-byte integers.
  • Since a finite number of bits are used to store
    each
  • value, only integers that fall within a certain
    range can
  • be represented on a computer.

35
  • Usually, the smallest number and the largest
    number
  • that can be stored in an n-bit integer is
  • For a 4-byte integer, the smallest and largest
    possible
  • value are -2,147,483,648 and 2,147,483,647,
    respec-
  • tively.
  • Attempts to use an integer larger than the
    largest possi-
  • ble value or smaller than the smallest possible
    value
  • result in an error called an overflow condition.

36
Real data
  • The integer type has two fundamental limitations
  • It is not possible to represent numbers with
    fractional
  • parts(0.25, 1.5, 3.14159 etc) as integer
    data.
  • 2. There are not enough bits available to
    represent
  • integers or very small negative integers.
  • To get around these limitations, computers
    include a
  • real or floating-point data type.
  • The real data type stores numbers in a type of
    scien-
  • tific notation.

37
  • We all know that very large or very small numbers
    can
  • be most conveniently written in scientific
    notation.
  • For example, the speed of light in a vacuum is
    about
  • 299,800,000 meters per second. This number is
    easier
  • to work with in scientific notation

exponent
mantissa
38
  • The real numbers in a computer are similar to the
    scien-
  • tific notation above except that a computer
    works in the
  • base 2 system instead of in the base 10 system.
  • Real numbers usually occupy 32 bits (4 bytes) of
    com-
  • puter memory, divided into two components a
    24-bit
  • mantissa and an 8-bit exponent.
Write a Comment
User Comments (0)
About PowerShow.com