      program frag_data
      character(80) aa
      character(9) ll
      open(1,file='DAT1',status='unknown')
      open(2,file='DAT2',status='unknown')
      open(3,file='DAT3',status='unknown')
      open(8,file='DAT4',status='unknown')
      open(4,file='DAT',status='unknown')
      print*,'FRAG_DATA'
      do
         read(5,'(a80)',end=1) aa
         write(4,'(a)') aa
      enddo
 1    continue
      rewind(4)
      do
         read(4,'(a80)') aa
         if(trim(aa)=='#SCHMUD.DATA') then
            do
               read(4,'(a80)') aa
               if(aa(1:1)=='#') goto 2
               write(1,'(a)') aa
            enddo
         endif
      enddo
 2    continue
      rewind(4)
      do
         read(4,'(a80)') aa
         if(trim(aa)=='#MODIFOLIN.DATA') then
            do
               read(4,'(a80)') aa
               if(aa(1:1)=='#') goto 3
               write(2,'(a)') aa
            enddo
         endif
      enddo
 3    continue
      rewind(4)
      do
      read(4,'(a80)',end=4) aa
         if(trim(aa)=='#CREANOIN.DATA') then
            do
            read(4,'(a80)',end=4) aa
               if(aa(1:1)=='#') goto 4
               write(3,'(a)') aa
            enddo
         endif
      enddo
 4    continue
      rewind(4)
      do
      read(4,'(a80)',end=5) aa
         if(trim(aa)=='#NOSCF.DATA') then
            do
            read(4,'(a80)',end=5) aa
               if(aa(1:1)=='#') goto 5
               write(8,'(a)') aa
            enddo
         endif
      enddo
 5    continue
      close(1)
      close(2)
      close(3)
      kk=0
      ll(1:6)='#LOCIN'
      ee: do
         kk=kk+1
         write(ll(7:9),'(i3)') kk
         ll(7:9)=adjustl(ll(7:9))
         rewind(4)
         do
         read(4,'(a80)',end=6) aa
            !print*,trim(aa)
            if(trim(aa)==ll) then
               open(1,file=ll(2:len_trim(ll)),status='unknown')
               do
               read(4,'(a80)',end=6) aa
                  if(aa(1:1)=='#') cycle ee
                  write(1,'(a)') aa
               enddo
               close(1)
            endif
         enddo
      enddo ee
 6    continue
      close(4,status='delete')
      end

