Try a function passing solution from gcc.gnu.org/ml/fortran/2006-09/msg00316.html