  An algorithm for the calculation of hyperfine structure and spectra of
diatomic molecules based on the variational nuclear motion is presented.
Hyperfine coupling terms considered are Fermi-contact, nuclear spin-electron
spin dipole-dipole, nuclear spin-orbit, nuclear spin-rotation and nuclear
electric quadrupole interactions. Initial hyperfine-unresolved wavefunctions
are obtained for given set of potential energy curves and associated couplings
by variation solution of the nuclear-motion Schr\"odinger equation. Fully
hyperfine-resolved parity-conserved rovibronic Hamiltonian matrices for a given
final angular momentum, $\bm{F}$, are constructed and then diagonalized to give
hyperfine-resolved energies and wavefunctions.Electric transition dipole moment
curves can then be used to generate a hyperfine-resolved line list by applying
rigorous selection rules.The algorithm is implemented in \textsc{Duo}, which is
a general program for calculating spectra of diatomic molecules. This approach
is tested for NO and MgH,and the results are compared to experiment and shown
to be consistent with those given the well-used effective Hamiltonian code
PGOPHER.
