Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program ex_7_18_v
  2. use Environment
  3.  
  4. implicit none
  5. character(*), parameter :: input_file = "../data/input.txt", output_file = "output.txt"
  6. integer :: In = 0, Out = 0, N = 0, i = 0, j=0, l, N_max, m, k
  7. real(R_) :: max
  8. real(R_), allocatable :: A(:, :), B(:)
  9. integer, allocatable :: Indexes(:, :), Ind_max(:, :)
  10. logical, allocatable :: Mask(:)
  11.  
  12. !READ AN NxN ARRAY
  13. open (file=input_file, newunit=In)
  14. read (In, *) N
  15. allocate (A(N, N))
  16. allocate (B(2*N))
  17. read (In, *) (A(i, :), i = 1, N)
  18. close (In)
  19.  
  20. allocate (Indexes(2*N, 2)) !AN N*N MATRIX CONTAINS M*N ELEMENTS. THIS ARRAY WILL CONTAIN INDICES COLUMNWISE.
  21. allocate (Mask(N), source=.false.)
  22.  
  23. !Indexes(:, 1) = [((i, i = 1, N), j = 1, N)]
  24. !Indexes(:, 2) = [((j, i = 1, N), j = 1, N)]
  25.  
  26. i=1
  27. j=1
  28. do m=1, N
  29. B(i) = abs(A(i, i))
  30. Indexes(i, 1) = i
  31. Indexes(i, 2) = j
  32. write (Out, *) Indexes(i, :)
  33. i=i+1
  34. j=j+1
  35. end do
  36.  
  37. i=N
  38. l=N+1
  39. j=1
  40. do k=1, N
  41. B(l) = abs(A(i, j))
  42. Indexes(i, 1) = i
  43. Indexes(i, 2) = j
  44. write (Out, *) Indexes (i, :)
  45. i=i-1
  46. l=l+1
  47. j=j+1
  48. end do
  49.  
  50. write (Out, *) Indexes(:, :)
  51.  
  52. max=maxval(B)
  53. mask = [B == max]
  54. N_max = count(Mask)
  55. write (Out, *) N_max
  56.  
  57. allocate (ind_max(N_max, 2))
  58. Ind_max(:, 1) = Pack(Indexes(:, 1), Mask)
  59. Ind_max(:, 2) = Pack(Indexes(:, 2), Mask)
  60.  
  61. open (file=output_file, encoding=E_, newunit=Out)
  62. write (Out, *) (A(i, :), i = 1, N)
  63. write (Out, *) "------------------------"
  64. write (Out, *) B
  65. write (Out, *) "MAX = ", max
  66. write (Out, *) (Ind_max(i, :), i = 1, UBound(Ind_max, 1))
  67. close (Out)
  68.  
  69. end program ex_7_18_v
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement