I just had a look at the Fortran code, and oh boy, it's not pretty, and far from "canonical" Fortran. I will submit a PR (hopefully later tonight) that makes it less ugly and slow.
(Protip: don't use if's inside tight loops. Just don't.)
(Protip: don't use if's inside tight loops. Just don't.)