!
! This is the set of usefull subroutines for access to
! BEC Data-Structure.
! Coded by: Borisov G.V. 03-aug-89
!

Subroutine psgndp(ndets,nrprc,ier)
include '[-.include]dsc1.inc'
include '[-.include]dsc3.inc'
equivalence (lrefer(1),lrloca),(lrefer(2),lrsize)
equivalence (lrefer(3),lrphys),(lrefer(9),lrtprc)
common/dssets/nsets,ndtot,ndet(20),iaddet(20)
common/dsproc/nproci,namepr(30),iabrel(30),irelab(30)
integer idet(1),ihit(1),ird(10)
real htd(2)
ier =0
if(lrgprc.eq.0) then

ier =1
return

end if
nrprc =icq(lrgprc+2)
nrtot =icq(lrgprc-3)
ndets =nrtot-3-nrprc
return

entry psgdnm(idc,ida,lrdet,ier)
ier =0
lrdet =lcq(lrgprc-idc)
ida =icq(lrgdet-5)
return

entry psgpnm(iprc,ipra,ier)
ier =0
nrtot =icq(lrgprc-3)
lad =lcq(lrgprc-nrtot+1)
iprcnm =icq(lad+iprc)
ipra =iucomp(iprcnm,namepr,nproci)
return

entry psgref(lrprc,ndim,nref,idet,ihit,ier)

c Takes all det,hit pairs from processor reference list
c lrprc - address of reference area
c ndim - max.dimension of idet,ihit
c nref - number of referencies
c idet(1:nref) - detector list
c ihit(1:nref) - corresponding hit numbers
c

ier =0
nwd =icq(lrprc)
lad =lrprc+nwd+1
nref =icq(lad)
if(nref.gt.ndim) then

nref =ndim
ier =1

end if
do i=1,nref
iref =icq(lad+i)
ihit(i) =iref/65536
idet(i) =iref.and.65535
end do
return

entry psghit(ida,iht,nwrd,ird,htd,ier)
ier =0
lad =lcq(lctd-ida)
if(lad.eq.0) then

ier =1
return

end if
nh =icq(lad)
if(nh/2.lt.iht) then

ier =2
return

end if
htd(1) =cq(lad+iht*2-1)
htd(2) =cq(lad+iht*2)
lad =lcq(lcpr-ida)
iad =icq(lad+iht-1)
if(iad.eq.0) then

ier =3
return

end if
nwrd =icq(lcpr+iad)
do i =1,nwrd
ird(i)=icq(lcpr+iad+i)
end do
lad =lcrd+icq(lcrd+1)+1+ida
iad =icq(lad).and.65535
do i =1,nwrd
ird(i) =icq(lcrd+iad-1+ird(i))
end do
return
end