discofighter411
discofighter411

Reputation: 19

Compile errors with Fortran90

All, I've been fighting these errors for hours, here's my code:

program hello
implicit none
integer :: k, n, iterator
integer, dimension(18) :: objectArray

call SetVariablesFromFile()
do iterator = 1, 18
    write(*,*) objectArray(iterator)
end do


contains
subroutine SetVariablesFromFile()
    IMPLICIT NONE
    integer :: status, ierror, i, x

    open(UNIT = 1, FILE = 'input.txt', &
    ACTION = 'READ',STATUS = 'old', IOSTAT = ierror)
    if(ierror /= 0) THEN
        write(*, *) "Failed to open input.txt!"
        stop
    end if

    do i = 1, 18
        objectArray(i) = read(1, *, IOSTAT = status) x
        if (status > 0) then
            write(*,*) "Error reading input file"
            exit
        else if (status < 0) then
            write(*,*) "EOF"
            exit
        end if
    end do
    close(1)

END subroutine SetVariablesFromFile

end program hello

I'm getting compile errors:

  1. make: * [hello.o] Error1
  2. Syntax error in argument list at (1)

I read online that the latter error could be due to a long line of code exceeding 132 characters, which doesn't appear to be the problem.I have no where to begin on the first error... any help would be much appreciated!

Upvotes: 0

Views: 439

Answers (1)

Kyle Kanos
Kyle Kanos

Reputation: 3264

This,

objectArray(i) = read(1, *, IOSTAT = status) x

is not valid Fortran. You need to write it as,

read(1,*,iostat=status) objectArray(i)

Setting it in this correct form, I received no compiler errors with ifort 12.1, nor with gfortran 4.4.3

Upvotes: 1

Related Questions