Mangepoint source Fortran source

  • Mangeage des petits points dnas une image
     program mangepoint
     implicit none
     integer source(6000,8000), resul(6000,8000)
     integer ic, il, sigma, iblancg, iblancd, lgr, nbvois, sigmatot
     integer nblig, nbcol, posit, icc, ill, distance2, sigma2
     character*90 ligne
     character*1 bout
     character*2 sigmachar
     character*30 nomfichier, nominput, nomoutput
     sigma = 0
     call getarg(1, nomfichier)
     call getarg(2, sigmachar)
     read (sigmachar, *) sigma
     if (sigma.eq.0) then
       print *, 'Sigma = 0 !'
       stop
     endif
     posit = len_trim(nomfichier) + 1
     nominput = nomfichier(1:posit-1)//'.pbm'
     call system('copy '//nominput//' old'//nominput)
     
     nomoutput= nominput
     sigmatot = (2*sigma + 1)*(2*sigma + 1) ! 
     sigma2 = sigma*(sigma + 1)
     print *, 'sigmatot = ', sigmatot
     call system('convert -compress none '//nominput//nominput)
     open (unit=8, file=nominput)
     open (unit=9, file=nomoutput)
     read (8, '(a)') ligne    ! P1
     write (9, '(a)') ligne
     read (8, '(a)') ligne  
     do while (index(ligne, '#').gt.0) 
       read (8, '(a)') ligne  
     enddo
     write (9, '(a)') ligne
     read (ligne, *) nbcol, nblig
     
     print *, nblig, nbcol
     ic = 1; il =1
     do while ((il.lt.nblig).and.(ic.lt.nbcol))
       read (8, '(a)', end=200) ligne
       lgr = len_trim(ligne)
       iblancg = 1
       iblancd = 0
       do while (iblancd.lt.lgr)
         iblancd = index(ligne, ' ') 
         bout = ligne(iblancg:iblancd - 1) 
         read (bout,*) source(ic,il)
         ic = ic + 1
         ic = mod(ic, nbcol)
         if (ic.eq.0) il = il + 1
         ligne(iblancd:iblancd) = '*' 
         iblancg = iblancd + 1
       enddo
     enddo
     print *, 'Lecture OK'
     goto 300

200 print *, 'Fin de fichier', ic, il 300 do ic = sigma, nbcol - sigma

       do il = sigma, nblig - sigma
         nbvois = 0
         resul(ic, il) = source(ic, il)
         do icc = ic - sigma, ic + sigma
           do ill = il - sigma, il + sigma
             distance2 = (icc - ic)*(icc - ic) + (ill - il)*(ill - il)
             if ((distance2.le.sigma2).and.(source(icc,
    +        ill).eq.1)) nbvois = nbvois + 1
           enddo
         enddo
         if (nbvois.lt..125*sigmatot) resul(ic, il) = 0
       enddo
     enddo
     print *, 'Fin du traitement'
     do il = 1, nblig 
       ic = 1     
       do while (ic.le.nbcol)
         write (9,*) (resul(icc, il), icc=ic, min(ic+19, nbcol))
         ic = ic + 20
       enddo
     enddo
     close (unit=8)
     close (unit=9)
     end