1. Trang chủ
  2. » Công Nghệ Thông Tin

introduction to fortran programming

31 239 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 31
Dung lượng 479 KB

Nội dung

BIL106E Introduction to Scientific & Engineering Computing Hüseyin TOROS, Ph.D. istanbul Technical University Faculty of Aeronautics and Astronautics Dept. of Meteorological Engineering Voice: 285 31 27 E-mail: toros@itu.edu.tr http://atlas.cc.itu.edu.tr/~toros An important fraction of our interaction will be via e-mail Useful Pages: http://www.be.itu.edu.tr/ http://atlas.cc.itu.edu.tr/~toros/bil106e.htm http://atlas.cc.itu.edu.tr/~F90/mainindex.html http://www.fortran.com/ http://www.foldoc.org (Free OnLine Dictionary of Computing) F Compiler: Read this first, Full installer (3.4Mb): win95nt.exe For more information syllabus_F 07/26/09 Introduction to Scientific & Engineering Computing 2 2 07/26/09 Introduction to Scientific & Engineering Computing • Fortran was originally created by a team lead by John Backus at IBM in 1957. Originally, the name was in all capital letters, but current usage is only requiring that the first letter be capitalized. • The name Fortran stands for FORmula TRANslator. It was originally aimed at scientific calculation and had limited support for working with characters. • Until the C language became popular, it was one of the few high level languages with a high level of portability between different computer systems. • Several websites indicate that the work on Fortran was started in 1954 and released commercially in 1957. • 20 September 1954 may have been the day that a small Fortran program was first successfully compiled. History & Background There have been several versions of Fortran. Fortran I, II and III are considered obsolete. The oldest Fortran versions which are considered of much use today were Fortran IV, and Fortran 66, which, as the name implies, was released in 1966. All later versions of Fortran are numbered after the year the standard was released. The versions of Fortran most commonly remaining in use are Fortran 77, Fortran 90, and Fortran 95. • It was the first High Level or Third Generation programming language. • Before it, all Programs were written in Assembler, where one Program Instruction corresponded to a single machine operation, and each model of computer featured its own Instruction Set. History & Background Why Fortran? • Among many computer scientists Fortran is the most widely used language in scientific computing, especially when high performance is required. • Concise language • Good compilers producing efficient machine code • Legacy: high-quality mathematical libraries available • New version have features helpful for parallelization 07/26/09 Introduction to Scientific & Engineering Computing 4 The F language F Fortran 77 Fortran 90  Easy to • learn • implement • understand  Powerful enough for use in large programs  Download F_World compiler, Installed F_World F is a subset of FORTRAN. The F compiler was written by Walt Brainerd 07/26/09 Introduction to Scientific & Engineering Computing 5 [...]... logical, 5) character Introduction to Scientific & Engineering Computing 07/26/09 23 Operators and assignment The following operators are supported Notice that the relational operators of the form op (like EQ.) have not been included The Fortran 90/95 feature that permits new operator definition is included and allows the op form There is also a defined assignment capability Arithmetic operators +, -, * ,/,**... comment Introduction to Scientific & Engineering Computing 07/26/09 •How Do I Run The Program? •First, prepare the program using an editor to enter the program text •A plain text editor such as Notepad, vi, nano, •Save the program text with the suffix f90 (e.g Hello.f90) •Run the FORTRAN compiler taking its input from this file and producing an executable program • If you used a plain text editor, run... davranişlar değildir Introduction to Scientific & Engineering Computing 07/26/09 07/26/09 Introduction to Scientific & Engineering Computing ! Write a program to calculates average of two number program average real::x,y,ave ! Type declarations read*,x,y ! Read the values Ave=(x+y)/2.0 !Calculation print*,”x= “,x, ”y= “,y print*,”average is= “,ave endprogram average Introduction to Scientific & Engineering...General Fortran Program Structure : Fortran constitutes an Imperative High Level programming language, in that the Source Code in Programs is not directly understood, let alone executed by the hardware Instead, the Code is submitted to a Compiler which writes out a Binary or Executable Module, containing (Machine Code) Instructions appropriate (and often peculiar to) the Hardware being used All Fortran. .. from the command window •gfortran –fimplicit-none –W hello.f90 -o hello.exe •Run the executable program (in the exe file) • gfortran hello.f90  /a.out •From F_world menu run program commands Introduction to Scientific & Engineering Computing 07/26/09 Comments • Comments are used to signal the intent of the programmer • Improve readability and understanding • An important aid to debugging and maintaining... assignment capability Arithmetic operators +, -, * ,/,** (Addition, Subtraction, Multiplication, Division, Exponentiation) Relational operators = Logical operators not., and., or., eqv., neqv Character concatenation // Defined operator letters Introduction to Scientific & Engineering Computing 07/26/09 24 program message ! variable declaration part character (len=25):: name , surname character(len=200)::... numbers 07/26/09 Introduction to Scientific & Engineering Computing 26 ! This program adds two numbers and displays the result program add real:: a,b,c print*,"Input two numbers (include a decimal point)" read*,a,b c=a+b print*,"The sum of the numbers you entered is", c end program add program sumofnumbers Introduction to Scientific & Engineering Computing 07/26/09 27 ! Write a program to calculates area... Constants may be declared and initialized The "Executable" Part follows, in which all computations, logic, and File handling take place Introduction to Scientific & Engineering Computing 07/26/09 Diagrammatic form of a Fortran Program : PROGRAM Statement : Optional to Name Program Non Executable Part : Non Executable Statements Executable Part : Executable Statements END : Completes Executable Part... are only there for someone reading the program, not for the compiler to use • Make Useful Comments Useful Comments • Not Useful: ! Add 1 to a a=a+1 • More Useful: ! Increment to account for new user login a=a+1 • Sometimes, Not Necessary: NumUsersLoggedIn = NumUsersLoggedIn + 1 !READ iN THREE iNTEGERS FROM THE KEYBOARD AND !PRINT THEM TO !THE SCREEN IN A DIFFERENT ORDER program number integer:: num1,... num3 print *, 'Enter 3 integers: ' read *, num1, num2, num3 print *, num2, num3, num1 stop end program number ! Write a program that reads in a temperature in Celsius and converts it ! to Fahrenheit, then prints result to the screen ! Read in the celsius temperature and print out the fahrenheit temp program centigrade _to_ fahrenheit implicit none ! Variable declarations; real :: temp_c, temp_f ! Ask for . been several versions of Fortran. Fortran I, II and III are considered obsolete. The oldest Fortran versions which are considered of much use today were Fortran IV, and Fortran 66, which, as. execution process 07/26/09 Introduction to Scientific & Engineering Computing 07/26/09 Introduction to Scientific & Engineering Computing General Fortran Program Structure : Fortran constitutes. features helpful for parallelization 07/26/09 Introduction to Scientific & Engineering Computing 4 The F language F Fortran 77 Fortran 90  Easy to • learn • implement • understand  Powerful

Ngày đăng: 24/10/2014, 21:27

TỪ KHÓA LIÊN QUAN