chu	function segaddscan(x, n, seg, direction)
	subroutine segad ( x, segaddscan, n, seg, direction )
****************************************************************************
*                                                                          *
*   DATA PARALLEL BLAS based on MPL                                        *
*                                                                          *
*   Version 1.0   1/9-92 ,                                                 *
*   For MasPar MP-1 computers                                              *
*                                                                          *
*   para//ab, University of Bergen, NORWAY                                 *
*                                                                          *
*   These programs must be called using F90 style array syntax.            *
*   Note that the F77 style calling sequence has been retained             *
*   in this version for compatibility reasons, be aware that               *
*   parameters related to the array dimensions and shape therefore may     *
*   be redundant and without any influence.                                *
*   The calling sequence may be changed in a future version.               *
*   Please report any BUGs, ideas for improvement or other                 *
*   comments to                                                            *
*                    adm@parallab.uib.no                                   *
*                                                                          *
*   Future versions may then reflect your suggestions.                     *
*   The most current version of this software is available                 *
*   from netlib@nac.no , send the message `send index from maspar'         *
*                                                                          *
*   REVISIONS:                                                             *
*                                                                          *
****************************************************************************
	implicit none
chu
	integer n
	real, array(n) :: x, segaddscan
	logical, array(n) :: seg
	character *1 direction
	real start
	integer k
*     .. Parameters ..
      REAL               ZERO
      PARAMETER        ( ZERO = 0.0E+0 )
*
c
c  suppose x = 1 2 3 4 5 6 7 8
c  and   seg = 0 1 0 0 1 1 0 1   (1 is true, 0 is false)
c   if direction is left then
c  segaddcan = 1 9 7 4 5 13 7 8
c
	if (direction .eq. 'L') then
	    start = zero
	    do k = n, 1, -1
	        start = start + x(k)
	        segaddscan(k) = start
	        if (seg(k)) start = zero
	    enddo
	else
c
c  direction = 'R'
c
	    start = zero
	    do k = 1, n
	        start = start + x(k)
	        segaddscan(k) = start
	        if (seg(k)) start = zero
	    enddo
	endif
	return
	end