      implicit none

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

      real :: values(mx,my),results(mx,my),ave(mx,my)
      integer :: id,i,j,iyear,imonth,iday,ihour,steps
      integer :: mask(mx*my)
      character(len=70) :: snd(2),sno(2),sna(2),input,model
      character(len=3) :: sea

      data snd /'_trGt_','.txt'/
      data sno /'_trGt_Std1981-2000_','.txt'/
      data sna /'_trGt_Mean1981-2000_','.txt'/

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

      open(1,file=trim(model)//trim(sna(1))//
     & trim(sea)//trim(sna(2)))
      read(1,'(10f9.3)')((ave(i,j),i=1,mx),j=1,my)

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

      results=0
      steps=0
      print*,trim(model)//trim(sno(1))//
     & trim(sea)//trim(sno(2))

      do
         read(3,'(i6,3i4.2)',end=99) iyear,imonth,iday,ihour
         read(3,'(10f9.3)')((values(i,j),i=1,mx),j=1,my)
         if(iyear.gt.1980.and.iyear.lt.2001) then
           do j=1,my
              do i=1,mx
                 results(i,j)=results(i,j)+(values(i,j)-ave(i,j))**2
              enddo
           enddo
           steps=steps+1
         endif
      enddo

99    do j=1,my
         do i=1,mx
            results(i,j)=(results(i,j)/real(steps))**.5
         enddo
      enddo

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

      write(2,'(10f9.3)') ((results(i,j),i=1,mx),j=1,my)

      close(1)
      close(3)
      close(2)
      close(4)
      end
