Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Rank mismatch and incompatible ranks 1 and 2

  1. Sep 15, 2015 #1
    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?!
     
  2. jcsd
  3. Sep 15, 2015 #2
    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Rank mismatch and incompatible ranks 1 and 2
  1. Ranking Algorithm (Replies: 22)

Loading...