open(99 may fault if 99 is open in parent application
Instead of opening a specific unit, it would be better to do something like this:
do iu = 1000, 10000 inquire(unit=iu, opened=is_open) if ( is_open ) cycle end do
something like the above should do it (and be portable).
Since the units are closed in the same call there should be no problem with the above as a function (return a unit)