
Subroutine Write_2D_Reg (Fname)
!Real, dimension (Nreg+1,Nmon) :: T2m_Reg_Mon, Pre_Reg_Mon
!Real, dimension (Nreg+1,Nmon) :: Sum_Geo_D1, Sum_Geo_D2, Sum_Geo_D3   ! Sum over Ntime of Geo_D1,2,3

Integer :: ireg, imon
Real :: Xlon(Nmon), Xlat(Nreg+1), X(Nmon,Nreg+1)
Character (Len=*) :: Fname
Character (Len=255) :: Var_ln

Do imon=1, Nmon; Xlon(imon)=imon; Enddo   ! Mang Lon
Do ireg=1, Nreg+1; Xlat(ireg)=ireg; Enddo ! Mang Lat

!------------------------------------------------------
Var_ln="Regional Mean of Monthly 2m temperature"
Do imon=1, Nmon; X(imon,:)=T2m_Reg_Mon(:,imon); Enddo
Call wr_ncdf_2d (trim(Fname), Xlon, Xlat, Nmon, Nreg+1, X, "T2m", trim(Var_ln), "deg C", "mon", "subreg", Miss)

Do imon=1, Nmon; X(imon,:)=Pre_Reg_Mon(:,imon); Enddo
Var_ln="Regional Mean of Monthly Precipitation"
Call wr_ncdf_2d_apd (trim(Fname), X, "Prec", Nmon, Nreg+1, trim(Var_ln), "mm/mon", "mon", "subreg", Miss)

!------------------------------------------------------
Do imon=1, Nmon; X(imon,:)=Sum_Geo_D1(:,imon); Enddo
Var_ln="Monthly Mean of Geographic Extent over the subregion for Drought D1"
Call wr_ncdf_2d_apd (trim(Fname), X, "Geo_D1", Nmon, Nreg+1, trim(Var_ln), "%", "mon", "subreg", Miss)

Do imon=1, Nmon; X(imon,:)=Sum_Geo_D2(:,imon); Enddo
Var_ln="Monthly Mean of Geographic Extent over the subregion for Drought D2"
Call wr_ncdf_2d_apd (trim(Fname), X, "Geo_D2", Nmon, Nreg+1, trim(Var_ln), "%", "mon", "subreg", Miss)

Do imon=1, Nmon; X(imon,:)=Sum_Geo_D3(:,imon); Enddo
Var_ln="Monthly Mean of Geographic Extent over the subregion for Drought D3"
Call wr_ncdf_2d_apd (trim(Fname), X, "Geo_D3", Nmon, Nreg+1, trim(Var_ln), "%", "mon", "subreg", Miss)

!------------------------------------------------------
Do imon=1, Nmon; X(imon,:)=Sum_NDM_D1(:,imon); Enddo
Var_ln="Monthly Mean of Number drought month over the subregion for Drought D1"
Call wr_ncdf_2d_apd (trim(Fname), X, "NDM_D1", Nmon, Nreg+1, trim(Var_ln), "mon", "mon", "subreg", Miss)

Do imon=1, Nmon; X(imon,:)=Sum_NDM_D2(:,imon); Enddo
Var_ln="Monthly Mean of Number drought month over the subregion for Drought D2"
Call wr_ncdf_2d_apd (trim(Fname), X, "NDM_D2", Nmon, Nreg+1, trim(Var_ln), "mon", "mon", "subreg", Miss)

Do imon=1, Nmon; X(imon,:)=Sum_NDM_D3(:,imon); Enddo
Var_ln="Monthly Mean of Number drought month over the subregion for Drought D3"
Call wr_ncdf_2d_apd (trim(Fname), X, "NDM_D3", Nmon, Nreg+1, trim(Var_ln), "mon", "mon", "subreg", Miss)

!------------------------------------------------------
Do imon=1, Nmon; X(imon,:)=Sum_Sev_D1(:,imon); Enddo
Var_ln="Monthly Mean of drought severity over the subregion for Drought D1"
Call wr_ncdf_2d_apd (trim(Fname), X, "Sev_D1", Nmon, Nreg+1, trim(Var_ln), "-", "mon", "subreg", Miss)

Do imon=1, Nmon; X(imon,:)=Sum_Sev_D2(:,imon); Enddo
Var_ln="Monthly Mean of drought severity over the subregion for Drought D2"
Call wr_ncdf_2d_apd (trim(Fname), X, "Sev_D2", Nmon, Nreg+1, trim(Var_ln), "-", "mon", "subreg", Miss)

Do imon=1, Nmon; X(imon,:)=Sum_Sev_D3(:,imon); Enddo
Var_ln="Monthly Mean of drought severity over the subregion for Drought D3"
Call wr_ncdf_2d_apd (trim(Fname), X, "Sev_D3", Nmon, Nreg+1, trim(Var_ln), "-", "mon", "subreg", Miss)

End Subroutine Write_2D_Reg

