subroutine output_2rdm_wrapper(rdm_defs, est, rdm, rdm_recv, rdm_recv_2, spawn)
! Call routines to output RDMs in all requested forms.
! We also calculate the Hermitian errors here, since this is something
! we typically want to do at the same point (the very end of a
! simulation usually), and this requires large parallel
! communications, as does the printing.
use LoggingData, only: tWrite_normalised_RDMs, tWrite_RDMs_to_read
use rdm_data, only: rdm_definitions_t, rdm_estimates_t, rdm_list_t, rdm_spawn_t, tOpenShell
use rdm_estimators, only: calc_hermitian_errors
use hash, only: clear_hash_table
type(rdm_definitions_t), intent(in) :: rdm_defs
type(rdm_estimates_t), intent(inout) :: est
type(rdm_list_t), intent(in) :: rdm
type(rdm_list_t), intent(inout) :: rdm_recv, rdm_recv_2
type(rdm_spawn_t), intent(inout) :: spawn
! Print the RDM popsfile, which requires no communication, first. This
! is in case we run out of memory during one of the other routines
! called here, which could crash if there isn't enough memory for
! communication! Then at least we can read the RDM back in...
if (tWrite_RDMs_to_read) call print_rdm_popsfile(rdm)
call calc_hermitian_errors(rdm, rdm_recv, spawn, est%norm, &
est%max_error_herm, est%sum_error_herm)
if (tGUGA) then
spawn%free_slots = spawn%init_free_slots(0:nProcessors - 1)
call clear_hash_table(spawn%rdm_send%hash_table)
call make_hermitian_rdm(rdm, rdm_defs%nrdms_standard, spawn, rdm_recv)
call print_spinfree_2rdm(rdm_defs, rdm_recv, est%norm)
if (t_print_molcas_rdms) then
call output_molcas_rdms(rdm_defs, rdm_recv, est%norm)
end if
else
if (tWriteSpinFreeRDM) &
call print_spinfree_2rdm_wrapper(rdm_defs, rdm, rdm_recv, spawn, est%norm)
if (tWrite_Normalised_RDMs) &
call print_rdms_spin_sym_wrapper(rdm_defs, rdm, rdm_recv, rdm_recv_2, &
spawn, est%norm, tOpenShell)
end if
end subroutine output_2rdm_wrapper