
	Program stdstarmaker
	Implicit None

	integer*4	date, starmax, k, i, j, instar(200,200), stdstarcnt(200,200)
	real*4		stdstar(200,200), radius, temp, maxr, minr
	character	strlist*31, outfile*33, infile*33, dum


	    print*,'enter date (0225=c1, 0301=c3)'
	    read 88, date
88	    format(i4)

	    do i=1,200
	    do j=1,200
	      instar(i,j)=0
	      stdstarcnt(i,j)=0
	      stdstar(i,j)=0.0
	    enddo
	    enddo

	    !!Camera 1
	    if(date.eq.0225)then
	      starmax=86
	      write(strlist,'(A31)') 'Star_Transits/str_list_0225.txt'
	      write(outfile,'(A33)') 'Star_Transits/stdstar_c1_form.grd'
	    endif
	    !!Camera 3
	    if(date.eq.0301)then
	      starmax=55
	      write(strlist,'(A31)') 'Star_Transits/str_list_0301.txt'
	      write(outfile,'(A33)') 'Star_Transits/stdstar_c3_form.grd'
	    endif
	    open(19,file=strlist,form='formatted')
	    
	    do k=1,starmax
	    
	    	read(19,190) infile
190		format(A33)

		print*, k, infile

	    	do i=1,200
	    	do j=1,200
	      	  instar(i,j)=0
	    	enddo
	    	enddo

		open(750,file=infile,readonly)
		read(750,7501)dum
		read(750,7501)dum
		read(750,7501)dum
		read(750,7501)dum
		read(750,7501)dum
7501		format(a10)
7502		format(20i6)
		do j=1,200
		  read(750,7502)(instar(i,j),i=1,200)
		enddo
		close(750)
		
		do i=1,200
		do j=1,200
		  if(instar(i,j).gt.0)then
		    stdstar(i,j)=stdstar(i,j)+float(instar(i,j))
		    stdstarcnt(i,j)=stdstarcnt(i,j)+1
		  endif
		enddo
		enddo

	    enddo
	    
	    maxr=0
	    minr=65000
	    do i=1,200
	     do j=1,200
	      if(stdstarcnt(i,j).gt.0)  stdstar(i,j)=stdstar(i,j)/float(stdstarcnt(i,j))
	      radius = sqrt( float((i-100)*(i-100) + (j-100)*(j-100)) )
	      if(radius.lt.55)then
	        if(stdstar(i,j).gt.maxr) maxr=stdstar(i,j)
	        if(stdstar(i,j).lt.minr) minr=stdstar(i,j)
	      endif
	     enddo
	    enddo

	    maxr=maxr-minr

	    do i=1,200
	     do j=1,200
	       temp=stdstar(i,j)-minr
	       if(temp.lt.0.0) temp=0.0
	       temp=temp*65000.0/maxr
	       stdstar(i,j)=temp
	     enddo
	    enddo

	    open (11,file = outfile, form = 'formatted')
	    write(11,11)
11	    format('DSAA'/'200 200'/'0 200'/'0 200'/'0 65000')
	    do j=1,200
	      write(11,'(20i6)')(nint(stdstar(i,j)),i=1,200)
	    enddo
	    close(11)
	    
	    End
