the following works without changing the file
type coordenate
real4 x
real4 y
end type coordenate
type(coordenate),dimension(:),allocatable :: data_point
!
real8 x1,y1
character129 filename
integer i
integer4 count_lines, ndata
external count_lines
!
filename='\tmp\utf-8-file.dat'
!
ndata = count_lines (filename)
write (,) ndata,' lines identified'
!
if (allocated(data_point)) deallocate(data_point)
allocate(data_point(ndata))
!
do i=1,ndata
call get_xy (x1,y1,i)
data_point(i)%x = x1
data_point(i)%y = y1
end do
write (,*) ndata,' lines recovered'
!
close(37)
end
integer*4 function count_lines (filename)
character filename*129
character line*80
integer*4 i, iostat
open (37,file=filename,status='old',action='read', iostat=iostat)
write (*,*) 'Opening file :',trim(filename),' iostat=',iostat
!
do i = 1,1000000
read (37,fmt='(a)', iostat=iostat) line
if ( iostat /= 0 ) then
write (*,*) 'iostat =',iostat,' at line',i
if ( iostat < 0 ) exit
end if
end do
rewind (37)
count_lines = i-1
end function count_lines
subroutine get_xy (x1,y1,i)
real*8 x1,y1
integer*4 i
integer*4 iostat
character line*80
!
x1 = -1
y1 = -1
read (37,fmt='(a)', iostat=iostat) line
if ( iostat /= 0 ) then
write (*,*) 'error reading file : iostat =',iostat,' at line',i
if ( iostat < 0 ) return
end if
!
call clean_line (line, i)
!
read (line,fmt='(2f30.0)',iostat=iostat) x1,y1
if ( iostat /= 0 ) then
write (*,*) 'error reading from line : iostat =',iostat,' at line',i
if ( iostat < 0 ) return
end if
!
end subroutine get_xy
subroutine clean_line (line, i)
!
! check for numeric line, removing parity characters
!
character line*(*), c
integer*4 i, j,k
!
do j = 1,len_trim(line)
c = line(j:j)
k = ichar (c)
if ( k > 127 ) then
write (*,*) 'parity set in line',i,j,' ',c,k-128
line(j:j) = ' '
cycle
end if
if ( index ('0123456789.+-, ',c) > 0 ) cycle
write (*,*) 'unrecognised character :',c,k
end do
!
end subroutine clean_line
I would use real*8 for the x values you are reading.
you could improve on clean_line to do more cleaning
John