Question about a common block

Question about a common block

--------------------
Visual fortran 6.6
Windows 2000
Pentium 4
--------------------
I have a question about a common block.
Until Now, I have programmed and compiled fortran programs in the workstation(compacq personal workstation XP 1000).In that I used COMMON like this way.

ROGRAM TEST
IMPLICIT REAL*8 (A-H, O-Z), INTEGER*4 (I-N)
COMMON /INTA/ INA(1000)
COMMON A(1000)
A(1) = 1.0
A(2) = 2.0
INA(1) = 1
INA(2) = 2
CALL HEHE
STOP
END

SUBROUTINE HEHE
IMPLICIT REAL*8 (A-H, O-Z), INTEGER*4 (I-N)
COMMON /INTA/ INA(1)
COMMON A(1)
WRITE(*,*) A(1), A(2)
WRITE(*,*) INA(1), INA(2)
RETURN
END

I declared array as common, COMMON A(1000), COMMON /INTA/ INA(1000) in main program,TEST and COMMON A(1), COMMON /INTA/ INA(1) in the subroutine, HEHE

The result is

1.00000000000000 2.00000000000000
1 2

In visual fortran, there is no error in compile, but error when executed like this

forrtl/

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

-- continued --

forrtl: severe (161): Program Exception - array bounds exceeded

If COMMON A(1), COMMON /INTA/ INA(1) in the subroutine, HEHE are replaced with COMMON A(1000), COMMON /INTA/ INA(1000) in the subroutine, the same result are given with workstation. But, my program has many this common blocks(COMMON ARRAY(1), initially it declared as COMMON ARRAY(100)). It is time consuming to replace (1) as original array size. And sometimes it is necessary to replace original array size as new array size(larger). In this case, I have to do replacing array size again!! Is there any method? (no need to replace common blocks)

I believe that the compiler is complaining about the reference to A(2) in your subroutine. The array is declared there as being only 1 element long, and so the index (2) is out-of-range.

I would suggest that you create a fortran 'include' file and place all your common declarations in it, and include the include file in every module that references anything in the common blocks. That way you only need to declare them once (can't get it wrong when you re-declare them since you only declare them once!)

If you need to initialize the contents of common you should use a 'blockdata' module.

Leave a Comment

Please sign in to add a comment. Not a member? Join today