 !  subroutine to save a outflow process
 !  By P. Shen, HKUST, June 2016
 !
	subroutine soutf(ntout,u,u1,outfil)
    use outflow_vars
	implicit none
	integer:: i,j,ntout,u,ctr,u1,ia,m,k
    double precision:: a
	character*1 sp
	character*255 outfil
 	character*31 scratch,header
	sp=char(32) ! space
	ctr=0
 !  write maximum flux of each outflow element 
	open (u,file=outfil,status='unknown',err=21)
	do 100, k=1,nooutflow
	     write(u,1000)  'THE MAX Q AT OUTFLOW ELEMENT: ',outflowcell(k),'IS: ',maxoutfq(k),' CM/s AT TIME: ',maxoutft(k)
    100	continue
 !  write outflow process of each outflow element 
  	do 120, k=1,nooutflow
  	 header='ELEMENT     TIME (HRS)     DISCHARGE (CMS)'
     write(u,1100) trim('ELEMENT'),trim('TIME (HRS)'),trim('DISCHARGE (CMS)'),trim('CV')
     write(u,1200) outflowcell(k),outflowht(1),outflowhq(k,1),outflowcv(k,1)
     do 110, m=2,(ntout+1)
      write(u,1300) outflowht(m),outflowhq(k,m),outflowcv(k,m)
     110    continue
    120 continue
    
    close (u)
 	return
 	
    21	continue
  	write (*,*) 'Error opening output file soutf 21'
	write (*,*) '--> ',outfil
	write (*,*) 'Check file name and status'
  	write (u1,*) 'Error opening output file soutf 21'
	write (u1,*) '--> ',outfil
	write (u1,*) 'Check file name and status'
	pause 'Press RETURN to exit'
	stop
	
 1000	format(A,I6,A,F6.2,A,F6.2)
 1100   format(T1,A,T15,A,T30,A)
 1200   format(T1,I6,T15,F6.2,T30,F8.2,T45,F6.4)
 1300   format(T15,F6.2,T30,F8.2,T45,F6.4)
 
	end

