      implicit none
      integer,parameter :: iq=5400,jq=2401,ntide=4
      real              :: x(iq),y(jq),omg(ntide)
      real              :: bcconv(iq,jq,ntide),dep(iq,jq)
      integer           :: i,j,n,iq1,jq1,ntide1
      real :: sum,pai
      pai=2.*asin(1.0)
!-----------------------------------------------------
!               x(i): longitude (unit: degree)
!               y(j): latitude  (unit: degree)
!             omg(n): tidal frequency (unit: radian/sec)
!                     n=1 -> M2, n=2 -> S2, 
!                     n=3 -> K1, n=4 -> O1
!           dep(i,j): averaged depth in each grid area (unit: meter)
!      bcconv(i,j,n): depth-integrated energy conversion rate from barotropic to baroclinic tide
!                     wihtin each grid area (unit: watt/meter**2)       
!-----------------------------------------------------
      open(10,file='BCCONV-DX01-15.E2-GLB-AVE2-M2S2K1O1-DMP30-ASM025-08MAY03.DATA', &
              form='unformatted') 
!-----------------------------------------------------
      read(10) iq1,jq1,ntide1
        if(iq1   .ne.iq   ) pause 
        if(jq1   .ne.jq   ) pause
        if(ntide1.ne.ntide) pause
      read(10) (  x(i),i=1,iq   ), &
               (  y(j),j=1,jq   ), &
               (omg(n),n=1,ntide)
      read(10) ((dep(i,j),i=1,iq),j=1,jq)
      do n=1,ntide
        read(10) ((bcconv(i,j,n),i=1,iq),j=1,jq)
      end do
!---------------------------
      do n=1,ntide
        sum=0.
        do j=1,jq
        do i=1,iq
          sum=sum+bcconv(i,j,n)
        end do
        end do
        write(6,*) 'Tidal Period(hrs)=',2.*pai/omg(n)/3600.,' GLOBAL TOTAL CONVERSION RATE(GW)=',sum/1.e+9
      end do
!---------------------------
      stop
      end

