Introduction to FORTRAN

Slides:



Advertisements
Similar presentations
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Advertisements

Introduction to Programming in C++ John Galletly.
879 CISC Parallel Computation High Performance Fortran (HPF) Ibrahim Halil Saruhan Although the [Fortran] group broke new ground …
Fortran Jordan Martin Steven Devine. Background Developed by IBM in the 1950s Designed for use in scientific and engineering fields Originally written.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
CS 415: Programming Languages Algol Aaron Bloomfield Fall 2005.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
1 CS 161 Introduction to Programming and Problem Solving Chapter 9 C++ Program Components Herbert G. Mayer, PSU Status 10/20/2014.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
ICE1341 Programming Languages Spring 2005 Lecture #14 Lecture #14 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Introduction to Fortran Fortran Evolution Drawbacks of FORTRAN 77 Fortran 90 New features Advantages of Additions.
Chapter 2 Basic Elements of Fortan
Fortran 9x HTML version. New F90 features Free source form Modules User-defined data types and operators Generic user-defined procedures Interface blocks.
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
VB in Context Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh Pittsburgh, Pa 15260
Guide To UNIX Using Linux Third Edition
Chapter 2 - Java Programming Fundamentals1 Chapter 2 Java Programming Fundamentals.
Guide To UNIX Using Linux Third Edition
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Basic Elements of C++ Chapter 2.
Fortran- Subprograms Chapters 6, 7 in your Fortran book.
CS102 Introduction to Computer Programming
Introduction to FORTRAN-90 University of Liverpool course.
Presented by: Destry Diefenbach
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Fortran: Specification Statements Session Six ICoCSIS.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
 Pearson Education, Inc. All rights reserved Formatted Output.
April 14, ICE 1341 – Programming Languages (Lecture #13) In-Young Ko Programming Languages (ICE 1341) Lecture #13 Programming Languages (ICE 1341)
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
FORTRAN FORmula TRANslator -Anand Trivedi. HISTORY  Designed and written from scratch in by an IBM team lead by John W. Backus as the first.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Hans-Peter Plag November 6, 2014 Session 4 (Programming Languages) (Data Types and Variables) Expressions and Operators Flow Control.
Lecture #5 Introduction to C++
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
Geog Basic Skills in Scientific Programming Syllabus, Introduction, Fundamentals of IDL Syntax.
Some Fortran programming tips ATM 562 Fall 2015 Fovell (see also PDF file on class page) 1.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
FORTRAN History. FORTRAN - Interesting Facts n FORTRAN is the oldest Language actively in use today. n FORTRAN is still used for new software development.
Introduction to Computer Sciences References: [1] Fortran 95/2003 for Scientists and Engineers (3e) by Stephen J. Chapman. [2] Using Fortran 90 by Chester.
Object Oriented Software Development 4. C# data types, objects and references.
Beginning Fortran Introduction 13 October 2009 *Black text on white background provided for easy printing.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
1 jcmt Summer 2003Programming Languages CSE3302 Programming Languages Summer 2003 Dr. Carter Tiernan.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Computer Programming - Key Concepts and Terms Computer Program – A computer program is a set of instructions for computer, arranged in logical order, using.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Zuse’s Plankalkül – 1945 Never implemented Problems Zuse Solved
Arithmetic Expressions Function Calls Output
Functions and Subroutines
APPENDIX a WRITING SUBROUTINES IN C
CSCI-235 Micro-Computer Applications
Lecture: MATLAB Chapter 1 Introduction
MatLab Programming By Kishan Kathiriya.
ICS103 Programming in C Lecture 3: Introduction to C (2)
Lecture2.
Introduction to the C Language
Chapter 2 - Introduction to C Programming
CS285 Introduction - Visual Basic
Chapter 2 - Introduction to C Programming
Review of C++ Language Basics
Chapter 2 - Introduction to C Programming
Outline Announcements Differences between FORTRAN and C
Introduction to C Programming
Presentation transcript:

Introduction to FORTRAN OBJECTIVES History and purpose of FORTRAN FORTRAN essentials Program structure Data types and specification statements Essential program control FORTRAN I/O subfunctions and subroutines Pitfalls and common coding problems Sample problems

FORTRAN History One of the oldest computer languages Version history created by John Backus and released in 1957 designed for scientific and engineering computations Version history FORTRAN 1957 FORTRAN II FORTRAN IV FORTRAN 66 (released as ANSI standard in 1966) FORTRAN 77 (ANSI standard in 1977) FORTRAN 90 (ANSI standard in 1990) FORTRAN 95 (latest ANSI standard version) Many different “dialects” produced by computer vendors (one of most popular is Digital VAX Fortran) Large majority of existing engineering software is coded in FORTRAN (various versions)

Why FORTRAN FORTRAN was created to write programs to solve scientific and engineering problems Introduced integer and floating point variables Introduced array data types for math computations Introduced subroutines and subfunctions Compilers can produce highly optimized code (fast) Lots of available numerical-math libraries Problems encouraged liberal use of GO TO statements resulted in hard to decipher and maintain (“spaghetti”) code limited ability to handle nonnumeric data no recursive capability

FORTRAN Today FORTRAN 77 is “standard” but FORTRAN 90/95 has introduced contemporary programming constructs There are proprietary compilers Compaq/HP Visual Fortran; Absoft Fortran; Lahey Fortran There is a free compiler in Unix-Linux systems f77, g77 g95 (under development) Available scientific libraries LINPACK: early effort to develop linear algebra library EISPACK: similar to Linpack IMSL: commercial library ($’s) NAG: commercial library ($’s)

Class Objectives Not nearly enough time to teach all the details of FORTRAN (which has evolved into a VERY complex language with many “dialects” …) We’ll try to highlight some of the most important features: that are confusing or often lead to problems, that appear in older programs written in FORTRAN 77 (or IV) that are quite different from contemporary languages For example: I/O instructions variable declarations subprograms: functions and subroutines We’ll look at some code fragments, and You’ll program a simple example problem

How to Build a FORTRAN Program FORTRAN is a complied language (like C) so the source code (what you write) must be converted into machine code before it can be executed (e.g. Make command) Executable File FORTRAN Program FORTRAN Compiler Link with Libraries Libraries Executable Code Source Code Object Code Make Changes in Source Code Test & Debug Program Execute Program

Any character: continuation line Statement Format FORTRAN 77 requires a fixed format for programs FORTRAN 90/95 relaxes these requirements: allows free field input comments following statements (! delimiter) long variable names (31 characters) PROGRAM MAIN C COMMENTS ARE ALLOWED IF A “C” IS PLACED IN COLUMN #1 DIMENSION X(10) READ(5,*) (X(I),I=1,10) WRITE(6,1000) X 1000 FORMAT(1X,’THIS IS A VERY LONG LINE OF TEXT TO SHOW HOW TO CONTINUE ’ * ‘THE STATEMENT TO A SECOND LINE’,/,10F12.4) 1-5 Label 6 7-72 Statements 73-80 Optional Line #s Any character: continuation line

Program Organization Most FORTRAN programs consist of a main program and one or more subprograms (subroutines, functions) There is a fixed order: Heading Declarations Variable initializations Program code Format statements Subprogram definitions (functions & subroutines)

Data Type Declarations Basic data types are: INTEGER – integer numbers (+/-) REAL – floating point numbers DOUBLE PRECISION – extended precision floating point CHARACTER*n – string with up to n characters LOGICAL – takes on values .TRUE. or .FALSE. COMPLEX – complex number Integer and Reals can specify number of bytes to use Default is: INTEGER*4 and REAL*4 DOUBLE PRECISION is same as REAL*8 Arrays of any type must be declared: DIMENSION A(3,5) – declares a 3 x 5 array (implicitly REAL) CHARACTER*30 NAME(50) – directly declares a character array with 30 character strings in each element FORTRAN 90/95 allows user defined types

Implicit vs Explicit Declarations By default, an implicit type is assumed depending on the first letter of the variable name: A-H, O-Z define REAL variables I-N define INTEGER variable Can use the IMPLICIT statement: IMPLICIT REAL (A-Z) makes all variables REAL if not declared IMPLICIT CHARACTER*2 (W) makes variables starting with W be 2-character strings IMPLICIT DOUBLE PRECISION (D) makes variables starting with D be double precision Good habit: force explicit type declarations IMPLICIT NONE User must explicitly declare all variable types

Other Declarations Define constants to be used in program: PARAMETER (PI=3.1415927, NAME=‘BURDELL’) PARAMETER (PIO2=PI/2, FLAG=.TRUE.) these cannot be changed in assignments can use parameters to define other parameters Pass a function or subroutine name as an argument: INTRINSIC SIN – the SIN function will be passed as an argument to a subprogram (subroutine or function) EXTERNAL MYFUNC – the MYFUNC function defined in a FUNCTION subprogram will be passed as an argument to another subprogram

Initializing Variables The DATA statement can be used to initialize a variable: DIMENSION A(10,10) – dimension a REAL array DATA A/100*1.0/ - initializes all values to 1.0 DATA A(1,1),A(10,1),A(5,5) /2*4.0,-3.0/ - initialize by element DATA (A(I,J),I=1,5,2),J=1,5) /15*2.0/ - initialize with implied-do list DATA FLAG /.TRUE./ - initialize a LOGICAL DATA NAME /30*’*’/ - initialize a CHARACTER string Cannot initialize: dummy argument in a function or subroutine definition function, function result variables in COMMON blocks (more details later…) DATA statements can appear within the program code