	parameter (size=4096)
	real      a(size*size)
	character*80 head(36)
	logical logi	
	character*60  f1
        integer b(16,16)
        integer d(16)

	do 5 i=1,16
5	d(i)=i*256-128+0.5
	
        if(iargc().lt.1)then
        write(*,*)
	write(*,*)'     Usage:  j_sky file'
	write(*,*)
	stop
	endif
	call getarg(1,f1)
        k=index(f1,'.')
        if(k.eq.0)f1=f1(1:lnblnk(f1))//'.fit'
        inquire(file=f1,exist=logi)
        if(.not.logi)stop ' file not found !'
	call readfits(f1,a,ncol,nrow)
	write(*,*)ncol,nrow
	mm=256
	do 10 i=1,16
	do 10 j=1,16
	x= stat1(a,ncol,nrow,i,j,mm)
10	b(i,j)=x
	do 20 i=1,16
20	write(*,'(16i4)')(b(i,j),j=1,16)
30	write(*,*)'input X,Y:'
	read(*,*)ix,iy
	jx=(ix+128)/256
        jy=(iy+128)/256
	if(jx.eq.0)jx=1
	if(jx.eq.16)jx=15
	if(jy.eq.0)jy=1
	if(jy.eq.16)jy=15
	dx=(ix-d(jx))/256.
	dy=(iy-d(jy))/256.
c	if(jx.eq.0)then
c 	  dx=0
c	  jx=1
c	endif
c	if(jx.eq.16)then
c	  dx=1
c	  jx=15
c	endif
c	if(jy.eq.0)then
c 	  dy=0
c	  jy=1
c	endif
c	if(jy.eq.16)then
c	  dy=1
c	  jy=15
c	endif
        x=b(jx,  jy  )*(1.-dx)*(1.-dy)
     c   +b(jx+1,jy  )*(   dx)*(1.-dy)
     c   +b(jx  ,jy+1)*(1.-dx)*(   dy)
     c   +b(jx+1,jy+1)*(   dx)*(   dy)
	write(*,*)jx,jy,dx,dy
        write(*,*)x
	goto 30
	end
	
        function stat1(a,n1,n2,m1,m2,mm)
        real a(n1,n2)
        integer*2 b(512*512)
        k=0
        j1=(m2-1)*mm
        do 10 j=1,mm
        i1=(m1-1)*mm
        j1=j1+1
        do 10 i=1,mm
        i1=i1+1
        if(a(i1,j1).gt.0.)then
          k=k+1
	  b(k)=a(i1,j1)
	endif
10	continue
        call whitexblack(b,1,k,x,s)
        stat1=s
        end


