introduction to fortran
play

Introduction to FORTRAN A Brief Summary of GNU FORTRAN Ashik Iqubal - PowerPoint PPT Presentation

Introduction to FORTRAN A Brief Summary of GNU FORTRAN Ashik Iqubal Department of Physics Ramakrishna Mission Vivekananda University Belur Math, Howrah ashik.iqubal@gmail.com August 31, 2012 FORTRAN: Data Types INTEGER REAL COMPLEX


  1. Introduction to FORTRAN A Brief Summary of GNU FORTRAN Ashik Iqubal Department of Physics Ramakrishna Mission Vivekananda University Belur Math, Howrah ashik.iqubal@gmail.com August 31, 2012

  2. FORTRAN: Data Types INTEGER REAL COMPLEX CHARACTER LOGICAL A. Iqubal FORTRAN

  3. FORTRAN: Data Type Examples Integer INTEGER :: variable1, variable2, .... Real REAL :: variable1, variable2, .... Complex COMPLEX :: variable1, variable2, .... Character CHARACTER(len=character length) :: variable1, variable2, .. Logical LOGICAL :: variable1, variable2, .... LOGICAL :: FLAG FLAG = .TRUE. or .FALSE Arrays REAL, DIMENSION(10) :: VAR A. Iqubal FORTRAN

  4. FORTRAN: Arithmetic Operators + Addition – Subtraction * Multiplication / Division ** Exponentiation A. Iqubal FORTRAN

  5. FORTRAN: Conditional IF Statement Code IF (condition) THEN statements END IF statements are evaluated if condition is true A. Iqubal FORTRAN

  6. FORTRAN: Nested Conditional Statement Code IF (condition1) THEN statements block 1 ELSE IF (condition2) THEN statements block 2 ..... ELSE statements END IF A. Iqubal FORTRAN

  7. FORTRAN: Named Block IF Conditional Statement Code [label:] IF (condition1) THEN statements block 1 ELSE IF (condition2) THEN [label] statements block 2 ..... ELSE [label] statements END IF A. Iqubal FORTRAN

  8. FORTRAN: Relational Operators < less than < = less than or equal to > greater than > = greater than or equal to == equal to / = not equal to A. Iqubal FORTRAN

  9. FORTRAN: Logical Operators .AND. AND .OR. OR .EQV. Logical Equivalence .NEQV. Logical Non-Equivalence .NOT. NOT A. Iqubal FORTRAN

  10. FORTRAN: Order of Evaluation 1 All arithmetic operations are evaluated first from left to right 2 All relational operators are evaluated working from left to right 3 All .NOT. operators are evaluated 4 All .AND. operators are evaluated working from left to right 5 All .OR. operators are evaluated working from left to right 6 All .EQV. and .NEQV. operators are evaluated working from left to right Parenthesis can be used to change the default order of evaluation A. Iqubal FORTRAN

  11. FORTRAN: DO Loops Code DO statements IF (exit-condition) EXIT statements END DO (Repeatedly) executes statements between DO and END DO until exit-condition is true A. Iqubal FORTRAN

  12. FORTRAN: DO WHILE Loops Code DO WHILE (condition) statements END DO If condition is true, repeatedly executes statements between DO and END DO A. Iqubal FORTRAN

  13. FORTRAN: Iterative Loops Code DO index = istart, iend, increment statements END DO 1 index = istart 2 if index*increment < iend*increment , then it executes the statements 3 index = index + increment 4 Repeat steps 2 - 3 A. Iqubal FORTRAN

  14. FORTRAN: Named Loops Code [label:] DO index = istart, iend, increment statements IF (cycle-condition) CYCLE [label] statements IF (exit-condition) EXIT [label] statements END DO A. Iqubal FORTRAN

  15. FORTRAN: Named Loops contd. Code [label:] DO statements IF (cycle-condition) CYCLE [label] statements IF (exit-condition) EXIT [label] statements END DO A. Iqubal FORTRAN

  16. FORTRAN: CYCLE and EXIT Statements EXIT statement exits loops block, jumping immediately to the next statement outside of the loop. CYCLE statement continues the loop after skipping the remaining statements in its current iteration. GOTO statement transfers control to another part of the program A. Iqubal FORTRAN

  17. FORTRAN: Function Code FUNCTION function-name (input-variables) IMPLICIT NONE REAL/INTEGER, INTENT(IN) :: input-variables REAL/INTEGER, :: function-name statements function-name = expression END FUNCTION function-name A. Iqubal FORTRAN

  18. FORTRAN: Recursive Function Code RECURSIVE FUNCTION function(input-var) RESULT(answer) IMPLICIT NONE REAL/INTEGER, INTENT(IN) :: input-var REAL/INTEGER :: answer statements answer = expression END FUNCTION function A. Iqubal FORTRAN

  19. FORTRAN: Subroutine Code SUBROUTINE subroutine-name (input-variables, output-variables) IMPLICIT NONE REAL/INTEGER, INTENT(IN) :: input-variables REAL/INTEGER, INTENT(OUT) :: output-variables REAL/INTEGER, INTENT(INOUT) :: common input/output-variables statements END SUBROUTINE subroutine-name Using RETURN in the subroutine returns to the calling program Subroutines can be called anywhere in the program by using : Code CALL subroutine-name(input-variables, output-variables) A. Iqubal FORTRAN

  20. FORTRAN: Recursive Subroutine If the subroutine is used recursively, then use Code RECURSIVE SUBROUTINE subroutine-name (variables) declarations and statements END SUBROUTINE subroutine-name A. Iqubal FORTRAN

  21. FORTRAN: Subroutine contd. Subroutines/Functions are generally placed at the end of the program after using a CONTAINS statement Code main program ....... CONTAINS SUBROUTINE subroutine-name (variables) ........ END SUBROUTINE subroutine-name END A. Iqubal FORTRAN

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend