[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ next ]


Fortran 90 Lessons for Computational Chemistry
Chapter 3 - Introduction to Fortran Arrays


3.1 Objectivos

The main aims of this session are the following

  1. present one dimension arrays as Fortran data structures.

  1. present the different ways of defining an array.

  1. present the DO loop syntax and the implicit DO and their use with matrices.

  1. explore dynamic arrays in Fortran 90

  1. present multidimensional arrays as Fortran data structures.


3.2 Main items.

Basic Definitions:

  1. rank: number of indices necessary to indicate unambiguously an array element.

  1. bounds: max and min values of the indices labelling array elements in each dimension.

  1. extent: number of elements in an array dimension.

  1. size: total number of a matrix.

  1. conformal: two arrays are conformal if both have the same rank and extent.

The following points should be emphasized:


3.3 Example Codes.


3.3.1 excode_3_1.f90

     PROGRAM ex_3_1
     !
     ! VARIABLES DEFINITION 
       IMPLICIT NONE
       REAL :: Total=0.0, Average=0.0
       INTEGER, PARAMETER :: Week=7
       REAL , DIMENSION(1:semana) :: Lab_Hours
       INTEGER :: Day
     !
       PRINT *,' Labor Time (hours per day during a week):'
       DO Day= 1, Week
          READ *, Lab_Hours(Day)
       ENDDO
     !
       DO Day = 1, Week
          Total = Total + Lab_Hours(Day)
       ENDDO
       Average = Total / Week
     !
       PRINT *,' Average Weekly Workload: '
       PRINT *, Average, ' hours'
     END PROGRAM ex_3_1

3.3.2 excode_3_2.f90

     PROGRAM ex_3_2
       !
       ! VARIABLE DEFINITION
       IMPLICIT NONE
       REAL :: Total=0.0, Average=0.0
       REAL , DIMENSION(:), ALLOCATABLE :: Lab_Hours
       INTEGER :: Day, Number_Days
       !
       PRINT *,' Number of workdays:'
       READ *, Number_Days
       !
       ALLOCATE(Lab_Hours(1:Number_Days))
       !
       PRINT *,' Daily hours of work in ', Number_Days, ' days.'
       DO Day = 1, Number_Days
          READ *, Lab_Hours(Day)
       ENDDO
       !
       DO Day=1, Number_Days
          Total = Total + Lab_Hours(Day)
       ENDDO
       Average = Total / Number_Days
     !
       PRINT *,' Average daily workhours in ',Number_Days, ' days : '
       PRINT *, Average, ' hours'
     !
     END PROGRAM ex_3_2

3.3.3 excode_3_3.f90

     PROGRAM ATTEND_CONTROL
       IMPLICIT NONE
       INTEGER , PARAMETER :: N_students = 3
       INTEGER , PARAMETER :: N_courses = 3
       INTEGER , PARAMETER :: N_lab = 3
       INTEGER :: student, course, lab
       CHARACTER*2 , DIMENSION(1:N_lab,1:N_courses,1:N_lab) :: attend = 'NO'
       DO student = 1, N_students
          DO course = 1,N_courses
             READ *,(attend(lab,course,student),lab = 1, N_lab)
          ENDDO
       ENDDO
       PRINT *,' Lab attendance : '
       DO student=1, N_students
          PRINT *,' Student = ', student
          DO course = 1,N_courses
             PRINT *,'   Course = ', course, ' : ', (attend(lab,course,student),lab=1,N_lab)
          ENDDO
       ENDDO
     END PROGRAM ATTEND_CONTROL

3.3.4 excode_3_4.f90

     PROGRAM ex_3_4
       IMPLICIT NONE
       REAL , DIMENSION(-180:180) :: Time=0
       INTEGER :: Degree, Strip
       REAL :: Value
     !
       DO Degree=-165,165,15
          Value=Degree/15
          DO Strip=-7,7
             Time(Degree+Strip)=Value
          ENDDO
       ENDDO
     !
       DO Strip=0,7
          Time(-180 + Strip) = -180/15
          Time( 180 - Strip) = 180/15
       ENDDO
     !
       DO Degree=-180,180
          PRINT *,Degree,' ',Time(Degree), 12 + Time(Degree)
       END DO
     END PROGRAM ex_3_4

[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ next ]


Fortran 90 Lessons for Computational Chemistry

0.0

Curro Pérez-Bernal mailto:francisco.perez@dfaie.uhu.es