I guess this is what you are trying to do. Because you don't know the size of array x(), you read in the number of data items into INTEGER variable n and use n to declare an array of exactly n elements. However, you would definitely get the following message:PROGRAM Array IMPLICIT NONE INTEGER :: n INTEGER, DIMENSION(1:n) :: x INTEGER :: i READ(*,*) n READ(*,*) (x(i), i=1, n) END PROGRAM Array
While the lower bound and upper bound of an array extent can be constants, PARAMETERs and variables, only formal argument array can use all three types. More precisely, in a main program or a module, the lower bound and upper bound of an array extent must be constants or PARAMETERs. In the above, variable n is used as an upper bound of array x()'s extent in the main program. This is incorrect.INTEGER, DIMENSION(1:n) :: x ^ cf90-521 f90comp: ERROR ARRAY, File = array1.f90, Line = 4, Column = 25 Local variable "N" must be a dummy argument or in common to be used in a bounds specification expression. f90: SunSoft F90 Version 1.0.1.0 (21229283) Fri Nov 14, 1997 18:12:12 f90: COMPILE TIME 0.060000 SECONDS f90: MAXIMUM FIELD LENGTH 2479728 DECIMAL WORDS f90: 9 SOURCE LINES f90: 1 ERRORS, 0 WARNINGS, 0 OTHER MESSAGES, 0 ANSI f90: CODE: 0 WORDS, DATA: 0 WORDS
To solve this problem, you should declare the array as follows:
Of course, you should make sure that you won't read in more than 10 elements into array x().PROGRAM Array IMPLICIT NONE INTEGER, PARAMETER :: SIZE = 10 INTEGER, DIMENSION(1:SIZE) :: x INTEGER :: n, i READ(*,*) n READ(*,*) (x(i), i=1, n) END PROGRAM Array