部分配列をサブルーチンの引数として渡す

[Sat Jul 16 11:15:16 JST 2011]

[am@aofd30 processor=x86_64]

3x2のサイズの配列A(3,2)の部分配列(サイズは3x1)A(:,1)とA(:,2)を、サブルーチンの引数としてわたす。

プログラム例

program test_bubun
! Description:
!
! Author: am
!
! Host: aofd30
! Directory: /work2/am/12.Work11/21.Climatology/32.Test2_Bi-linear/src
!
! Revision history:
!  This file is created by /usr/local/mybin/nff.sh at 11:07 on 07-16-2011.
!  use
!  implicit none
  integer A(3,2)
  write(*,'(a)')'Program test_bubun starts.'
  write(*,*)''
  A(1,1)=1
  A(2,1)=2
  A(3,1)=3
  A(1,2)=4
  A(2,2)=5
  A(3,2)=6
  print *,"2D Array:"
  do i=1,3
    print *,(A(i,j),j=1,2)
  enddo
  print *
  print *,"1D Array:"
  j=1
  print *,'j= ',j
  call bubun(A(:,j),3)
  print *
  print *,"1D Array:"
  j=2
  print *,'j= ',j
  call bubun(A(:,j),3)
  write(*,*)
  write(*,'(a)')'Done program test_bubun.'
end program test_bubun
subroutine bubun(B,im)
  integer B(im)
  do i=1,im
    print *,B(i)
  enddo
end subroutine bubun

実行例

$ ./test_bubun

Program test_bubun starts.

2D Array:

1 4

2 5

3 6

1D Array:

j= 1

1

2

3

1D Array:

j= 2

4

5

6

Done program test_bubun.