Fortran Tutorial Fortran spaces for code qqqqqqCODE

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Control Statements. Define the way of flow in which the program statements should take place. Control Statements Implement decisions and repetitions.
IF statement (i) Single statement. IF ( logical expression ) statement Example: read(*,*) a if (a. lt. 0) a = -a write(*,*) a Or read(*,*) a if (a < 0)
Control Structures Ranga Rodrigo. Control Structures in Brief C++ or JavaEiffel if-elseif-elseif-else-end caseinspect for, while, do-whilefrom-until-loop-end.
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
N ATIONAL E NERGY R ESEARCH S CIENTIFIC C OMPUTING C ENTER 1 Mixed Language Programming on Seaborg Mark Durst NERSC User Services.
Input and Output READ WRITE OPEN. FORMAT statement Format statements allow you to control how data are read or written. Some simple examples: Int=2; real=
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.
P1PMF Split1 QBASIC. P1PMF Split2QBasic Command Prompt Will launch the emulator DOS operating system? Press Alt + Enter to display the widescreen.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Fortran Jordan Martin Steven Devine. Background Developed by IBM in the 1950s Designed for use in scientific and engineering fields Originally written.
Review of Scientific Programming in C and Fortran Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration.
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
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 Perl Bioinformatics. What is Perl? Practical Extraction and Report Language A scripting language Components an interpreter scripts: text.
FORTRAN The Only Real Computer Programming Language.
Scalar Variables Start the file with: #! /usr/bin/perl –w No spaces or newlines before the the #! “#!” is sometimes called a “shebang”. It is a signal.
Flow of Control MINS298c Fall 1998 Chapter 9. Overview ABAP Programming Structures for: –Iteration –Decisions Control Flow –If … Then –Do & While loops.
FORTRAN.  Fortran or FORmula TRANslation was developed in the 1950's by IBM as an alternative to Assembly Language. First successfull high level language.
Shell Programming 1. Understanding Unix shell programming language: A. It has features of high-level languages. B. Convenient to do the programming. C.
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.
Functions. Program complexity the more complicated our programs get, the more difficult they are to develop and debug. It is easier to write short algorithms.
Lab 8 Shell Script Reference:
Introduction to FORTRAN-90 University of Liverpool course.
Introduction to FORTRAN
Beginning Fortran Fortran (77) Basics 22 October 2009 *Black text on white background provided for easy printing.
Fortran. You will come across two versions of Fortran, 77 and 90/95 It is a higher-level languages must be translated into the low-level machine language.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
April 14, ICE 1341 – Programming Languages (Lecture #13) In-Young Ko Programming Languages (ICE 1341) Lecture #13 Programming Languages (ICE 1341)
CPTR 124 Review for Test 1. Development Tools Editor Similar to a word processor Allows programmer to compose/save/edit source code Compiler/interpreter.
Scientific Computing Division A tutorial Introduction to Fortran Siddhartha Ghosh Consulting Services Group.
FORTRAN FORmula TRANslator -Anand Trivedi. HISTORY  Designed and written from scratch in by an IBM team lead by John W. Backus as the first.
How to Write a Fortran Jiffy (C)2005 Mark Rould University of Vermont.
Class Review. Basic Unix Commands list files in a directory: ls list files in a directory: ls remove files: rm remove files: rm rename files: mv rename.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
/* C Programming for the Absolute Beginner */ // by Michael Vine #include main() { printf(“\nC you later\n”); system(“pause”); }
Perl Practical(?)‏ Extraction and Report Language.
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
Chapter 3. Outline Relational Operators Loops Decisions Logical Operators Precedence Summary.
Geog Basic Skills in Scientific Programming Syllabus, Introduction, Fundamentals of IDL Syntax.
Introduction to Computer Programming
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
Shell Script2 Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
1 Chapter 3: Loops and Logic. 2 Control Statements If statement Example NumberCheck.java Relational operators (, >=, ==, !=) Using code blocks with If.
Week Five Agenda Link of the week Review week four lab assignment This week’s expected outcomes Next lab assignment Break-out problems Upcoming deadlines.
More on F90 Outline: I.Parameter statements II.Comments III.Program layout-- execution part IV.if/then/else V.Case statements VI.do loops VII.goto VIII.Intrinsic.
Flow Control. The order in which commands execute in a shell script is called the flow of the script. When you change the commands that execute based.
Lab 8 Shell Script Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
Structures or Derived Types. Real Life Objects Often structured –Students, Employees, Cars, Accounts, Cricket matches, flats etc contain heterogeneous.
Shell script – part 2 CS 302. Special shell variable $0.. $9  Positional parameters or command line arguments  For example, a script myscript take 2.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Unary, Binary, logical Operations, Explicit type conversion Lecture 6 Instructor: Haya Sammaneh.
Batch Files Flow of Control to Strengthen Copyright © by Curt Hill.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Presentation By :- Nikhil R. Anande ( ) Electronic & Communication Engineering. 3 nd Year / 5 th Semester FACULTY GUIDE : RAHIUL PATEL SIR MICROCONTROLLER.
1 Lecture 8 Shell Programming – Control Constructs COP 3353 Introduction to UNIX.
Basic concepts of C++ Presented by Prof. Satyajit De
Agenda Bash Shell Scripting – Part II Logic statements Loop statements
Sequence, Selection, Iteration The IF Statement
Fortran 90/95 Programming Victor Anisimov, NCSA
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
C# and the .NET Framework
Chapter 3: Understanding C# Language Fundamentals
Type & Typeclass Syntax in function
Repetition (While Loop) LAB 9
DATA TYPES AND OPERATIONS
REPETITION Why Repetition?
Presentation transcript:

Fortran Tutorial Fortran 77 7-72 spaces for code qqqqqqCODE program progname ! ! Comments are preceded by ! “!” or “C” implicit none C C Data initialization to C follow… integer :: i,j,k,n,m real :: x,y,z integer, dimension(3) :: larray real, dimension(3) :: rvec,forces real, dimension(0:3,8) :: tensor character(len=6) :: name ! Comment. logical :: some_flag,another_flag complex :: phase,factor real, parameter :: four = 4.0E0 ! ===================================== ! Beyond this point expressions are ! allowed. 7-72 spaces for code qqqqqqCODE Must leave six spaces for “statement label”. Single precision (kind=4) Double precision (kind=8) Comments can be added at the end of a line.

Fortran Tutorial ! ! Data initiation continued... x = 1.50E0 y = 10.0E0 rvec(1) = 0.100E0 rvec(2) = 0.000E0 rvec(3) = 0.750E0 forces(1:3) = 0.00E0 phase = (2.0E0,1.25E0) tensor(0,:) = 0.0E0 tensor(1:3,:) = 3.0E0 name = ‘PRESS’ some_flag = .true. another_flag = .false. do i=1,3 forces(i) = 0.0E0 enddo do i=1,3 do j=1,3 tensor(i,j) = 3.0E0 enddo

Fortran Tutorial ! ! Conditional statements if (i == 3) statement if (x >= 0.0E0 ) then statement endif if ( a > x .and. b < y ) then if ( c == 0.0E0 ) then else if ( c > 0.0E0 ) then else if (some_flag) then ... if (.not.another_flag) then ... if (name == ‘PRESS’ ) then ... F90 F77 Operation == .eq. Equal to /= .ne. Not equal to > .gt. Greater than >= .ge. Greater or equal to < .lt. Less than <= .le. Less than or equal to

Fortran Tutorial ! ! Loop statements do i=1,3 statement enddo do i=1,n-1 do j=i+1,n do i=1,10 if (force(i) > 10.0E0) exit do if (condition) break do i=1,10 statement if (condition) goto 10 enddo 10 continue

Fortran Tutorial ! ! Loop statements (continued) do i=1,n,3 ! Increment by 3 statement enddo ! While loop... i = 0 do while (i<n) i = i + 1

Fortran Tutorial Fortran 77 Continuation symbol at space #5 ! ! Expressions x = a * b / c x = a**3 * b + c/d x = exp( sqrt( x**2 + y**2 + & z**2) ) ! Complex variables... phase = (1.0E0,1.0E0) ! Equals 1+i phase = cmplx(a,b) ! Equals a+ib c = conjg(phase) ! Equals a-ib a = real(phase) b = aimag(phase) ! Floating points & integers... i = 3.45E0 ! Equals 3 i = -2.76E0 ! Equals –3 ! Good practice ... i = int( real(j)*force(k)/2.0E0 ) Fortran 77 x = exp( sqrt( x**2 + y**2 + & z**2) ) Continuation symbol at space #5

Fortran Tutorial End of program Begin the subroutine ! ! Subroutines... call myroutine(a,b,3,x,y,z,flag) stop end ! ----------------------------------- subroutine myroutine(a,b,k,x,y,z,root) implicit none real :: a,b,x,y,z integer :: k logical :: root integer :: i a = (x**2+y**2+z**2) do i=1,k a = a + b**I enddo if (root) a = sqrt(a) return end subroutine !-------------------------------------- End of program Begin the subroutine Return control back to calling program or routine End the routine

Fortran Tutorial ! ! User functions... integer :: n,x,factorial . x = factorial(n) stop end ! ----------------------------------- function factorial(n) implicit none integer :: factorial,n integer :: i if (i<0) return(0) if (i=0) return(1) factorial = 1 do i=1,n factorial = factorial * i enddo return end function !--------------------------------------

Fortran Tutorial in integer n spaces long. ! fn.d floating point n spaces long, d spaces after the decimal place. an character string n spaces long. en.d exponential n spaces long, d spaces after the decimal point. (n>=d+7) esn.d scientific n spaces long, d spaces ln logical n spaces long. x space. t tab. ! ! Output... ! Free format -> write(*,*) ‘This is a tutorial.’ write(*,*) ‘The answer is ‘,i ! Fixed format -> write(*,100) i 100 format(‘This is a tutorial.’,/, & ‘The answer is ‘,i3) write(*,200) (force(i),I=1,3) 200 format(/,’Particle force = ‘,3f4.1) name = ‘alpha’ do i=1,n write(*,300) name,i,x,y,z enddo 300 format(‘ data set ‘,a5,’: iter = ‘, & i3,’, force = ‘,3(x,f4.1)) Particle force = 1.0 0.4 1.8 data set alpha: iter = 1, force = 10.1 1.2 –2.9 data set alpha: iter = 2, force = 1.4 0.1 –4.3 data set alpha: iter = 3, force = 2.3 0.3 2.5 data set alpha: iter = 4, force = -2.1 1.2 2.8 data set alpha: iter = 5, force = -3.9 **** –0.2

Fortran Tutorial Status clause (possible values) ! ! External files... open(unit=6,file=‘myfile’, & form=‘formatted’,status=‘old’) ! File with I/O unit=6 is now open. ! Unformatted read---> read(6,*) a,b,c ! These are read(6,*) x,y,z ! on separate read(6,*) (force(i),i=1,3) ! lines. ! Formatted read---> read(6,100) i,j,name 100 format(2x,i3,x,i3,3x,a6) close(unit=6) ! Close file. ! -------------------------------------- ! Write to files... open(unit=7,file=‘output’, & form=‘formatted’,status=‘new’) write(7,200) name,x,y,z 200 format(2x,a6,’ data -> ‘,3(2x,f5.2)) close(unit=7) Status clause (possible values) ‘old’,’new’,’unknown’, ‘scratch’,’replace’ form clause (possible values) ‘formatted’, ‘unformatted’

Fortran Tutorial Run the program COMPILING... -> f90 –o executable program.f Linking many files -> f90 –c code1.f -> f90 –c code2.f -> f90 –o executable code1.o code2.o program.f Example: -> f90 –o prog.x code1.o code2.o program.f -> prog.x To run in “background” -> prog.x & -> Check the status of a run -> ps –a Kill a run -> kill –9 6445 Run the program Code will run in background and allow you use other commands. Include process ID (from”ps –a”)