C%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
C%%%%   Subroutine "clean" is used to clear the file created   %%%%
C%%%%   by AELAS                                               %%%%
C%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        subroutine clean

        use constant
        implicit none 

        integer num, strnum        
        character(len=64) :: cmd, filename
        logical :: filefound

C       delete the file POS_{num}_{strnum}.vasp

        do num=1,21
           do strnum=1,ndef
        
              write(filename,'(a4,i02.2,a1,i03.3,a5)') 
     &                                'POS_',num,'_',strnum,'.vasp'

              inquire (file=filename, exist=filefound)
              if (filefound) then
                      write (cmd, '("/bin/rm ", A)' ) trim (filename)
                      call system (cmd)
              endif

           enddo
        enddo

C       delete the file OSZICAR_{num}_{strnum}

        do num=1,21
           do strnum=1,ndef
        
              write(filename,'(a8,i02.2,a1,i03.3)') 
     &                               'OSZICAR_',num,'_',strnum

              inquire (file=filename, exist=filefound)
              if (filefound) then
                      write (cmd, '("/bin/rm ", A)' ) trim (filename)
                      call system (cmd)
              endif

           enddo
        enddo

C       delete the file INPOS
C       delete the file RECELL


        filename='INPOS'

        inquire (file=filename, exist=filefound)
        if (filefound) then
                write (cmd, '("/bin/rm ", A)' ) trim (filename)
                call system (cmd)
        endif        


        filename='RECELL'

        inquire (file=filename, exist=filefound)
        if (filefound) then
                write (cmd, '("/bin/rm ", A)' ) trim (filename)
                call system (cmd)
        endif

C       delete the file incar_clx and incar_stc

        filename='incar_rlx'

        inquire (file=filename, exist=filefound)
        if (filefound) then
                write (cmd, '("/bin/rm ", A)' ) trim (filename)
                call system (cmd)
        endif

        filename='incar_stc'

        inquire (file=filename, exist=filefound)
        if (filefound) then
                write (cmd, '("/bin/rm ", A)' ) trim (filename)
                call system (cmd)
        endif        

C       delete the file NEWKPT

        filename='NEWKPT'

        inquire (file=filename, exist=filefound)
        if (filefound) then
                write (cmd, '("/bin/rm ", A)' ) trim (filename)
                call system (cmd)
        endif 

C       delete the file RELAS

        filename='RELAS'

        inquire (file=filename, exist=filefound)
        if (filefound) then
                write (cmd, '("/bin/rm ", A)' ) trim (filename)
                call system (cmd)
        endif 

C       delete the file EDATA

C        filename='EDATA'
C
C        inquire (file=filename, exist=filefound)
C        if (filefound) then
C                write (cmd, '("/bin/rm ", A)' ) trim (filename)
C                call system (cmd)
C        endif 

C       delete the file ENGFILE

        filename='ENGFILE'

        inquire (file=filename, exist=filefound)
        if (filefound) then
                write (cmd, '("/bin/rm ", A)' ) trim (filename)
                call system (cmd)
        endif 

C       delete the file DEFMODE

        filename='DEFMODE'

        inquire (file=filename, exist=filefound)
        if (filefound) then
                write (cmd, '("/bin/rm ", A)' ) trim (filename)
                call system (cmd)
        endif         

        end
C%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
C%%%%                        End of clear.f                    %%%%
C%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%      
