SUBROUTINE ReturnAlphaOpenDet(nI, nJ, iLutnI, iLutSym, tCalciLutSym, tCalcnISym, tSwapped)
INTEGER(KIND=n_int), intent(inout) :: iLutSym(0:NIfTot), iLutnI(0:NIfTot)
integer(kind=n_int) :: iLutTemp(0:NIfTot)
INTEGER :: i, nTemp(NEl)
integer, intent(inout) :: nJ(NEl), nI(NEl)
LOGICAL, intent(in) :: tCalciLutSym, tCalcnISym
logical, intent(out) :: tSwapped
IF(tCalciLutSym) THEN
CALL FindExcitBitDetSym(iLutnI, iLutSym)
end if
IF(tCalcnISym) THEN
CALL FindDetSpinSym(nI, nJ, NEl)
end if
! iLutnI is 'less' than iLutSym, so iLutSym is the determinant with
! the first open-shell = alpha. Swap them around.
! Only count up to NIfD to avoid Yamanouchi symbol etc.
i = DetBitLT(iLutnI, iLutSym, NIfD)
IF(i == 1) THEN
iLutTemp(:) = iLutnI(:)
iLutnI(:) = iLutSym(:)
iLutSym(:) = iLutTemp(:)
! CALL FindDetSpinSym(nI,nJ,NEl)
nTemp(:) = nI(:)
nI(:) = nJ(:)
nJ(:) = nTemp(:)
tSwapped = .true.
else if(i == 0) THEN
CALL Stop_All("ReturnAlphaOpenDet", "Shouldn't have closed shell determinants in here")
ELSE
tSwapped = .false.
end if
END SUBROUTINE ReturnAlphaOpenDet