	program fixUphot
C  June 25, 2003
C This program fixes the U-band photometry for a 42-inch catalog
	character*80 infile,date
	character*120 inline
	write(6,11)
11	format('Input the date (5sept02)',$)
	read(5,1111) date
	last=lnblnk(date)
	fact=1.138
	if(date(1:last).eq.'29nov00') fact=1.083
	if(date(1:last).eq.'30nov00') fact=1.083
	if(date(1:last).eq.'5jan01') fact=1.083
	write(6,13) fact
13	format('Factor is:',f8.3)
	write(6,12) 
12	format('Input the file name (M33C.ubvrird)',$)
	read(5,1111) infile
1111	format(a80)
	last=lnblnk(infile)
	open(unit=1,file=infile(1:last),status='old')
	open(unit=2,file=infile(1:last)//'f',status='new')
15	read(1,14,end=99) inline
14	format(a120)
	if((inline(1:1).eq.'#').or.(inline.eq.'')) then
	write(2,14) inline
	go to 15
	end if
Cwrite(6,14) inline
	call bear(inline,ihr,imin,sec,ideg,iamin,asec,isuc)
Cwrite(6,*) isuc,ihr,imin
	if(isuc.eq.0) go to 15
C Now find the photometry
C Now clean up "inline" and find the 3rd ":" while you're at it.
	ic=0
	ib=0
	do 110 i=1,115
	if(inline(i:i+4).eq.'INDEF') write(inline(i:i+4),111)
111	format('99.99')
	if(inline(i:i).eq.':') ic=ic+1
Cwrite(6,1123) i,inline(i:i),ic
1123	format('i,inline(i),ic=',i5,1x,a1,i5)
C this is obscure, but it is really finding the 3rd one.  thing about it.
	if(ic.eq.2) ib=i
110	continue
	if(ib.eq.0) stop "problem here"
Cwrite(6,14) inline
Cwrite(6,*) ib
	read(inline(ib+10:120),*) v,ve,bmv,bmve,umb,umbe,vmr,vmre,
     &  rmi,rmie
	if(umb.lt.0.) then
	umbf=umb*fact
	else
	umbf=umb
	end if
	inline(ib+10:120)=''
	write(inline(ib+10:120),140)
     &  v,ve,bmv,bmve,umbf,umbe,vmr,vmre,
     &  rmi,rmie
140	format(10f8.2)
	write(2,14) inline
	go to 15
99	stop
	end
	subroutine bear(inline,ihr,imin,sec,ideg,iamin,asec,isuc)
C The assumption is that the ra and dec have been printed as 12.3H 12.2h
	implicit double precision (a-h,o-z)
	character*120 inline
	character*1 sign
C step by step
	isuc=0
	i=2
1	continue
	if(inline(i:i).eq.':') then
	read(inline(i-2:i-1),*) ihr
	else
	i=i+1
	if(i.eq.120) return 
	go to 1
	end if
	read(inline(i+1:i+2),*) imin
	read(inline(i+4:i+9),*) sec
	k=i+10
2	if(inline(k:k).eq.':') then
C first see if there's a minus sign or not
	sign=''
	do 3 j=i+10,k
	if(inline(j:j).eq.'-') sign='-'
3	continue
	read(inline(i+10:k-1),*) ideg
	ideg=abs(ideg)
	read(inline(k+1:k+3),*) iamin
	read(inline(k+4:k+8),*) asec
	if(sign.eq.'-') then
	ideg=-ideg
	iamin=-iamin
	asec=-asec
	end if
	isuc=1
	return
	else
	k=k+1
	go to 2
	end if
	end
