	character*80 f0,f1,head(108)
        real a(2048,2048)
        integer badtype

	if(iargc().lt.1)then
	  write(*,*)
	  write(*,*)'         ******** smooth 2048*2048 Pic. ********'
	  write(*,*)
	  write(*,*)'    ssmooth batchfile'
	  write(*,*)
	  stop
	endif

	call getarg(1,f0)         
	open(97,file=f0,status='old')
10111   read(97,"(a)",end=10112)f1
	call gethead(f1,head)
        ipos=indexpos(head,'INSTRUME')
        if(ipos.gt.70)stop 'not our fits file**'
        badtype=0                             !                 zjzx.bad
        if(head(ipos)(13:13).eq.'1')badtype=1 ! new controller, ljl.bad
        if(indexpos(head,'MPP     ').gt.70)badtype=0
        if(head(ipos)(13:13).eq.'5')badtype=5 ! ccd5
        if(head(ipos)(17:17).eq.'4')badtype=4 ! thin ccd, no bad pixel
	if(badtype.ne.0)goto 10111

	write(*,'(a)')f1

	call readfits(f1,a,n1,n2)
c 105
	i103=2049-103
	i104=2049-104
	i105=2049-105
	i106=2049-106
	do 105 i=2049-1150,2048
	a(i104,i)=a(i103,i)
105     a(i105,i)=a(i106,i)
c 516
	i514=2049-514
	i515=2049-515
	i516=2049-516
	i517=2049-517
	i518=2049-518
	do 516 i=2049-952,2048
        a(i515,i)=a(i514,i)
        a(i516,i)=(a(i514,i)+a(i518,i))/2.
516	a(i517,i)=a(i518,i)

c 839
	i837=2049-837
	i838=2049-838
	i839=2049-839
	i840=2049-840
	do 838 i=2049-420,2048
	a(i838,i)=a(i837,i)
838	a(i839,i)=a(i840,i)
c 1308
	i1306=2049-1306
	i1307=2049-1307
	i1308=2049-1308
	i1309=2049-1309
	do 1308 i=2049-756,2049-390
	a(i1307,i)=a(i1306,i)
1308	a(i1308,i)=a(i1309,i)
c 677
	i676=2049-676
	i677=2049-677
	i678=2049-678
	i679=2049-679
	do 677 i=2049-1028,2049-927
	a(i677,i)=a(i676,i)
677	a(i678,i)=a(i679,i)
c 1081
	i1801=2049-1801
	i1802=2049-1802
	do 1801 i=2049-863,2049-792
1801	a(i1801,i)=a(i1802,i)

c 1844
	i1843=2049-1843
	i1844=2049-1844
	i1845=2049-1845
	i1846=2049-1846
	do 1844 i=2049-318,2048
	a(i1844,i)=a(i1843,i)
1844    a(i1845,i)=a(i1846,i)
c 1924
	i1922=2049-1922
	i1923=2049-1923
	i1924=2049-1924
	i1925=2049-1925
	i1926=2049-1926
	i1927=2049-1927
	do 1924 i=2049-617,2048
        a(i1923,i)=a(i1922,i)
        a(i1924,i)=(a(i1922,i)+a(i1927,i))/2.
        a(i1925,i)=(a(i1922,i)+a(i1927,i))/2.
1924	a(i1926,i)=a(i1927,i)

	do 2048 i=1,2048
	a(1,i)=a(3,i)
2048	a(2,i)=a(3,i)

	nhead=indexpos(head,'END     ')
        if(nhead.lt.72)nhead=72
        if(nhead.gt.72)nhead=108
	call swap4(a,n1*n2*4)
        k=lnblnk(f1)+1
        f1(k:k)=char(0)
	call writefits(f1,head,80*nhead,1)
	call writefits(f1,a,n1*n2*4,0)
c do shift end
	goto 10111
10112   close(97)
	end

	subroutine gethead(f1,head)
	character*80 f1,head(108)
	open(52,file=f1,status='old',access='direct',recl=8640)
	read(52,rec=1)head
	close (52)
	end
	
        function indexpos(head,f1)
        character*80 head(108),f1*8
        do 10 indexpos=1,108
10      if(head(indexpos)(1:8).eq.f1)return
        end
