‘‌• ™£¤—œ™...

download  ‘‌• ™£¤—œ™ •££‘›™‘£ ¤œ—œ‘ œ—§‘‌›“©‌ œ—§‘‌™©‌

If you can't read please download the document

  • date post

    08-Jan-2016
  • Category

    Documents

  • view

    36
  • download

    0

Embed Size (px)

description

ΠΑΝΕΠΙΣΤΗΜΙΟ ΘΕΣΣΑΛΙΑΣ ΤΜΗΜΑ ΜΗΧΑΝΟΛΟΓΩΝ ΜΗΧΑΝΙΚΩΝ ΒΙΟΜΗΧΑΝΙΑΣ. ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ Η/Υ. Ι. Σαρρής , sarris@uth.gr , τηλ . 2421074090. Διάλεξη 2 : Πίνακες και δυναμικά δεδομένα στη FORTRAN 90. Εαρινό εξάμηνο 200 9. Οργάνωση παρουσίασης. - PowerPoint PPT Presentation

Transcript of  ‘‌• ™£¤—œ™...

  • 2: FORTRAN 90 2009 /. , sarris@uth.gr, . 2421074090

  • /, .

    : .

    .

  • (static arrays) . . /.

    (dynamic arrays) , , /. , , / .

  • Fortran 77, DES :Dimension " " ( : )

    . . .

    .Dimension (15), (10, 10), C(-5 : 5), (3, 2, 2)

    (15) 15 . (10,10) 10*10 = 100 . C(-5:5) 11 . (3, 2, 2) 3*2*2 = 12 .

  • Fortran 90/95 Dimension :, Dimension ( : ) :: " "

    , . .

    .. :Real, Dimension (15) :: , , C(-5 : 5), (3, 2, 2)

    Integer, Dimension (10, 10) :: , , C

  • , Dimension, , , .

    .. :

    Real X(5, 5), Y(5, 5)Integer Tab(100), Pin(10, 20)

  • )

    Do End Do:

    Integer ADimension A(5)Write(*, *) " "Do i =1, 5Read(*, *) A(i)End Do

    Integer ADimension A(5)Write(*, *) " "Read(*, *)

  • )

    (implied) Do:

    Integer ADimension A(5)Write(*, *) " "Read(*, *) (A(i), i = 1, 5)

    Do :("" , " " = " ", " ", "")

    .. Read(*, *) (A(i), i = 1, 10, 2)

  • ) Integer, Dimension (5) :: A(1) = 10(2) = 20(3) = 30(4) = 40(5) = 50

    ) Data : =(//)..REAL A(4)DATA A=(/2.4,4.0,8,5.9/)

  • .

    :

    Integer ADimension A(3, 2)Do i =1, 3Do j =1, 2Read(*, *) A(i, j)End DoEnd Do

  • .

    :

    Integer ADimension A(3, 2)Do j =1, 2Do i =1, 3Read(*, *) A(i, j)End DoEnd Do

  • Integer ADimension A(3, 2)Read(*, *)

    , 6 .

    Fortran .

  • (implied) Do. , Do, Do :

    Integer ADimension A(3, 2)Read(*, *) ((A(i,j), j = 1, 2), i = 1, 3)

    . i j, j i.

  • Data (3, 2)

    :

    Data A / 1, 2, 3, 2, 4, 6 /

  • . Do End DoInteger ADimension A(5)Do i =1, 5Write(*, *) A(i)End Do . DoInteger ADimension A(5)Write(*, *) (A(i), i = 1, 5) . Integer ADimension A(5)Write(*, *)

  • ;

  • ()

  • (),IF(.NOT.ALLOCATED(B))ALLOCATE(B(-10:10,3))

  • REAL,ALLOCATABLE::X(:,:)...ALLOCATE(X(10,2),STAT=IERR)IF(IERR).GT.0) CALL HANDLERX=0.0...DEALLOCATE(X)...ALLOCATE(X(-10:10),5),STAT=JERR)

  • ()

  • PROGRAM automatIMPLICIT NONEREAL, ALLOCATABLE ::A(:,:)INTEGER ::i,n,m

    READ*,n,mALLOCATE(A(n,m),STAT=IERR)IF(IERR).GT.0) CALL HANDLER A = 1.

    CALL auto(A,n,m) DEALLOCATE(A)

    CONTAINS

    SUBROUTINE auto(c,n,m)INTEGER, INTENT(IN) ::n, mREAL, INTENT(IN) ::c(n,m) !INTEGER ::i,jREAL::b(n,m) ! FORALL(i=1:n,j=1,m)b(i,j)=c(i,j)*c(i,j)END FORALL END SUBROUTINE auto

    END PROGRAM automat

  • INTEGER, ALLOCATABLE, DIMENSION(:)::X

    ALLOCATE(X(3),STAT=IERR)IF(IERR).GT.0) CALL HANDLERX=(/1,2,3/); PRINT *, X! : 1 2 3n = SIZE(X)X=test(x,n); PRINT *, X! : 1 4 9IF (ALLOCATED(X)) DEALLOCATED (X)

    CONTAINS FUNCTION test(x,n) RESULT(y)INTEGER, INTENT(IN) ::n, x(:) ! INTEGER, DIMENSION(n) ::y !y=x*x END FUNCTION test

    END

  • ()

  • TYPE ( ) :: 1 :: 2 END TYPE ( )[PROGRAM ] Implicit None ..END [PROGRAM [ ]]

  • .TYPE STUDENTSCHARACTER (LEN=20) :: SURNAME ! CHARACTER (LEN=10) :: NAME ! INTEGER (KIND=2) :: AEMINTEGER (KIND=1) :: GRADEEND TYPE STUDENTS

    TYPE (STUDENTS) :: STUDENT TYPE ( ) ::

  • .STUDENT=STUDENTS(, ,1234,9)STUDENT.SURNAME=STUDENT.NAME=STUDENT.AEM=1234STUDENT.GRADE=9

  • ()

  • ()

  • IMPLICIT NONETYPE IDEAL REAL ::VOLUME,PRESSURE,T CHARACTER(11)::HEADEREND TYPE IDEAL

    TYPE (IDEAL):: C(5) ! C IDEALREAL::CONSTANTINTEGER::IREAL,PARAMETER::R=0.0820556

    C%HEADER=(/PRESSURE,VOLUME,TEMPERATURE,,/)C(1)%PRESSURE=15; C%T=298C%VOLUME =(/100,80,60,40,20/)CONTANT = C(1)%PRESSURE*C(1)%VOLUMEC(:)%PRESSURE=CONSTANT/C(:)%VOLUME

    ! :WRITE(*,(X,3A11,)) (C(I)%HEADER,I=1,3)

    ! :DO I=1,5WRITE(*,(F6.2,6X,F5.1,8X,F5.1)) C(I)%PRESSURE, C(I)%VOLUME, C(I)%TEND DOEND