	character*80 f1,f2,head(72)
	character*2 f3
	real a(2048,2048)

	if(iargc().lt.2)then
	  write(*,*)
          write(*,*)'    add2line file outfile [2]'
          write(*,*)
	  stop
	endif

	call getarg(1,f1)
	call gethead(f1,head)
	call readata(a,f1)	

	call getarg(2,f2)
	i2=2
	if(iargc().eq.3)then
	  call getarg(3,f3)
	  read(f3(1:),*)i2
	endif

	do 10 j=1,2048
	do 10 i=2048,1026,-1
10	a(i,j)=a(i-i2,j)

	call swap4(a,2048*2048*4)
	k=2048*2048*4+5760
	open(50,file=f2,status='unknown',access='direct',recl=k)
	write(50,rec=1)head,a
	close(50)
	end

        subroutine readata(a,f1)
        integer c(720),a(1)
        character*80 f1,ch*2880
        equivalence (c,ch)
        nn=720         
        open(1,file=f1,status='old',access='direct',recl=nn*4)
        read(1,rec=1)ch
        n1=2048   
        n2=2048
        n=1   
55      k=index(ch,'END          ')
        if(k.eq.0)then
          n=n+1    
          read(1,rec=n)ch
          goto 55  
        endif   
        i=0
        k1=n+1
        k2=n+(n1*n2-1)/nn
        do 60 k=k1,k2
        if(mod(k,200).eq.0)call dispdot()
        read(1,rec=k)ch
        do 60 j=1,nn
        i=i+1
60      a(i)=c(j)
        close (1)
	call swap4(a,n1*n2*4)
        end
 
	subroutine gethead(f1,head)
	character*80 f1,head(72)
	open(52,file=f1,status='old',access='direct',recl=5760)
	read(52,rec=1)head
	close (52)
	end
