user1807833
user1807833

Reputation: 21

Fortran subroutines with arrays

I am having an issue with the subroutine in this program, which is at the end of the program. I am getting an error for the division of the arrays in the subroutine, which says "unclassifiable statement." Hope someone can help!

PROGRAM subroutine1
IMPLICIT NONE

INTEGER:: err, ierr, counter, y ,i ,j 
!INTEGER, ALLOCATABLE:: gamenum(:)
CHARACTER(30):: fname
REAL, ALLOCATABLE:: AB(:), H(:), TB(:), BA (:), SP(:)

100 Format (A)
200 Format (I2)
300 Format (F9.3)

! 1.Open file

WRITE(*,100)"Please enter a filename:"
READ(*,*) fname

OPEN (UNIT=10, FILE=fname, STATUS="OLD", ACTION="READ", IOSTAT=err)
IF(err.NE.0) STOP "An error occured when opening the file."

! 2.Count Lines

READ(10,*)

counter=0
DO
    READ(10,*,IOSTAT=ierr)
    IF(ierr .NE. 0) EXIT
    counter=counter+1
END DO

!WRITE(*,200) counter

! 3. allocate array

ALLOCATE(AB(counter)) 
ALLOCATE(H(counter))
ALLOCATE(TB(counter)) 
ALLOCATE(BA (counter)) 
ALLOCATE(SP(counter))

! 4. read in data

REWIND(10)

READ(10,*)

DO i=1,counter
    READ(10,*) AB(i), H(i), TB(i)   
END DO

REWIND(10)

! 5. Call subroutine

    CALL arraycalc(counter,AB,H,TB,BA,SP)

! 6. Write out
WRITE(*,100)"Game    AB       H       TB       BA       SP" 

DO i=1,counter
    WRITE(*,200,ADVANCE="NO") i
    WRITE(*,'(5F9.3)') AB(i), H(i), TB(i), BA(i), SP(i)
END DO

END PROGRAM subroutine1

!HERE IS THE PART WHERE I'M HAVING TROUBLE  

SUBROUTINE arraycalc(counter,AB,H,TB,BA,SP)
IMPLICIT NONE

INTEGER, INTENT(IN)::counter
INTEGER::i
REAL,INTENT(INOUT)::AB,H,TB
REAL,INTENT(INOUT):: BA,SP

DO i=1,counter
    BA(i)=H(i)/AB(i)
END DO

DO i=1,counter
    SP(i)=TB(i)/AB(i)
END DO

END SUBROUTINE

Upvotes: 2

Views: 327

Answers (1)

eriktous
eriktous

Reputation: 6659

Inside the subroutine, AB, H, TB, BA, and SP are not declared as arrays, so the statement that gives the error indeed makes no sense. They are scalars, so can not be indexed.

Upvotes: 2

Related Questions