	program sat11a
	
!-----------------------------------------------------------------------Declare
	implicit none
	real*4 :: Period, mecorrect, satmass, satmass1, satmass2, diff, orbit1, orbit2
	real*4 :: earthdist, jupiterdist, catch, centmass, suncorrect, vel, circ, moondist
	real*4 :: G, catch4, fin, years, Msun, Mjupiter, Mearth, Mmoon, twopi, Rad, days
	parameter (twopi = 6.2831853071795864, G = 6.674d-11, Msun = 1.9891d30)
	parameter (Mjupiter = 1.8933d27, moondist = 385000000, earthdist = 1.4959787d11)
10	parameter (jupiterdist = 7.785d11, Mearth = 5.9722d24, Mmoon = 7.347d22)
	rad = 0 ; centmass = 0 ; fin = 0
	print*, "-------------"
	print*, "V 2211221715"
	print*, "-------------"
	print*, "This program calculates the orbital velocity of two satellites in the same" 
	print*, "orbit around a central body, and gives the velocity difference and the"
	print*, "time to collide - assuming they started off 180 degrees around from each" 	
	print*, "other. The formula used is Kepler's binary star period calculator, and it"  
	print*, "is not limited to systems that fully comply with the binary star definition."  
20	print*, "The calculation can be extended to systems that wouldn't typically be" 
	print*, "considered as binary systems. For example, if we take the Sun and the Earth,"   
	print*, "or the Earth and the Moon, we still obtain the correct results" 
	print*
	print*, "-----------------------------------------------------------------------------"
	print*, "The masses of the Moon, Earth, Jupiter and the Sun are given for you to use." 	
	print*  
	print*, "The Moon's orbital radius is 385,000,000 meters, Earth's is 1.4959787e11"
	print*, "meters, and Jupiter's is 7.785e11 meters"
	print*
30	print*, "The mass of the Moon is 7.347e22 Kg, Earth is 5.97219e24 Kg," 
	print*, "Jupiter is 1.89817e27 Kg and the Sun is 1.9891e30 Kg. " 
	print*		
	print*, "Use the Earth Moon system to start with, and you will see that a man made" 
	print*, "satellite of eg 1000 Kg at the Moon's distance is over 6 meters per second" 	
	print*, "slower in its orbit than the Moon."
	print*, "For input, use actual masses and distances in Kilograms and meters." 
	print*, "Scientific notation can be used."
	print*, "Or input : 0 for the Moon, 1 for the Earth, 2 for Jupiter, 3 for the Sun"
! ----------------------------------------------------------------------------Input
40	print*
	print*, "----------------------------------------------------------------------"
	print*, "Choose the central mass (or enter 0 for Moon mass, 1 for Earth, 2 for" 
	print*, "Jupiter, 3 for the Sun.) "
	read*, centmass
		if (centmass==0) then 
			centmass = Mmoon 
		else if (centmass==1) then
			centmass = Mearth 
		else if (centmass==2) then
50			centmass = Mjupiter 
		else if (centmass==3) then
			centmass = Msun 	 		
		end if	
	print*, "Orbital radius is (or enter 0 for Moon's orbit, 1 for the Earth's,"
	print*, "or 2 for Jupiter's)."
	read*, Rad
		if (rad==0) then 
			rad = moondist 				!  Moon orbit 
60		else if (rad == 1) then 
			Rad = earthdist 			! Earth orbit
		else if (rad==2) then			
			rad = jupiterdist   			! Jupiter orbit
		end if
	circ = twopi * Rad
	print*, "Orbital radius is ", rad," meters"
	print*, "Central mass is ", centmass," Kg"
	print*,"Orbit circumference is ",circ," meters"
	print*," "
70	print*, "LIGHTER SATELLITE FIRST OR THE RESULT WILL BE NEGATIVE: Because the lighter" 		
	print*, "satellite being slower is caught up by the heavier one."
	print*
	print*, "Enter the mass of satellite 1 in Kg (or 0 for the Moon, 1 for Earth, 2 for" 	
	print*, "Jupiter, 3 for the Sun)."
	read*, satmass1
		if (satmass1==0) then
			satmass1 = Mmoon 
		else if (satmass1 ==1) then
			satmass1 = Mearth 
80		else if (satmass1 ==2) then
			satmass1 = Mjupiter 
		else if (satmass1 ==3) then
			satmass1 = Msun				
		end if	
	print*
	print*, "Central mass is ", centmass," Kg"
	print*, "Satellite 1 mass is ", satmass1," Kg"	
!--------------------------------------------------------------------- calculations
	satmass = satmass1	
90 		call calculate(Period,twopi,Rad,G,centmass,satmass,vel,circ,years)
	print*, "----- satellite 1 -----"
	print*
	print*, "-----------------------------------------------------------------"
	orbit1 = vel
	print* 
	print*, "Enter the mass of satellite 2 in Kg (or 0 for the Moon, 1 for the Earth,"  		
	print*, "2 for Jupiter, 3 for the Sun)."  
	read*, satmass2
		if (satmass2==0) then
100			satmass2 = Mmoon 
		else if (satmass2==1) then
			satmass2 = Mearth 
		else if (satmass2==2) then
			satmass2 = Mjupiter 
		else if (satmass2==3) then			
			satmass2 = Msun			
		end if			
	print*, "Satellite 2 mass is ", satmass2," Kg"
110	satmass = satmass2		
		call calculate(Period,twopi,Rad,G,centmass,satmass,vel,circ,years)
	print*, "----- satellite 2 -----"
	print*
	print*, "----------------------------------------------------------------"
	orbit2 = vel
	diff=orbit2-orbit1
	print*, "The orbital velocity difference is ",diff, " m/s"
	print*, "Assuming the 2 satellites started opposite to each other,"
	print*,"the catch up time is :- "
120	catch = ((circ / 2) / diff) /60/60/24/365.25
	print*, catch," years" 
	print*, "Press 0 to finish, or 1 to restart."
	read*, fin
		if (fin==0) then 
			goto 129
		else if (fin>0) then 
			goto 40
		end if
129	end program sat11a
	!----------------------------------------------------------------------- subroutine
	subroutine calculate(Period,twopi,Rad,G,centmass,satmass,vel,circ,years)
		real*4 :: Period, centmass, satmass, vel, twopi, Rad, days, circ, G, years
		print*, "The orbit circumference is ", circ," meters"
		Period = twopi * sqrt((Rad * Rad * Rad) / (G * ( centmass + satmass)))	
		vel = circ / Period
		print*, "The orbital velocity is ", vel," m/s"
		print*, "The period of orbit is ", Period, " seconds" 
		days = Period/86400
		years = days / 365.25
140		print*
		print*, "Orbit time is ",days,"    days"
		print*, "or            ",years,"    years"
		print*, "Satelite mass is    ",satmass," Kg"
		print*
	end subroutine calculate