*...:....1....:....2....:....3....:....4....:....5....:....6....:....7....:....8 program frag character*75 line character*8 spec character*40 file,svfile integer*4 i,n,m,lspec integer*4 m1/0/,m2/0/,m3/0/,m4/0/ intrinsic MAX0 read(*,'(a)') spec do i=1,40 file(i:i)=' ' end do file='emmcntl.' lspec=0 do i=1,8 if (spec(i:i).ne.' ') then file(8+i:8+i)=spec(i:i) lspec=lspec+1 end if end do open(unit=10,file=file,status='old',form='formatted') n=0 10 read(10,'(a)',end=20) line n=n+1 go to 10 20 continue rewind(10) m=MAX0(1,n/4) if (m .le. n) then m1=m else m1=n end if if (m1+m .le. n) then m2=m else m2=n-m1 end if if (m1+m2+m .le. n) then m3=m else m3=n-m1-m2 end if m4=n-m1-m2-m3 if (m4-m1 .eq. 3) then m1=m1+1 m2=m2+1 m3=m3+1 m4=m4-3 else if (m4-m1 .eq. 2) then m1=m1+1 m2=m2+1 m4=m4-2 else if (m4-m1 .eq. 1) then m1=m1+1 m4=m4-1 end if write(*,'(1x,i4,a,a)') n,' lines in ',file(1:20) file(8+lspec+1:8+lspec+1)='.' file(8+lspec+2:8+lspec+2)='n' file(8+lspec+3:8+lspec+3)='1' write(*,'(1x,i4,a,a)') m1,' lines in ',file(1:23) open(unit=20,file=file,status='unknown',form='formatted') do i=1,m1 read(10,'(a)') line write(20,'(a)') line end do close(20) svfile=file file(8+lspec+3:8+lspec+3)='2' write(*,'(1x,i4,a,a)') m2,' lines in ',file(1:23) open(unit=20,file=file,status='unknown',form='formatted') if (m2.ne.0) then do i=1,m2 read(10,'(a)') line write(20,'(a)') line end do else write(20,'(a)') line write(*,'(6x,a,a)') 'substituted a copy of ',svfile(1:23) end if close(20) svfile=file file(8+lspec+3:8+lspec+3)='3' write(*,'(1x,i4,a,a)') m3,' lines in ',file(1:23) open(unit=20,file=file,status='unknown',form='formatted') if (m3.ne.0) then do i=1,m3 read(10,'(a)') line write(20,'(a)') line end do else write(20,'(a)') line write(*,'(6x,a,a)') 'substituted a copy of ',svfile(1:23) end if close(20) svfile=file file(8+lspec+3:8+lspec+3)='4' write(*,'(1x,i4,a,a)') m4,' lines in ',file(1:23) open(unit=20,file=file,status='unknown',form='formatted') if (m4.ne.0) then do i=1,m4 read(10,'(a)') line write(20,'(a)') line end do else write(20,'(a)') line write(*,'(6x,a,a)') 'substituted a copy of ',svfile(1:23) end if close(20) end