!     *********************
!     INITIATION of PROGRAM
!     *********************
      program Water_Tank
c	Water Tank Emptying (Cylindrical Cross-Section)
!	Ordinary Differential Equation: dh/dt=-a*SQRT(h) or dh/dt=-a*h^(1/2)

!     ***********************
!     DEFINITION of VARIABLES
!     ***********************
      implicit none

	integer size, N
	parameter (size=1000, N=1000)

c	dimension x(100), f(100)
c	dimension x(size), f(size)
      real*8 h(size), dt, S2, S1, A, H0	 
      integer i, j

!	************************
!	DEFINITION of FORMATTING
!	************************

!	Format of the 'read' files 
5	format(f10.5,x,f10.5,x,f10.5,x,i3)

!	Format of the 'write' files 
15    format(10f10.5)


!	**************
!	OPEN DATA FILE
!	**************
!	Open the READ files
      open(10,file='Water_Tank_Data.txt')  !Opens the x, f datasets

!	Open the WRITE/PRINT files
	open(20,file='Water_Tank_Out.txt')

!	**************
!	READ DATA FILE
!	**************
!	Read the available Water_Tank_Data file containing dt, S2, S1, H0 values 
c     do i=1,N
	read(10,*) dt, S1, S2, H0
c	enddo

!	Inititalize/Nullize the summators for iterative process
c	sum1=0.
c	sum2=0.
c	sum3=0.
c	sum4=0.

	A=S2/S1

	do i=1,N
	 if(i.eq.1) then
	  h(i)=H0
	 elseif(i.gt.1) then 
	  h(i)=h(i-1)-dt*A*SQRT(h(i-1))       !dh/dt=-a*h^(1/2)
!	  h(n+1)-h(n)=-A*dt*(h(n)^(1/2))
	 endif
	 
	 write(20,15) h(i)
	 write(*,*) 'i=', i, '   ', 'h=', h(i)
	 pause    
 
	 if(h(i).le.0.001) GO TO 200

	enddo

200	close(10)
	close(20)
	      
      stop
      
      end