Post on 16-May-2018
What is Programming
What is Programming?
It is a means for instructing a SOMEONE to perform Tasks
May 8, 2012 3 ChE 208 Lecture 1 Mohammad Mazharul Islam
What is Computer Programming
Computer Programming is instructing a computer to do something for you
Computer programming is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. The purpose of programming is to create a program that exhibits a certain desired behavior. It is often shortened to PROGRAMMING or CODING
May 8, 2012 4 ChE 208 Lecture 1 Mohammad Mazharul Islam
Why do Chemical Engineers Need Computer Programming
The increased use of personal computers by engineers has greatly revolutionized and expedited the design of process plants and equipment in the chemical process industries. In addition, the availability of expensive flowsheeting packages has reduced to some extent the requirement of programming languages. However, situations often occur where either a package is not readily available, too expensive, or of a limited scope, and the design problem lies beyond the boundary of the flowsheeting packages. The designer is often required to review other alternatives or develop his or her own specific program for the application.
May 8, 2012 5 ChE 208 Lecture 1 Mohammad Mazharul Islam
Components of a modern computer
May 8, 2012 7 ChE 208 Lecture 1 Mohammad Mazharul Islam
CPU = Central Processing Unit
Control Unit Arithmetic logic unit
Main Memory
Input Devices
Output Devices
External Memory
Internal Data Representation and Storage
Only the two binary digits 0 and 1 are used for any kind of data storage within a computer
Memory unit required to store a digit is called bit
8 bit = 1Byte (The BIG “B”)
May 8, 2012 8 ChE 208 Lecture 1 Mohammad Mazharul Islam
Decimal Number System
May 8, 2012 9 ChE 208 Lecture 1 Mohammad Mazharul Islam
• Decimal or 10-base system: 0 1 2 3 4 5 6 7 8 9
•Any number in this system can be written in expanded form as: where, an is the multiplying factor and n is the exponent term
•For example: 48510 = 4×102+8×101+5×100
∑ × nia 10
Binary Number System
May 8, 2012 10 ChE 208 Lecture 1 Mohammad Mazharul Islam
•Binary system has only two digits: 0 and 1
•Binary to decimal conversion:
1012=1×22+0×21+1×20=510
•Real numbers Conversion:
6.62510 =1×22+1×21+0×20+1×2-1+0×2-2+1×2-3
So 6.62510 =101.1012
Storing Numbers in Memory: Integers
Positive integers are represented in the binary form, with the leftmost bit set to 0 The representation of a negative integer –n is obtained by first finding the binary representation of n, complementing it (changing each 0 to 1 and 1 to 0), and then adding 1 to the result. This method is known as Ones’ Complement method.
May 8, 2012 11 ChE 208 Lecture 1 Mohammad Mazharul Islam
31-bit field Sign bit: 0 for positive 1 for negative
Storing Numbers in Memory: Integers
May 8, 2012 12 ChE 208 Lecture 1 Mohammad Mazharul Islam
Storing -58:
Representation of 58:
00000000000000000000000000111010
Complement of this bit string:
11111111111111111111111111000101
Add 1:
11111111111111111111111111000110
Storing Numbers in Memory: Real Numbers
May 8, 2012 13 ChE 208 Lecture 1 Mohammad Mazharul Islam
24-bit field: Fraction
Sign bit: 0 for positive 1 for negative
7-bit field: Exponent
Computer Programs
A computer program is a step-by-step list of instructions written for a computer in it’s own kind of language
BUT A computer only understands 0 and 1
May 8, 2012 14 ChE 208 Lecture 1 Mohammad Mazharul Islam
Computer Programs: Machine Languages
The basic instructions to a computer are composed of a sequence of 1 and 0, that the computer follows as it runs them through the processor In the beginning, programs looked like “…….10101001……110101………011111010……101010101………“
These coding languages were called Machine Languages
•Directly understandable by the computer •Tedious •Erroneous •Time-consuming
May 8, 2012 15 ChE 208 Lecture 1 Mohammad Mazharul Islam
Computer Programs: Assembly Languages
May 8, 2012 16 ChE 208 Lecture 1 Mohammad Mazharul Islam
•To overcome these problems, American mathematician Grace Murray Hopper developed Assembly Language in 1952 •Assembly language uses easy to remember terms—such as SUB for a subtraction operation, and MPY for a multiplication operation •Example:
MOV AL, 61h ; Load AL with 97 decimal (61 hex)
•much easier •must be translated into machine code before it can be understood and run by the computer. •Special utility programs called assemblers needed •Still not fully useful to humans
Computer Programs: High-Level Languages
Then someone decided, why don't we make a program that will translate English-like words into assembly language, so we can write code in English? Now the programmer can write code like “x = 5 + 8;” or, print*,’good morning’;
This new way enabled writing more complex code, as it was now more readable and easy to program These are called High-level Languages
•Very easy to understand and write by humans •Needs a compiler or debugger or assembler to transform the code to machine language
May 8, 2012 17 ChE 208 Lecture 1 Mohammad Mazharul Islam
Computer Programs: High-Level Languages
Some High-level Languages
May 8, 2012 19 ChE 208 Lecture 1 Mohammad Mazharul Islam
A useful computer language
A useful computer language is: • ‘easy’ for a human to understand • ‘easy’ for a compiler to convert to the obscure machine instructions
Of course one may argue about what the word ‘easy’ above means.
May 8, 2012 20 ChE 208 Lecture 1 Mohammad Mazharul Islam
FORmula TRANslation
ForTran (Formula Translation) is a general-purpose, procedural, imperative programming language that is especially suited to numeric and scientific computing. Originally developed by IBM in the 1950s for scientific and engineering applications, Fortran came to dominate the area of programming for over half a century in computationally intensive areas such as numerical weather prediction, finite element analysis, computational fluid dynamics, computational physics and computational chemistry.
May 8, 2012 21 ChE 208 Lecture 1 Mohammad Mazharul Islam
History of ForTran
ForTran was originally developed by IBM in the late 1950’s. The first official standard was published by ANSI in 1966, followed by significant revisions in 1977. The next standard, published in 1990, represented a more dramatic change, and that published in 1995 a very minor set of changes. In 2003 and 2007, ForTran released new versions supporting object-oriented and more complex scripting features. To learn more about ForTran’s history, click:
http://en.wikipedia.org/wiki/Fortran
May 8, 2012 22 ChE 208 Lecture 1 Mohammad Mazharul Islam
Why ForTran?
ForTran’s historic advantage is its simplicity: easy for humans to learn, easy for compilers to translate into the optimal sequence of instructions for a computer to execute. On some machines, the same algorithm written in Fortran would typically run ten to twenty times faster than that written in C. It is the most popular language in the area of high-performance computing and is used for programs that benchmark and rank the world's fastest supercomputers.
May 8, 2012 23 ChE 208 Lecture 1 Mohammad Mazharul Islam
Why ForTran?
SUMMARY OF FORTRAN ADVANTAGES
a) Scientifically oriented b) Better optimized code c) A lot of existing code d) Easier to learn e) More efficient mathematics f) Easier to use and more robust g) Better diagnostics
May 8, 2012 24 ChE 208 Lecture 1 Mohammad Mazharul Islam
Cons
Not being a general-purpose language, there are some things Fortran is very bad at. Anyone trying to write a compiler or operating system in Fortran is probably mad or about to become mad. Fortran is not suitable for highly graphical program output For more visit http://www.ibiblio.org/pub/languages/fortran/ch1-2.html
May 8, 2012 25 ChE 208 Lecture 1 Mohammad Mazharul Islam
Software and References
We will use Silverfrost ftn95 Personal Edition as the ForTran Compiler, which can be downloaded form the following link:
http://www.silverfrost.com/11/ftn95/ftn95_fortran_95_for_windows.aspx
Reference Books: 1. Introduction to ForTran 90 for Scientists and Engineers, Brian D Hahn, Department of Applied Mathematics, University of Cape Town, 1993 2. LF Fortran 95 Language Reference, Lahey Computer Systems, Inc., 3. FORTRAN 95, Martin Counihan, University of Southampton 4. An Introduction to Programming in ForTran 90, University of Durham Information Technology Service, 2007 5. List of numerous ForTran resources on the web
May 8, 2012 26 ChE 208 Lecture 1 Mohammad Mazharul Islam