Well.. the file is still unread.. I think I should post the codes=>
=>The program I used to create the data is
program xytable
! this code is to create data for the interpolation code written in console12
implicit none
integer::i,j
integer,parameter::m=50
real,dimension(1:m)::t,h
real,dimension(m,2)::A ! a 2D matrix to store x & y
!create data
do i=1,m
t(i)=(i*1.-1.)/2.
h(i)=f(t(i))
A(i,1)=t(i)
A(i,2)=h(i)
end do
!save data
open(1,file='xytable.txt')
do i=1,m
print*,(A(i,j),j=1,2)
write(1,*)(A(i,j),j=1,2)
end do
close(1)
!define function f(x)
contains
function f(t)
real::f,t
f=2*t**2-t
end function f
end program xytableThe data as appear in the text file are:
0.0000000E+00 0.0000000E+00
0.5000000 0.0000000E+00
1.000000 1.000000
1.500000 3.000000
2.000000 6.000000
2.500000 10.00000
3.000000 15.00000
3.500000 21.00000
4.000000 28.00000
4.500000 36.00000
5.000000 45.00000
5.500000 55.00000
6.000000 66.00000
6.500000 78.00000
7.000000 91.00000
7.500000 105.0000
8.000000 120.0000
8.500000 136.0000
9.000000 153.0000
9.500000 171.0000
10.00000 190.0000
10.50000 210.0000
11.00000 231.0000
11.50000 253.0000
12.00000 276.0000
12.50000 300.0000
13.00000 325.0000
13.50000 351.0000
14.00000 378.0000
14.50000 406.0000
15.00000 435.0000
15.50000 465.0000
16.00000 496.0000
16.50000 528.0000
17.00000 561.0000
17.50000 595.0000
18.00000 630.0000
18.50000 666.0000
19.00000 703.0000
19.50000 741.0000
20.00000 780.0000
20.50000 820.0000
21.00000 861.0000
21.50000 903.0000
22.00000 946.0000
22.50000 990.0000
23.00000 1035.000
23.50000 1081.000
24.00000 1128.000
24.50000 1176.000
=>The program I am reading the data in is:
program readtext
implicit none
!interface between main program and subroutine
interface
subroutine polint(x,y,xin,yout,dyout)
use nrtype
real(sp),dimension(:),intent(in)::x,y
real(sp),intent(in)::xin
real(sp),intent(out)::yout,dyout
end subroutine polint
end interface
!declare variables
real,allocatable,dimension(:)::x,y
real::xin,yout,dyout,t,h
integer::p,st,row,col
integer,parameter::n=50
real,dimension(n,2)::A
!make memory for the input x and y arrays
if(allocated(x)) then
deallocate(x)
end if
if(allocated(y))then
deallocate(y)
end if
allocate(x(1:n),y(1:n),stat=p)
if(p /= 0) then
print*,"allocation error"
stop
end if
!load data into the code
open(unit=1,file='xytable.txt',form='formatted',iostat=st)
if(st/=0)then
print*,'Error opening file. File load status=',st
stop
else
print*,'file opened correctly!.ios=',st
end if
do row = 1,n
read(1,*,end=50)(A(row,col),col=1,2)
end do
50 do row = 1,n
print*,(A(row,col),col=1,2)
end do
print*, "dimension of x and y arrays="
print*,n
end program readtext
I reach the statement '50' but all the numbers in both columns are zeros. I've been advised to change the read loop to:
read(1,*,end=50) A(row,:)
read(1,*,end=50) A(row,1),A(row,2)
but the result is unchanged.. I really can't see where the problem lies.