Fortran Rank mismatch and incompatible ranks 1 and 2

  • Thread starter Thread starter astroastro
  • Start date Start date
  • Tags Tags
    rank
AI Thread Summary
The discussion centers on a Fortran programming issue encountered by a beginner. The user attempted to run a code snippet that defines a 2D array but received errors related to incompatible ranks and mismatches in array references. The solution provided highlights a typo in the array declaration. The original code used "dimension(row: column)", which creates a one-dimensional array with indices from "row" to "column". The correct declaration should be "dimension(row, column)", which properly defines a two-dimensional array with the specified number of rows and columns. This correction resolves the errors and allows the program to function as intended.
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?!
 
Technology news 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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
22
Views
5K
Replies
4
Views
2K
Replies
5
Views
5K
Replies
12
Views
3K
Replies
1
Views
3K
Replies
2
Views
2K
Replies
7
Views
14K
Back
Top