init_spin_diff_output Subroutine

public subroutine init_spin_diff_output(funit)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: funit

Contents

Source Code


Source Code

    subroutine init_spin_diff_output(funit)
        ! routine to initialize the instant spin-diff output
        integer, intent(in) :: funit
        character(*), parameter :: this_routine = "init_spin_diff_output"
        character(30) :: filename
        character(43) :: filename2
        character(12) :: num
        logical :: exists
        integer :: i, ierr

        filename = "spin_diff_stats"

        if (tReadPops) then
            open(funit, file=filename, status='unknown', position='append')
        else
            inquire (file=filename, exist=exists)

            if (exists) then
                i = 1
                do while (exists)
                    write(num, '(i12)') i
                    filename2 = trim(adjustl(filename))//"."// &
                                trim(adjustl(num))

                    inquire (file=filename2, exist=exists)
                    if (i > 10000) call stop_all(this_routine, &
                                                 "error finding free spin_diff_stats")

                    i = i + 1
                end do

                call rename(filename, filename2)
            end if

            open(funit, file=filename, status='unknown', iostat=ierr)

        end if

    end subroutine init_spin_diff_output