Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program ex_7_18_v
- use Environment
- implicit none
- character(*), parameter :: input_file = "../data/input.txt", output_file = "output.txt"
- integer :: In = 0, Out = 0, N = 0, i = 0, j=0, l, N_max, m, k
- real(R_) :: max
- real(R_), allocatable :: A(:, :), B(:)
- integer, allocatable :: Indexes(:, :), Ind_max(:, :)
- logical, allocatable :: Mask(:)
- !READ AN NxN ARRAY
- open (file=input_file, newunit=In)
- read (In, *) N
- allocate (A(N, N))
- allocate (B(2*N))
- read (In, *) (A(i, :), i = 1, N)
- close (In)
- allocate (Indexes(2*N, 2)) !AN N*N MATRIX CONTAINS M*N ELEMENTS. THIS ARRAY WILL CONTAIN INDICES COLUMNWISE.
- allocate (Mask(N), source=.false.)
- !Indexes(:, 1) = [((i, i = 1, N), j = 1, N)]
- !Indexes(:, 2) = [((j, i = 1, N), j = 1, N)]
- i=1
- j=1
- do m=1, N
- B(i) = abs(A(i, i))
- Indexes(i, 1) = i
- Indexes(i, 2) = j
- write (Out, *) Indexes(i, :)
- i=i+1
- j=j+1
- end do
- i=N
- l=N+1
- j=1
- do k=1, N
- B(l) = abs(A(i, j))
- Indexes(i, 1) = i
- Indexes(i, 2) = j
- write (Out, *) Indexes (i, :)
- i=i-1
- l=l+1
- j=j+1
- end do
- write (Out, *) Indexes(:, :)
- max=maxval(B)
- mask = [B == max]
- N_max = count(Mask)
- write (Out, *) N_max
- allocate (ind_max(N_max, 2))
- Ind_max(:, 1) = Pack(Indexes(:, 1), Mask)
- Ind_max(:, 2) = Pack(Indexes(:, 2), Mask)
- open (file=output_file, encoding=E_, newunit=Out)
- write (Out, *) (A(i, :), i = 1, N)
- write (Out, *) "------------------------"
- write (Out, *) B
- write (Out, *) "MAX = ", max
- write (Out, *) (Ind_max(i, :), i = 1, UBound(Ind_max, 1))
- close (Out)
- end program ex_7_18_v
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement