FORTRAN Short Course Week 1 Kate T-C February 17, 2008.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

C Programming for engineers Teaching assistant: Ben Sandbank Home page:
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
Introduction to Primitives. Overview Today we will discuss: –The eight primitive types, especially int and double –Declaring the types of variables –Operations.
Lecture 1: Intro to Computers Yoni Fridman 6/28/01 6/28/01.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Program Design and Development
Computing Components 01/26/11. Announcements & Reminders Programs 1 due Friday, 9/2/11 What is my late policy? Proxy Codes for Labs  You should be able.
22-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
8 November Forms and JavaScript. Types of Inputs Radio Buttons (select one of a list) Checkbox (select as many as wanted) Text inputs (user types text)
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
1 I.Introduction to Algorithm and Programming Algoritma dan Pemrograman – Teknik Informatika UK Petra 2009.
CS102 Introduction to Computer Programming
Why Program? Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer.
Chapter Introduction to Computers and Programming 1.
01- Intro-Java-part1 1 Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology June 2008.
CPS120: Introduction to Computer Science Lecture 8.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
1 TOPIC 1 INTRODUCTION TO COMPUTER SCIENCE AND PROGRAMMING Topic 1 Introduction to Computer Science and Programming Notes adapted from Introduction to.
Introduction to Python
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Fall, 2006Introduction to FORTRAN1 (2 + 2 = ???) Numbers, Arithmetic Nathan Friedman Fall, 2006.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 9, 2015)
Georgia Institute of Technology Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology Aug 2005.
Lesson 1b: Computer Systems and Program Development CPS118.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
An Introduction to Computers August 12, 2008 Mrs. C. Furman.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
Introduction to Computer Systems and the Java Programming Language.
Mrs. Ulshafer August, 2013 Java Programming Chapter 1.
Data Representation The storage of Text Numbers Graphics.
Copyright © – Curt Hill Types What they do.
CS Class 03 Topics  Sequence statements Input Output Assignment  Expressions Read pages Read pages 40 – 49 for next time.
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.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Computer Systems. Bits Computers represent information as patterns of bits A bit (binary digit) is either 0 or 1 –binary  “two states” true and false,
CPS120: Introduction to Computer Science Variables and Constants.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
CS 177 Recitation Week 1 – Intro to Java. Questions?
Introduction to Computer Programming using Fortran 77.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Chapter 1: Introduction to Computers and Programming
The Study of Computer Science Chapter 0
BASIC PROGRAMMING C SCP1103 (02)
Topics Introduction Hardware and Software How Computers Store Data
BASIC PROGRAMMING C SCP1103 (02)
Building Java Programs
The Study of Computer Science Chapter 0
Other Kinds of Arrays Chapter 11
The Study of Computer Science
Building Java Programs Chapter 2
Introduction to Java, and DrJava part 1
Topics Introduction Hardware and Software How Computers Store Data
C++ Data Types Data Type
Logical Computer System
How Computers Work Part 1 6 February 2008.
Tonga Institute of Higher Education IT 141: Information Systems
Introduction to Primitives
Introduction to Primitives
Tonga Institute of Higher Education IT 141: Information Systems
Primitive Types and Expressions
Unit 3: Variables in Java
Introduction to Java, and DrJava
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

FORTRAN Short Course Week 1 Kate T-C February 17, 2008

What are we talking about this week? Quick Intro to the Class Three Laws of Computer Science How does a computer actually work? Developing a plan and a program Dive into Fortran! Variables, Types, Arrays, Arithmetic Functions, Order of Operations

The Plan

Goals of this Class Learn how to write workable, understandable, debuggable Fortran 90/95 code and programs Learn a bit more about how computers work Learn how to think about your problem in a way that will help you write good programs

NOT Goals of This Class Learn everything there is to know about programming!!! (Every language is different) Learn how to read/write Fortran 77 or old Fortran code Become an expert in Fortran or HPC Learn every option of aspects of Fortran We won’t learn every error, every built-in function or data type, or all that much about compiler options

THREE LAWS OF COMPUTER SCIENCE Because Turing says...

Law #1 The word CODE is already plural. Think of it like deer or fish Corollary: It is only acceptable to say “codes” if you are talking about launching missiles or cryptography. And I mean it!

Law #2 Computers ONLY do what you tell them to! If something is wrong, it’s probably your own fault. I’m sorry. But it is. Corollary: Sometimes you don’t know you told the computer to do it wrong, or somebody else did the telling.

Law #3 Do not re-invent the wheel. Corollary: You probably won’t know it’s a wheel as you’re inventing it.

So, what are we doing? Fortran is a programming language (an old one) Fortran is a *compiled* language How do you want to think about this? Magic words Operating a machine

How does a computer work? CPU RAM Hard Drive Power Video USB BIOS

How does a computer work? Input Processing Output User Processor Visual Memory Processor Memory Memory Processor Visual User Processor Memory Repeat as necessary!

How does a computer work? User Input: Keyboard, Microphone, video camera, digital camera... Visual Output: Monitor, printer, speakers, Braille terminal... Memory (slowest to fastest): CDs/DVDs, External Hard Drives, flash drives, Internal Hard Drives, RAM, Cache (L3, L2, L1), Registers Processor = CPU (Central Processing Unit) takes numbers (in binary) and does math the result is numbers (in binary)

Basically, Computers Can store binary numbers. The binary can be interpreted into lots of different types of numbers or even text or graphics Binary is divided up into bits, bytes and words Can perform math on binary numbers Everything that you see or do on a computer boils down to a line of math A program is just a long series of mathmatical operations performed on lots and lots of numbers

How do we write a program? We need a language that is easier than just writing billions of 1’s and 0’s (Let’s use Fortran!) We need a program that can translate our computer language into 1’s and 0’s that the computer understands (called the compiler) We need a way to tell the computer to run and store our program (the operating system)

Our first Fortran Program PROGRAM ILikePie ! Written by Kate T-C ! For the Fortran Short Course ! This program is a bad joke. real :: pi = print *, ‘I Like’, pi END PROGRAM ILikePie

Things in the program Each line is a statement The program runs top to bottom, in order Program start, program name Comment block Variable declaration Output statement - Print is your friend! Program end

Compile the Program >f90 ILikePie.f90 Or replace ‘f90’ with a call to your Fortran compiler (need to talk to your local computer guy to find this one out) We can also do... >f90 ILikePie.f90 -o Pie This is called Compile-Time.

Run the program >a.out... or (if we used -o )... >Pie... or navigate to the program in your window environment and double-click. You wrote a computer program! This is called Run-Time.

Code Talker

Let’s do another one! Who uses Fortran? Well, climate modelers! So, let’s write a climate model... Energy In = Energy Out

Translating the model into Fortran Variables, Literals and Constants Types Input, action, output Implicit None See example program ClimateModel.f90

Variable Types real - a floating point number double precision - a floating point number using twice the bytes for more accuracy integer - a straight-up whole number complex - numbers that include an imaginary component logical - two values: true or false character - variable contains text

Arithmetic Operators Computer languages follow the algebraic Order of Operations 1. Parenthesis () 2. Exponentiation ** 3. Multiplication and Division *, / 4. Addition and Subtraction +, - Please Excuse My Dear Aunt Sally

Arithmetic Operators Try it out, what do you get for the following statements? *10 (10-3+2)*10 3**2+1 3**(2+1) 3**2**0.5

Reals and Integers Mixing types in arithmetic can be confusing If operands are all integers, the result is an integer, otherwise, the result is real. 8.0/4.0=2.0, 8.0/4=2.0, 8/4=2 Integer division truncates the result 10.0/4.0=2.5, 10.0/4=2.5, 10/4=2 We can save some trouble by casting to make sure everything is the correct type Because computers use binary, technically, ALL division and multiplication is truncated!

Really Big or Really Small Numbers Different computers and compilers use different numbers of bits to represent integers (8, 16, or 32) and reals (32 or 64). A 16 bit (signed) integer has 1 bit for the sign and 15 for the number, so 2**15 = 32,768 numbers possible (range is -16,383 to 16,384) A 32 bit real has a 24 bit mantissa and 8 bit exponent, range is ~10**(2**(8-1)) = 10**(+/-)128 Try to write code that doesn’t produce overly large or overly small numbers to avoid problems.

Another Example! What else do we use Fortran for around here? It’s basically the fastest way to manipulate large amounts of data. To perform operations on data, we could either declare thousands of “real” variables (one for each data point) or just declare one Array. Check out example Statistics.f90

Arrays Give one name to a series of numbers Each element in the array has an Index or Subscript - which must be an integer You can declare an array of any type using the ‘dimension’ attribute You can fill the array when you declare it using (/x,y,z/) notation or fill it at run-time using input data from other sources (files, stdio, instrumentation, etc)

What did we cover today? Three Laws of Computer Science How a computer works Three things a computer can do Writing a Fortran program - text, compile, run We learned about the Print *, statement Literals, Variables and Constants Implicit None and Variable Types Arithmetic operators and the Order of Operations Arrays

Homework Sure, why not? your code and program output to me if you want feedback My office is ATS 404 if you need help