Rank mismatch and incompatible ranks 1 and 2

  • Context: Fortran 
  • Thread starter Thread starter astroastro
  • Start date Start date
  • Tags Tags
    rank
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 replies · 7K views
astroastro
Messages
5
Reaction score
0
Hi I'm completely new in fortran programming and I just ran this code
program array_test
implicit none
integer, parameter :: row = 3, column = 4
integer :: i, j
integer, dimension(row: column) :: array2
open(1, file = "matrix.txt")
array2 = reshape((/1,2,3,4,5,6,7,8,9,10,11,12/),(/row,column/))
do i = 1, row
write(1, "(12i5)") (array2(i, j), j = 1, column)
enddo
end program

and I get these errors :
7 Incompatible ranks in 1 and 2 in assignment
9 ranks mismatch in array reference (2/1)
can u help me out?!
 
on Phys.org
It looks like you have a typo in the declaration of your array.

You have "dimension(row:column)" ...(notice the colon character ": ") this means that it is a one dimensional array where valid indeces will be from "row" to "column", inclusive.

What you probably meant to do was "dimension(row, column)"...(notice the comma) this means that it is a 2 dimensional array where the valid indeces for each dimension start in the default of 1 and go up to and including the number provided, "row" for the 1st dimension; "column" for the 2nd.