Introduction to FORTRAN-90 University of Liverpool course.

Slides:



Advertisements
Similar presentations
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Advertisements

IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
Fortran: Genel Bilgiler Dr. Mürtezaoğlu. ENF 102 Bilgisayar Programlama Dili Fortran 90.
17 March, 2000 CS1001 Lecture 2 Programming and problem solving Software engineering practices.
ME1107 Computing Y Yan
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Three types of computer languages
Program Design and Development
CSCE Syntax Details Fortran is not case sensitive; any use of capitals is for the programmer’s convenience. All programs are “wrapped” with PROGRAM.
Chapter 2 Basic Elements of Fortan
Introduction to a Programming Environment
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
FORTRAN PROGRAMMING BASICS MET 50. Programming Basics The basic layout of all programs is as follows (p.33) PROGRAM name = heading (i.e., title) Specifications.
Introduction to Programming (in C++) Introduction Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
CCSA 221 Programming in C CHAPTER 2 SOME FUNDAMENTALS 1 ALHANOUF ALAMR.
COMPUTER SCIENCE I C++ INTRODUCTION
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
High-Level Programming Languages: C++
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Simple Program Design Third Edition A Step-by-Step Approach
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
Fall, 2006Introduction to FORTRAN1 (2 + 2 = ???) Numbers, Arithmetic Nathan Friedman Fall, 2006.
Invitation to Computer Science, Java Version, Second Edition.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or directs the computer what to do. PROGRAMMING LANGUAGE.
TMF1013 : Introduction To Computing Lecture 1 : Fundamental of Computer ComputerFoudamentals.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 1- 1 October 20, October 20, 2015October 20, 2015October 20,
Fall, 2006Selection1 Choices, Choices, Choices! Selection in FORTRAN Nathan Friedman Fall, 2006.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
C++ Programming: Basic Elements of C++.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
Control Structures (A) Topics to cover here: Introduction to Control Structures in the algorithmic language Sequencing.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Introduction to programming Carl Smith National Certificate Year 2 – Unit 4.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Lecture III Start programming in Fortran Yi Lin Jan 11, 2007.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
Introduction to Computer Sciences References: [1] Fortran 95/2003 for Scientists and Engineers (3e) by Stephen J. Chapman. [2] Using Fortran 90 by Chester.
CHAPTER 1: INTRODUCTION C++ Programming. CS 241 Course URL: Text Book: C++ How to Program, DETITEL & DEITEL, eighth Edition.
The Hashemite University Computer Engineering Department
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Introduction to C++.  Computers: CPU, Memory & Input / Output (IO)  Program: Sequence of instructions for the computer.  Operating system: Program.
© Peter Andreae Java Programs COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
Introduction to Computer Programming using Fortran 77.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Software Engineering Algorithms, Compilers, & Lifecycle.
Low-Level Programming Languages, Pseudocode and Testing Chapter 6.
Topics Designing a Program Input, Processing, and Output
Chapter 1: Introduction to computers and C++ Programming
Variables, Expressions, and IO
Lecture 2 Introduction to Programming
Chapter 2 part #3 C++ Input / Output
Building Java Programs Chapter 2
Introduction to C++ Programming
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Chapter 2 part #3 C++ Input / Output
Unit 3: Variables in Java
Presentation transcript:

Introduction to FORTRAN-90 University of Liverpool course

Telling a Computer What To Do To get a computer to perform a specific task it must be given a sequence of unambiguous instructions or a program. An everyday example is instructions on how to assemble a bedside cabinet. The instructions must be followed precisely and in the correct order: 1. insert the spigot into hole `A', 2. apply glue along the edge of side panel, 3. press together side and top panels 4. attach toggle pin `B' to gromit `C' and so on

Programming Languages Programming languages must be: totally unambiguous (unlike natural languages, for example, English), expressive --- it must be fairly easy to program common tasks practical --- it must be an easy language for the compiler to translate simple to use. All programming languages have a very precise syntax (or grammar). This ensures all syntactically­correct programs have a single meaning.

High­level Programming Languages Assembler code is a Low­Level Language. Fortran 90, Fortran 77, ADA, C and Java are High­ Level Languages. a program is a series of instructions to the CPU, could write all programs in assembler code but this is a slow, complex and error­prone process high­level languages are more expressive, more secure and quicker to use the high­level program is compiled (translated) into assembler code by a compiler.

An Example Problem To convert from o F (Fahrenheit) to o C (Centigrade) we can use the following formula: C = 5 (F - 32) / 9 To convert from o C to K (Kelvin) we add 273. The program would accept a Fahrenheit temperature as input and produce the Centigrade and Kelvin equivalent as output.

An Example Program PROGRAM Temp_Conversion IMPLICIT NONE INTEGER :: Deg_F, Deg_C, K PRINT*, ''Please type in the temp in F'' READ*, Deg_F Deg_C = 5*(Deg_F ­ 32)/9 PRINT*, ''This is equal to'', Deg_C, ''C'' K = Deg_C PRINT*, ''and'', K, ''K'' END PROGRAM Temp_Conversion This program, called Temp.f90, can be compiled: f90 Temp.f90 and run: a.out

Analysis of Program The code is delimited by PROGRAM... END PROGRAM statements. Between these there are two distinct areas. Specification Part specifies named memory locations (variables) for use specifies the type of the variable, Execution Part reads in data calculates the temp in o C and K and prints out results.

Specification Part IMPLICIT NONE --- this should always be present. Means all variables must be declared. INTEGER :: Deg_F, Deg_C, K --- declares three INTEGER (whole number) variables. Other variable types: REAL --- real numbers, e.g., 3:1459, 0:31459, LOGICAL --- take values.TRUE. or.FALSE., CHARACTER --- contains single alphanumeric character, e.g., 'a', CHARACTER(LEN=12) --- contains 12 alphanumeric characters, a string, Fortran 90 is not case sensitive. K is the same as k and INTEGER is the same as integer.

Execution Part This is the part of the program that does the actual `work'. PRINT*, ''Please type in the temp in F'' --- writes string to screen, READ*, Deg_F --- reads a value from the keyboard and assigns it to the INTEGER variable Deg F, Deg_C = 5*(Deg_F­32)/9 --- the expression on the RHS is evaluated and assigned to the INTEGER variable Deg C * is the multiplication operator, ­ is the subtraction operator, / is the division operator, (takes longer than *) = is the assignment operator. PRINT*, ''This is equal to'', Deg_C, ''C'' --- displays a string on the screen followed by the value of a variable (Deg_C) followed by a second string (''C''). By default, input is from the keyboard and output to the screen.

How to Write a Computer Program There are 4 main steps: 1. specify the problem, 2. analyse and break down into a series of steps towards solution, 3. write the Fortran 90 code, 4. compile and run (i.e., test the program). It may be necessary to iterate between steps 3 and 4 in order to remove any mistakes. The testing phase is very important.

Compiling and running 1.Create a program using notepad with file extension.f90 – e.g. prog.f90 2.Compile by typing f90 prog.f90 3.Run by typing a.out (f90 by default creates an executable called a.out) 4.To give the executable a different name, use f90 –o name prog.f90. Then type name to run the program.

Free and Fixed format The original Fortran language used a so-called fixed format, where the first 5 columns were used for labels, column 6 for a continuation character and columns 7-72 for code. Such programs can be written with Fortran 90, but must have an extension.f. The default for Fortran 90 is free format, since there is far less need for labels in this language. Free format programs must have extension.f90 (more about this later)

PROGRAM QES IMPLICIT NONE INTEGER :: a, b, c, D REAL :: Real_Part, Imag_Part PRINT*, ''Type in values for a, b and c'' READ*, a, b, c IF (a /= 0) THEN ! Calculate discriminant D = b*b ­ 4*a*c IF (D == 0) THEN ! one root PRINT*, ''Root is '', ­b/(2.0*a) ELSE IF (D > 0) THEN ! real roots PRINT*, ''Roots are'',(­b+SQRT(REAL(D)))/(2.0*a),& ''and'', (­b­SQRT(REAL(D)))/(2.0*a) ELSE ! complex roots Real_Part = ­b/(2.0*a) ! D < 0 so must take SQRT of ­D Imag_Part = (SQRT(REAL(­D))/(2.0*a)) PRINT*, ''1st Root'', Real_Part, ''+'', Imag_Part, ''i'' PRINT*, ''2nd Root'', Real_Part, ''­'', Imag_Part, ''i'' END IF ELSE ! a = 0 PRINT*, ''Not a quadratic equation'' END IF END PROGRAM QES