	program reweight
c
c	redetermine weights for observations in grading.orb7, based on fits to 
c	rms dRho/Rho vs Rho/RhoLim
c
	character*21 data1
	character*3  code,dd1
	character*2  dd2
	character*86 data2
	character*1  c62,c63,c64
	dimension en(6),wtmean(6),wtrms(6)
c
	open(10,file='grading.orb7',status='UNKNOWN')
	open(11,file='grading.orb8',status='UNKNOWN')
c
	do 100 ic=1,6
	en(ic)=0.
	wtmean(ic)=0.
	wtrms(ic)=0.
  100	continue
c
  200	read(10,901,end=800) data1,code,data2,enn,dd1,dd2,tel,
     $     c62,c63,c64,rho
  901	format(a21,a3,a86,t34,f2.0,a3,a2,f2.0,3a1,t58,f8.4)
c
c	determine additional observer codes
c
	if  (c62 .eq. 'E')                          code='XVI'
	if ((c62 .eq. 'G')   .or. (c62 .eq. 'H'))   code='VPH'
	if  (c62 .eq. 'O')                          code='VPH'
	if ((c62 .eq. 'J')   .or. (c62 .eq. 'K'))   code='XSP'
	if ((c62 .eq. 'N')   .or. (c62 .eq. 'P'))   code='XSP'
	if ((c62 .eq. 'Q')   .or. (c62 .eq. 'S'))   code='XSP'
	if ((c62 .eq. 'U')   .or. (c62 .eq. 'V'))   code='XSP'
	if ((c62 .eq. 'X')   .or. (c62 .eq. 'T'))   code='XSP'
	if ((dd1 .eq. 'MKT') .or. (dd1 .eq. 'NOI')) code='XSP'
	if ((dd1 .eq. 'MCA') .or. (dd1 .eq. 'HRT')) code='CSP'
	if ((dd1 .eq. 'MSN') .or. (dd1 .eq. 'FEK')) code='CSP'
	if ((dd1 .eq. 'FU ') .or. (dd1 .eq. 'SHU')) code='CSP'
	if ((dd1 .eq. 'LU ') .or. (dd1 .eq. 'CHR')) code='CSP'
c
c	adjust telescope aperture
c
	if  (c63 .eq. '8') tel=tel+100.
	if  (c63 .eq. 'S') tel=tel+200.
	if  (c63 .eq. 'T') tel=tel+300.
	if ((dd1 .eq. 'ANJ') .or. (dd1 .eq. 'MRR')) tel=240.
	if  (dd1 .eq. 'MKT')                        tel=23.6*39.37
	if  (dd1 .eq. 'NOI')                        tel=37.5*39.37
	if ((dd1 .eq. 'LAB') .and. (dd2 .eq. '01')) tel= 5.0*39.37
	if ((dd1 .eq. 'KUL') .and. (dd2 .eq. '01')) tel= 6.0*39.37
	if ((dd1 .eq. 'KOE') .and. (dd2 .eq. '02')) tel=20.0*39.37
	if (tel .eq. 0.0) go to 200
c
c	adjust nnights
c
	if ((c63 .eq. 'A') .or. (c64 .eq. 'O')) enn=enn+10.
	if ((c63 .eq. 'B') .or. (c64 .eq. '8')) enn=enn+20.
	if  (c63 .eq. 'C') enn=enn+30.
	if  (c63 .eq. 'D') enn=enn+40.
	if  (c63 .eq. 'E') enn=enn+50.
c
c	adjust weight for uncertain measures, etc
c
  	fact=1.0
	if ((c63 .eq. '3') .or. (c63 .eq. 'U')) fact=0.5
	if ((c64 .eq. 'D') .or. (c64 .eq. 'E')) fact=0.5
  	if ((c64 .eq. 'U') .or. (c64 .eq. '5')) fact=0.5
	if ((c63 .eq. '4') .or. (c63 .eq. '9')) go to 200
	if ((c64 .eq. 'F') .or. (c64 .eq. 'N')) go to 200
 	if ((c64 .eq. 'R') .or. (c64 .eq. 'S')) go to 200
  	if  (c64 .eq. '9')                      go to 200
	if  (c64 .eq. '6')                      rho=rho*60.
c	
	rholim=5.3596/tel
	x=rho/rholim
c	
	itype=3
	if  (code .eq. 'VPH')                         itype=2
	if ((code .eq. 'VS ') .or. (code .eq. 'VL ')) itype=1
c
	if ((itype .eq. 1) .and. (x .lt. 1.4)) 
     $     w1 = 0.710442 -0.807388*x +0.3711700*x**2 -0.05581570*x**3
	if ((itype .eq. 1) .and. (x .ge. 1.4)) 
     $     w1 = 0.190430 -0.028076*x +0.0021362*x**2 -0.00005746*x**3
	if ((itype .eq. 1) .and. (x .ge. 7.0)) 
     $     w1 = 0.103455 -0.003657*x +0.0000500*x**2 -0.00000022*x**3
	if (w1 .lt. 0.015) w1=0.015
c
	if ((itype .eq. 2) .and. (x .lt.  20.)) 
     $     w1 = 0.110840 -0.011873*x +0.0005499*x**2 -0.00000980*x**3
	if ((itype .eq. 2) .and. (x .ge.  20.)) 
     $     w1 = 0.018280 -0.000184*x +0.0000008*x**2
	if ((itype .eq. 2) .and. (x .ge. 100.)) 
     $     w1 = 0.007500
c
	if ((itype .eq. 3) .and. (x .lt.  3.))
     $     w1 = 0.397269 -0.298306*x +0.0908508*x**2 -0.00958455*x**3
	if ((itype .eq. 3) .and. (x .ge.  3.))
     $     w1 = 0.111693 -0.022882*x +0.0018639*x**2 -0.00004715*x**3
	if ((itype .eq. 3) .and. (x .ge. 10.))
     $     w1 = 0.022200 -0.000020*x
c
	wt=0.01/w1/w1
	if (wt .gt. 99.9) wt=99.9
	write(11,902) data1,code,data2,wt
  902	format(a21,a3,a86,f6.1)
c
c	add to mean and rms arrays
c
	if (code .eq. 'VS ') ic=1
	if (code .eq. 'VL ') ic=2
	if (code .eq. 'VPH') ic=3
	if (code .eq. 'XVI') ic=4
	if (code .eq. 'XSP') ic=5
	if (code .eq. 'CSP') ic=6
	en(ic)=en(ic)+1.
	wtmean(ic)=wtmean(ic)+wt
	wtrms(ic)=wtrms(ic)+wt*wt
  	go to 200
c
  800	do 850 ic=1,6
  	wtmean(ic)=wtmean(ic)/en(ic)
  	wtrms(ic)=sqrt(wtrms(ic)/en(ic))
  	write(6,903) en(ic),wtmean(ic),wtrms(ic)
  903	format(f8.0,2f12.4)
  850	continue
  999	stop
  	end
