03Introduction%20to%20Fortran-handout

03Introduction%20to%20Fortran-handout - Start Programming...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Start Programming in Fortran Amir Hossein Rabbani Winter, 2009
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Outline In this course you will learn: How to use Read/Write statements When to comment our program How to write a simple Fortran program How to perform arithmetic operations in Fortran and save the results into variables How to ask users for input
Background image of page 2
Quick Review PROGRAM program-name IMPLICIT NONE {declarations} {statements} {subprograms} END PROGRAM program-name FoRTraN iS NOT CaSe-SENsitivE: program == PROgram == proGRAM == PROGRAM
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The Write Statement The WRITE statement has one of the forms: WRITE (*,*) “The message we want” WRITE (*,*) exp where exp is an arithmetic expression or simply a variable Each expression is evaluated and the value is displayed on the screen . To write two things on 1 line, just put a comma between 2 strings: WRITE (*,*) exp 1 , exp 2 , exp 3 , . . .,exp n Example: WRITE (*,*) “Two plus Three is: ”, 2+3 Question: How does Fortran know whether to write “5” or “2+3” on screen?
Background image of page 4
Controlling  Output The computer chooses how to display the output on the screen We may want to control how the output appears Display monetary numbers with two decimal points Align data in columns Later we study FORMAT codes that give us that kind of control We also will see how to put the output values into a file or write to some device other than the screen
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Comments If you write “ ! ” (that is not contained inside a string) before a line, the computer will ignore it. Comments are used to signal the intent of the programmer Improve readability and understanding An important aid to debugging and maintaining code Comments can appear anywhere in the program Comments are only there for someone reading the program, not for the compiler to use.
Background image of page 6
Example of Commenting PROGRAM hello !The above always goes at the top of a program IMPLICIT NONE !I do not know yet what this is for, but my !teacher told me to put it there. WRITE (*,*) “Hello World!“ !The above prints the words”Hello World” !The next line is what we do to end a !program in Fortran END PROGRAM hello
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Let’s Code…
Background image of page 8
First Example Elmer Fudd wants to go hunting. Before doing so, he wants to learn how to cook. His recipe for cooking rabbit tells him to set the oven to 200 degrees Celsius . However, Elmer's oven was made in England and the display is in Fahrenheit . Elmer is lousy at math and wants us to help him. What temperature should he set his (Fahrenheit) oven to?
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Cel200ToFah !This program converts 200 Celsius !to Fahrenheit IMPLICIT NONE WRITE (*,*) (200 * 1.8) + 32 !The above prints what 200 degrees Celsius in !Fahrenheit is. END PROGRAM
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 42

03Introduction%20to%20Fortran-handout - Start Programming...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online