Rank mismatch and incompatible ranks 1 and 2

  • Context: Fortran 
  • Thread starter Thread starter astroastro
  • Start date Start date
  • Tags Tags
    rank
Click For Summary
SUMMARY

The discussion centers on a Fortran programming error related to array declaration. The user encountered rank mismatch errors due to incorrectly declaring a two-dimensional array with "dimension(row:column)" instead of the correct "dimension(row, column)". The use of a colon creates a one-dimensional array, leading to incompatible ranks during assignment. Correcting the array declaration resolves the issue.

PREREQUISITES
  • Understanding of Fortran programming syntax
  • Knowledge of array dimensions in Fortran
  • Familiarity with the reshape function in Fortran
  • Basic file I/O operations in Fortran
NEXT STEPS
  • Review Fortran array declaration syntax
  • Learn about the reshape function in Fortran
  • Explore common Fortran error messages and their resolutions
  • Practice file I/O operations in Fortran programming
USEFUL FOR

This discussion is beneficial for novice Fortran programmers, educators teaching Fortran, and anyone troubleshooting array-related errors in their Fortran code.

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.
 

Similar threads

  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 22 ·
Replies
22
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 11 ·
Replies
11
Views
5K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 7 ·
Replies
7
Views
14K