Beginning Fortran Introduction 13 October 2009 *Black text on white background provided for easy printing.

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

Lecture 2 Introduction to C Programming
Need for Arrays Exercise Read the IDs and the grades for all ICS 101 students. Compute and print the average of the students. Print the grades and IDs.
Conditional Statements Introduction to Computing Science and Programming I.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Chapter 4 Loops and Character Manipulation Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
Introduction to C Programming
1.2 – Open Sentences and Graphs
CS 106 Introduction to Computer Science I 03 / 17 / 2008 Instructor: Michael Eckmann.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Fundamentals of Python: From First Programs Through Data Structures
Java Unit 9: Arrays Declaring and Processing Arrays.
Fortran- Subprograms Chapters 6, 7 in your Fortran book.
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Introduction to FORTRAN
Beginning Fortran Fortran (77) Basics 22 October 2009 *Black text on white background provided for easy printing.
Mr C Johnston ICT Teacher BTEC IT Unit 06 - Lesson 05 Learning To Program.
For Loops. Challenge: Racer ● Simulate a race that says “Now on lap X” for 10 laps. ● Make X vary, so it says 1, then 2, then 3 ● Use only one output.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Multi-Dimensional Arrays
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
FORTRAN FORmula TRANslator -Anand Trivedi. HISTORY  Designed and written from scratch in by an IBM team lead by John W. Backus as the first.
CPS120: Introduction to Computer Science
COMP102 Lab 081 COMP 102 Programming Fundamentals I Presented by : Timture Choi.
I Power Int 2 Computing Software Development High Level Language Constructs.
CMPS 1371 Introduction to Computing for Engineers CONDITIONAL STATEMENTS.
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
M180: Data Structures & Algorithms in Java Arrays in Java Arab Open University 1.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Some Fortran programming tips ATM 562 Fall 2015 Fovell (see also PDF file on class page) 1.
CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Introduction to Java Java Translation Program Structure
Scope When we create variables and functions, they are limited in where they are visible and where they can be referenced For the most part, the identifiers.
Programming, an introduction to Pascal
Introduction to Matlab Module #4 Page 1 Introduction to Matlab Module #4 – Programming Topics 1.Programming Basics (fprintf, standard input) 2.Relational.
I Power Higher Computing Software Development High Level Language Constructs.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
Beginning Fortran Fortran (77) Advanced 29 October 2009 *Black text on white background provided for easy printing.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Repetition. Loops Allows the same set of instructions to be used over and over again Starts with the keyword loop and ends with end loop. This will create.
CPS120: Introduction to Computer Science Variables and Constants.
IS2802 Introduction to Multimedia Applications for Business Lecture 4: JavaScript, Loops, and Conditional Statements Rob Gleasure
CS 106 Introduction to Computer Science I 03 / 22 / 2010 Instructor: Michael Eckmann.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Perl for Bioinformatics Part 2 Stuart Brown NYU School of Medicine.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 6 Arrays.
Chapter 9 Introduction to Arrays Fundamentals of Java.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
PH2150 Scientific Computing Skills Control Structures in Python In general, statements are executed sequentially, top to bottom. There are many instances.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Repetition Statements
Unit 2 Technology Systems
Dept of Computer Science University of Maryland College Park
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
Agenda Control Flow Statements Purpose test statement
Engineering Innovation Center
MATLAB: Structures and File I/O
Logical Operators and While Loops
Arrays, For loop While loop Do while loop
The Data Element.
The Data Element.
Presentation transcript:

Beginning Fortran Introduction 13 October 2009 *Black text on white background provided for easy printing

What is Fortran? One of the oldest programming languages still in use Fortran77, Fortran90 Used primarily by geophysical sciences: – Good at math and manipulation of large data sets – Consistent with earliest NWP models

I program in Fortran…

… …

Why Learn It? If you are pursuing a graduate degree in AOS, you will eventually run into Fortran: – An assignment – A research problem – Someone else’s code* *THIS is why commenting code is so important (later on that)

Your Typical Program c PROGRAM MYPROGRAM STOP END Program Options Declaration of Variables MAIN CODE

Your Typical Program c PROGRAM MYPROGRAM STOP END Program Options Declaration of Variables MAIN CODE The first seven columns of the program code are reserved for special functions – most lines of code begin on the seventh column

Your Typical Program c PROGRAM MYPROGRAM STOP END Program Options Declaration of Variables MAIN CODE This line identifies the code as a program (instead of, say, a subroutine) and gives it the name MYPROGRAM.

Your Typical Program c PROGRAM MYPROGRAM STOP END Program Options Declaration of Variables MAIN CODE All variables used in the code have to be declared at the top, before any of the main code is run.

Your Typical Program c PROGRAM MYPROGRAM STOP END Program Options Declaration of Variables MAIN CODE Here is where the magic happens.

Your Typical Program c PROGRAM MYPROGRAM STOP END Program Options Declaration of Variables MAIN CODE This identifies the end of the program

A More Complicated Program PROGRAM MYPROGRAM Options Declaration of Variables MAIN CODE CALL MYSUBROUTINE MAIN CODE STOP END SUBROUTINE MYSUBROUTINE Options Declaration of Variables MAIN CODE CALL MYSUBROUTINE MAIN CODE RETURN END

A More Complicated Program PROGRAM MYPROGRAM Options Declaration of Variables MAIN CODE CALL MYSUBROUTINE MAIN CODE STOP END SUBROUTINE MYSUBROUTINE Options Declaration of Variables MAIN CODE RETURN END Being able to trace the flow of information is by far the most important thing to learn about programming, in Fortran or in any other language. You will eventually have to write code that is not only able to perform complicated functions, but is readable to someone else who wishes to use it.

Declaring Variables All variables in the program must be of a specific type: – Numbers – Letters, Words, Phrases, Names, etc. – Logic Variables – 1-D, 2-D, 3-D, etc. blocks of these

Numbers Numbers can be: – Integers – This is any integer value (e.g. -5, 0, 1) – “Real”/”Floating-Point”/etc. – This is any number (e.g. 5.6, ) In general, “integer” variables are good for keeping counts of things, while “real” variables are used for data.

Character Strings Any variable that is a set of letters is a string of CHARACTERs. – Name – Messages (UH_OH = ‘Program failed!’) – File names

Logical Variables LOGICAL variables are either ‘true’ or ‘false’, and are usually used to determine if some set of criteria has occurred or not. IF (Some variable is greater than 5) THEN its_greater_than_five = TRUE ENDIF

Arrays Usually you are going to need a whole block of numbers representing your data set (e.g. a block of numbers representing vorticity at every point in some domain) You can specify an array of any of these variable types

Arrays The array has a type (INTEGER, REAL, etc.), a single name, and a set of dimensions: VALUES(55,90)

Arrays The array has a type (INTEGER, REAL, etc.), a single name, and a set of dimensions: VALUES(4,3) Variable array called VALUES

Arrays The array has a type (INTEGER, REAL, etc.), a single name, and a set of dimensions: VALUES(4,3) Array set with 4 elements in one dimension, And 3 in the other. This array has a total of (4*3) = 12 elements.

Arrays The array has a type (INTEGER, REAL, etc.), a single name, and a set of dimensions: VALUES (1,1) VALUES (1,1) VALUES (2,1) VALUES (2,1) VALUES (3,1) VALUES (3,1) VALUES (4,1) VALUES (4,1) VALUES (1,2) VALUES (1,2) VALUES (1,3) VALUES (1,3) VALUES (1,2) VALUES (1,2) VALUES (2,2) VALUES (2,2) VALUES (3,2) VALUES (3,2) VALUES (2,3) VALUES (2,3) VALUES (3,3) VALUES (3,3) VALUES (4,3) VALUES (4,3) Each element of VALUES is identifiable by its index.

Arrays The array has a type (INTEGER, REAL, etc.), a single name, and a set of dimensions: VALUES(3,2) VALUES (1,1) VALUES (1,1) VALUES (2,1) VALUES (2,1) VALUES (3,1) VALUES (3,1) VALUES (4,1) VALUES (4,1) VALUES (1,2) VALUES (1,2) VALUES (1,3) VALUES (1,3) VALUES (1,2) VALUES (1,2) VALUES (2,2) VALUES (2,2) VALUES (3,2) VALUES (3,2) VALUES (2,3) VALUES (2,3) VALUES (3,3) VALUES (3,3) VALUES (4,3) VALUES (4,3) Each element of VALUES is identifiable by its index.

Arrays

Loops Values in arrays have indices that correspond to their location in the array Loops provide the ability to go through each member of the array individually: For i = 1, 3 For j = 1, 2 VALUES(i,j) End

Scientific Computing Scientific computing generally involves dealing with very large sets of data over many dimensions, and mathematically manipulating the data in a desirable way Arrays, loops, logical traps, etc. Poor coding technique will come back to bite you!

Comments All coding languages allow you to sneak in messages in the code itself to allow a reader to understand what is going on – these are called “comments” For i = 1, 4 c c I’m looping over the first index of VALUES here. c

Comments All coding languages allow you to sneak in messages in the code itself to allow a reader to understand what is going on – these are called “comments” For i = 1, 4 c c I’m looping over the first index of VALUES here. c Code sees this identifier as “comment” and Skips it.

In The Next Few Weeks Fortran – Basics Fortran – “Advanced” Matlab 1 Matlab 2 Matlab 3 IDL 1 IDL 2