      SUBROUTINE COF2GRD(S,IV,GRD,NFT,YLATS,DLAT,IINDEX)
C
C Re-written to use NEC FFT routines instead of Cray FFT routines
C
C Chris Peters, GSC     February 6, 1996
C
            save
      INCLUDE "parmanl"
      dimension IINDEX(IMAX)
      real s(*),grd(IMAX,JMAX)
      real b(720),al(0:240),bl(240),r(480),trigs(1440)
Chou
      real qlnt( NCOEF ), qlnv( NCOEF2 )
      real temp1(720)
      integer work(15)
C      common /temptsd/ temp
C      data temp / 720 * 0.0/
      dimension xlat( JMAX )
      data ifrst/0/
      if(ifrst.eq.0) then
         write(0,*) 'IN COF2GRD'
         write(6,'(10i7)')IINDEX
           do 1 j = 1, JMAX 
           xlat(j) = (ylats + float(j-1) * dlat)
1          continue
           ifrst = 99
      end if
      do 60 ll = 1, JMAX
        if ( xlat(ll).gt.0.0 ) then
          ihem = 1
        else
          ihem =-1
        endif
      colrad = (90.0 - abs(xlat(ll)))*3.14159265 / 180.0
c     write(6,'(1x,2i5,2f10.4)') ll,ihem,xlat(ll),colrad
      If(colrad.ne.0.0) then
        call pln2h(qlnt,qlnv,colrad)
        cosli = 1.0 / sin(colrad)
        if(iv.ne.0) then
           call SUMVHS(s,temp1,qlnv,1,ihem)
c       if( ll.le.2.or.ll.eq.(jmax-1)) then
c         write(0,'("  here comes temp after call to SUMVHS")')
c         write(0,'(1p10e12.3)')(temp1(ipp),ipp=1,nft)
c       endif
        else
           call SUMSHS(s,temp1,qlnt,1,ihem)
        end if
        nft2 = nft+2
c       if((ll.le.2.or.ll.eq.(jmax-1))) then
c         write(0,'("  here comes temp before call to FFTidim")')
c         write(0,'(1p10e12.3)')(temp1(ipp),ipp=1,nft)
c       endif
        call FFTidim(temp1,b,work,al,bl,r,trigs,nft,nft2,JCAP12,1,1)
c       if((ll.le.2.or.ll.eq.(jmax-1))) then
c         write(0,'("  here comes temp after call to FFTidim")')
c         write(0,'(1p10e12.3)')(temp1(ipp),ipp=1,nft)
c       endif
        do 88921 iq2 = 1,imax
         iq3 = IINDEX(iq2)
           if(iv.ne.0) then
                grd(iq2,ll) = temp1(iq3) * cosli
           else
                grd(iq2,ll) = temp1(iq3)
           end if
88921   continue
      endif
60    continue
      return
      end
