program OW_vint2rms

use sep

implicit none
real			:: gradz,v0,vsalt,o1,o2,d1,d2,vsal,vh2o
integer			:: i1,i2,n1,n2,j
real,allocatable		:: velin(:,:),velout(:,:)

call sep_init()
call sep_begin_prog()

call from_history("n1",n1); call from_history("d1",d1); call from_history("o1",o1)
call from_history("n2",n2); call from_history("d2",d2); call from_history("o2",o2)
call to_history("n1",n1); call to_history("d1",d1); call to_history("o1",o1)
call to_history("n2",n2); call to_history("d2",d2); call to_history("o2",o2)
call to_history("eout",4);call to_history("label3","")

allocate(velin(n1,n2),velout(n1,n2))
call sreed("in",velin,4*n1*n2)

if(int2rms) then
   velout(1,:)=velin(1,:)
   do i2=1,n2
      do i1=2,n1
         velout(i1,i2)=sqrt(sum(velin(1:i1,i2)**2)/i1)
      end do
   end do
else
   velout(1,:)=velin(1,:)
   do i2=1,n2
      do i1=2,n1
         velout(i1,i2)=sqrt(velin(i1,i2)**2-velin(i1-1,i2)**2)*n1)
      end do
   end doend if
call srite("out",velout,4*n1*n2)
deallocate(velin,velout)
call sep_end_prog()
end program
