      implicit none

      integer,parameter :: mx=180
      integer,parameter :: my=91
      real,parameter :: pi=3.1415926

      real :: p(mx+1,my),q(mx,my),lat(mx,my)
      real :: mp,phi,dpx1,dpx2,dpy1,dpy2,dp
      integer :: id,i,j,iyear,imonth,iday,ihour
      character(len=70) :: snd(2),sno(2),input,model
      character(len=3) :: sea

      data snd /'_SLP_','.txt'/
      data sno /'_Gt_','.txt'/

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

      do j=1,my
         do i=1,mx
            lat(i,j)=(j-1)*2-90
         enddo
      enddo

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

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

      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)')((p(i,j),i=1,mx),j=1,my)
         do j=1,my
            p(mx+1,j)=p(1,j)
         enddo
         i=1
         do j=2,my-1
            phi=pi*lat(i,j)/180.
            dpx1=(p(i,j)-p(mx,j))/cos(phi)
            dpx2=(p(i+1,j)-p(i,j))/cos(phi)
            dpy1=p(i,j)-p(i,j-1)
            dpy2=p(i,j+1)-p(i,j)
            dp=(dpx1**2+dpx2**2)/2.+(dpy1**2+dpy2**2)/2.
            q(i,j)=dp
         enddo
         do i=2,mx
            do j=2,my-1
               phi=pi*lat(i,j)/180.
               dpx1=(p(i,j)-p(i-1,j))/cos(phi)
               dpx2=(p(i+1,j)-p(i,j))/cos(phi)
               dpy1=p(i,j)-p(i,j-1)
               dpy2=p(i,j+1)-p(i,j)
               dp=(dpx1**2+dpx2**2)/2.+(dpy1**2+dpy2**2)/2.
               q(i,j)=dp
            enddo
         enddo
         write(2,'(i6,3i4.2)') iyear,imonth,iday,ihour
         write(2,'(10f9.3)') ((q(i,j),i=1,mx),j=2,my-1)
      enddo

99    close(3)
      close(2)
      end
