!-----------------------------------------------------------------------------
Subroutine Calc_Geographic_Extent
Integer :: ifile, it, ist, ireg, idrou1,idrou2,idrou3, itotal
! Area_Reg1(Nreg,Ntime)
!Real, dimension (Nreg+1,Ntime,Nfile) :: Geo_D1, Geo_D2, Geo_D3                     ! Spatial Extent 7 subregion + Entire Country
!Geo_D1=Miss; Geo_D2=Miss; Geo_D3=Miss

Do ireg=1, Nreg+1
   if (ireg<=Nreg) then
      Do it=1, Ntime
         idrou1=0; idrou2=0; idrou3=0; itotal=0     ! Tong so tram bi han va Tong so tram duoc xet trong tung spell
         Do ist=1, Nst
               if (Int(Reg(ist))==ireg) then
                  itotal=itotal+1        ! Tong so tram duoc xet trong 1 thang  
                  if (D1(ist,it)==1) idrou1=idrou1+1   ! Tong so tram bi anh huong
                  if (D2(ist,it)==1) idrou2=idrou2+1   ! Tong so tram bi anh huong
                  if (D3(ist,it)==1) idrou3=idrou3+1   ! Tong so tram bi anh huong
               endif
         Enddo
         Geo_D1(ireg,it)=real(idrou1)/real(itotal)*100.   ! Phan tram so tram bi anh huong
         Geo_D2(ireg,it)=real(idrou2)/real(itotal)*100.   ! Phan tram so tram bi anh huong
         Geo_D3(ireg,it)=real(idrou3)/real(itotal)*100.   ! Phan tram so tram bi anh huong
      Enddo
   else if (ireg==Nreg+1) then
      Do it=1, Ntime
         idrou1=0; idrou2=0; idrou3=0; itotal=0     ! Tong so tram bi han va Tong so tram duoc xet trong tung spell
         Do ist=1, Nst
               if (Int(Reg(ist))>=1.AND.Int(Reg(ist))<=Nreg) then
                  itotal=itotal+1        ! Tong so tram duoc xet trong 1 thang  
                  if (D1(ist,it)==1) idrou1=idrou1+1   ! Tong so tram bi anh huong
                  if (D2(ist,it)==1) idrou2=idrou2+1   ! Tong so tram bi anh huong
                  if (D3(ist,it)==1) idrou3=idrou3+1   ! Tong so tram bi anh huong
               endif
         Enddo
         Geo_D1(ireg,it)=real(idrou1)/real(itotal)*100.   ! Phan tram so tram bi anh huong
         Geo_D2(ireg,it)=real(idrou2)/real(itotal)*100.   ! Phan tram so tram bi anh huong
         Geo_D3(ireg,it)=real(idrou3)/real(itotal)*100.   ! Phan tram so tram bi anh huong
      Enddo
   endif
Enddo
End Subroutine Calc_Geographic_Extent 
!-----------------------------------------------------------------------------

