Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 37 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
37
Dung lượng
2,22 MB
Nội dung
FORTRAN 90 LECTURE Yetmen Wang Fortran 90/95/2000 INTRODUCTION FORTRAN VERSIONS PROGRAM STRUCTURE NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING SIGNIFICANT FEATURES FORTRAN HISTORY STRENGTHS WEAKENESSES POINTER DYNAMIC STORAGE FORmula TRANslation Developed by the IBM team led by John Backus The first high-level programming language Mainly intended for mathematical computations Areas of Application Numerical Analysis System Simulation Scientific Computations Engineering Procedures Introduction Introduction Fortran 90/95/2000 INTRODUCTION FORTRAN VERSIONS PROGRAM STRUCTURE NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING SIGNIFICANT FEATURES FORTRAN HISTORY STRENGTHS WEAKENESSES POINTER DYNAMIC STORAGE Fortran History Fortran History Published by IBM in 1957 MS PowerStation 4.0 Sold to Digital with DEC, it developed into Digital Visual Fotran 5.x Digital was later merged with Compaq; CVF 6.x emerged CVF development team was purchased by Intel HP merged with Compaq, introducing HP CVF 6.6a Intel Fortran, combining CVF, developed Intel Visual Fortran 8.x Fortran 90/95/2000 INTRODUCTION FORTRAN VERSIONS PROGRAM STRUCTURE NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING SIGNIFICANT FEATURES FORTRAN HISTORY STRENGTHS WEAKENESSES POINTER DYNAMIC STORAGE Fortran Versions Fortran Versions 1962 FORTRAN IV 1966 FORTRAN 66 1978 FORTRAN 77 1992 FORTRAN 90 Array Semi-OOP Resembles MATLAB 1997 FORTRAN 95 HPF extension more OOP 2003 FORTRAN 2000 Fully OOP Fortran 90/95/2000 INTRODUCTION FORTRAN VERSIONS PROGRAM STRUCTURE NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING SIGNIFICANT FEATURES FORTRAN HISTORY STRENGTHS WEAKENESSES POINTER DYNAMIC STORAGE Strengths Strengths Array language and object-oriented programming Higher computational speed compared to C/C++ and MATLAB Maintains plenty of legacy codes Easy-to-learn compared to C/C++ The majority of individuals in the numerical computing field still use Fortran to develop program(s) Fortran 90/95/2000 INTRODUCTION FORTRAN VERSIONS PROGRAM STRUCTURE NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING SIGNIFICANT FEATURES FORTRAN HISTORY STRENGTHS WEAKENESSES POINTER DYNAMIC STORAGE Weaknesses Weaknesses File I/O is difficult to modify and comprehend Low reusability and high cost of code maintenance Lack of numerical and graphical libraries Difficult to convert the codes into applications Platform porting Interfacing to other language Fortran 90/95/2000 INTRODUCTION FORTRAN VERSIONS PROGRAM STRUCTURE NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING SIGNIFICANT FEATURES FORTRAN HISTORY STRENGTHS WEAKENESSES POINTER DYNAMIC STORAGE A good description of Fortran programing. PROGRAM name IMPLICIT NONE STOP END declarations statements Program Structure Program Structure Fortran 90/95/2000 INTRODUCTION FORTRAN VERSIONS PROGRAM STRUCTURE NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING SIGNIFICANT FEATURES FORTRAN HISTORY STRENGTHS WEAKENESSES POINTER DYNAMIC STORAGE Significant Features Significant Features New Source Form New Source Form Object-Oriented Programming Object-Oriented Programming Array Programming Array Programming Dynamic Memory Allocation Dynamic Memory Allocation Pointer Pointer Fortran 90/95/2000 INTRODUCTION FORTRAN VERSIONS PROGRAM STRUCTURE NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING SIGNIFICANT FEATURES FORTRAN HISTORY STRENGTHS WEAKENESSES POINTER DYNAMIC STORAGE New Source Form New Source Form Free Format Free Format IMPLICIT NONE IMPLICIT NONE Statements Statements Fortran 90/95/2000 INTRODUCTION FORTRAN VERSIONS PROGRAM STRUCTURE NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING SIGNIFICANT FEATURES FORTRAN HISTORY STRENGTHS WEAKENESSES POINTER DYNAMIC STORAGE New Source Form – Free Format New Source Form – Free Format names of variables may consist of up to 31 characters 132 characters per line up to 39 continuation lines blanks are significant & as line continuation character ; as statement separator for multiple statements per line ! as comment symbol [...]... NEW SOURCE FORM Fortran 90/ 95/2000 INTRODUCTION Object-Oriented Programming FORTRAN HISTORY FORTRAN VERSIONS Functionality STRENGTHS WEAKENESSES PROGRAM STRUCTURE SIGNIFICANT FEATURES NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING POINTER DYNAMIC STORAGE TYPE MODULE Attributes INTERFACE Overload Fortran 90/ 95/2000 INTRODUCTION Object-Oriented Programming - Functionality FORTRAN HISTORY FORTRAN VERSIONS... B END FUNCTION END INTERFACE Fortran 90/ 95/2000 INTRODUCTION Array Programming FORTRAN HISTORY FORTRAN VERSIONS Whole Array STRENGTHS WEAKENESSES PROGRAM STRUCTURE SIGNIFICANT FEATURES NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING POINTER DYNAMIC STORAGE Array Section Intrinsic Functions Fortran 90/ 95/2000 INTRODUCTION Array Programming – Whole Array FORTRAN HISTORY FORTRAN VERSIONS Assignment ... mod(i+99, 100) ) + A( mod(i+1, 100) ) ) / 2 ENDDO Fortran 90/ 95/2000 INTRODUCTION Pointer FORTRAN HISTORY FORTRAN VERSIONS Introduction STRENGTHS WEAKENESSES PROGRAM STRUCTURE SIGNIFICANT FEATURES NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING POINTER DYNAMIC STORAGE Association Status Example Fortran 90/ 95/2000 INTRODUCTION Pointer - Introduction FORTRAN HISTORY FORTRAN VERSIONS A pointer has the POINTER... whose value has changed from 3.14 to 2.718 Fortran 90/ 95/2000 INTRODUCTION Dynamic Storage FORTRAN HISTORY FORTRAN VERSIONS Allocatable Array STRENGTHS WEAKENESSES PROGRAM STRUCTURE SIGNIFICANT FEATURES NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING POINTER DYNAMIC STORAGE Pointer Fortran 90/ 95/2000 INTRODUCTION Dynamic Storage – Allocatable Array FORTRAN HISTORY FORTRAN VERSIONS STRENGTHS WEAKENESSES... of the same shape Multiply them and assign the result to array C DYNAMIC STORAGE FORTRAN 77 FORTRAN 90+ REAL A(5, 5), B(5, 5), C(5, 5) i LOOP j LOOP C(j, i) = A(j, i) * B(j, i) END i LOOP END j LOOP REAL, DIMENSION (5, 5) :: A, B, C C=A*B Fortran 90/ 95/2000 INTRODUCTION Array Programming – Array Section FORTRAN HISTORY FORTRAN VERSIONS STRENGTHS WEAKENESSES PROGRAM STRUCTURE SIGNIFICANT FEATURES NEW... SHAPE , SIZE, ALLOCATED, LBOUND, and UBOUND DYNAMIC STORAGE array constructor functions MERGE, SPREAD, RESHAPE, PACK and UNPACK Fortran 90/ 95/2000 INTRODUCTION Array Programming – Intrinsic Functions FORTRAN HISTORY FORTRAN VERSIONS Example - CSHIFT STRENGTHS FORTRAN 77 FORTRAN 90+ PROGRAM STRUCTURE REAL :: A(0:99), B(0:99) SIGNIFICANT FEATURES DO i = 0, 99 REAL :: A(100), B(100) B = ( CSHIFT(A, +1) +... Array Section FORTRAN HISTORY FORTRAN VERSIONS STRENGTHS Example REAL :: A(10, 10) WEAKENESSES PROGRAM STRUCTURE SIGNIFICANT FEATURES A(4:10, 5) NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING POINTER DYNAMIC STORAGE 1 2 3 4 5 6 7 8 9 A(1:10:2, 1:10:2) 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 Fortran 90/ 95/2000 INTRODUCTION Array Programming – Intrinsic Functions FORTRAN HISTORY FORTRAN VERSIONS... : [column stride] ) Fortran 90/ 95/2000 INTRODUCTION Array Programming – Array Section FORTRAN HISTORY FORTRAN VERSIONS STRENGTHS Example REAL :: A(10, 10) WEAKENESSES PROGRAM STRUCTURE SIGNIFICANT FEATURES A(2:6, 4:8) NEW SOURCE FORM 1 2 3 4 5 6 7 8 9 OO PROGRAMMING ARRAY PROGRAMMING POINTER DYNAMIC STORAGE A(:, 1:3) 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 Fortran 90/ 95/2000 INTRODUCTION... DEALLOCATE (A) Fortran 90/ 95/2000 INTRODUCTION Dynamic Storage - Pointer FORTRAN HISTORY FORTRAN VERSIONS STRENGTHS WEAKENESSES PROGRAM STRUCTURE SIGNIFICANT FEATURES NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING POINTER DYNAMIC STORAGE Use a pointer Can be passed to a procedure in an unallocated state An explicit INTERFACE is required when passing a pointer to a procedure Fortran 90/ 95/2000 INTRODUCTION.. .Fortran 90/ 95/2000 INTRODUCTION New Source Form - IMPLICIT NONE FORTRAN HISTORY FORTRAN VERSIONS STRENGTHS WEAKENESSES PROGRAM STRUCTURE SIGNIFICANT FEATURES NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING POINTER DYNAMIC STORAGE The first line after any USE statements Used to inhibit the old Fortran feature that treats, by default, all variable . PROGRAMMING SIGNIFICANT FEATURES FORTRAN HISTORY STRENGTHS WEAKENESSES POINTER DYNAMIC STORAGE Fortran Versions Fortran Versions 1962 FORTRAN IV 1966 FORTRAN 66 1978 FORTRAN 77 1992 FORTRAN 90 Array Semi-OOP Resembles. FORTRAN 90 LECTURE Yetmen Wang Fortran 90/ 95/2000 INTRODUCTION FORTRAN VERSIONS PROGRAM STRUCTURE NEW SOURCE FORM OO PROGRAMMING ARRAY PROGRAMMING SIGNIFICANT FEATURES FORTRAN HISTORY STRENGTHS WEAKENESSES POINTER DYNAMIC. merged with Compaq, introducing HP CVF 6.6a Intel Fortran, combining CVF, developed Intel Visual Fortran 8.x Fortran 90/ 95/2000 INTRODUCTION FORTRAN VERSIONS PROGRAM STRUCTURE NEW SOURCE FORM OO