RE: file reading problem



In a previous article, Bart Vandewoestyne <MyFirstName.MyLastName@xxxxxxxxxx> wrote:
>I feel silly... i must have been staring at this for too long but
>i cannot see the problem... I am trying to read the first line of
>a text file to do some processing on it... I'm doing something
>like the following:
>
> ...
>
> character(len=*), intent(in) :: pointset_file
> ...
> integer(kind=i4b), parameter :: max_chars = 100
> integer(kind=i4b) :: my_unit
> character(len=max_chars) :: line
> integer(kind=i4b) :: ios
>
> ...
>
> call get_unit(my_unit)
> open(unit=my_unit, file=pointset_file, iostat=ios, status="old", &
> access="sequential", action="read")
> if (ios == 0) then
> write(unit=*, fmt="(A)") "ERROR: could not open file "//pointset_file
> end if
>
> read (unit=my_unit, fmt="(A)", iostat=ios) line
> if (ios /= 0) then
> print *, "ERROR"
> end if
> print *, "line = ", line
>
> ...
>
>
>Opening the file goes without problems, but reading the first
>line of the file and trying to put the content in `line' always
>seems to give errors because `ios' is nonzero and the content of
>`line' is not the first line of my file.
>
>What am i overlooking here? I've been staring at this for too
>long now...
>
>Regards,
>Bart
>
>--
> "Share what you know. Learn what you don't."

You need to print "error, ios=",ios
and look it up.

Chris
.



Relevant Pages