Got stuff working, but it seems as if it does not work with threading enabled. Likely in my poor understanding of threadprivate in Fortran.