[Fortran] 纯文本查看 复制代码
program main
implicit none
real :: ra_val1(11),ra_val2(11),ra_add(9)
integer :: ia_index(2,9)
integer :: i
ra_add = [0.014000,0.016500,0.016500,0.014000,0.014000,0.014750,0.014750,0.010750,0.010750]
ia_index(:,1) = [ 1 , 2 ]
ia_index(:,2) = [ 1 , 9 ]
ia_index(:,3) = [ 1 , 11 ]
ia_index(:,4) = [ 2 , 3 ]
ia_index(:,5) = [ 3 , 4 ]
ia_index(:,6) = [ 4 , 8 ]
ia_index(:,7) = [ 4 , 10 ]
ia_index(:,8) = [ 5 , 6 ]
ia_index(:,9) = [ 6 , 7 ]
ra_val1 = 0.
ra_val2 = 0.
! 写法1
do i=1,9
ra_val1(ia_index(1,i)) = ra_val1(ia_index(1,i)) + ra_add(i)
ra_val1(ia_index(2,i)) = ra_val1(ia_index(2,i)) + ra_add(i)
enddo
! 写法2
ra_val2(ia_index(1,:)) = ra_val2(ia_index(1,:)) + ra_add
ra_val2(ia_index(2,:)) = ra_val2(ia_index(2,:)) + ra_add
write(*,"(A6,2A12)") "No.","Val1","Val2"
do i=1,11
write(*,"(I6,2F12.6)") i,ra_val1(i),ra_val2(i)
enddo
stop
end program