정보

    • 업무명    :  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]

     

     참고 문헌

    [논문]

    • 없음

    [보고서]

    • 없음

    [URL]

    • 없음

     

     문의사항

    [기상학/프로그래밍 언어]

    • sangho.lee.1990@gmail.com

    [해양학/천문학/빅데이터]

    • saimang0804@gmail.com
    • 네이버 블러그 공유하기
    • 네이버 밴드에 공유하기
    • 페이스북 공유하기
    • 카카오스토리 공유하기