FORTRAN error array bound is not scalar integer

Click For Summary

Discussion Overview

The discussion revolves around a FORTRAN programming error related to array bounds, specifically the message "array bound is not scalar integer." Participants explore the implications of using loop variables to define array sizes within subroutines and the potential causes of the error encountered by the original poster (OP).

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • The OP seeks assistance with a FORTRAN error related to array bounds and provides a code snippet for context.
  • One participant suggests that the issue arises from using a real index for a 2-dimensional array, which is considered poor programming practice, asserting that all array indices must be integers.
  • Another participant counters that there are no 2-dimensional arrays in the provided code, emphasizing that all arrays are 1-dimensional and that the indices are indeed integers derived from the loop variable.
  • A different participant proposes that the error may stem from implicit typing in the subroutine, indicating that variables not declared may default to types that could lead to the error when used as indices.

Areas of Agreement / Disagreement

Participants express differing views on the cause of the error, with no consensus reached regarding the specific issue in the OP's code. Some believe it relates to array indexing practices, while others suggest it may be due to variable typing.

Contextual Notes

The discussion highlights potential limitations in the provided code snippets, as some participants indicate that critical portions of the code are missing, which may be necessary for diagnosing the error accurately.

sathish
Messages
2
Reaction score
0
FORTRAN error "array bound is not scalar integer"

I'd like to know if a loop can be created, inside which I can call a subroutine in which there are arrays to be defined whose size varies as a function of loop variable. I tried as following, but got error "array bound is not scalar integer".
How to solve this issue?
attaching my code snippet here...


Code:
    . 
    . 
    iloop: do i=5,24,0.5 
    jloop: do j=5,20 
    call check(i,j,divlen,Machexit,final) 
    if (final.eq.1) exit iloop 
    enddo jloop 
    enddo iloop 
    . 
    . 
    end program 
! 

    Subroutine check(i,j,divlen,Machexit,final) 
    INTEGER, PARAMETER :: IVLpts=10 
    real :: i,divlen,Machexit 
    integer :: final,j 
    integer :: exppts,intstrtpts,contourstrtpts,totalpts,P1,P2,P3,P4,P5,P6,P7 
    exppts=((j*IVLpts)+((j-1)*(IVLpts-1))) 
    P2=(exppts-IVLpts) 
    P3=(IVLpts-1) 
    P6=(exppts-P2) 

    call check2(IVLpts,i,j,divlen,Machexit,final,exppts,P2,P3,P6) 

    End subroutine check 
! 

    Subroutine check2(IVLpts,i,j,divlen,Machexit,final,exppts,P2,P3,P6) 
    Real, PARAMETER :: gamma=1.4d0,Mini=1.02d0 
    integer,allocatable :: expcontourpts(:),M(:),x(:),y(:) 
    real,allocatable :: AoverAstar(:),Mvariance(:) 
    allocate(expcontourpts(exppts)) 
    allocate(M(exppts)) 
    allocate(x(exppts)) 
    allocate(y(exppts)) 
    allocate(AoverAstar(P6)) 
    allocate(Mvariance(P6)) 
    . 
    . 
    . 
    End subroutine check2 
!
 
Technology news on Phys.org
Well for one thing, one index of your 2-dimensional array is real, the other index is an integer. This is BAAAAAD programming practice. All of your array indexes must be integers.
 
SteamKing said:
Well for one thing, one index of your 2-dimensional array is real, the other index is an integer. This is BAAAAAD programming practice. All of your array indexes must be integers.

but there are no 2-d arrays at all...
all the arrays are 1-d and all the indexes are integers, which are functions of J (from main prog J=5,20).
So am not sure of what you have mentioned.
Anyway, thanks for the reply...
 
Then the problem lies in a portion of your code not included in the snippets attached to the OP. If you want help tracking down the error, you'll have to post the complete source code.
 
I think the error message is correct.

The problem is that you seem to be using implicit typing; meaning, there are variables that you have no declared in your subroutine and hence they would end up being INTEGERs only and only if the first letter of the variable is in between I and N, inclusive; otherwise, they will be REALs.

In your sub check2, the last 4 arguments do not start with I-N, so, they are real and you use them as indices during the allocation.

Anyway, that's all I can gather on a 1-second look at the code.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 5 ·
Replies
5
Views
8K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
13K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
11
Views
16K