      implicit none

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

      real :: values(mx,my),results(mx,my),lambda(mx,my)
      integer :: id,i,j,iyear,imonth,iday,ihour,lon,lat
      character(len=70) :: snd(2),sno(2),snm,input,model
      character(len=3) :: sea

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

      snm='_gt_lambda.txt'

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

      open(4,file=trim(sea)//trim(snm))

      do j=1,my
         do i=1,mx
            read(4,*) lon,lat,lambda(i,j)
         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)')((values(i,j),i=1,mx),j=1,my)
         do j=1,my
            do i=1,mx
               if(abs(lambda(i,j)).lt.1E-5) then
               if(abs(values(i,j)).lt.1E-5) values(i,j)=0.0001
               results(i,j)=log(values(i,j))
               else
               if(abs(values(i,j)).lt.1E-5.and.lambda(i,j).lt.0) then
               values(i,j)=0.0001
               endif
               results(i,j)=((values(i,j)**lambda(i,j))-1)/lambda(i,j)
               endif
               if(abs(results(i,j)).gt.100000) then
               print*,iyear,imonth,iday,ihour
               print*,i,j,results(i,j),values(i,j),lambda(i,j)
               stop
               endif
            enddo
         enddo
         write(2,'(i6,3i4.2)') iyear,imonth,iday,ihour
         write(2,'(10f9.3)') ((results(i,j),i=1,mx),j=1,my)
      enddo

99    close(3)
      close(2)
      close(4)
      end
