	program writedata
	integer, parameter :: NST=52, NYR=19, NMN=12
	integer, parameter :: syear=1989
	integer :: ist, iyr, imn, idy, itest
	integer :: NDY, YR
	real, dimension(NST) :: lon, lat
	character ( len = 30 ), dimension(NST) :: stname
	character ( len = 8), dimension(12) :: mon = (/'JAN','FEB','MAR','APR','MAY','JUN','JUL','AUS','SEP','OCT','NOV','DEC'/) 
	real, dimension(NST,NYR,NMN) :: regdata
	! -------------------------------------------

	! read Station name
	open(1,file="STATIONS_SEA_fnl.txt",status="old")
	do ist=1,NST
	   read(1,*) stname(ist), lon(ist), lat(ist)
	enddo
	close (1)

	! read Grads data
	regdata=-99
	open(3,file="KQ.txt",status="old")
	do ist=1,NST
	   YR=syear
	   do iyr=1,NYR
	      do imn=1,NMN
	            read(3,*) regdata(ist,iyr,imn)
	      enddo
	      YR=YR+1
	   enddo
	enddo
	close(3)
!
	do ist=1,NST
	open(6,file="KQ/"//trim(stname(ist))//"_mn_ECE_INDEX",status="unknown")
           write(6,*) "Monthly   ECE_INDEX" 
!	   write(6,61) stname(ist),lon(ist),lat(ist)
!	   YR=syear
	   do iyr=1,NYR
	         write(6,63) syear+iyr-1, (regdata(ist,iyr,imn),imn=1,NMN)
	      YR=YR+1
	   enddo
	enddo
	close (6)
	61 format(1x,A14,F8.3,2X,F8.3)
	62 format(1x,I6,3X,12(A8,2X))
	63 format(1x,I4,2X,12(F8.3,2X))
	end
