module dso_mod

implicit none
contains
!======================================================================
subroutine owdso(wgcig,n1,n2,o2,d2,n3,mdso)
integer                                                     :: mdso
real						:: wgcig(:,:,:),h
real,allocatable					:: ogcig(:,:,:)
integer						:: ix,ish,iz
integer                                                     :: n1,n2,n3,n4
real                                                        :: d1,d2,d3,d4,o1,o2,o3,o4
allocate(ogcig(n1,n2,n3))
write(0,*) n1,n2,n3
write(0,*) d2
write(0,*) o2

do ish=1,n2
   h=(ish-1)*d2+o2
   if (mdso==0) then
      h=abs(h/((n2-1)*d2+o2))
      ogcig(:,ish,:)=wgcig(:,ish,:)*h*h
   else if (mdso>=1) then
      if (h < 0) then
         ogcig(:,ish,:)=(wgcig(:,ish+1,:)-wgcig(:,ish,:))/d2
      else if (h > 0) then
         ogcig(:,ish,:)=-(wgcig(:,ish,:)-wgcig(:,ish-1,:))/d2
      end if
   end if
end do

if (mdso==1) then
   do ish=1,n2
      h=(ish-1)*d2+o2
      if (h == 0) ogcig(:,ish,:)=0
   end do
else if (mdso==2) then
   do ish=1,n2
      h=(ish-1)*d2+o2
      ogcig(:,ish,:)=ogcig(:,ish,:)*h*h
   end do
end if
wgcig=ogcig
deallocate(ogcig)
end subroutine
end module
