@mcc I especially like this little postscriptum:"If you want a truly Fortran 90 answer, as you've tagged, then it won't be as nice but it still can be done."