What I wrote to combine them is this:
Program RK4
implicit none
real k1,k2,k3,k4,h,t,R
integer i,n
real a
read*,n,h
t=0
R=0
Do i=1,n
k1=h*(1/a(t))
k2=h*(1/a(t+h/2.0))
k3=h*(1/a(t+h/2.0))
k4=h*(1/a(t+h))
t=t+h
R=R+(k1+2*k2+2*k3+k4)*(1/6.0)
write(*,*)t,R
End Do
end program
!-----------------------------------------
SUBROUTINE Scale_Factor(h,n,t,a)
implicit none
real t,a,k1,k2,k3,k4,h,g
integer i,n
t=0
a=0.001
Do i=1,n
k1=h*g(a)
k2=h*g(a+k1/2.0)
k3=h*g(a+k2/2.0)
k4=h*g(a+k3)
t=t+h
a=a+(k1+2*k2+2*k3+k4)*(1/6.0)
write(*,*)t,a
END DO
END SUBROUTINE
!-------------------------
FUNCTION g(a)
implicit none
real a,g
g=sqrt((1.0/a)+(1.0/a**2))
END FUNCTION
But I know it is not correct.