https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78854
--- Comment #2 from janus at gcc dot gnu.org --- I'm afraid I have too little knowledge of the I/O parts of libgfortran to fix, but I can at least give some pointers to where things appear to go wrong ... In the function "nml_write_obj" at line 2210 of write.c there is a block starting with: if (obj->dtio_sub != NULL) { int unit = dtp->u.p.current_unit->unit_number; This whole block deals with calling DTIO procedures. Apparently the line above that sets the unit is not enough to deal with internal units. It seems that there is some code to deal with internal units e.g. in the function "write_block" in transfer.c: if (is_internal_unit (dtp)) ...