Get q on psi mesh
integer, intent(in) :: ns
real(i2mex_r8), intent(in) :: psi(ns)
real(i2mex_r8), intent(out) :: q(ns)
integer, intent(out) :: ier
    Get d q /d psi on psi mesh
integer, intent(in) :: ns
real(i2mex_r8), intent(in) :: psi(ns)
    Get d^2 q /d psi^2 on psi mesh
integer, intent(in) :: ns
real(i2mex_r8), intent(in) :: psi(ns)
real(i2mex_r8), intent(out) :: qpp(ns)
integer, intent(out) :: ier
    Compute the safety factor profile from g, X and Z and return the result
    in q. This routine it typically used when the q profile information needed
    to build i2mex is not available from the equilibrium. *NOTE* This routine
    does NOT require i2mex to be initialized. Also be warned that the present
    implementation suffers frmo some inaccuracy near axis.
integer, parameter :: r8=selected_real_kind(12,100)
integer, intent(in) :: nt1, ns
real(i2mex_r8), intent(in) :: g(ns)     x^2 B.grad phi
real(i2mex_r8), intent(in) :: psi(ns)     pol flux/2*pi
real(i2mex_r8), intent(in) :: x(nt1, ns), z(nt1, ns)     the grid
real(i2mex_r8), intent(out) :: q(ns)
integer, intent(out) :: ier