Problem reading from file with arrays
On Fortran 95, I get an error message saying that itemarray(size) cannot be intent(out) which doesn't make any sense because you are reading itemarray from a file. How can I fix this error?
In this subroutine I am basically trying to read from a file and store values in arrays.
Below is the code for the subroutine I am referring to.开发者_运维知识库 Any help is appreciated. Thanks for your time.
SUBROUTINE readItems(size,itemarray,priarray,quarray)
INTEGER:: iost=0, i=0
INTEGER, INTENT(OUT):: quarray(50)
INTEGER, INTENT(OUT):: size
REAL, INTENT(OUT):: priarray(50)
CHARACTER(20),INTENT(OUT)::itemarray(50)
CHARACTER(20)::namefiletoread
PRINT*,"Enter the name of file you would like to read: "
READ*,namefiletoread
OPEN(UNIT=77,FILE = namefiletoread, ACTION = "READ", STATUS="REWIND",IOSTAT=iost)
IF(iost>0)STOP "Problem opening the file!"
DO i=1, size
READ(77,'(A,F6.2,I8)',IOSTAT=iost), itemarray(i), priarray(i),quarray(i)
IF(iost<0)STOP
END DO
END SUBROUTINE
The problem could be with the variable "size". It is declared intent(out), so clearly it doesn't come from the calling function, and it doesn't seem to be assigned anywhere before you start iterating over it.
精彩评论