head	1.3;
access;
symbols;
locks
	rolf:1.3; strict;
comment	@# @;


1.3
date	2013.09.16.23.31.48;	author rolf;	state Exp;
branches;
next	1.2;

1.2
date	2013.04.17.02.33.39;	author rolf;	state Exp;
branches;
next	1.1;

1.1
date	2009.09.23.03.41.11;	author rturner;	state Exp;
branches;
next	;


desc
@Boss function to call the recursive subroutines that calculate
the alpha, beta, gamma, and xi probabilities.
@


1.3
log
@Adapted code so that each sequence in the data can have
its own starting value.  (This is given by the maximum likelihood
ispd which is 1 for the "largest gamma value" and 0 elsewhere.)
@
text
@subroutine recurse(fy,xispd,tpm,nreps,epsilon,lns,nstate,nis,cis,
                   wrk,xlc,ntot,nxi,alpha,beta,gamma,xi,xisum)

implicit double precision(a-h,o-z)
logical cis
dimension xispd(nstate,nis), xlc(ntot), lns(nreps)
dimension tpm(nstate,nstate), wrk(nstate,nstate)
dimension fy(nstate,ntot), alpha(nstate,ntot), beta(nstate,ntot)
dimension gamma(nstate,ntot), xi(nstate,nstate,nxi), xisum(nstate,nstate)

# Set zero and one:
zero = 0.d0
one  = 1.d0

# Run through the replicates.
kstop = 0
do k = 1,nreps {
	n = lns(k)
        nm1 = n - 1
	kstart = 1 + kstop
        if(cis) {
            kis = one
        } else {
            kis = k
        }

# Update the alpha's.
	call afun(fy(1,kstart),xispd(1,kis),tpm,epsilon,n,nstate,wrk,
                  xlc(kstart),alpha(1,kstart))

# Update the beta's.
	call bfun(fy(1,kstart),xispd(1,kis),tpm,epsilon,n,nstate,wrk,
                  beta(1,kstart))

# Update the gamma's.
	call gfun(alpha(1,kstart),beta(1,kstart),epsilon,n,
                  nstate,wrk,gamma(1,kstart))

# Update the xi's.
	call xfun(alpha(1,kstart),beta(1,kstart),fy(1,kstart),
                  tpm,epsilon,n,nstate,nm1,wrk,xi(1,1,kstart-k+1))

# Increment kstop.
kstop = kstop + lns(k)
}

kstop = kstop - nreps
# Sum up the xi's.
do i = 1,nstate {
	do j = 1,nstate {
		xisum(i,j) = zero
		do k = 1,kstop {
			xisum(i,j) = xisum(i,j) + xi(i,j,k)
		}
	}
}

return
end
@


1.2
log
@Adjusted the dimensioning --- no more 1's.  Fixed up
the final dimension of xi to be nxi = L - nreps where L
is the toadal length of y.
@
text
@d1 2
a2 2
subroutine recurse(fy,xispd,tpm,nreps,epsilon,lns,nstate,wrk,xlc,
                   ntot,nxi,alpha,beta,gamma,xi,xisum)
d5 2
a6 1
dimension xispd(nstate), xlc(ntot), lns(nreps)
d11 1
a11 1
# Set zero:
d13 1
d21 5
d28 1
a28 1
	call afun(fy(1,kstart),xispd,tpm,epsilon,n,nstate,wrk,
d32 1
a32 1
	call bfun(fy(1,kstart),xispd,tpm,epsilon,n,nstate,wrk,
@


1.1
log
@Initial revision
@
text
@d1 2
a2 2
subroutine recurse(fy,xispd,tpm,nreps,epsilon,n,nstate,wrk,xlc,
                   alpha,beta,gamma,xi,xisum)
d5 4
a8 4
dimension xispd(1), xlc(1)
dimension tpm(nstate,1), wrk(nstate,1)
dimension fy(nstate,1), alpha(nstate,1), beta(nstate,1), gamma(nstate,1)
dimension xi(nstate,nstate,1), xisum(nstate,1)
d14 1
d16 3
a18 1
	kstart = (k-1)*n + 1
d34 4
a37 1
                  tpm,epsilon,n,nstate,wrk,xi(1,1,kstart-k+1))
d40 1
a41 1
kstop = nreps*(n-1)
@
