print_rdm_popsfile Subroutine

public subroutine print_rdm_popsfile(rdm)

Arguments

Type IntentOptional Attributes Name
type(rdm_list_t), intent(in) :: rdm

Contents

Source Code


Source Code

    subroutine print_rdm_popsfile(rdm)

        ! Print the RDM object stored in rdm to a file called RDM_POPSFILE.
        ! This is done in a binary form, which can be quickly read in a
        ! subsequent NECI simulation (see read_2rdm_popsfile). The RDM is
        ! printed directly in its int_rdm form, rather than decoding signs
        ! to their real(dp) form.

        use Parallel_neci, only: MPIBarrier
        use util_mod, only: get_free_unit

        type(rdm_list_t), intent(in) :: rdm

        integer :: ielem, iproc, ierr, pops_unit

        do iproc = 0, nProcessors - 1

            if (iproc == iProcIndex) then
                ! Let the first processor clear the file to start with.
                if (iproc == 0) then
                    pops_unit = get_free_unit()
                    open(pops_unit, file='RDM_POPSFILE', status='replace', form='unformatted')
                    ! Let the first processor start by printing the number of
                    ! RDMs being sampled.
                    write (pops_unit) rdm%sign_length
                else
                    pops_unit = get_free_unit()
                    open(pops_unit, file='RDM_POPSFILE', status='old', position='append', form='unformatted')
                end if

                do ielem = 1, rdm%nelements
                    write(pops_unit) rdm%elements(:, ielem)
                end do

                close(pops_unit)
            end if

            ! Wait for the current processor to finish printing its RDM elements.
            call MPIBarrier(ierr)
        end do

    end subroutine print_rdm_popsfile