Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 320 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
320
Dung lượng
838,5 KB
Nội dung
Fortran 95-2003 for Scientists and Engineers Transparencies prepared by Anthony T. Chronopoulos CHAPTER 1 CS1073 Chapter 1 Intro. to Computers and the Fortran Language The Computer In summary, the major components of the computer are: CPU Main Memory Secondary Memory Input Devices (e.g. keyboard, tapes etc) Output Devices (e.g. display, monitor, tapes etc). Chapter 1 Intro. to Computers and the Fortran Language The CPU The Central Processing Unit is "heart“ (or better “brain”) of a computer. The CPU consists of three main parts: The Control Unit - coordinates activities of the computer The Arithmetic Logic Unit (ALU) - performs the calculations Registers - store a small amount of data and instructions Chapter 1 Intro. to Computers and the Fortran Language • Main Memory (RAM) It is larger than the Registers and smaller than the hard drive. It temporarily stores the program currently being run by the computer and also the data required by the programs. RAM is volatile, i.e. when power is interrupted, then what was stored in RAM is lost. Chapter 1 Intro. to Computers and the Fortran Language Secondary Memory It is a permanent (non-volatile) storage. The hard drive is the best example, but also USB, CDs, tapes, etc. The size of hard drives is larger than that of RAM. However, accessing data stored on a hard drive (or other secondary memory) takes much longer (5-10 times) than from RAM. Chapter 1 Intro. to Computers and the Fortran Language Computer Languages Each computer has its own machine language (Assembly) used to execute very basic operations. Operations are: load and store (data, to and from memory), and add, subtract, multiply, or divide. The problem with a machine language is that it is very difficult to program and use, and also it can be unique for a computer. Chapter 1 Intro. to Computers and the Fortran Language Thus, computer scientists design high-level language that are easy to program and use. The programs must be converted to a machine-language (by compilers and linkers) for the computer to run them. Examples are Fortran, C, C++, Java etc. The benefit of a high-level language (e.g. Fortran) is that a program and can be compiled on any machine that has a Fortran compiler. Chapter 1 Intro. to Computers and the Fortran Language Data Representation in a Computer Data is represented by millions of switches, each of which can be either ON (1) or OFF (0). 0 and 1 are the two binary digits (bits). We use a combination of 0's and 1's to represent the other numbers (and characters as well).The smallest common combination of bits (0's and 1's) is called a byte. A byte is a group of 8 bits. A word is a group of 2, 4, or 8 bytes. Our PCs have 4-byte words. Chapter 1 Intro. to Computers and the Fortran Language • The Binary Number System The number system used by humans is the decimal system. The decimal system is a base=10 system. There are 10 digits (0-9). Each digit in a number represents a power of 10. The number 221 is: 2 * 10^2+ 2 * 10^1 + 1 * 10^0 (where 10^i is 10 raised to exponent i =0,1,2, ). [...]... the largest and smallest numbers that can be represented The number of bits in the exponent e.g 1-byte exponent (with the 3-byte mantissa) allows a range of approximately 10^-38 to 10^38 (i.e [10^-38 , 10^38] ) Chapter 1 Intro to Computers and the Fortran Language Evolution of Fortran: Fortran I: Fig 1-5 Fortran 77: Fig 1-6 Fortran 90 /2003: Fig 1-7 Chapter 1 Intro to Computers and the Fortran Language... very important To comment in FORTRAN, one uses the exclamation point (!) All comments after the ! are ignored by the compiler Chapter 2: Basic Elements of Fortran One can use labels in some statements A label can be any number between 1 and 99999 Statement labels are less common in modern FORTRAN Chapter 2: Basic Elements of Fortran 2.4 Structure of a FORTRAN Program A FORTRAN program can be divided... handed in) Page 12 , Quiz 1 (answers are on the back): 1(a),2(a),6,7 CS1073 CHAPTER 2 Chapter 2: Basic Elements of Fortran 2.2 The Fortran Character Set (Table 2-1) The following are valid in a Fortran 90 /95 program: alpha-numeric: a-z, A-Z, 0-9, and _ (the underscore); arithmetic symbols: +, -, *, /, ** miscellaneous symbols: e.g , comma decimal point < etc less than Chapter 2: Basic Elements of Fortran. .. Computers and the Fortran Language • • Two other number systems that are also useful are octal (base 8) and hexadecimal (base 16) Table 1-1 shows the conversion between these systems for the decimals: 0,1, …,15 Chapter 1 Intro to Computers and the Fortran Language Types of Data Three common types of data are stored in a computer's memory: character, integer, real Each type has unique characteristics and. .. integers Chapter 1 Intro to Computers and the Fortran Language Real Data The real data type stores numbers in a format similar to scientific notation For example, the speed of light in a vacuum is about 299,800,000 meters per second The number in scientific notation would be 2.998 * 10^8 (m/s) meters per second Chapter 1 Intro to Computers and the Fortran Language A format similar to scientific notation... 0.1 and 1.0, called the mantissa, which is multiplied or divided by 10 a certain number of times, where this number is called the exponent e.g 17877.0 (in fraction, base=10 form): 0.17877x10^5 a ×10b exponent mantissa The same technique as was used for integers to distinguish positive and negative numbers will be used for both the mantissa and the exponent Chapter 1 Intro to Computers and the Fortran. .. a different amount of memory Chapter 1 Intro to Computers and the Fortran Language Character Data A typical system for representing character data may include the following: Letters: A through Z and a through z Digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) Miscellaneous symbols, e.g (", ', ?, , , =, %, &) Chapter 1 Intro to Computers and the Fortran Language • • In the past, it has been common to use... Chapter 1 Intro to Computers and the Fortran Language Integer Data Integer data ( e.g -1, -355, 0, 1993) are represented exactly on computers However, only a finite number can be stored Most machines will use 4 bytes of memory to represent integers Smallest n-bit integer: -2^(n-1) Largest n-bit integer: 2^(n-1) - 1 e.g n=32 for 4-byte numbers Chapter 1 Intro to Computers and the Fortran Language With 4... Computers and the Fortran Language Similarly, converting a number from binary (base 2) to decimal (base 10) The number 101: 1 * 2^2+ 0 * 2^1 + 1 * 2^0 = 4 +0+ 1 = 5 If n bits are available, then those bits can represent 2^n possible values e.g One byte (n=8 bits) can represent 256 possible values Two bytes (n=16 bits) can represent 65,536 possible values Chapter 1 Intro to Computers and the Fortran. .. of a FORTRAN Statement A program consists of a series of statements designed to accomplish the goal to be accomplished There are two basic types of statements: Executable statements describe the actions taken by the program (additions, subtractions, multiplications, divisions) Non-executable statements provide information necessary for proper operation of the program Chapter 2: Basic Elements of Fortran . Fortran 95- 2003 for Scientists and Engineers Transparencies prepared by Anthony T. Chronopoulos CHAPTER 1 CS1073 Chapter 1 Intro. to Computers and the Fortran Language The. linkers) for the computer to run them. Examples are Fortran, C, C++, Java etc. The benefit of a high-level language (e.g. Fortran) is that a program and can be compiled on any machine that has a Fortran. Computers and the Fortran Language Thus, computer scientists design high-level language that are easy to program and use. The programs must be converted to a machine-language (by compilers and linkers)