포인터 값을 리턴하는 함수
배열에서 다섯번째 값을 리턴하는 함수
PROGRAM ef
! test program of function every_fifth
USE fifth
IMPLICIT NONE
INTEGER, DIMENSION(:), POINTER :: ptr_a
INTEGER, DIMENSION(:), POINTER :: ptr_b
INTEGER :: istat
INTEGER :: i
ALLOCATE(ptr_a(1:100), STAT = istat)
DO i = 1, 100
ptr_a(i) = i
END DO
ptr_b => every_fifth(ptr_a)
WRITE (*,'(1X, A)') 'Original'
WRITE (*,100) ptr_a
100 FORMAT (1X, 10I4)
WRITE (*,'(/,1X,A)') "After using 'every_fifth' pointer-valued function"
WRITE (*,100) ptr_b
END PROGRAM ef
위 소스를 ef.95로 저장
MODULE fifth
CONTAINS
FUNCTION every_fifth (ptr_array) RESULT (ptr_fifth)
IMPLICIT NONE
INTEGER, DIMENSION(:), POINTER :: ptr_array
INTEGER, DIMENSION(:), POINTER :: ptr_fifth
INTEGER :: low
INTEGER :: high
low = LBOUND(ptr_array, 1)
high = UBOUNd(ptr_array, 1)
ptr_fifth => ptr_array(low:high:5)
END FUNCTION every_fifth
END MODULE fifth
위 소스를 every_fifth.f95로 저장
컴파일 및 프로그램 테스트
'Programming > Fortran' 카테고리의 다른 글
sort and search using binary tree (0) | 2009.01.14 |
---|---|
Using pointers in procedures (0) | 2009.01.13 |
Insertion sort using linked list (0) | 2009.01.10 |
usign direct access, formatted file (0) | 2009.01.06 |
NAMELIST I/O (0) | 2009.01.06 |