!-----------------------------------------------------------------------------
Subroutine Geographic_Extent
Integer :: it, ilon, ilat, ireg, ispl, NSpel, ista, iend, idrou, itotal
! Area_Reg1(Nreg,Ntime)
 Area_Reg1=Miss; Area_Reg2=Miss; Area_Reg3=Miss
! Drough D1
Do ireg=1, Nreg
   NSpel=NSpel_Reg1(ireg)   ! Number of Spells
   Do ispl=1, NSpel
      idrou=0; itotal=0     ! Tong so tram bi han va Tong so tram duoc xet trong tung spell
      ista=IS_Reg1(ireg,ispl); iend=IE_Reg1(ireg,ispl)   ! Start and End time of this spell
      Do it=ista, iend      ! Search over entire spell
         Do ilon=1, Nlon
            Do ilat=1, Nlat
               if (Reg(ilon,ilat)==ireg) then
                  itotal=itotal+1        ! Tong so tram duoc xet trong tung spell
                  if (D1(ilon,ilat,it)==1) idrou=idrou+1   ! Tong so tram bi anh huong
               endif
            Enddo
         Enddo
      Enddo
      Area_Reg1(ireg,ispl)=real(idrou)/real(itotal)*100.   ! Phan tram so tram bi anh huong
!      print*,ireg, Spel_Reg1(ireg,ispl), itotal, idrou, Area_Reg1(ireg,ispl); pause
   Enddo
Enddo
! Drough D2
Do ireg=1, Nreg
   NSpel=NSpel_Reg2(ireg)   ! Number of Spells
   Do ispl=1, NSpel
      idrou=0; itotal=0     ! Tong so tram bi han va Tong so tram duoc xet trong tung spell
      ista=IS_Reg2(ireg,ispl); iend=IE_Reg2(ireg,ispl)   ! Start and End time of this spell
      Do it=ista, iend      ! Search over entire spell
         Do ilon=1, Nlon
            Do ilat=1, Nlat
               if (Reg(ilon,ilat)==ireg) then
                  itotal=itotal+1        ! Tong so tram duoc xet trong tung spell
                  if (D2(ilon,ilat,it)==1) idrou=idrou+1   ! Tong so tram bi anh huong
               endif
            Enddo
         Enddo
      Enddo
      Area_Reg2(ireg,ispl)=real(idrou)/real(itotal)*100.   ! Phan tram so tram bi anh huong
!      print*,ireg, Spel_Reg1(ireg,ispl), itotal, idrou, Area_Reg1(ireg,ispl); pause
   Enddo
Enddo
! Drough D3
Do ireg=1, Nreg
   NSpel=NSpel_Reg3(ireg)   ! Number of Spells
   Do ispl=1, NSpel
      idrou=0; itotal=0     ! Tong so tram bi han va Tong so tram duoc xet trong tung spell
      ista=IS_Reg3(ireg,ispl); iend=IE_Reg3(ireg,ispl)   ! Start and End time of this spell
      Do it=ista, iend      ! Search over entire spell
         Do ilon=1, Nlon
            Do ilat=1, Nlat
               if (Reg(ilon,ilat)==ireg) then
                  itotal=itotal+1        ! Tong so tram duoc xet trong tung spell
                  if (D3(ilon,ilat,it)==1) idrou=idrou+1   ! Tong so tram bi anh huong
               endif
            Enddo
         Enddo
      Enddo
      Area_Reg3(ireg,ispl)=real(idrou)/real(itotal)*100.   ! Phan tram so tram bi anh huong
!      print*,ireg, Spel_Reg1(ireg,ispl), itotal, idrou, Area_Reg1(ireg,ispl); pause
   Enddo
Enddo
End Subroutine Geographic_Extent
!-----------------------------------------------------------------------------

