Topic: reading data from a file
I can write to an output file, but i can't seem to read from a data file:
program helloworld
integer i
integer, parameter :: out_unit=20
integer, parameter :: in_unit=5
real m
i=1
t=0.0
x=0.0
v=0.0
del=.000005
a=0.0
p0=1.013*10**7
patm=1.013*10**6
vol0=2.0*10**3
area=7.98
m=38.6
topen=.01
open(unit=out_unit,file="results.txt",action="write",status="replace")
open(unit=in_unit,file="data1.txt",action="read")
read(in_unit,*),p0
read(in_unit,*),vol0
read(in_unit,*),m
read(in_unit,*),area
read(in_unit,*),topen
print *, "p0",p0," dynes/cm**2"
print *, "vol0",vol0," cm**3"
print *, "mass",m," gm"
print *, "area",area," cm**2"
print *, "Time to open valve",topen,"sec"
print *, " Time(sec) Distance (m) Velocity (m/sec) P/P0"
20 if (x.lt.100.0) then
if (t.lt.topen) then
p1=(p0-patm)*( 3.0*(t/topen)**2-2.0*(t/topen)**3)
else
p1=p0-patm
endif
p=(p1)*(vol0/(vol0+area*x))
a=p*area/m
v=v+a*del
x=x+v*del
i=i+1
t=t+del
if (i.eq.101) then
i=1
Print *, t,x/100.0,v/100.0,p/p0
write(out_unit,*) t,x/100.0,v/100.0,p/p0
endif
if (i.ne.101) then
goto 20
endif
else
30 print *, "1 meter barrel length reached"
print *, " Time (sec) Distance (m) Velocity (m/sec) P/P0"
print *, t,x/100.0,v/100.,p/p0,i
endif
close(out_unit)
close(in_unit)
end program helloworld