1
votes

I am having trouble reading a large ascii file (with a 6 line header) into an array. Here is the relevant code...

    ! skip ahead 6 lines in the ascii file
    do i=1, 6
        read (20, *)
    end do
    do row = 1, nrow
        read(20,*) data(row,:)
    end do

I get the message "Fortran runtime error: Bad integer for item 3991 in list input". I've looked col 3991 and nothing looks out of the ordinary. Does anyone know how to skip past the header properly? I am compiling an .f90 file with gfortran. Thanks.

edit: I also tried this instead of the first do loop...

read (20, *) temp, ncol
read (20, *) temp, nrow
read (20, *) temp, xcord
read (20, *) temp, ycord
read (20, *) temp, cell
read (20, *) temp, nodata

My header is:

ncols         4193
nrows         2322
xllcorner     604374.4763
yllcorner     810341.0601
cellsize      30
NODATA_value  -9999
1
What's in the header? - IanH
ncols 4193 nrows 2322 xllcorner 604374.4763 yllcorner 810341.0601 cellsize 30 NODATA_value -9999 - user14241
Sorry, I am a n00b here and can't figure out how to format that last response. But in case you're wondering, I also tried without the do loop by just having 6 lines in the code reading one by one with proper variables of proper data types for each read (usually character, int) - user14241
Since the error msg is about item 3991 the problem is probably not with the header, but farther down in the file. A technique that I use when I'm having trouble finding a problem like this is to read the line into a character string, echo the string to output, then do the "actual" read from the string. The last "echo" output will show you the input that causes the problem. - M. S. B.
Thanks for the tip. I'll try and remember this in the future. - user14241

1 Answers

0
votes

Sorry to waste people's time. I just realized that my data was float not int data. The error message couldn't have been any more clear. Thanks for the help.