subroutine open_idempotence_files
! Open new output file and mfile to write output to
! This is used when checking model evaluation idempotence, to avoid
! polluting the final output file and mfile with intermediate result checks
use global_variables, only: output_prefix
use constants, only: nout, mfile
implicit none
! Close existing output file and mfile (could be original out and mfiles
! or idem scratch files)
close(unit = nout)
close(unit = mfile)
! Open scratch files with same units
open(unit=nout, file=trim(output_prefix)//'IDEM_OUT.DAT', action='write', status='replace')
open(unit=mfile, file=trim(output_prefix)//'IDEM_MFILE.DAT', action='write', status='replace')
end subroutine open_idempotence_files