정보
-
업무명 : Arrey Function 예제
-
작성자 : 이상호
-
작성일 : 2019-08-25
-
설 명 :
-
수정이력 :
내용
[특징]
-
Fortran90에서 배열 관련 유용한 내장 함수가 존재하며 이 프로그램은 이러한 목적을 달성하기 위해 고안된 소프트웨어

[기능]
-
배열 개수
-
배열 이동
-
배열 합계
-
배열 인덱스
-
최댓값/최솟값에 해당하는 인덱스
[사용법]
-
소스 코드를 컴파일 (pgf90 Arrey_Function_Example.f90)
-
소스 코드를 실행 (./a.out)
[사용 OS]
-
Linux
[사용 언어]
-
Fortran
소스 코드
[전체]
implicit none
integer, dimension(3,3) :: a
integer, dimension(9) :: b
character(10) :: c
a = reshape( (/0,4,0,2,5,0,0,0,9/), (/3,3/) )
b = reshape( (/0,4,0,2,5,0,0,0,9/), (/9/) )
c = ' abcd '
call COUNT_FUN(a,b)
call CSHIFT_FUN(a,b)
call RESHAPE_FUN(a,b)
call SUM_FUN(a,b)
call INDEX_FUN(c)
call MAXLOC_FUN(a,b)
call UBOUND_FUN(a,b)
end
!**************************************************************************************
subroutine COUNT_FUN(a,b)
implicit none
integer, dimension(3,3) :: a
integer, dimension(9) :: b
integer :: i, cc, cc1, cc2, cc3, cc4
do i=1,3
write(*,*) a(i,1:3)
enddo
write(*,*) '****************************************************&
*********************************'
cc = count(a(1:3,1:3) /= 0)
cc1 = count(a(1:2,1:2) /= 0)
cc2 = count(a(1:2,2:3) /= 0)
cc3 = count(a(2:3,1:2) /= 0)
cc4 = count(a(2:3,2:3) /= 0)
! write(*,*) cc,cc1,cc2,cc3,cc4
! write(*,*) '****************************************************&
! *********************************'
! write(*,*) maxloc(b)
! write(*,*) maxval(b), b(maxloc(b))
! write(*,*) minloc(b)
! write(*,*) minval(b), b(maxloc(b))
return
end subroutine COUNT_FUN
!**************************************************************************************
subroutine CSHIFT_FUN(a,b)
integer, dimension(3,3) :: a
integer, dimension(9) :: b
! write(*,*) cshift(a,shift=1)
! write(*,*) eoshift(a,shift=1)
! write(*,*) '****************************************************&
! *********************************'
! write(*,*) cshift(b,shift=1)
! write(*,*) eoshift(b,shift=1)
!
return
end subroutine CSHIFT_FUN
!**************************************************************************************
subroutine RESHAPE_FUN(a,b)
integer, dimension(3,3) :: a
integer, dimension(9) :: b,d
d(1:9)=reshape(a, (/9/))
! write(*,*) d(1:9)
! write(*,*) b(1:9)
end subroutine RESHAPE_FUN
!**************************************************************************************
subroutine SUM_FUN(a,b)
integer, dimension(3,3) :: a
integer, dimension(9) :: b
! write(*,*) sum(a(1:3,1)), size(a(1:3,1)), real(sum(a(1:3,1)))/size(a(1:3,1))
! write(*,*) sum(a(1:3,2)), size(a(1:3,2)), sum(a(1:3,2))/real(size(a(1:3,2)))
! write(*,*) sum(a(1:3,3)), size(a(1:3,3)), real(sum(a(1:3,3)))/real(size(a(1:3,3)))
return
end subroutine SUM_FUN
!**************************************************************************************
subroutine INDEX_FUN(c)
character(10) :: c,d
d = trim(adjustl(c))
! write(*,*) trim(c),' ',adjustl(c), len(c), len_trim(c), len_trim(adjustl(c))
! write(*,*) index(d,'bc'), index(d,'cb')
! write(*,*) scan(d,'bc'), scan(d,'cb')
! write(*,*) verify(d,'bc'), verify(d,'cb'), verify(d,'ad')
! write(*,*) repeat('a',3)
!
return
end subroutine INDEX_FUN
!**************************************************************************************
subroutine MAXLOC_FUN(a,b)
integer, dimension(3,3) :: a
integer, dimension(9) :: b
! write(*,*) maxloc(a(:,:1)), maxval(a(:,:1))
! write(*,*) minloc(a), minval(a), minloc(a(:,:)), minval(a(:,:))
return
end subroutine MAXLOC_FUN
!**************************************************************************************
subroutine UBOUND_FUN(a,b)
integer, dimension(1:3,2:4) :: a
integer, dimension(9) :: b
! a(1:3,2:5) LBOUND(a,1)=1, LBOUND(a,2)=3
! LBOUND(a,2)=2, LBOUND(a,2)=4
write(*,*) lbound(a,2), ubound(a,2), lbound(a), ubound(a)
write(*,*) lbound(b(:),1), ubound(b(:),1)
return
end subroutine UBOUND_FUN
!**************************************************************************************
[GitHub GIST]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit none | |
integer, dimension(3,3) :: a | |
integer, dimension(9) :: b | |
character(10) :: c | |
a = reshape( (/0,4,0,2,5,0,0,0,9/), (/3,3/) ) | |
b = reshape( (/0,4,0,2,5,0,0,0,9/), (/9/) ) | |
c = ' abcd ' | |
call COUNT_FUN(a,b) | |
call CSHIFT_FUN(a,b) | |
call RESHAPE_FUN(a,b) | |
call SUM_FUN(a,b) | |
call INDEX_FUN(c) | |
call MAXLOC_FUN(a,b) | |
call UBOUND_FUN(a,b) | |
end | |
!************************************************************************************** | |
subroutine COUNT_FUN(a,b) | |
implicit none | |
integer, dimension(3,3) :: a | |
integer, dimension(9) :: b | |
integer :: i, cc, cc1, cc2, cc3, cc4 | |
do i=1,3 | |
write(*,*) a(i,1:3) | |
enddo | |
write(*,*) '****************************************************& | |
*********************************' | |
cc = count(a(1:3,1:3) /= 0) | |
cc1 = count(a(1:2,1:2) /= 0) | |
cc2 = count(a(1:2,2:3) /= 0) | |
cc3 = count(a(2:3,1:2) /= 0) | |
cc4 = count(a(2:3,2:3) /= 0) | |
! write(*,*) cc,cc1,cc2,cc3,cc4 | |
! write(*,*) '****************************************************& | |
! *********************************' | |
! write(*,*) maxloc(b) | |
! write(*,*) maxval(b), b(maxloc(b)) | |
! write(*,*) minloc(b) | |
! write(*,*) minval(b), b(maxloc(b)) | |
return | |
end subroutine COUNT_FUN | |
!************************************************************************************** | |
subroutine CSHIFT_FUN(a,b) | |
integer, dimension(3,3) :: a | |
integer, dimension(9) :: b | |
! write(*,*) cshift(a,shift=1) | |
! write(*,*) eoshift(a,shift=1) | |
! write(*,*) '****************************************************& | |
! *********************************' | |
! write(*,*) cshift(b,shift=1) | |
! write(*,*) eoshift(b,shift=1) | |
! | |
return | |
end subroutine CSHIFT_FUN | |
!************************************************************************************** | |
subroutine RESHAPE_FUN(a,b) | |
integer, dimension(3,3) :: a | |
integer, dimension(9) :: b,d | |
d(1:9)=reshape(a, (/9/)) | |
! write(*,*) d(1:9) | |
! write(*,*) b(1:9) | |
end subroutine RESHAPE_FUN | |
!************************************************************************************** | |
subroutine SUM_FUN(a,b) | |
integer, dimension(3,3) :: a | |
integer, dimension(9) :: b | |
! write(*,*) sum(a(1:3,1)), size(a(1:3,1)), real(sum(a(1:3,1)))/size(a(1:3,1)) | |
! write(*,*) sum(a(1:3,2)), size(a(1:3,2)), sum(a(1:3,2))/real(size(a(1:3,2))) | |
! write(*,*) sum(a(1:3,3)), size(a(1:3,3)), real(sum(a(1:3,3)))/real(size(a(1:3,3))) | |
return | |
end subroutine SUM_FUN | |
!************************************************************************************** | |
subroutine INDEX_FUN(c) | |
character(10) :: c,d | |
d = trim(adjustl(c)) | |
! write(*,*) trim(c),' ',adjustl(c), len(c), len_trim(c), len_trim(adjustl(c)) | |
! write(*,*) index(d,'bc'), index(d,'cb') | |
! write(*,*) scan(d,'bc'), scan(d,'cb') | |
! write(*,*) verify(d,'bc'), verify(d,'cb'), verify(d,'ad') | |
! write(*,*) repeat('a',3) | |
! | |
return | |
end subroutine INDEX_FUN | |
!************************************************************************************** | |
subroutine MAXLOC_FUN(a,b) | |
integer, dimension(3,3) :: a | |
integer, dimension(9) :: b | |
! write(*,*) maxloc(a(:,:1)), maxval(a(:,:1)) | |
! write(*,*) minloc(a), minval(a), minloc(a(:,:)), minval(a(:,:)) | |
return | |
end subroutine MAXLOC_FUN | |
!************************************************************************************** | |
subroutine UBOUND_FUN(a,b) | |
integer, dimension(1:3,2:4) :: a | |
integer, dimension(9) :: b | |
! a(1:3,2:5) LBOUND(a,1)=1, LBOUND(a,2)=3 | |
! LBOUND(a,2)=2, LBOUND(a,2)=4 | |
write(*,*) lbound(a,2), ubound(a,2), lbound(a), ubound(a) | |
write(*,*) lbound(b(:),1), ubound(b(:),1) | |
return | |
end subroutine UBOUND_FUN | |
!************************************************************************************** |
참고 문헌
[논문]
- 없음
[보고서]
- 없음
[URL]
- 없음
문의사항
[기상학/프로그래밍 언어]
- sangho.lee.1990@gmail.com
[해양학/천문학/빅데이터]
- saimang0804@gmail.com
'프로그래밍 언어 > Fortran' 카테고리의 다른 글
[Fortran] 포트란 퇴각검색을 이용한 스도쿠 풀이 알고리즘 (0) | 2019.09.05 |
---|---|
[Fortran, Gnuplot, ShellScript] 기상 자료를 이용한 통계 분석 및 가시화 (0) | 2019.09.01 |
[Fortran] 포트란 지상 관측소를 기준으로 근접한 1/4/9 위성 픽셀에 대해 평균 수행 (0) | 2019.08.25 |
[Fortran] 포트란 끝말잇기 자가 학습 알고리즘 (2) | 2019.07.28 |
[Fortran] 포트란 Himawari-8/AHI (2 km)을 CERES (20 km)로 공간 해상도 일치 (0) | 2019.07.25 |