Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
708 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...