	parameter (n=12000)
	real mag(16),am(n,4)
	integer  n1(n),nc(4)
	character*133 d0,d1,d2,d3,d4
	character*20 f1,f2
        character*1 a1(n),bm(n,4),color(4),mc,mark(16)
	logical lo

	kk=iargc()
	if(kk.lt.5)then
	  write(*,*)
	  write(*,*)'     Usage: dim2 mag_file2 diim i 16.0 20.0 [1] [1]'
	  write(*,*)
	  write(*,*)'           dimm means d-i & i-m'
	  write(*,*)'           last 2 para as fig center'
	  write(*,*)'           + mark means used APER_photometric'
	  write(*,*)
	  write(*,*)'                           jiang, 020422'
	  write(*,*)
	  stop
	endif
	call getarg(1,f1)
	k=index(f1,'.')
	if(k.eq.0)f1=f1(1:lnblnk(f1))//'.mag'
	inquire(file=f1,exist=lo)
	if(.not.lo)stop "file not found!"		
        open(1,file=f1,status='old')
        read(1,'(a)')d0
	call getarg(2,f2)
	do 6 i=1,4
	color(i)=f2(i:i)
	nc(i)=0
	do 5 j=29,126,6
5	if(color(i).eq.d0(j:j))nc(i)=(j-29)/6
	if(nc(i).eq.0)then
	  write(*,*)'Can not find color: ',color(i)
	  stop
	endif
6	continue
	call getarg(3,f2)
	do 7 i=1,4
	if(f2(1:1).eq.color(i))goto 8
7	continue
	write(*,*)'Cannot found mag_limit_color: ',f2(1:1)
	stop	
8	mc=color(i)
	mk=i
	call getarg(4,f2)
	read(f2(1:),*)xm1
	call getarg(5,f2)
	read(f2(1:),*)xm2
	c1=1.
	c2=1.
	if(kk.gt.5)then
	  call getarg(6,f2)
	  read(f2(1:),*)c1
	endif
	if(kk.gt.6)then
	  call getarg(7,f2)
	  read(f2(1:),*)c2
	endif
	in=0
10      read(1,'(a)',end=19)d1
        read(1,'(a)')d2
	do i=1,4
	read(1,'(a)')d3
	enddo
	read(1,'(a)')d4
	do i=1,15
	read(1,'(a)')d3
	enddo
        do i=1,16
c        read(d1(i*6+26:),'(f6.2)')mag(i)
        read(d4(i*6+26:),'(f6.2)')mag(i)
        read(d2(i*6+26:),'(a1)'),mark(i)
c        err(i)=k*0.001
        enddo
	in=in+1
	a1(in)=d1(1:1)
	n1(in)=in
	do 11 i=1,4
	am(in,i)=mag(nc(i))
11	bm(in,i)=mark(nc(i))
        goto 10
19      close(1)
	m=in
	  write(*,*)'total: ',m
	call  pgbegin(0,"/xw",1,1)
	call  pgenv(c1-2,c1+2,c2-2,c2+2,0,0)
	k=0
        do 110 i=1,m
	if(a1(i).ne.' '.and.a1(i).ne.'e')goto 110
	do 111 j=1,4
111	if(am(i,j).eq.0.0)goto 110
	if(am(i,mk).lt.xm1)goto 110
	if(am(i,mk).gt.xm2)goto 110
	ij=1
	do 112 j=1,4
112	if(bm(i,j).eq.'X')ij=2
        x=am(i,1)-am(i,2)
        y=am(i,3)-am(i,4)
	call pgpoint(1,x,y,ij)
	k=k+1
110	continue
	call pglabel(color(1)//'-'//color(2),color(3)//'-'//color(4),f1)	
	write(f1(1:),"(f5.1,' ~',f5.1)")xm1,xm2
	call pgtext(c1-1.5,c2+1.5,"mag  "//mc//': '//f1)
	write(f1(1:),"(i5)"),k
	call pgtext(c1-1.5,c2+1.2,"star num: "//f1)
	call pgend
        end
