program SHto2DGrid
      use SHTOOLS

      implicit none
      integer, parameter ::   degmax = 3600
      real*8 ::               lat, lon, cilm(2,degmax+1, degmax+1),interval
      real*8 ::               a,f
      real*8 ::               grd(3601,7201)
      integer ::              nmax, lmax, l, i,nlat,nlong,lmaxfile,norm
      character*80 ::         shfile
      
      write(*,*) 'Input file name of Spherical Harmonics'
      read(*,*) shfile
      call SHRead(shfile, cilm, lmaxfile)
      write(*,*) 'lmaxfile',lmaxfile
      write(*,*) 'Input lmax of use'
      read(*,*) lmax
      write(*,*) 'Input Semi-Major Axis of the Flattened Ellipsoid [m]'
      read(*,*) a
      write(*,*) 'Input Flattening of Refference Ellipsoid'
      read(*,*) f
      write(*,*) 'Input Grid Spacing in Degree'
      read(*,*) interval
      call MakeGrid2D (grd,cilm,lmax,interval,nlat,nlong,norm=1,f=f,a=a)
      open (10,file='grd.out',status='unknown')
      do l=1,nlat
      do i=1,nlong
      lat=90.0d0-interval*dble(l-1)
      lon=0.0d0+interval*dble(i-1)
      write (10,*) lon, lat, grd(l,i)
      enddo
      enddo
      stop
end program  SHto2DGrid
