	parameter (mm=120)
	character*48 ff(mm),f1,fit,fcat,fcatmp
	character*80 head(72),ch*1,ch5*5
	integer*2 map(49*49),ma(49*49)
	real d(2048,2048)
	byte bell
	bell=7
        if(iargc().eq.0)then
          write(*,*)
	  write(*,*)'   DISPLAY fits star (99*99)******* 99.3'
	  write(*,*)
	  write(*,*)'    Usage: mo3 file [number]'
	  write(*,*)
	  write(*,*)'      mark ? to file *.catmp (use *.fit *.cat)'
          stop
        endif

        call getarg(1,fcat)
	ipp=0
	istar=0
	if(iargc().eq.2)then
	  call getarg(2,f1)
	  read(f1(1:),*)ipp
	  write(*,*)ipp
	endif
	fit=fcat
	k=index(fit,'.')
        if(k.eq.0)fit=fit(1:lnblnk(fit))//'.fit'
	k=index(fit,'.')
	i=index(fcat,'.')
	if(i.eq.0)fcat=fit(1:k)//'cat'
	fit=fit(1:k)//'fit'
	write(*,*)fit
	write(*,*)fcat

        inquire(file=fit,exist=i)
        if(i.eq.0)stop ' *.fit file not found !'
	k=index(fit,'.')
        call gethead(fit,head)
	fit(k+4:k+4)=char(0)
        inquire(file=fcat,exist=i)
        if(i.eq.0)stop ' *.cat file not found !'
	fcatmp=fit(1:k)//'catmp'

	read(head(3)(65:),'(i5)')iframe
        iframe=iframe/2+1
	write(*,*)'......readata'
        call readfits(fit,d,2048,2048)

	call pgbegin(0,'/xw',1,1)
	open(1,file=fcat,status='old')
	open(2,file=fcatmp,status='unknow')
	read(1,'(a)')f1
	write(2,'(a)')f1(1:lnblnk(f1))
	do 5 i=1,ipp
	read(1,'(a)',end=6)f1
	if(f1(1:1).ne.' ')istar=istar+1
5	write(2,'(a)')f1
6       call pgsch(0.)
	call pgsci(0)
        call pgenv(0.,12.,10.,0.,0,0)
	call pgsch(0.8)
	write(*,*)' left   button------delete or recover'
	write(*,*)' middle button------save & exit'
	write(*,*)' right  button------next page'
10	call pgpage1
	i=0
11	i=i+1
	read(1,'(a)',end=20)ff(i)
	if(i.ne.mm)goto 11
	i=i+1
20	m=i-1
	
	ii=18
	jj=32
	do 30 i=1,m
	read(ff(i)(25:),*)x,y,xmag
	ix=nint(x)
	iy=nint(y)
	k=0
	ip=0
	do 40 i1=ix-24,ix+24
	do 40 j1=iy-24,iy+24
	k=k+1
	x=d(i1,j1)/iframe
	if(x.gt.32767.)x=32767.
        if(x.le.10.)then
          map(k)=32767
        else
          ip=ip+1
          ma(ip)=x
          map(k)=x
        endif
40      continue
        call whitexblack(ma,1,ip,white,sigma)
        if(white.gt.0.)then
          xw=white
        else
          white=xw
        endif

	call ximage2(map,49,ii,jj,white*0.95,white+20.*sigma)
	ii=ii+54
	if(ii.gt.630)then
	  ii=18
	  jj=jj+66
	endif
	write(ch5(1:),'(f5.2)')xmag
	x=mod(i-1,12)+0.1
	y=(i-1)/12
	y=y*1.03+0.15
	j=1
	if(ff(i)(1:1).ne.' ')then
	  j=5
	  istar=istar+1
	endif
	call pgsci(j)
	call pgtext(x,y,ch5)
30	continue



60	call pgcurse(x,y,ch)
	ich=ichar(ch)
      if(ich.eq.128)then
        ix=nint(x+0.5)
        iy=nint(y*0.97+0.42)
	k=(iy-1)*12+ix
	if(k.gt.m.or.k.lt.1)then
	  write(*,'(a)')bell
	  goto 60
	endif
	ch=ff(k)(1:1)
	if(ch.eq.' ')then
	  ch='?'
	  istar=istar+1
	  j=5
	else
	  ch=' '
	  istar=istar-1
	  j=1
	endif
	call pgsci(j)
	ff(k)(1:1)=ch
	read(ff(k)(25:),*)x1,y1,xmag
	write(ch5(1:),'(f5.2)')xmag
	write(*,"(i4,': ',a)")ipp+k,ff(k)
	xx=mod(k-1,12)+0.1
	xy=(k-1)/12
	xy=xy*1.03+0.15
	call pgtext(xx,xy,ch5)
	goto 60
      endif
      if(ich.eq.132)then
	do 70 i=1,m
70	write(2,'(a)')ff(i)
	ipp=ipp+m
	if(m.ne.120)goto 79
	write(*,*)ipp,':'
        goto 10
      endif
      if(ich.eq.130)then
	do 71 i=1,m
71	write(2,'(a)')ff(i)
	ipp=ipp+m
72	read(1,'(a)',end=79)f1
	ipp=ipp+1
	write(2,'(a)')f1
	if(f1(1:1).ne.' ')istar=istar+1
	goto 72
      endif		
      goto  60  	
c----------------------------------
79	call pgend
73	close (2)
	call unlink(fcat)
	call system("mv "//fcatmp//" "//fcat)
	write(*,*)ipp,'  stars ',istar,'  marked_star'
	end

	subroutine gethead(f1,head)
	character*80 head(72),f1*48
	open(1,file=f1,status='old',access='direct',recl=5760)
	read(1,rec=1)head
	close(1)
	end

        subroutine ximage2(map,n,ix,iy,black,white)
        integer*2 map(n,n)
        character dummy
        real rbuf(101*101+2)
        n16=86
        d=n16/(black-white)
        rbuf(1)=ix
        rbuf(2)=iy
        i6=2
        do 30 j=1,n
        do 30 i=1,n
        k=nint(d*(map(i,j)-white))
        if(k.lt.1)k=1
        if(k.gt.n16)k=n16
        i6=i6+1
30      rbuf(i6)=k+15
        i6=n+2
        call xwdriv(27,rbuf,i6,dummy)
        call pgebuf
        end
