subroutine pivotare(n, nb, a, b, prag, k, n_sch_linii, kod)
real a(n,n), b(n,nb)
real arow(n), brow(nb)
integer width

!n_sch_linii =0
kod =0
! Indicele liniei pivotului
ipvt =k; pivot =a(k,k)
	do irow =k+1,n
	if(abs(a(irow,k)) >abs(pivot)) then
	ipvt =irow
	pivot =a(irow,k)
	endif
	enddo

! Test marime pivot: pivot =ab(ipvt, k)
	if(abs(pivot) < prag) then
	iwk =width(k)
	write(1, '(/, a, I<iwk>, a, 1pg15.7)') ' Linia ', k, ': Pivot =', pivot
	kod = -1		!k
	return
	endif

! Inter-schimba liniile "k" si "ipvt"
! Nu, daca ipvt =k:
if(ipvt /=k) then
arow =a(k,:); brow =b(k,:)
n_sch_linii =n_sch_linii+1

a(k,:) =a(ipvt,:); b(k,:) =b(ipvt,:)
a(ipvt,:) =arow; b(ipvt,:) =brow
endif

END
