diff --git a/src/main.f90 b/src/main.f90 index 2355770..aa1fda5 100644 --- a/src/main.f90 +++ b/src/main.f90 @@ -1,7 +1,7 @@ program main use const_and_precisions, only : wp_, one, zero use logger, only : INFO, ERROR, set_log_level, log_message - use units, only : set_active_units + use units, only : set_active_units, close_units use gray_cli, only : cli_options, parse_cli_options use gray_core, only : gray_main use gray_params, only : gray_parameters, gray_data, gray_results, & @@ -143,6 +143,7 @@ program main call deinit_profiles(data%profiles) call deinit_misc deallocate(results%dpdv, results%jcd) + call close_units contains diff --git a/src/units.f90 b/src/units.f90 index f4dffca..d9e014e 100644 --- a/src/units.f90 +++ b/src/units.f90 @@ -40,6 +40,23 @@ contains end subroutine set_active_units + subroutine close_units + ! Close all the active units to flush the buffer. + + implicit none + + integer :: i + + if (allocated(active_units)) then + do i = 1, size(active_units) + close(active_units(i)) + end do + deallocate(active_units) + end if + + end subroutine close_units + + function unit_active(unit) result(on) ! Checks whether the given `unit` is active