implicit none

integer, parameter :: Nst=25, Styr=1960, Styr1=1980, Enyr=2000, Ncl=1
integer, parameter :: Nyr=Enyr-Styr+1, Nyr1=Enyr-Styr1+1, Nmon=12
character(len=11), dimension(Nst) :: TenTram
real, dimension(Nst) :: Lat, Lon
real, dimension(Nst,Ncl) :: Dat_Thuy
real, dimension(Nyr,Nmon,Nst) :: Dat_R, Dat_T
real, dimension(Nyr1,Nmon,Nst) :: Dat1
integer :: Yr, iyr, ist, imon, icl
character(len=11) :: tam

!----------

open (221, file='./INPUT/Rain_OBS.txt', status='old')
open (222, file='./INPUT/T2m_OBS.txt', status='old')
open (223, file='./INPUT/KV.txt', status='old')

!open (331, file='./INPUT/Out4Crt_sta.txt', status='new')
open (331, file='./INPUT/Out4Crt_sta.txt', status='unknown')

!----------

Do ist = 1,Nst
    Read (221,*) TenTram(ist)
    Do iyr = 1, Nyr
	Read (221,*) Yr, (Dat_R(iyr,imon,ist),imon = 1,Nmon)
	Print *, Yr
    Enddo
Enddo

!----------

Do ist = 1,Nst
    Read (222,*) TenTram(ist)
    Do iyr = 1, Nyr
	Read (222,*) Yr, (Dat_T(iyr,imon,ist),imon = 1,Nmon)
	Print *, Yr
    Enddo
Enddo

!----------

Do ist = 1,Nst
    Read (223,*) TenTram(ist), Lon(ist), Lat(ist), (Dat_Thuy(ist,icl),icl=1,Ncl)
    Write (*,*) TenTram(ist), Lon(ist), Lat(ist), (Dat_Thuy(ist,icl),icl=1,Ncl)
Enddo

!----------

print*,'b4 writing'
Do iyr = Styr1, Styr1
    Do imon = 1, Ncl
	Do ist = 1, Nst
	    Write (331,'(i4.4,2x,i2,2x,a15,2x,f6.2,2x,f5.2,2x,f6.1)') iyr,imon,      &
	    Trim(TenTram(ist)), Lon(ist), Lat(ist), Dat_Thuy(ist,imon)
	Enddo
    Enddo
Enddo

!----------

Close (221)
Close (222)
Close (223)
     print*,'ok crt1'
End
