#include <math.h>
#include <stdio.h>

#define CONVERSION_ONLY 0 

 
extern npairs;
extern int *n;
extern int numfiles;

struct hapdata {
        int n;
        int n00;
        int n01;
        int n10;
        int n11;
        int n0q;
        int n1q;
        int nq0;
        int nq1;
        int nqq;
        double  d12;
        int ad ;
        }  ; 
extern struct hapdata  *hv ;
 
extern npairs;


double lnlikemshap( double c,double conv,double conlen, int nsites, double *recrates, double *****prob, double **ppoly  )
{
	int i, j  ;
	double sum, r ;
  double getprobmscond( struct hapdata,  double, int,double *, double ****, double *ppoly );
  double lnval( double ) ;


	sum = 0.0 ;
	for( i =0 ; i< npairs; i++){
	  if( CONVERSION_ONLY )  r = c*( 0.0  + 2.*1.0*conlen*(1.0 - exp( -hv[i].d12/conlen) ))  ;
	  else r = c*( hv[i].d12  + 2.*conv*conlen*(1.0 - exp( -hv[i].d12/conlen) ))  ; 
	  for( j=numfiles-1;  n[j] != hv[i].n ; j--);
          sum += lnval(  getprobmscond(hv[i], r, nsites,recrates, prob[j], ppoly[j] )) ;
	}

/*
if( CONVERSION_ONLY ) fprintf(stdout," 0.0   %lf  %lf", c, sum);
else  fprintf(stdout,"  %lf %lf  %lf\n", c, conv ,  sum);
fflush(stdout);
*/
	return( sum ) ;
}


