Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
704 views
in Technique[技术] by (71.8m points)

fortran - Writing assumed-size array causes "upper bound shall not be omitted..."

I am writing code to add on a closed-source Finite-Element Framework that forces me (due to relying on some old F77 style approaches) in one place to rely on assumed-size arrays.

Is it possible to write an assumed-size array to the standard output, whatever its size may be?

This is not working:

module fun

implicit none

contains

subroutine writer(a)
integer, dimension(*), intent(in) :: a
write(*,*) a
end subroutine writer

end module fun


program test
use fun
implicit none

integer, dimension(2) :: a

a(1) = 1
a(2) = 2

call writer(a)

end program test

With the Intel Fortran compiler throwing

error #6364: The upper bound shall not be omitted in the last dimension of a reference to an assumed size array.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The compiler does not know how large an assumed-size array is. It has only the address of the first element. You are responsible to tell how large it is.

 write(*,*) a(1:n)

Equivalently you can use an explicit-size array

integer, intent(in) :: a(n)

and then you can do

write(*,*) a

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...