      program convolution 
*     *******************
*
      implicit none
*
      integer             dim,maxdim
*
      parameter (dim=1,maxdim=64)
*
      character*8         name1,name2,name3
      integer             npix1(dim)
      integer             npix2(dim)
      real*8  		  start1(dim)
      real*8 		  start2(dim)
      real*8  		  step1(dim)
      real*8 		  step2(dim)
      character*72        ident1,ident2
      character*64        cunit1,cunit2
      integer             pntr1,pntr2,pntr3
      integer             stat1,stat2,stat3
      integer		  naxis1,naxis2
      integer             no1,no2,no3
      integer		  acts
      integer  		  kun
      integer		  knul
      integer		  k_status
*
      real*4 madrid(1)
*
      integer		  Nima,Npsf
      real*8  		  ImaC(maxdim)
      real*8		  PsfC(maxdim)
*
      common /vmr/madrid
*
      Common/CF/ImaC,PsfC,Nima,Npsf
*
      call stspro('convolution')
*
*     Lecture des noms de fichiers
*
      call stkrdc('IN_A',1,1,8,acts,name1,kun,knul,k_status)
      call stkrdc('IN_B',1,1,8,acts,name2,kun,knul,k_status)
      call stkrdc('OUT_A',1,1,8,acts,name3,kun,knul,k_status)
*
      call stiget(name1,10,0,1,dim,naxis1,npix1,start1,step1,
     +            ident1,cunit1,pntr1,no1,stat1)
*
      call stiget(name2,10,0,1,dim,naxis2,npix2,start2,step2,
     +            ident2,cunit2,pntr2,no2,stat2)
*
      call stiput(name3,10,1,1,naxis1,npix1,start1,step1,
     +            ident1,cunit1,pntr3,no3,stat3)
*
      call Con(madrid(pntr1),madrid(pntr2),madrid(pntr3),
     +           npix1(1),npix2(1))
*
      call stfclo(no1,stat1)
      call stfclo(no2,stat2)
*
      close(1)
*
      call stsepi
*
      end
*
*     ***************************************
      subroutine Con(Ima,Psf,Mod,NpIma,NpPsf)
*     ***************************************
*
      implicit none
*
      integer             NpIma,NpPsf
      real                Ima(NpIma)
      real                Mod(NpIma)
      real                Psf(NpPsf)
*
      integer             dim,maxdim
*
      parameter(dim=1,maxdim=64)
*
      real*8              ImaC(maxdim)
      real*8              PsfC(maxdim)
      real*8              Temp1(maxdim)
      integer             Nima,Npsf
*
      Common/CF/ImaC,PsfC,Nima,Npsf
*
      integer             i
*
      Nima=NpIma
      Npsf=NpPsf
      do 1 i=1,maxdim
        ImaC(i)=0.d0
        PsfC(i)=0.d0
    1 continue
      do 2 i=1,Nima
        ImaC(i)=Ima(i)
    2 continue
      do 3 i=1,Npsf
        PsfC(i)=Psf(i)
    3 continue
*
      call Convolve(ImaC,Temp1)
      do 4 i=1,Nima
        Mod(i)=Temp1(i)
    4 continue
*
      return
      end
*
*     ****************************
      subroutine Convolve(Mod,Res)
*     ****************************
*
      implicit none
*
      integer MaxDim
*
      parameter (maxdim=64)
*
      real*8  Mod(maxdim),Res(maxdim)
*
      real*8              ImaC(maxdim)
      real*8              PsfC(maxdim)
      integer             Nima,Npsf
*
      Common/CF/ImaC,PsfC,Nima,Npsf
*
      integer        i,ics,ics1,ip,imin,imax,ii
      real*8         SC
*
      ics=(Npsf-1)/2
      ics1=ics+1
      do 1 i=1,Nima
        Res(i)=Mod(i)
    1 continue
      do 15 i=1,Nima
        imin=max(1,i-ics)
        imax=min(i+ics,Nima)
        SC=0.d0
        ip=ics1-i
        do 13 ii=imin,imax
          SC=SC+Mod(ii)*PsfC(ii+ip)
   13   continue
        Res(i)=SC
   15 continue
      return
      end
