3

I'm trying to read integers from a file to an array. But I get an error when I run the program.

PROGRAM MINTEM

INTEGER TEMP(4,7), I, J, MINIMUM, CURRENT

OPEN(UNIT=1, FILE='temps.dat')
READ (1,*) ((TEMP(I,J),J=1,7),I=1,4)

MINIMUM = TEMP(1,1)
DO I = 1,4
    DO J = 1,7
        IF (TEMP(I,J) < MINIMUM) THEN
            MINIMUM = TEMP(I,J)
        END IF
    END DO
END DO


PRINT *, "MINIMUM TEMPERATURE = ", MINIMUM
END PROGRAM MINTEM

Input file looks like this:

 22
100 90 80 70 60 100 90 80 70 60 100 90 80 70 60 100 90 80 70
100 90
1
  • 2
    as it currently stands, you seem to be trying to read in 4*7=28 elements Commented Nov 6, 2012 at 5:40

1 Answer 1

2

The file you provided can be read in using this:

integer, allocatable :: t(:)
open(1,file='temp.dat')
read(1,*) N   ! your first line with 22
allocate( t(N-1) )  ! further on you only have 21 elements
read(1,*)t          ! so, read them in 
print*, t
deallocate(t)
close(1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.