      implicit none

      integer,parameter :: mx=180
      integer,parameter :: my=89
      integer,parameter :: ma=13

      real :: values(mx*my)
      integer :: id,i,iyear,imonth,iday,ihour
      integer :: loc(ma,1400),steps(1)
      character(len=70) :: snd(2),sno(3),snm(3),input,model
      character(len=3) :: sea
      character(len=4) :: area(1)

      data snd /'_trGt_Standardized_','.txt'/
      data snm /'locations/','180x89_','.txt'/
      data sno /'_trGt_Standardized_','_','.txt'/
c      data area /'SP','SA','SIO','ETSP','TSA','TSIO','WTSP',
c     & 'ETNP','TNA','NIO','WTNP','NP','NA'/

      call get_command_argument(1,input)
      read(input,*) model
      call get_command_argument(2,input)
      read(input,*) sea
      call get_command_argument(3,input)
      read(input,*) area

      steps=0
      do id=1,1
         open(30,file=trim(model)//trim(sno(1))//trim(area(id))//
     & trim(sno(2))//trim(sea)//trim(sno(3)))
         open(20,file=trim(snm(1))//trim(area(id))//
     & trim(snm(2))//trim(sea)//trim(snm(3)))
         do i=1,1400
            read(20,*,end=97) loc(id,i)
            steps(id)=steps(id)+1
         enddo
97       continue
         close(20)
      enddo

      open(5,file=trim(model)//trim(snd(1))//
     & trim(sea)//trim(snd(2)))

      print*,trim(model)//trim(sno(1))//trim(area(id))//
     & trim(sno(2))//trim(sea)//trim(sno(3))

      do
      read(5,'(i6,3i4.2)',end=99) iyear,imonth,iday,ihour
      read(5,'(10f9.3)')(values(i),i=1,mx*my)
      do id=1,1
      write(30,'(i6,3i4.2,i6)') iyear,imonth,iday,ihour,steps(id)
      write(30,'(10f9.3)')(values(loc(id,i)),i=1,steps(id))
      enddo
      enddo

99    continue
      do id=1,1
         close(30)
      enddo
      close(3)
      end
