Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program lab_7_23
  2.     use Environment
  3.     implicit none
  4.    
  5.     Character(*), parameter :: input = "../data/input.txt", output = "output.txt"
  6.     integer :: In = 0, Out = 0, N, M, max_value, i, j, k
  7.     integer, allocatable :: A(:,:), B(:,:), C(:,:)
  8.     integer, allocatable :: Ind(:,:), Indexes(:,:)
  9.     logical, allocatable :: mask(:)
  10.  
  11.     open (file = input, newunit=In)
  12.         read(In, *) N, M
  13.         allocate(A(N,M))
  14.         read(In, *) (A(i,:),i=1, N)
  15.     close (In)
  16.    
  17.     write(*, "(4i3)") (A(i,:), i = 1, N)
  18.     allocate(B(N, M-1))
  19.     allocate(C(N-1, M-1))
  20.     Indexes(:, 2) = [((j, i = 1, N-1), j = 1, M-1)]
  21.     write(*,*) "Indexes is", Indexes
  22.  
  23.  
  24.  
  25.    
  26.     do i = 1, M-1
  27.         B(:,i) = A (:,i) + A(:,i+1)
  28.     end do
  29.    
  30.     do i = 1, N-1
  31.         C(i,:) = B(i,:) + B(i+1, :)
  32.     end do
  33.    
  34.     deallocate(B)
  35.    
  36.     max_value = maxval(C)
  37.    
  38.     write(*,*) "C Array", C
  39.     write(*,*) max_value
  40.    
  41.     allocate(mask((N-1)*(M-1)))
  42.     mask = [C == max_value]
  43.    
  44.     allocate(Ind(Count(C .eq. 32),2))
  45.    
  46.     Ind(:, 1) = Pack(Indexes(:, 1), Mask)
  47.     Ind(:, 2) = Pack(Indexes(:, 2), Mask)
  48.  
  49.     write(*,"(2i2)") Ind
  50. end program lab_7_23
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement