      integer idim,jdim,yy,mm,dd,hh,mond(12),cnt(4),Pmax,mday
      parameter(idim=360,jdim=181,Pmax=9200)
      real idata(idim*jdim)
      integer idx(4,Pmax),tcnt,isea,yr
      character ifname*120,cyr*4,carea*4,csea(4)*3
      data csea/'jfm','amj','jas','ond'/
      data mond/31,28,31,30,31,30,31,31,30,31,30,31/

      call GETARG(1,carea)
      do isea=1,4
        open(1,file="locations/Surroundings4ERAint_"//trim(carea)
     &         //"180x89_"//csea(isea)//".txt")
        cnt(isea)=1
        read(1,*)
110     read(1,*,end=120) idx(isea,cnt(isea))
        cnt(isea)=cnt(isea)+1
        goto 110
120     continue
        cnt(isea)=cnt(isea)-1
        close(1)
      enddo

      print*,cnt(1:4)

      open(11,file="Ht/ERAintHs_"//trim(carea)//"180x89_"//
     &     csea(1)//".txt")
      open(12,file="Ht/ERAintHs_"//trim(carea)//"180x89_"//
     &     csea(2)//".txt")
      open(13,file="Ht/ERAintHs_"//trim(carea)//"180x89_"//
     &     csea(3)//".txt")
      open(14,file="Ht/ERAintHs_"//trim(carea)//"180x89_"//
     &     csea(4)//".txt")
      do yr=1979, 2010
        tcnt=0
        write(cyr,'(i4)') yr
        ifname='wave_1x1/wave_data_229_'//
     &         trim(cyr)//'.dat'
        print*,trim(ifname)
        open(10,file=trim(ifname),form='unformatted',access='direct',
     &       recl=idim*jdim*4)
        do mm=1,12
          if(mm.eq.2.and.int(yr/4)*4.eq.yr) then
            mday=mond(mm)+1
          else
            mday=mond(mm)
          endif
          do dd=1,mday
            do hh=0,18,6
              tcnt=tcnt+1
C             print*,mm,dd,hh,tcnt
              read(10,rec=tcnt) idata
              if(mm.lt.4) then
                isea=1
              else if(mm.lt.7) then
                isea=2
              else if(mm.lt.10) then
                isea=3
              else
                isea=4
              endif
              do i=1,cnt(isea)
                if(idata(idx(isea,i)).le.0..or.idata(idx(isea,i))
     &              .gt.100.) then
                  print*,isea,i,idx(isea,i),mm,dd,hh,idata(idx(isea,i))
                  stop
                endif
              enddo
C             if(isea.eq.1) then
              write(10+isea,'(i6,3i3,i5)') yr,mm,dd,hh,cnt(isea)
              write(10+isea,'(10f8.3)') (idata(idx(isea,i)),
     &            i=1,cnt(isea))
C             endif
            enddo
          enddo
        enddo
        close(10)
        print*,yr,'done'
      enddo
      close(11)
      close(12)
      close(13)
      close(14)

      end
