/* file aldistst_prot.c */


#if !defined(COMPILE_ENVIRONMENT)
#include <gp/stdcenvf.h> /* std compile environment for functions */
#endif

  int aldist_static_prot(ALIGNMENT_INT_PROT *pal, int *perr)
 /**********************************************************************/
 /*                                                                    */
 /*    Computes and returns the alignment distance between the         */
 /* symbols in the two integer strings in *pal (nsa and nsb).          */
 /*    Assumes the strings are already in alignment; designed to work  */
 /* with pal->auxtab[].                                                */
 /*                                                                    */
 /*   *perr = 0 means a.o.k.                                           */
 /*   error codes:                                                     */
 /*   11:invalid input parameters                                      */
 /*                                                                    */
 /**********************************************************************/

  {
/* data: */
  char *proc = "aldist_static_prot";
  PROTECTED_INT_STR sxix, *sxi = &sxix;
  ALIGNMENT_INT_PROT *pal2, *pdummy=NULL;
  pcodeset *pcode1;
  int i,j,k,distance,d;
  boolean dont_return_alignment = F;
/* code: */
db_enter_msg(proc,0); /* debug only */
  *perr=0;
  pcode1 = pal->pcset;
  pal2 = make_al_int_prot2("aldist_static_prot/pal2",pcode1->lower_code);
  pal2->aligned = F;
  alloc_prot_int_str_guts(sxi,133);
  distance = 0;
  if (!pal->aligned)
    {fprintf(stderr,"%s: *ERR: input alignment NOT ALIGNED.\n",proc);
     *perr=11; goto RETURN;
    }
  if (pal->nsa->str[0] != pal->nsb->str[0])
    {fprintf(stderr,"%s: *ERR: astr length=%d but bstr length=%d.\n",
      proc,pal->nsa->str[0],pal->nsb->str[0]);
     *perr=11; goto RETURN;
    }
  for (k=1; k <= pal->nsa->str[0]; k++) 
    {i = pal->nsa->str[k];
     nstrcpy_prot_s(pal2->nsa,lc_istr_prot(sxi,i,pcode1,pal));
     j = pal->nsb->str[k];
     nstrcpy_prot_s(pal2->nsb,lc_istr_prot(sxi,j,pcode1,pal));
     d = aldist2_prot(pal2,wod2_prot,dont_return_alignment,pdummy,perr);

if (db_level > 1)
  {printf("%s slot #%d: i=%d, j=%d -- input aln is:\n",pdb,k,i,j);
   dump_int_alignment_prot(pal2);
   printf("%s alignment d = %d\n",pdb,d);
  }
     distance += d;
    }
RETURN:
  free_al_int_prot(pal2);
  dealloc_prot_int_str_guts(sxi);
 db_leave_msg(proc,0); /* debug only */
  return distance;
  } /* end of function "aldist_static_prot" */
