650 IMPLICIT NONE
651 INTEGER N, NASS1, LSMALL, LLARGE, LMERGE
652 INTEGER PERM( N ), ITLOC( N )
653 INTEGER SMALL(LSMALL), LARGE(LLARGE), MERGE(LMERGE)
654 INTEGER PSMALL, PLARGE, PMERGE, VSMALL, VLARGE, VMERGE
655 psmall = 1
656 plarge = 1
657 pmerge = 1
658 DO WHILE ( psmall .LE. lsmall .or. plarge.LE. llarge )
659 IF ( psmall .GT. lsmall ) THEN
660 vmerge = large( plarge )
661 plarge = plarge + 1
662 ELSE IF ( plarge .GT. llarge ) THEN
663 vmerge = small( psmall )
664 psmall = psmall + 1
665 ELSE
666 vsmall = small( psmall )
667 vlarge = large( plarge )
668 IF ( perm( vsmall ) .LT. perm( vlarge ) ) THEN
669 vmerge = vsmall
670 psmall = psmall + 1
671 ELSE
672 vmerge = vlarge
673 plarge = plarge + 1
674 END IF
675 END IF
676 merge( pmerge ) = vmerge
677 itloc( vmerge ) = pmerge + nass1
678 pmerge = pmerge + 1
679 END DO
680 pmerge = pmerge - 1
681 RETURN
subroutine merge(x, itab, itabm1, cmerge, imerge, imerge2, iadmerge2, nmerge_tot)