Taylor Shropshire
Taylor Shropshire

Reputation: 11

Fortran 90 read file

I am getting my hands wet with Fortran, and am wanting to read a txt file into a an array. I feel like I have tried everything. The txt file is comma seperated 11 rows with 1 number on each row.

Here is my code

program test

real:: obs1,i,jj,count,x_1
real,allocatable:: x(:)

open(1,file='data1.txt',status='old',action='read')
read(1,*) obs1 

allocate(x(obs1))

do i=1, obs1
read(1,*) x_1
x(i)=x_1
end do

do jj=1, obs1
print*,x(jj)
end do 

end program test

this is the error I am receiving:

The highest data type rank permitted is INTEGER(KIND=8)

Upvotes: 1

Views: 1235

Answers (1)

High Performance Mark
High Performance Mark

Reputation: 78316

This statement

allocate(x(obs1))

contains an error, though I'm not sure it's the one that matches the error message you report. obs1 is a real variable, but array dimensions (and indices) have to be integers. Change the declaration of obs1 to

integer :: obs1

Your compiler ought to complain about using a real variable in the do loop control too, do i=1, obs1. Again, use an integer.

As an aside, since you are new to Fortran, learn to use implicit none in every scope within your programs. SO will provide many questions and answers to explain what it means and why it is important, so will any of your favourite Fortran tutorials.

Upvotes: 1

Related Questions