Exemplo n.º 1
0
/**
 *  Convert f0-contour with equal spaced sampling points to pitch markers.
 *
 * @param idSrc        source f0-contour
 * @param idDst        target pitch marker
 * @param n            target sum of pitch marker lengths
 * @param srate        sampling rate
 * @return O_K if sucessfull, not exec otherwise
 */
INT16 CGEN_PUBLIC CPMproc::F02pm(CData *idSrc, CData* idDst, INT32 n, INT32 srate) {

  INT16* p_pm = NULL;
  INT32    n_pm = 0;

  if(CData_IsEmpty(idSrc) == TRUE) return NOT_EXEC;
  if(n <= 0)                       return NOT_EXEC;

  DLPASSERT(CData_GetNComps(idSrc) == 1);

  CREATEVIRTUAL(CData,idSrc,idDst);

  CData_Reset(idDst, TRUE);

  dlm_f02pm((FLOAT64*)idSrc->XAddr(0,0), idSrc->GetNRecs(), &p_pm, &n_pm, n, srate);

  CData_AddComp(idDst, "pm",   T_SHORT);
  CData_AddComp(idDst, "v/uv", T_SHORT);
  CData_Allocate(idDst, n_pm);
  ISETFIELD_RVALUE(idDst, "fsr", 1000.0/srate);

  dlp_memmove(idDst->XAddr(0,0), p_pm, 2*n_pm*sizeof(INT16));

  /* clean up */
  DESTROYVIRTUAL(idSrc,idDst)

  dlp_free(p_pm);

  return(O_K);
}
Exemplo n.º 2
0
/* DP decoder backtrack function
 *
 * This function performes the backtracking after decoding.
 *
 * @param glob  Pointer to the global memory structure
 * @param itDst Destination transducer for backtracking
 * @return <code>NULL</code> if successfull, the error string otherwise
 */
const char *fsts_sdp_backtrack(struct fsts_glob *glob,CFst *itDst){
  INT32 gwi;
  CDlpObject_Copy(BASEINST(itDst),BASEINST(((CFst*)glob->algo)));
  if((gwi=CData_FindComp(AS(CData,itDst->ud),"~GW"))<0){
    CData_AddComp(AS(CData,itDst->ud),"~GW",T_DOUBLE);
    gwi=CData_GetNComps(AS(CData,itDst->ud))-1;
  }
  CData_Dstore(AS(CData,itDst->ud),itDst->m_nGw,0,gwi);
  return NULL;
}
Exemplo n.º 3
0
/**
 * Adds three auxiliary components to the state table of this instance. These
 * components are used by {@link -compose CFst_Compose} and
 * {@link -best_n CFst_BestN} to associate a composed state with its source
 * states and an epsilon filter mode. The method sets the field
 * {@link ic_sd_aux m_nIcSdAux} to the first component added.
 *
 * @param _this Pointer to automaton instance
 * @see Cps_DelSdAux CFst_Cps_DelSdAux
 * @see Cps_SetSdAux CFst_Cps_SetSdAux
 * @see Cps_FindState CFst_Cps_FindState
 */
void CGEN_PRIVATE CFst_Cps_AddSdAux(CFst* _this)
{
  /* Add auxiliary components to state table */
  CData_AddComp(AS(CData,_this->sd),"X"  ,DLP_TYPE(FST_ITYPE));
  CData_AddComp(AS(CData,_this->sd),"Y"  ,DLP_TYPE(FST_ITYPE));
  CData_AddComp(AS(CData,_this->sd),"Flg",T_BYTE             );

  DLPASSERT((_this->m_nIcSdAux = CData_FindComp(AS(CData,_this->sd),"X"  ))>=0);
  DLPASSERT(                     CData_FindComp(AS(CData,_this->sd),"Y"  ) >=0);
  DLPASSERT(                     CData_FindComp(AS(CData,_this->sd),"Flg") >=0);

  /* Initialize hash node pool */
  DLPASSERT(_this->m_lpCpsHnpool   ==NULL);
  DLPASSERT(_this->m_nCpsHnpoolSize==0   );
  _this->m_lpCpsHnpool    = (void**)dlp_calloc(100,sizeof(hnode_t*));
  _this->m_nCpsHnpoolSize = 0;
  dlp_memset(_this->m_lpCpsKeybuf,0,3*sizeof(FST_ITYPE));

  /* Initialize composed state hash map */
  DLPASSERT(_this->m_lpCpsHash==NULL);
  _this->m_lpCpsHash = hash_create(HASHCOUNT_T_MAX,CFst_Cps_HashCmp,CFst_Cps_HashFn,_this);
  hash_set_allocator((hash_t*)_this->m_lpCpsHash,CFst_Cps_HashAllocNode,CFst_Cps_HashFreeNode,_this);
}
Exemplo n.º 4
0
/**
 *  Convert (unequal spaced) pitch markers to f0-contour with equal spaced
 * sampling points.
 *
 * @param idSrc        source pitch marks
 * @param idDst        target fo-contour
 * @param n            target number of sampling points of f0-contour
 * @param srate        sampling rate
 * @return O_K if sucessfull, not exec otherwise
 */
INT16 CGEN_PUBLIC CPMproc::Pm2f0(CData *idSrc, CData* idDst, INT32 n, INT32 srate) {

  if(CData_IsEmpty(idSrc) == TRUE) return NOT_EXEC;
  if(n <= 0)                       return NOT_EXEC;

  DLPASSERT(CData_GetNComps(idSrc) == 2);

  CREATEVIRTUAL(CData,idSrc,idDst);

  CData_Reset(idDst, TRUE);
  CData_AddComp(idDst, "~F0", T_DOUBLE);

  CData_Allocate(idDst, n);

  dlm_pm2f0((INT16*)idSrc->XAddr(0,0), idSrc->GetNRecs(), (FLOAT64*)idDst->XAddr(0,0), idDst->GetNRecs(), srate);

  ISETFIELD_RVALUE(idDst, "fsr", 1000.0/srate);

  /* clean up */
  DESTROYVIRTUAL(idSrc,idDst)

  return(O_K);
}
Exemplo n.º 5
0
/**
 * Import midi notes of a midifile into data, needs external program midiconvert
 *
 * @param lpsFilename Name of file to import
 * @param iDst        Pointer to instance to import
 * @param lpsFiletype Type of file to import
 * @return <code>O_K</code> if successful, a (negative) error code otherwise
 */
INT16 CGEN_PROTECTED CDlpFile_Midi_ImportMidi
(
  CDlpFile*   _this,
  const char* lpsFilename,
  CDlpObject* iDst,
  const char* lpsFiletype
)
{
   char  lpsTempFile[L_PATH];
   char  lpsCmdline    [3*L_PATH] = "";
   INT16 nErr                     =O_K;

   strcpy(lpsTempFile,dlp_tempnam(NULL,"dlabpro_midi_import"));
   sprintf(lpsCmdline,"midiconvert %s %s", lpsFilename, lpsTempFile);

   if (system(lpsCmdline)!=0) { nErr=IERROR(_this,FIL_EXEC,lpsCmdline,0,0); }
   else {
      CData *idDst = AS(CData,iDst);
      /*Prepare data*/
      CData_Reset(iDst,TRUE);
      CData_AddComp(idDst,"CHAN",T_UCHAR);
      CData_AddComp(idDst,"VOL",T_UCHAR);
      CData_AddComp(idDst,"INST",T_UCHAR);
      CData_AddComp(idDst,"NOTE",T_UCHAR);
      CData_AddComp(idDst,"TIME",T_UINT);
      CData_AddComp(idDst,"LGTH",T_UINT);
      CData_AddComp(idDst,"VEL",T_UCHAR);
      /*import*/
      IF_NOK(CDlpFile_ImportAsciiToData(_this,lpsTempFile,iDst,"csv"))
        nErr = IERROR(iDst,FIL_IMPORT,lpsTempFile,"csv",0);
      /*Set midifilter specific data descriptions and clean data*/
      CData_SetDescr(idDst, DESCR0, CData_Dfetch(idDst,0,5));
      CData_DeleteRecs(idDst,0,1);
   }
   if (remove(lpsTempFile)==-1) nErr=IERROR(_this,FIL_REMOVE,"temporary ",lpsTempFile,0);
   /* Clean up */
   return nErr;
}
Exemplo n.º 6
0
/**
 * Packs <code>nArgs<code> function arguments plus the zero-th argument (the
 * function itself) from <code>iCaller</code>'s stack into the data transfer
 * object <code>iDto</code>.
 */
void CGEN_PROTECTED CProcess::Marshal
(
  CDlpObject* iDto,
  CFunction*  iCaller,
  INT32       nArgs
)
{
  CData*      idSign  = NULL;                                                   // Signature table
  StkItm*     pStkItm = NULL;                                                   // Stack item to marshal
  INT32       nArg    = 0;                                                      // Argument loop counter
#ifndef USE_FORK
  CDlpObject* iRoot   = NULL;
  CDlpObject* iSrc    = NULL;
  CDlpObject* iDst    = NULL;
  CData*      idGlob  = NULL;                                                   // Globals table
  CData*      idIncl  = NULL;                                                   // Includes table
  hscan_t     hs;
  hnode_t*    hn;
  SWord*      lpWord  = NULL;
  char*       psClsName;
  char*       psInsName;
#endif

  // Marshal function arguments                                                 // ------------------------------------
  idSign = (CData*)CDlpObject_Instantiate(iDto,"data",PRC_S_IDSIGN,FALSE);      // Create signature table
  CData_AddComp(idSign,"name",L_SSTR);                                          // Add component to table
  for (nArg=0; nArg<=nArgs; nArg++)                                             // Loop over arguments
  {                                                                             // >>
    pStkItm = iCaller->StackGet(0);                                             //   Get stack top
    Pack(iDto,idSign,pStkItm,NULL);                                             //   Pack into data transfer object
    iCaller->Pop(FALSE);                                                        //   Remove stack top
  }                                                                             // <<

#ifndef USE_FORK
  // Marshal global variables                                                   // ------------------------------------
  iRoot = GetRoot();                                                            // Get root function
  if (m_bGlobal && iRoot)                                                       // /global option set
  {                                                                             // >>
    idGlob = (CData*)CDlpObject_Instantiate(iDto,"data",PRC_S_IDGLOB,FALSE);    //   Create globals table
    CData_AddComp(idGlob,"clas",L_SSTR);                                        //   Add component to table
    CData_AddComp(idGlob,"name",L_SSTR);                                        //   Add component to table
    hash_scan_begin(&hs,iRoot->m_lpDictionary);                                 //   Initialize
    while ((hn = hash_scan_next(&hs))!=NULL)                                    //   Loop over root function's dict.
    {                                                                           //   >>
      lpWord = (SWord*)hnode_get(hn);                                           //     Get pointer to SWord struct
      if ((lpWord->nWordType == WL_TYPE_INSTANCE) && lpWord->lpData)            //     Entry is a non-NULL instance
      {                                                                         //     >>
        iSrc = (CDlpObject*)lpWord->lpData;                                     //       Get instance pointer
        psClsName = iSrc->m_lpClassName;                                        //       Get pointer to class name
        psInsName = iSrc->m_lpInstanceName;                                     //       Get pointer to instance name
        //if (CDlpObject_OfKind("function",iSrc)) continue;                     //       No functions, please
        if (iSrc==iCaller) continue;                                            //       Not the caller!
        if (iSrc->m_nClStyle & CS_SINGLETON) continue;                          //       No singletons!
        if (CDlpObject_FindInstanceWord(m_iDto,psInsName,NULL)) continue;       //       Shadowed by an argument
        iDst = CDlpObject_Instantiate(m_iDto,psClsName,psInsName,FALSE);        //       Create copy to pack
        iDst->Copy(iSrc);                                                       //       Copy content
        CData_AddRecs(idGlob,1,10);                                             //       Add index entry
        CData_Sstore(idGlob,psClsName,CData_GetNRecs(idGlob)-1,0);              //       Write index entry
        CData_Sstore(idGlob,psInsName,CData_GetNRecs(idGlob)-1,1);              //       Write index entry
      }                                                                         //     <<
    }                                                                           //   <<
  }                                                                             // <<

  // Marshal includes                                                           // ------------------------------------
  if (m_bInclude && iRoot)                                                      // /include option set
  {                                                                             // >>
    idIncl = (CData*)CDlpObject_Instantiate(iDto,"data",PRC_S_IDINCL,FALSE);    //   Create include table
    CData_Copy(idIncl,((CFunction*)iRoot)->m_idSfl);                            //   Copy includes
  }                                                                             // <<
#endif
}
Exemplo n.º 7
0
/*
 * Manual page at fst_man.def
 */
INT16 CGEN_PUBLIC CFst_Product
(
  CFst* _this,
  CFst* itSrc1,
  CFst* itSrc2,
  INT32  nUnit1,
  INT32  nUnit2
)
{
  INT32      nC           = 0;                                                   /* Current component                  */
  INT32      nFCS2        = 0;                                                   /* 1st data comp. of state tab.itSrc2 */
  INT32      nXCS1        = 0;                                                   /* No. of comps. of state tab. itSrc1 */
  INT32      nXCS2        = 0;                                                   /* No. of comps. of state tab. itSrc2 */
  INT32      nFCT2        = 0;                                                   /* 1st data comp. of trans.tab.itSrc2 */
  INT32      nXCT1        = 0;                                                   /* No. of comps. of trans.tab. itSrc1 */
  INT32      nXCT2        = 0;                                                   /* No. of comps. of trans.tab. itSrc2 */
  INT32      nRls1        = 0;                                                   /* Rec. len. of state table of itSrc1 */
  INT32      nRls2        = 0;                                                   /* Rec. len. of state table of itSrc2 */
  INT32      nRlt1        = 0;                                                   /* Rec. len. of trans.table of itSrc1 */
  INT32      nRlt2        = 0;                                                   /* Rec. len. of trans.table of itSrc2 */
  FST_ITYPE nS1          = 0;
  FST_ITYPE nS2          = 0;
  FST_ITYPE nFS1         = 0;
  FST_ITYPE nFS2         = 0;
  FST_ITYPE nXS1         = 0;
  FST_ITYPE nXS2         = 0;
  FST_ITYPE nT           = 0;
  FST_ITYPE nIni         = 0;
  FST_ITYPE nTer         = 0;
  FST_ITYPE nT1          = 0;
  FST_ITYPE nT2          = 0;
  FST_ITYPE nFT1         = 0;
  FST_ITYPE nFT2         = 0;
  FST_ITYPE nXT1         = 0;
  FST_ITYPE nXT2         = 0;
  char*     lpsBuf       = NULL;                                                /* String buffer                      */
  INT16     nVirt        = 0;                                                   /* Auxiliary: patching ovrl.args. bug */
  BOOL      bNoloopsSave = FALSE;                                               /* Save buffer for /noloops option    */

  /* Validate */
  CHECK_THIS_RV(NOT_EXEC);
  if (itSrc1==NULL || itSrc2==NULL)
  {
    CFst_Reset(BASEINST(_this),TRUE);
    return O_K;
  }
  if (nUnit1<0 || nUnit1>=UD_XXU(itSrc1)) return IERROR(_this,FST_BADID,"unit",nUnit1,0);
  if (nUnit2<0 || nUnit2>=UD_XXU(itSrc2)) return IERROR(_this,FST_BADID,"unit",nUnit2,0);

  /* Initialize */
  /* HACK: Multiple overlapping arguments on _this not handled correctly by
           CREATEVIRTUAL --> */
  if (_this==itSrc1 && _this==itSrc2) return IERROR(_this,ERR_GENERIC,"Invalid arguments",0,0);
  if      (itSrc1==_this) { CREATEVIRTUAL(CFst,itSrc1,_this); nVirt=1; }
  else if (itSrc2==_this) { CREATEVIRTUAL(CFst,itSrc2,_this); nVirt=2; }
  /* <-- */
  bNoloopsSave = _this->m_bNoloops;
  CFst_Reset(BASEINST(_this),TRUE);
  _this->m_bNoloops = bNoloopsSave;

  /* Initialize destination state table */
  nFS1  = UD_FS(itSrc1,nUnit1);
  nXS1  = UD_XS(itSrc1,nUnit1);
  nFS2  = UD_FS(itSrc2,nUnit2);
  nXS2  = UD_XS(itSrc2,nUnit2);
  nRls1 = CData_GetRecLen(AS(CData,itSrc1->sd)) - CData_GetCompOffset(AS(CData,itSrc1->sd),IC_SD_DATA);
  nRls2 = CData_GetRecLen(AS(CData,itSrc2->sd)) - CData_GetCompOffset(AS(CData,itSrc2->sd),IC_SD_DATA);
  nXCS1 = CData_GetNComps(AS(CData,itSrc1->sd)) - IC_SD_DATA;
  nXCS2 = CData_GetNComps(AS(CData,itSrc2->sd)) - IC_SD_DATA;
  nFCS2 = IC_SD_DATA + nXCS1;
  for (nC=IC_SD_DATA; nC<IC_SD_DATA+nXCS1; nC++)
    CData_AddComp
    (
      AS(CData,_this->sd),
      CData_GetCname(AS(CData,itSrc1->sd),nC),
      CData_GetCompType(AS(CData,itSrc1->sd),nC)
    );
  for (nC=IC_SD_DATA; nC<IC_SD_DATA+nXCS2; nC++)
    CData_AddComp
    (
      AS(CData,_this->sd),
      CData_GetCname(AS(CData,itSrc2->sd),nC),
      CData_GetCompType(AS(CData,itSrc2->sd),nC)
    );

  /* Initialize destination transition table */
  nFT1  = UD_FT(itSrc1,nUnit1);
  nXT1  = UD_XT(itSrc1,nUnit1);
  nFT2  = UD_FT(itSrc2,nUnit2);
  nXT2  = UD_XT(itSrc2,nUnit2);
  nRlt1 = CData_GetRecLen(AS(CData,itSrc1->td)) - CData_GetCompOffset(AS(CData,itSrc1->td),IC_TD_DATA);
  nRlt2 = CData_GetRecLen(AS(CData,itSrc2->td)) - CData_GetCompOffset(AS(CData,itSrc2->td),IC_TD_DATA);
  nXCT1 = CData_GetNComps(AS(CData,itSrc1->td)) - IC_TD_DATA;
  nXCT2 = CData_GetNComps(AS(CData,itSrc2->td)) - IC_TD_DATA;
  nFCT2 = IC_TD_DATA + nXCT1;
  for (nC=IC_TD_DATA; nC<IC_TD_DATA+nXCT1; nC++)
    CData_AddComp
    (
      AS(CData,_this->td),
      CData_GetCname(AS(CData,itSrc1->td),nC),
      CData_GetCompType(AS(CData,itSrc1->td),nC)
    );
  for (nC=IC_TD_DATA; nC<IC_TD_DATA+nXCT2; nC++)
    CData_AddComp
    (
      AS(CData,_this->td),
      CData_GetCname(AS(CData,itSrc2->td),nC),
      CData_GetCompType(AS(CData,itSrc2->td),nC)
    );

  /* Copy input and output symbol tables */
  CData_Copy(_this->is,itSrc1->is);
  CData_Copy(_this->os,itSrc2->os);

  /* Initialize destination unit */
  lpsBuf = (char*)dlp_calloc
  (
    CData_GetCompType(AS(CData,itSrc1->ud),IC_UD_NAME) +
    CData_GetCompType(AS(CData,itSrc2->ud),IC_UD_NAME) + 2,
    sizeof(char)
  );
  sprintf
  (
    lpsBuf,"%s.%s",
    (const char*)CData_XAddr(AS(CData,itSrc1->ud),nUnit1,IC_UD_NAME),
    (const char*)CData_XAddr(AS(CData,itSrc2->ud),nUnit2,IC_UD_NAME)
  );
  CFst_Addunit(_this,lpsBuf);
  dlp_free(lpsBuf);

  /* Add product states */
  CFst_Addstates(_this,0,nXS1*nXS2,FALSE);

  /* Copy state qualification (including final state flag) */
  for (nS1=0; nS1<nXS1; nS1++)
    for (nS2=0; nS2<nXS2; nS2++)
    {
      if ((SD_FLG(itSrc1,nS1+nFS1)&0x01)==0x01 && (SD_FLG(itSrc2,nS2+nFS2)&0x01)==0x01)
        SD_FLG(_this,nS1*nXS2+nS2) |= 0x01;
      if (nRls1>0)
        dlp_memmove
        (
          CData_XAddr(AS(CData,_this ->sd),nS1*nXS2+nS2,IC_SD_DATA),
          CData_XAddr(AS(CData,itSrc1->sd),nS1+nFS1    ,IC_SD_DATA),
          nRls1
        );
      if (nRls2>0)
        dlp_memmove
        (
          CData_XAddr(AS(CData,_this ->sd),nS1*nXS2+nS2,nFCS2     ),
          CData_XAddr(AS(CData,itSrc2->sd),nS2+nFS2    ,IC_SD_DATA),
          nRls2
        );
    }

  CData_AddRecs(AS(CData,_this->td),nXT1*nXT2,_this->m_nGrany);
  /* Loop over all transitions of both factors */
  for (nT=0, nT1=nFT1; nT1<nFT1+nXT1; nT1++)
    for (nT2=nFT2; nT2<nFT2+nXT2; nT2++, nT++)
    {
      /* Get product of initial and terminal state */
      nIni = TD_INI(itSrc1,nT1)*nXS2 + TD_INI(itSrc2,nT2);
      nTer = TD_TER(itSrc1,nT1)*nXS2 + TD_TER(itSrc2,nT2);
      if (_this->m_bNoloops && nIni==nTer) continue;

      /* Add product transition */
      *(FST_ITYPE*)CData_XAddr(AS(CData,_this->td),nT,IC_TD_INI) = nIni;
      *(FST_ITYPE*)CData_XAddr(AS(CData,_this->td),nT,IC_TD_TER) = nTer;

      /* Copy transition qualification */
      dlp_memmove
      (
        CData_XAddr(AS(CData,_this ->td),nT ,IC_TD_DATA),
        CData_XAddr(AS(CData,itSrc1->td),nT1,IC_TD_DATA),
        nRlt1
      );
      dlp_memmove
      (
        CData_XAddr(AS(CData,_this ->td),nT ,nFCT2     ),
        CData_XAddr(AS(CData,itSrc2->td),nT2,IC_TD_DATA),
        nRlt2
      );
    }

  /* Finish destination instance */
  CData_SelectRecs(AS(CData,_this->td),AS(CData,_this->td),0,nT);
  UD_XT(_this,0) = nT;
  /* TODO: Trim result !? */

  /* Clean up */
  if (nVirt==1) { DESTROYVIRTUAL(itSrc1,_this); }
  if (nVirt==2) { DESTROYVIRTUAL(itSrc2,_this); }
  return O_K;
}
Exemplo n.º 8
0
/*
 * Manual page at statistics.def
 */
INT16 CGEN_PUBLIC CStatistics_Pool
(
  CStatistics* _this,
  CStatistics* iSrc,
  CData*       idMap
)
{
  INT32   i          = 0;                                                        /* Current component index           */
  INT32   nC         = 0;                                                        /* Current pooled statistics class   */
  INT32   nCs        = 0;                                                        /* Current source class index        */
  INT32   nXC        = 0;                                                        /* Number of pooled classes          */
  INT32   nRpb       = 0;                                                        /* Statistics raw data block size    */
  INT16  nCheckSave = 0;                                                        /* Saved check level                 */
  CData* idAux      = NULL;                                                     /* Auxilary data instance #1         */
  CData* idPmp      = NULL;                                                     /* Pooling map                       */
  CData* idPcd      = NULL;                                                     /* Pooled class raw data buffer      */

  /* Initialize */                                                              /* --------------------------------- */
  CHECK_THIS_RV(0);                                                             /* Check this instance               */
  IF_NOK(CStatistics_Check(iSrc))                                               /* Check source statistics           */
    return IERROR(_this,ERR_INVALARG,"iSrc",0,0);                               /* ...                               */
  nCheckSave = _this->m_nCheck;                                                 /* Save check level                  */
  CStatistics_Reset(BASEINST(_this),TRUE);                                      /* Reset destination                 */
  _this->m_nCheck = nCheckSave;                                                 /* Restore check level               */
  IFIELD_RESET(CData,"dat");                                                    /* Create pool raw stats. data inst. */

  /* Protocol */                                                                /* --------------------------------- */
  IFCHECK                                                                       /* On verbose level 1                */
  {                                                                             /* >>                                */
    printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols());             /*   Print protocol header           */
    printf("\n   statistics -pool");                                            /*   ...                             */
    printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols());printf("\n");/*   ...                             */
  }                                                                             /* <<                                */

  /* No map --> pool all classes */                                             /* --------------------------------- */
  if (CData_IsEmpty(idMap))                                                     /* NULL or empty map instance        */
  {                                                                             /* >>                                */
    IFCHECK printf("\n   Empty pooling map --> pool all classes");              /*   Protocol (verbose level 1)      */
    CStatistics_PoolInt(_this->m_idDat,iSrc->m_idDat,0);                        /*   Pool sum data                   */
    CStatistics_PoolInt(_this->m_idDat,iSrc->m_idDat,1);                        /*   Pool min data                   */
    CStatistics_PoolInt(_this->m_idDat,iSrc->m_idDat,2);                        /*   Pool max data                   */
    STA_PROTOCOL_FOOTER(1,"done");                                              /*   Print protocol footer           */
    return O_K;                                                                 /*   That's it                       */
  }

  IFCHECK printf("\n   Pooling by map");                                        /* Protocol (verbose level 1)        */
  ICREATEEX(CData,idAux,"CStatistics_Pool.~idAux",NULL);                        /* Create auxilary data instance #1  */
  ICREATEEX(CData,idPmp,"CStatistics_Pool.~idPmp",NULL);                        /* Create pooling map                */
  ICREATEEX(CData,idPcd,"CStatistics_Pool.~idPcs",NULL);                        /* Create pooled raw stats.data inst.*/

  /* Find and copy map component (pooled class) */                              /* --------------------------------- */
  for (i=0; i<CData_GetNComps(idMap); i++)                                      /* Loop over components of idMap     */
    if (dlp_is_numeric_type_code(CData_GetCompType(idMap,i)))                   /*   Is current component numeric?   */
    {                                                                           /*   >> (Yes)                        */
      CData_SelectComps(idPmp,idMap,i,1);                                       /*     Copy component                */
      break;                                                                    /*     Have ready :)                 */
    }                                                                           /*   <<                              */
  if (CData_IsEmpty(idPmp))                                                     /* Have not got map component        */
  {                                                                             /* >>                                */
    IERROR(_this,STA_BADCOMP,"map",BASEINST(idMap)->m_lpInstanceName,"numeric");/*   Error message                   */
    DLPTHROW(STA_BADCOMP);                                                      /*   Throw exception                 */
  }                                                                             /* <<                                */

  /* Create source class component */                                           /* --------------------------------- */
  CData_AddComp(idPmp,"srcc",T_LONG);                                           /* Add source class index component  */
  for (i=0; i<CData_GetNRecs(idPmp); i++) CData_Dstore(idPmp,i,i,1);            /* Fill it                           */

  /* Finish pooling map and initialize pooling */                               /* --------------------------------- */
  CData_Sortup(idPmp,idPmp,0);                                                  /* Sort map by pooled class index    */
  nXC = (INT32)CData_Dfetch(idPmp,CData_GetNRecs(idPmp)-1,0)+1;                 /* Get greatest pooled class index   */
  IFCHECK printf("\n   Pooling %ld statistics classes",(long)nXC);              /* Protocol (verbose level 1)        */
  IFCHECKEX(3) CData_Print(idPmp);                                              /* Print pooling map (verbose lvl.3) */
  nRpb = CData_GetNRecsPerBlock(iSrc->m_idDat);                                 /* Get block size                    */

  /* Prepare pooled statistics */                                               /* --------------------------------- */
  CData_Scopy(_this->m_idDat,iSrc->m_idDat);                                    /* Create target raw data components */
  CData_Allocate(_this->m_idDat,nRpb*nXC);                                      /* Allocate target raw data          */
  CData_SetNBlocks(_this->m_idDat,nXC);                                         /* Set target statistics block number*/

  /* Pooling loop */                                                            /* --------------------------------- */
  for (i=0; i<CData_GetNRecs(idPmp); )                                          /* Loop over pooling map             */
  {                                                                             /* >>                                */
    /* - Copy raw statistics data of one pooled class */                        /*   - - - - - - - - - - - - - - - - */
    nC = (INT32)CData_Dfetch(idPmp,0,0);                                         /*   Get pooled class index          */
    IFCHECK printf("\n     Pooled class %3ld");                                 /*   Protocol (verbose level 1)      */
    for (i=0; i<CData_GetNRecs(idPmp); i++)                                     /*   Loop over partition of pool.map */
    {                                                                           /*   >>                              */
      if (nC != (INT32)CData_Dfetch(idPmp,0,0)) break;                           /*     Not the current class anymore */
      nCs = (INT32)CData_Dfetch(idPmp,i,1);                                      /*     Get source class index        */
      IFCHECK printf("\n     - Source class %3ld",nCs);                         /*     Protocol (verbose level 1)    */
      CData_SelectBlocks(idAux,iSrc->m_idDat,nCs,1);                            /*     Copy raw stats. data block    */
      CData_Cat(idPcd,idAux);                                                   /*     Append to buffer              */
    }                                                                           /*   <<                              */

    /* - Pool data */                                                           /*   - - - - - - - - - - - - - - - - */
    CData_SetNBlocks(idPcd,CData_GetNRecs(idPcd)/nRpb);                         /*   Set block count of aggr. buffer */
    IFCHECK                                                                     /*   Protocol (verbose level 1)      */
      printf("\n     - Aggregating %ld statistics classes",                     /*   |                               */
      (long)CData_GetNBlocks(idPcd));                                           /*   |                               */
    CStatistics_PoolInt(idAux,idPcd,0);                                         /*   Pool sum data                   */
    CStatistics_PoolInt(idAux,idPcd,1);                                         /*   Pool min data                   */
    CStatistics_PoolInt(idAux,idPcd,2);                                         /*   Pool max data                   */

    /* - Store pooled raw statistics data block */                              /*   - - - - - - - - - - - - - - - - */
    dlp_memmove                                                                 /*   Copy pooled raw stats. data     */
    (                                                                           /*   |                               */
      CData_XAddr(_this->m_idDat,nC*nRpb,0),                                    /*   | To target statistics block    */
      CData_XAddr(idAux,0,0),                                                   /*   | From aggregation buffer       */
      CData_GetNRecs(idAux)*CData_GetRecLen(idAux)                              /*   | Length of aggregation buffer  */
    );                                                                          /*   |                               */

    /* - Clean up auxilary instances */                                         /*   - - - - - - - - - - - - - - - - */
    CData_Reset(idPcd,TRUE);                                                    /*   Clear aggregation buffer        */
  }

  /* Clean up */                                                                /* --------------------------------- */
  IDESTROY(idAux);                                                              /* Destroy auxilary data instance #1 */
  IDESTROY(idPmp);                                                              /* Destroy pooling map               */
  IDESTROY(idPcd);                                                              /* Destroy pooled cls. raw data inst.*/
  STA_PROTOCOL_FOOTER(1,"done");                                                /* Print protocol footer             */
  return O_K;                                                                   /* Ok                                */

DLPCATCH(STA_BADCOMP)                                                           /* == Catch STA_BADCOMP exception    */
  IDESTROY(idAux);                                                              /* Destroy auxilary data instance #1 */
  IDESTROY(idPmp);                                                              /* Destroy pooling map               */
  IDESTROY(idPcd);                                                              /* Destroy pooled cls. raw data inst.*/
  STA_PROTOCOL_FOOTER(1,"FAILED");                                              /* Print protocol footer             */
  return NOT_EXEC;                                                              /* Not ok                            */
}
Exemplo n.º 9
0
/*
 * Manual page at fst_man.def
 */
INT16 CGEN_PUBLIC CFst_Rcs(CFst* _this, INT32 nUnit, FLOAT64 nSeed)
{
#ifdef __UNENTANGLE_FST

  return IERROR(_this,FST_INTERNAL,__FILE__,__LINE__,0);
  /* NOTE: __UNENTANGLE_FST was defined (probably in dlp_config.h or fst.def).
   *       Undefine it to use this feature!
   */

#else /* #ifdef __UNENTANGLE_FST */

  INT32      nU     = 0;                                                        /* Current unit                       */
  FST_ITYPE nS     = 0;                                                        /* Current state                      */
  FST_ITYPE nS2    = 0;                                                        /* Current state                      */
  FST_ITYPE nFS    = 0;                                                        /* First state of current unit        */
  FST_ITYPE nXS    = 0;                                                        /* Number of states of current unit   */
  FST_ITYPE nT     = 0;                                                        /* Current transition                 */
  FST_ITYPE nFT    = 0;                                                        /* First transition of current unit   */
  FST_ITYPE nXT    = 0;                                                        /* Number of tran. of current unit    */
  CData*    idP    = NULL;                                                     /* Incidence matrix                   */
  CData*    idB    = NULL;                                                     /* Constanct vector of (idP-E)idX=idB */
  CData*    idI    = NULL;                                                     /* idI = (idP-E)^-1                   */
  CData*    idX    = NULL;                                                     /* Solution of (idP-E)idX=idB         */
  FST_WTYPE nPSum  = 0.;                                                       /* Probability sum/state              */
  INT32      nIcW   = -1;                                                       /* Index of probability comp. in td   */
  INT32      nIcRcs = -1;                                                       /* Index of ref. counter comp. in sd  */
  INT32      nIcRct = -1;                                                       /* Index of ref. counter comp. in td  */

  /* Validation */
  CHECK_THIS_RV(NOT_EXEC);
  CFst_Check(_this);

  if (CFst_Wsr_GetType(_this,&nIcW)!=FST_WSR_PROB)
    return IERROR(_this,FST_MISS,"transition probability component",NC_TD_PSR,"transition table");

  /* Initialize - Find or add reference counters */
  nIcRcs = CData_FindComp(AS(CData,_this->sd),NC_SD_RC);
  nIcRct = CData_FindComp(AS(CData,_this->td),NC_TD_RC);
  if (nIcRcs<0)
  {
    CData_AddComp(AS(CData,_this->sd),NC_SD_RC,DLP_TYPE(FST_WTYPE));
    nIcRcs = CData_GetNComps(AS(CData,_this->sd))-1;
  }
  if (nIcRct<0)
  {
    CData_AddComp(AS(CData,_this->td),NC_TD_RC,DLP_TYPE(FST_WTYPE));
    nIcRct = CData_GetNComps(AS(CData,_this->td))-1;
  }

  /* Initialize - Create auxilary instances */
  ICREATEEX(CData,idP,"~CFst_Reverse.idP",NULL);
  ICREATEEX(CData,idB,"~CFst_Reverse.idB",NULL);
  ICREATEEX(CData,idI,"~CFst_Reverse.idI",NULL);
  ICREATEEX(CData,idX,"~CFst_Reverse.idX",NULL);

  /* Loop over units */
  for (nU=nUnit<0?0:nUnit; nU<UD_XXU(_this); nU++)
  {
    CData_Reset(BASEINST(idP),TRUE);
    CData_Reset(BASEINST(idB),TRUE);
    CData_Reset(BASEINST(idI),TRUE);
    CData_Reset(BASEINST(idX),TRUE);
    nFS = UD_FS(_this,nU);
    nXS = UD_XS(_this,nU);
    nFT = UD_FT(_this,nU);
    nXT = UD_XT(_this,nU);

    /* Export transposed ergodic incidence matrix */
    IF_NOK(CData_AddNcomps(idP,DLP_TYPE(FST_WTYPE),UD_XS(_this,nU)+1)) break;
    IF_NOK(CData_Allocate (idP,UD_XS(_this,nU)+1)                    ) break;
    IF_NOK(CData_AddNcomps(idB,DLP_TYPE(FST_WTYPE),1                )) break;
    IF_NOK(CData_Allocate (idB,UD_XS(_this,nU)+1)                    ) break;

    /* Fill transposed incidence matrix
       (summing up probabilities of parallel transitions) */
    for (nT=nFT; nT<nFT+nXT; nT++)
      *(FST_WTYPE*)CData_XAddr(idP,TD_TER(_this,nT),TD_INI(_this,nT)) +=
        *(FST_WTYPE*)CData_XAddr(AS(CData,_this->td),nT,nIcW);

    for (nS=0; nS<nXS; nS++)
    {
      if ((SD_FLG(_this,nS+nFS)&0x01)==0x01)     /* Connect final states with start state */
      {
        for (nS2=1, nPSum=0.; nS2<nXS; nS2++)
          nPSum += *(FST_WTYPE*)CData_XAddr(idP,nS2,nS);

        *(FST_WTYPE*)CData_XAddr(idP,0,nS) = 1.-nPSum;
      }

      *(FST_WTYPE*)CData_XAddr(idP,nS,nS)-=1.;   /* Subtract eigenvalue 1 from main diagonal */
      *(FST_WTYPE*)CData_XAddr(idP,nXS,nS)=1.;   /* Additional equation implementing constraint sum(P_state)=1 */
      *(FST_WTYPE*)CData_XAddr(idP,nS,nXS)=1.;   /* Additional variable making incidence matrix quadratic */
    }

    /* Fill constant vector */
    CData_Fill(idB,CMPLX(1.),CMPLX(0.));

    /* Calculate eigenvector of length 1 and eigenvalue 1
       --> stationary state probabilities */
    CMatrix_Op(idI,idP,T_INSTANCE,NULL,T_IGNORE,OP_INVT);
    CMatrix_Op(idX,idB,T_INSTANCE,idI,T_INSTANCE,OP_MULT);

    /* Fill in state reference counters */
    if (nSeed>0.) nSeed /= CData_Dfetch(idX,0,0); else nSeed = 1.;
    for (nS=0; nS<nXS; nS++)
      CData_Dstore(AS(CData,_this->sd),nSeed*CData_Dfetch(idX,nS,0),nS+nFS,nIcRcs);

    /* Calculate stationary transition probabilities */
    for (nT=nFT; nT<nFT+nXT; nT++)
      CData_Dstore
      (
        AS(CData,_this->td),
        CData_Dfetch(AS(CData,_this->sd),TD_INI(_this,nT)+nFS,nIcRcs) *
          CData_Dfetch(AS(CData,_this->td),nT,nIcW),
        nT,nIcRct
      );

    /* Clean up */
    IDESTROY(idP);
    IDESTROY(idB);
    IDESTROY(idI);
    IDESTROY(idX);

    /* Stop in single unit mode */
    if (nUnit>=0) break;
  }

  return O_K;

#endif /* #ifdef __UNENTANGLE_FST */
}
Exemplo n.º 10
0
/*
 * Manual page at fst_man.def
 */
INT16 CGEN_PUBLIC CFst_Probs(CFst* _this, INT32 nUnit)
{
  INT32          nU     = 0;                                                     /* Current unit                      */
  FST_ITYPE     nS     = 0;                                                     /* Current state                     */
  FST_ITYPE     nT     = 0;                                                     /* Current transition                */
  FST_ITYPE     nXS    = 0;                                                     /* Number of states in current unit  */
  INT16         nWsrt  = 0;                                                     /* Weight semiring type              */
  INT32          nIcW   = -1;                                                    /* Weight component in td            */
  INT32          nIcPfl = -1;                                                    /* Floor probability component in sd */
  INT32          nIcRct = -1;                                                    /* Reference counter component in td */
  INT32          nTrCnt = 0;                                                     /* Number of outgoing trans./state   */
  FST_WTYPE     nW     = 0.;                                                    /* Current weight                    */
  FST_WTYPE     nRc    = 0.;                                                    /* Current reference counter/prob.   */
  FST_WTYPE     nRcSum = 0.;                                                    /* Reference counter sum/state       */
  FST_WTYPE     nTW    = 0.;                                                    /* trans.weight                      */
  FST_WTYPE     nTWAgg = 0.;                                                    /* trans.weight aggregator for MAP   */
  CData*        idTd   = NULL;                                                  /* Pointer to transition table       */
  FST_TID_TYPE* lpTI   = NULL;                                                  /* Automaton iterator data structure */
  BYTE*         lpT    = NULL;                                                  /* Current transition (iteration)    */
  FST_WTYPE     nMAP   = _this->m_bUsemap ? _this->m_nMapexp : 0.;              /* MAP exponent (0:off,1:min,-1:max) */
  INT32          nMAPi  = 0;                                                     /* MAP iteration index               */

  /* Validation */                                                              /* --------------------------------- */
  CHECK_THIS_RV(NOT_EXEC);                                                      /* Check this pointer                */
  CFst_Check(_this);                                                            /* Check FST(s)                      */

  /* Initialize */                                                              /* --------------------------------- */
  idTd   = AS(CData,_this->td);                                                 /* Get pointer to transition table   */
  nIcRct = CData_FindComp(AS(CData,_this->td),NC_TD_RC);                        /* Find reference counters           */
  nWsrt  = CFst_Wsr_GetType(_this,&nIcW);                                       /* Find weights and get type         */
  switch (nWsrt)                                                                /* branch for weight semiring type   */
  {                                                                             /* >>                                */
    case FST_WSR_NONE:                                                          /*   No weights                      */
      CData_AddComp(idTd,NC_TD_PSR,DLP_TYPE(FST_WTYPE));                        /*     Add some                      */
      nIcW = CData_GetNComps(idTd)-1;                                           /*     Get index of new weight comp. */
      for (nT=0; nT<UD_XXT(_this); nT++)                                        /*     Initialize probabilities      */
        CData_Dstore(idTd,1.,nT,nIcW);                                          /*     ...                           */
      break;                                                                    /*     *                             */
    case FST_WSR_PROB:                                                          /*   Probabilities                   */
      break;                                                                    /*     * (nothing to be done)        */
    case FST_WSR_TROP: /* fall through */                                       /*   Tropical weights                */
    case FST_WSR_LOG:                                                           /*   Logarithmic weights             */
      for (nT=0; nT<UD_XXT(_this); nT++)                                        /*     Loop over all transitions     */
        CData_Dstore(idTd,                                                      /*       Convert to probabilities    */
          exp(-1.*CData_Dfetch(idTd,nT,nIcW)),nT,nIcW);                         /*       |                           */
      break;                                                                    /*     *                             */
    default:                                                                    /*   Unknown weight semiring         */
      DLPASSERT(FMSG("Unknown weight semiring"));                               /*     New weight semiring type?     */
      CData_SetCname(idTd,nIcW,NC_TD_PSR);                                      /*     Rename to probabilities       */
      for (nT=0; nT<UD_XXT(_this); nT++)                                        /*     Initialize probabilities      */
        CData_Dstore(idTd,1.,nT,nIcW);                                          /*     ...                           */
  }                                                                             /* <<                                */
  if (_this->m_nSymbols>0 && _this->m_nRcfloor>0.)                              /* Smoothing enabled                 */
  {                                                                             /* >>                                */
    if (CData_FindComp(AS(CData,_this->sd),"~PFL")<0)                           /*   No floor prob. comp. at states  */
      CData_AddComp(AS(CData,_this->sd),"~PFL",DLP_TYPE(FST_WTYPE));            /*     Add it                        */
    nIcPfl = CData_FindComp(AS(CData,_this->sd),"~PFL");                        /*   Get index of floor prob. comp.  */
  }                                                                             /* <<                                */

  /* Loop over units */                                                         /* --------------------------------- */
  for (nU=nUnit<0?0:nUnit; nU<UD_XXU(_this); nU++)                              /* For all units ...                 */
  {                                                                             /* >>                                */
    lpTI = CFst_STI_Init(_this,nU,FSTI_SORTINI);                                /*   Get sorted transition iterator  */

    /* Loop over states */                                                      /*   - - - - - - - - - - - - - - - - */
    for (nS=0,nXS=UD_XS(_this,nU); nS<nXS; nS++)                                /*   For all states of the unit ...  */
    /* Loop over MAP-Iterations if MAP enabled */                               /*   - - - - - - - - - - - - - - - - */
    for(nMAPi=0;nMAPi<(nMAP!=0.?10:1);nMAPi++)                                  /*   For all MAP-iterations ...      */
    {                                                                           /*   >>                              */
      /* Pass 1: Count outgoing transitions and sum up reference counters */    /*                                   */
      nRcSum = 0.;                                                              /*     Reset ref. ctr. accumulator   */
      nTWAgg = 0.;                                                              /*     Reset MAP TW accumulator      */
      nTrCnt = 0;                                                               /*     Reset transition counter      */
      lpT    = NULL;                                                            /*     Initialize transition pointer */
      while ((lpT=CFst_STI_TfromS(lpTI,nS,lpT))!=NULL)                          /*     Enumerate transitions at nS   */
      {                                                                         /*     >>                            */
        nRc = nIcRct>=0                                                         /*       Get ref. ctr. or prob.      */
            ? CData_Dfetch(idTd,CFst_STI_GetTransId(lpTI,lpT),nIcRct)           /*       |                           */
            : *CFst_STI_TW(lpTI,lpT);                                           /*       |                           */
        if (nRc>=0.) nRcSum+=nRc;                                               /*       Accumulate non-neg. values  */
        if (nMAP!=0. && nRc>0.)                                                 /*       if MAP enabled and T. used  */
        {                                                                       /*       >>                          */
          nTW = *CFst_STI_TW(lpTI,lpT);                                         /*         get trans.weight          */
          if(nTW<=0.) nTW=0.0001;                                               /*         solve prob. with 0 TW's   */
          nTWAgg += nTW*log(nTW);                                               /*         acc. TW's                 */
        }                                                                       /*       <<                          */
        nTrCnt++;                                                               /*       Count transitions           */
      }                                                                         /*     <<                            */
      if (nIcPfl)                                                               /*     Smoothing eneabled            */
        CData_Dstore(AS(CData,_this->sd),                                       /*       Store floor probability     */
          _this->m_nRcfloor / (nRcSum + _this->m_nSymbols*_this->m_nRcfloor),   /*       |                           */
          nS,nIcPfl);                                                           /*       |                           */
                                                                                /*                                   */
      /* Pass 2: Calculate probabilities */                                     /*                                   */
      if (nTrCnt)                                                               /*     If there were trans. at nS    */
      {                                                                         /*     >>                            */
        lpT = NULL;                                                             /*       Initialize transition ptr.  */
        while ((lpT=CFst_STI_TfromS(lpTI,nS,lpT))!=NULL)                        /*       Enumerate transitions at nS */
        {                                                                       /*       >>                          */
          nRc = nIcRct>=0                                                       /*         Get ref. ctr. or prob.    */
              ? CData_Dfetch(idTd,CFst_STI_GetTransId(lpTI,lpT),nIcRct)         /*         |                         */
              : *CFst_STI_TW(lpTI,lpT);                                         /*         |                         */
          if (nMAP!=0.)                                                         /*         if MAP enabled            */
          {                                                                     /*         <<                        */
            nTW = *CFst_STI_TW(lpTI,lpT);                                       /*           get trans.weight        */
            if(nTW<=0.) nTW=0.0001;                                             /*           solve prob. with 0 TW's */
            if(nIcRct>=0 && _this->m_nSymbols>0 && _this->m_nRcfloor>0)         /*           do jeffrey smooth?      */
              nRc = nRcSum * (nRc + (FST_WTYPE)_this->m_nRcfloor) /             /*             smooth nRc            */
                (nRcSum + ((FST_WTYPE)_this->m_nSymbols*_this->m_nRcfloor));    /*             |                     */
            nTW = (nRc<=0. ? 0. : (nRc+nMAP*nTW*log(nTW))/(nRcSum+nMAP*nTWAgg));/*           do MAP-iteration        */
            *CFst_STI_TW(lpTI,lpT) = nTW;                                       /*           write trans.weight      */
          }                                                                     /*         >>                        */
          else                                                                  /*         else                      */
            if (nIcRct<0 || _this->m_nSymbols<=0 || _this->m_nRcfloor<=0.)      /*         No ref.ctrs. or smoothing */
              *CFst_STI_TW(lpTI,lpT) =                                          /*           Store equally distrib.  */
                nRcSum==0. ? 1./(FST_WTYPE)nTrCnt : nRc/nRcSum;                 /*           | or renormalized probs.*/
            else                                                                /*         Ref. ctrs. or smoothing   */
              *CFst_STI_TW(lpTI,lpT) =                                          /*           Store Jeffrey smoothed  */
                (nRc + (FST_WTYPE)_this->m_nRcfloor) /                          /*           | probabilities         */
                (nRcSum + ((FST_WTYPE)_this->m_nSymbols*_this->m_nRcfloor));    /*           |                       */
        }                                                                       /*       <<                          */
      }                                                                         /*     <<                            */
    }                                                                           /*   <<                              */
    CFst_STI_Done(lpTI);                                                        /*   Destroy iterator                */
    if (nUnit>=0) break;                                                        /*   Stop in single unit mode        */
  }                                                                             /* <<                                */

  /* Convert back to logarithmic/tropical weights */                            /* --------------------------------- */
  if (nWsrt==FST_WSR_LOG || nWsrt==FST_WSR_TROP)                                /* Loarithmic or tropical weights    */
    for (nT=0; nT<UD_XXT(_this); nT++)                                          /*   Loop over all transitions       */
    {                                                                           /*   >>                              */
      nW = CData_Dfetch(idTd,nT,nIcW);                                          /*     Get probability               */
      nW = nW>0. ? -log(nW) : _this->m_nWceil;                                  /*     Convert to log./trop. weight  */
      CData_Dstore(idTd,nW,nT,nIcW);                                            /*     Store weight                  */
    }                                                                           /*   <<                              */

  /* Clean up */                                                                /* --------------------------------- */
  return O_K;                                                                   /* The end                           */
}