Fortran runtime error: Bad real number in item 1 of list input

I am getting run time error: Bad real number in item 1 of list input for this sample problem. Please, suggest the correct way.

    implicit double precision (a-h,o-x)
    parameter (ni=150)  
    dimension x(ni)
    open(40,file='fortin')
    do 80 i=1,5
    read(40,*)x(i)
    write(*,*)i,x(i)
80  continue
    stop
    end

The data in the fortin file arranged in column

   1.0     
   5.0     
   3.0
   5.0
   7.0

Upvotes: 3

Views: 34225

Answers (2)

haibuihoang
haibuihoang

Reputation: 171

In my case, the problem lies in the data file, not the code.

My problem turn out to be the file is in Unicode format. When I view in vi, it's shown fine. But when I view in a viewer that does not support unicode, such as using midnight commander, it look like a mess. The one who sent me the file later told me that he save the file in UTF-16.

Upvotes: 0

Kyle Kanos
Kyle Kanos

Reputation: 3264

Your code expects only numbers and it appears you have characters in the file. You can do one of two things to fix this:

  1. Delete the words at the top of the fortin file
  2. Add a single read(*,*) (no need for anything following it) before the loop

Upvotes: 2

Related Questions