open_pops_head Subroutine

public subroutine open_pops_head(iunithead, formpops, binpops, filename_stem)

Arguments

Type IntentOptional Attributes Name
integer, intent(out) :: iunithead
logical, intent(out) :: formpops
logical, intent(out) :: binpops
character(len=255), intent(in), optional :: filename_stem

Contents

Source Code


Source Code

    subroutine open_pops_head(iunithead, formpops, binpops, filename_stem)
        integer, intent(out) :: iunithead
        logical, intent(out) :: formpops, binpops
        character(255) :: popsfile
        character(255), intent(in), optional :: filename_stem
        character(255) :: identifier

        if (present(filename_stem)) then
            identifier = filename_stem
        else
            identifier = "POPSFILE"
        endif

        if (iProcIndex == root) then
            iunithead = get_free_unit()
            call get_unique_filename(trim(identifier), tIncrementPops, .false., &
                                     iPopsFileNoRead, popsfile)
            inquire (file=popsfile, exist=formpops)

            if (formpops) then
                print *, "READING", popsfile
                open (iunithead, file=popsfile, status='old')
                binpops = .false.
            else
                ! If we are using split popsfiles, the filenames are a bit
                ! different.
                if (tSplitPops) then
                    call get_unique_filename('POPSFILEBIN-0', tIncrementPops, &
                                             .false., iPopsFileNoRead, &
                                             popsfile)
                else
                    call get_unique_filename(trim(identifier)//'BIN', tIncrementPops, &
                                             .false., iPopsFileNoRead, &
                                             popsfile)
                end if
                inquire (file=popsfile, exist=binpops)
                if (binpops) then
                    call get_unique_filename(trim(identifier)//'HEAD', tIncrementPops, .false., iPopsFileNoRead, popsfile)
                    open (iunithead, file=popsfile, status='old')
                else
                    call stop_all("open_pops_head", "No POPSFILEs detected...")
                endif
            endif
            rewind (iunithead)
        endif
        call MPIBCast(binpops)
        call MPIBCast(formpops)

    end subroutine open_pops_head