Exemple #1
0
INT16 CGEN_PROTECTED CCgen::OnMain()
{
  char lpsProjectname[L_INPUTLINE+1];
  GetNextDefToken(lpsProjectname);
  if (m_nAncestor > 0) return O_K;

  if (!dlp_strlen(lpsProjectname))
	return IERROR(this,ERR_EXPECTAFTER,"name","MAIN:",0);
    
  if (m_bAppend)
  {
    if (dlp_strncmp(m_lpsProject,lpsProjectname,dlp_strlen(lpsProjectname)) != 0 || !m_bMainProject)
    {
      IERROR(this,ERR_APPEND,"MAIN:",lpsProjectname,0);
      if (!dlp_strlen(m_lpsProject)) EXIT(ERR_EXPPROJECT,"/append MAIN:",0,0);
      return NOT_EXEC;
    }
  }

  // Set project code
  SetCreating(CR_PROJECT,NULL);
  m_bMainProject = TRUE;
  dlp_strcpy(m_lpsProject,lpsProjectname);  

  return O_K;
}
Exemple #2
0
/**
 * Check histogram data.
 */
INT16 CGEN_PROTECTED CHistogram::CheckHisto()
{
  INT16 mode;

  if (data_empty (m_hist) == TRUE)
    return IERROR(this,HIS_EMPTY,0,0,0);

  if (data_chtype (m_hist, T_DOUBLE) != TRUE)
    return IERROR(this,HIS_TYPE,0,0,0);

  m_bins = (INT32) data_descr(m_hist,DESCR2);

  if (m_bins < 0 || m_bins > data_nrec(m_hist))
    return IERROR(this,HIS_HISTO,0,0,0);

  m_hdim = data_ndim(m_hist);
  m_nhist = data_nblock(m_hist);
  if (m_nhist == 0)
    m_nhist = data_nrec(m_hist) / m_bins;

  set_data_nblock(m_hist, m_nhist);

  if (m_nhist == 0)
    return IERROR(this,HIS_HISTO,0,0,0);

  mode = (INT16) data_descr(m_hist,DESCR1);
  if (mode >= 1 && mode <= 3)
    m_hmode = mode;
  else
    set_data_descr (m_hist,mode,DESCR1);

  return (O_K);
}
Exemple #3
0
/**
 * Base class implementation of destructor.
 *
 * @param _this This instance
 */
void CDlpObject_Destructor(CDlpObject* _this)
{
  SWord*   lpWord;
  hnode_t* hn;
  hscan_t  hs;

  DEBUGMSG(-1,"CDlpObject_Destructor for '%s'",_this->m_lpInstanceName,0,0);

  /* Detach external instances */
  hash_scan_begin(&hs,_this->m_lpDictionary);
  while ((hn = hash_scan_next(&hs))!=NULL)
  {
    DLPASSERT((lpWord = (SWord*)hnode_get(hn))!=NULL); /* NULL entry in dictionary */

    if
    (
      lpWord->nWordType == WL_TYPE_FIELD &&
      lpWord->ex.fld.nType == T_INSTANCE
    )
    {
      CHECK_IPTR(*(CDlpObject**)lpWord->lpData,lpWord->ex.fld.nISerialNum);
      if (CDlpObject_GetParent(*(CDlpObject**)lpWord->lpData)!=_this)
        *(CDlpObject**)lpWord->lpData = NULL;
    }
  }

#ifndef __NORTTI
  /* Clear words */
  if(NOK(CDlpObject_UnregisterAllWords(_this)) )
    IERROR(_this,ERR_DESTROY," Error while UnregisterAllWords of instance %s !",
      _this->m_lpInstanceName,0);
  /* Clear operators */
  if(NOK(CDlpObject_UnregisterAllOperators(_this)) )
    IERROR(_this,ERR_DESTROY," Error while UnregisterAllOperators of instance %s !",
      _this->m_lpInstanceName,0);
#endif

  /* Destroy dictionaries */
  if(!hash_isempty(_this->m_lpObsIds))
    IERROR(_this,ERR_DESTROY,
      " Destructor of instance '%s': hash 'ObsIds' not empty !",
      _this->m_lpInstanceName,0);
  if(!hash_isempty(_this->m_lpDictionary))
    IERROR(_this,ERR_DESTROY,
      " Destructor of instance '%s': hash 'Dictionary' not empty !",
      _this->m_lpInstanceName,0);
  if(!hash_isempty(_this->m_lpOpDict))
    IERROR(_this,ERR_DESTROY,
      " Destructor of instance '%s': hash 'OpDict' not empty !",
      _this->m_lpInstanceName,0);

  hash_destroy(_this->m_lpObsIds    );
  hash_destroy(_this->m_lpDictionary);
  hash_destroy(_this->m_lpOpDict);

#ifdef __cplusplus
  /* Unregister */
  dlp_xalloc_unregister_object(_this);
#endif
}
Exemple #4
0
/**
 * Fills a data table with the sample size (frequency) or the estimated a-priori
 * probability of the classes.
 *
 * @param _this
 *          Pointer to this CStatistics instance
 * @param idDst
 *          Pointer to the destination data instance
 * @param bProb
 *          If <code>TRUE</code> the method estimates class a-priori
 *          probabilities otherwise it stores the classes' sample sizes
 * @return <code>O_K</code> if successsfull, a (negative) error code otherwise
 */
INT16 CGEN_PUBLIC CStatistics_FreqEx
(
  CStatistics* _this,
  CData*       idDst,
  BOOL         bProb
)
{
  INT32    c     = 0;                                                            /* Class loop counter                */
  INT32    C     = 0;                                                            /* Number of statistics classes      */
  INT32    nTsz  = 0;                                                            /* Total sample size                 */
  FLOAT64* lpSsz = NULL;                                                         /* Pointer to class' c sample size   */

  /* Validate */                                                                /* --------------------------------- */
  if (!idDst) return IERROR(_this,ERR_NULLARG,"idDst",0,0);                     /* Check output data instance        */
  CData_Reset(idDst,TRUE);                                                      /* Clear destination instance        */
  CHECK_THIS_RV(NOT_EXEC);                                                      /* Check this pointer                */
  IF_NOK(CStatistics_Check(_this))                                              /* Check instance data               */
    return IERROR(_this,STA_NOTSETUP," ( use -status for details)",0,0);        /* ...                               */

  /* Initialize */                                                              /* --------------------------------- */
  C = CStatistics_GetNClasses(_this);                                           /* Get number of statistics classes  */
  CData_Array(idDst,T_DOUBLE,1,C);                                              /* Allocate output data instance     */
  CData_SetNBlocks(idDst,C);                                                    /* Set block number                  */
  if (!CData_XAddr(idDst,0,0)) return IERROR(_this,ERR_NOMEM,0,0,0);            /* Should have been successfull ...  */

  /* Store sample sizes / estimated a-rpior probabilities */                    /* --------------------------------- */
  nTsz = bProb ? CStatistics_GetNSamples(_this) : 1;                            /* Get frequency divident            */
  for (c=0; c<C; c++)                                                           /* Loop over classes                 */
  {                                                                             /* >>                                */
    DLPASSERT((lpSsz = CStatistics_GetPtr(_this,c,STA_DAI_SSIZE)));             /*   Get ptr. to class' c sample size*/
    CData_Dstore(idDst,lpSsz[0]/(FLOAT64)nTsz,c,0);                              /*   Store sample size of class c    */
  }                                                                             /* <<                                */

  return O_K;
}
Exemple #5
0
/**
 * Initialize one record from a token list.
 *
 * @param lpsInit Null ('\0') separated list of tokens. A double null "\0\0"
 *                is expected as list terminator!
 * @param nRec    Record index of first cell to initialize
 * @param nComp   Component index of first cell to initialize
 * @return O_K if successfull, a negative error code otherwise
 */
INT16 CGEN_PUBLIC CData_InitializeRecordEx
(
  CData*      _this,
  const char* lpsInit,
  INT32        nRec,
  INT32        nComp
)
{
  const char* lpsToken = NULL;
  INT32  nXC            = 0;
  INT32  nC             = 0;

  nXC = CData_GetNComps(_this);
  nC  = nComp;

  if (nC<0   || nC>=nXC                    ) return NOT_EXEC;
  if (nRec<0 || nRec>=CData_GetNRecs(_this)) return NOT_EXEC;

  for (lpsToken=lpsInit; *lpsToken && nC<nXC; lpsToken+=dlp_strlen(lpsToken)+1, nC++)
    if (dlp_strcmp(lpsToken,"*")!=0)
      IF_NOK(dlp_sscanx(lpsToken,CData_GetCompType(_this,nC),CData_XAddr(_this,nRec,nC)))
        IERROR(_this,DATA_BADINITIALIZER,lpsToken,(int)nRec,(int)nC);

  if (*lpsToken) return IERROR(_this,DATA_INITIALIZERS,"many",0,0);
  if (nC<nXC   ) IERROR(_this,DATA_INITIALIZERS,"few" ,0,0);
  return O_K;
}
Exemple #6
0
/**
 * Export midi notes of  data instance into midifile, needs external program midiconvert
 *
 * @param lpsFilename Name of file to export
 * @param iSst        Pointer to instance to export
 * @param lpsFiletype Type of file to export
 * @return <code>O_K</code> if successful, a (negative) error code otherwise
 */
INT16 CGEN_PROTECTED CDlpFile_Midi_ExportMidi
(
  CDlpFile*   _this,
  const char* lpsFilename,
  CDlpObject* iSrc,
  const char* lpsFiletype
)
{
  char  lpsTempFile[L_PATH];
  char  lpsCmdline    [3*L_PATH] = "";
  INT16 nErr                     =O_K;

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

  CData *idSrc = AS(CData,iSrc);
  CData_InsertRecs(idSrc, 0, 1, 1);
  CData_Dstore(idSrc, CData_GetDescr(idSrc,DESCR0),0,5);
  IF_NOK(CDlpFile_ExportAsciiFromData(_this,lpsTempFile,iSrc,"csv"))
       nErr = IERROR(iSrc,FIL_EXPORT,lpsTempFile,"csv",0);
  CData_DeleteRecs(idSrc,0,1);

  if (system(lpsCmdline)!=0) { nErr=IERROR(_this,FIL_EXEC,lpsCmdline,0,0); }

  if (remove(lpsTempFile)==-1) nErr=IERROR(_this,FIL_REMOVE,"temporary ",lpsTempFile,0);

  /* Clean up */
  return nErr;
}
Exemple #7
0
/*
 * Manual page at fst_man.def
 */
INT16 CGEN_PUBLIC CFst_Intersect
(
  CFst* _this,
  CFst* itSrc1,
  CFst* itSrc2,
  INT32  nUnit1,
  INT32  nUnit2
)
{
  CFst*  itAux1  = NULL;
  CFst*  itAux2  = NULL;
  CData* idAux   = NULL;
  INT32   nIcTis1 = -1;
  INT32   nIcTos1 = -1;
  INT32   nIcTis2 = -1;
  INT32   nIcTos2 = -1;
  INT16  nErr    = O_K;

  nIcTis1 = CData_FindComp(AS(CData,itSrc1->td),NC_TD_TIS);
  nIcTos1 = CData_FindComp(AS(CData,itSrc1->td),NC_TD_TOS);
  nIcTis2 = CData_FindComp(AS(CData,itSrc2->td),NC_TD_TIS);
  nIcTos2 = CData_FindComp(AS(CData,itSrc2->td),NC_TD_TOS);

  if (nIcTis1<0) return IERROR(_this,FST_MISS,"input symbol component","","transition table of left operand");
  if (nIcTis2<0) return IERROR(_this,FST_MISS,"input symbol component","","transition table of right operand");

  ICREATEEX(CFst ,itAux1,"CFst_Intersect.itAux1",NULL);
  ICREATEEX(CFst ,itAux2,"CFst_Intersect.itAux2",NULL);
  ICREATEEX(CData,idAux ,"CFst_Intersect.idAux" ,NULL);
  CFst_Copy(BASEINST(itAux1),BASEINST(itSrc1));
  CFst_Copy(BASEINST(itAux2),BASEINST(itSrc2));

  if (nIcTos1>=0)
  {
    CData_DeleteComps(AS(CData,itAux1->td),nIcTos1,1);
    CData_SelectComps(idAux,AS(CData,itAux1->td),nIcTis1,1);
    CData_SetCname(idAux,0,NC_TD_TOS);
    CData_Join(AS(CData,itAux1->td),idAux);
  }
  if (nIcTos2>=0)
  {
    CData_DeleteComps(AS(CData,itAux2->td),nIcTos2,1);
    CData_SelectComps(idAux,AS(CData,itAux2->td),nIcTis2,1);
    CData_SetCname(idAux,0,NC_TD_TOS);
    CData_Join(AS(CData,itAux2->td),idAux);
  }

  nErr = CFst_Compose(_this,itAux1,itAux2,nUnit1,nUnit2);

  IDESTROY(itAux1);
  IDESTROY(itAux2);
  IDESTROY(idAux);

  return nErr;
}
Exemple #8
0
/*
 * Manual page at statistics.def
 */
INT16 CGEN_PUBLIC CStatistics_Setup
(
  CStatistics*    _this,
  INT32         nOrder,
  INT32         nDim,
  INT32         nCls,
  CData*          idLtb,
  INT32         nIcLtb
)
{
  INT32    c     = 0;                                                         /* Statistics class loop counter     */
  INT32    n     = 0;                                                         /* Dimension loop couner             */
  FLOAT64* lpMin = NULL;                                                      /* Ptr. to class' k minimum vector   */
  FLOAT64* lpMax = NULL;                                                      /* Ptr. to class' k maximum vector   */

  /* Validate */                                                                /* --------------------------------- */
  CHECK_THIS_RV(NOT_EXEC);                                                      /* Check this pointer                */
  if (nOrder<2) nOrder = 2;                                                     /* Default order is 2                */
  if (nDim  <1) nDim   = 1;                                                     /* Default dimensionality is 1       */
  if (nCls  <1) nCls   = 1;                                                     /* Default number of classes is 1    */

  /* Initialize statistics */                                                   /* --------------------------------- */
  CStatistics_Reset(_this,TRUE);                                                /* Start over                        */
  IFIELD_RESET(CData,"dat");                                                    /* Create/reset statistic data       */
  CData_Array(_this->m_idDat,T_DOUBLE,nDim,nCls*(nOrder+nDim+2));               /* Allocate statistic data           */
  CData_SetNBlocks(_this->m_idDat,nCls);                                        /* Set number of blocks              */
  if (CData_IsEmpty(_this->m_idDat)) return IERROR(_this,ERR_NOMEM,0,0,0);      /* Check if it worked out...         */
  for (c=0; c<nCls; c++)                                                        /* Loop over classes                 */
  {                                                                             /* >>                                */
    lpMin = CStatistics_GetPtr(_this,c,STA_DAI_MIN);                            /*   Get ptr. to class' k min. vec.  */
    lpMax = CStatistics_GetPtr(_this,c,STA_DAI_MAX);                            /*   Get ptr. to class' k max. vec.  */
    for (n=0; n<nDim; n++)                                                      /*   Loop over dimensions            */
    {                                                                           /*   >>                              */
      lpMin[n] = T_DOUBLE_MAX;                                                  /*     Initialize minimum vector     */
      lpMax[n] = T_DOUBLE_MIN;                                                  /*     Initialize maximum vector     */
    }                                                                           /*   <<                              */
  }                                                                             /* <<                                */

  /* Initialize label table */                                                  /* --------------------------------- */
  if (CData_IsEmpty(idLtb)) return O_K;                                         /* No label table -> that's it       */
  if (CData_GetNRecs(idLtb)!=nCls)                                              /* Bad number of labels              */
    return IERROR(_this,STA_NOTSETUP," (wrong no. of labels in idLtb)",0,0);    /*   -> Error                        */
  if (nIcLtb<0)                                                                 /* Label component not specified     */
    for (nIcLtb=0; nIcLtb<CData_GetNComps(idLtb); nIcLtb++)                     /*   Seek first symbolic component   */
      if (dlp_is_symbolic_type_code(CData_GetCompType(idLtb,nIcLtb)))           /*   ...                             */
        break;                                                                  /*   ...                             */
  if (!dlp_is_symbolic_type_code(CData_GetCompType(idLtb,nIcLtb)))              /* Label component not symbolic      */
    return IERROR(_this,STA_NOTSETUP," (label comp. not found in idLtb)",0,0);  /*   -> Error                        */
  IFIELD_RESET(CData,"ltb");                                                    /* Create/reset label table          */
  CData_SelectComps(_this->m_idLtb,idLtb,nIcLtb,1);                             /* Copy label table                  */

  return O_K;                                                                   /* Done                              */
}
Exemple #9
0
/*
 * Manual page at process.def
 */
INT32 CGEN_PUBLIC CProcess::Start()
{
  const SMic* pMic    = NULL;                                                   // Method invocation context of Start()
  CFunction*  iCaller = NULL;                                                   // Function calling Start()
  CFunction*  iFnc    = NULL;                                                   // Process function
  StkItm*     pStkItm = NULL;                                                   // Stack item
  INT32       nArgs   = 0;                                                      // Number of process function arguments

  // Validate and initialize                                                    // ------------------------------------
  if (m_nState!=0)                                                              // Not virginal
    return IERROR(this,PRC_CANTSTART,"multiple starts not allowed",0,0);        //   Forget it!
  if (!(pMic = CDlpObject_MicGet(_this))) return -1;                            // Get method invocation context
  iCaller = (CFunction*)CDlpObject_OfKind("function",pMic->iCaller);            // Get calling CFunction
  if (!iCaller) return -1;                                                      // Must be a function!

  // Initialize process                                                         // ------------------------------------
  sprintf(m_psTmpFile,"%s%ld",dlp_tempnam(NULL,"~dLabPro#process#"),(long)dlp_time());// Initialize temp. file name prefix

  // Marshal arguments                                                          // ------------------------------------
  if (!(pStkItm=iCaller->StackGet(0))) return IERROR(this,PRC_TOOFEWARGS,0,0,0);// Get stack top
  if (pStkItm->nType==T_INSTANCE)                                               // Stack top is an instance
    iFnc = (CFunction*)CDlpObject_OfKind("function",pStkItm->val.i);            //   Get function to be called
  if (iFnc)                                                                     // This process is a function call
  {                                                                             // >>
    IFIELD_RESET(CDlpObject,"dto");                                             //   Create data transfer object
    nArgs = CData_GetNRecs(iFnc->m_idArg);                                      //   Get number of function arguments
    Marshal(m_iDto,iCaller,nArgs);                                              //   Marshal arguments for transfer
  }                                                                             // <<
  else                                                                          // This process is a program call
    dlp_strcpy(m_psCmdLine,iCaller->PopString(0));                              //   Get program command line

#ifdef USE_FORK
  if (iFnc)                                                                     // This process is a function call
  {                                                                             // >>
    m_hPid=fork();                                                              //   Fork the process
    if(m_hPid>0){                                                               //   Parent process >>
      m_nState |= PRC_DATASENT;                                                 //     Remember data have been sent
      m_nState |= PRC_RUNNING;                                                  //     Set running flag
      m_hThread = 0;                                                            //     Clear thread handle
      return O_K;                                                               //     Everything is fine
    }                                                                           //   <<
    if(m_hPid==0) return DoJobFork(iCaller,iFnc);                               //   The child process runs the function
    return IERROR(this,PRC_CANTSTART,"fork() failed",0,0);                      //   On error (fid<0) we return
  }                                                                             // <<
#endif
  // Start job in watcher thread                                                // ------------------------------------
  m_hPid = 0;                                                                   // Reset process id
  SendData();                                                                   // Send transfer data
  m_hThread = dlp_create_thread(DoJob,this);                                    // Do the job and watch it

  return O_K;                                                                   // Yo!
}
Exemple #10
0
/*
 * Manual page at statistics.def
 */
INT16 CGEN_PUBLIC CStatistics_Merge(CStatistics* _this, CStatistics* iSrc)
{
	INT32   nB    = 0;                                                            /* Current block                     */
	INT32   nC    = 0;                                                            /* Current component                 */
	INT32   nR    = 0;                                                            /* Current record                    */
	INT32   nXB   = 0;                                                            /* Number of statistics blocks       */
	INT32   nXC   = 0;                                                            /* Number of components              */
	INT32   nXR   = 0;                                                            /* Number of records per block       */
	FLOAT64 nVal  = 0.;                                                           /* Merged statistics value           */
	FLOAT64 nVal1 = 0.;                                                           /* Statistics value of this instance */
	FLOAT64 nVal2 = 0.;                                                           /* Statistics value of source inst.  */

  /* Initialize */                                                              /* --------------------------------- */
  CHECK_THIS_RV(NOT_EXEC);                                                      /* Check this instance               */
  if (_this==iSrc) return O_K;                                                  /* Nothing to be done                */
  IF_NOK(CStatistics_Check(iSrc))                                               /* Check source statistics           */
    return IERROR(_this,ERR_INVALARG,"iSrc",0,0);                               /* ...                               */

  /* Check-up */                                                                /* --------------------------------- */
  nXB = CData_GetNBlocks      (AS(CData,_this->m_idDat));                       /* Get number of statistics blocks   */
  nXC = CData_GetNComps       (AS(CData,_this->m_idDat));                       /* Get number of components          */
  nXR = CData_GetNRecsPerBlock(AS(CData,_this->m_idDat));                       /* Get number of records per block   */
  if                                                                            /* Instances incompatible if ...     */
  (                                                                             /* |                                 */
    nXB != CData_GetNBlocks      (AS(CData,iSrc->m_idDat)) ||                   /* | ... no. of blocks mismatch   OR */
    nXC != CData_GetNComps       (AS(CData,iSrc->m_idDat)) ||                   /* | ... no. of comps. mismatch   OR */
    nXR != CData_GetNRecsPerBlock(AS(CData,iSrc->m_idDat))                      /* | ... no. of records mismatch     */
  )                                                                             /* |                                 */
  {                                                                             /* >>                                */
  	return IERROR(_this,STA_INCOMPAT,0,0,0);                                    /*   So sorry ...                    */
  }                                                                             /* <<                                */

  /* Do merge */                                                                /* --------------------------------- */
  for (nB=0; nB<nXB; nB++)                                                      /* Loop over blocks                  */
  	for (nR=0; nR<nXR; nR++)                                                    /*   Loop over records of block      */
  		for (nC=0; nC<nXC; nC++)                                                  /*     Loop over components          */
			{                                                                         /*     >>                            */
				nVal1 = CData_Dfetch(AS(CData,_this->m_idDat),nB*nXR+nR,nC);            /*       Get value from this         */
				nVal2 = CData_Dfetch(AS(CData,iSrc ->m_idDat),nB*nXR+nR,nC);            /*       Get value from source       */
				switch (nR)                                                             /*       Depending on value type     */
				{                                                                       /*       >>                          */
				case STA_DAI_MIN: nVal = MIN(nVal1,nVal2); break;                       /*         Aggregate minimums        */
				case STA_DAI_MAX: nVal = MAX(nVal1,nVal2); break;                       /*         Aggregate maximums        */
				default         : nVal = nVal1+nVal2;      break;                       /*         Aggregate all other       */
				}                                                                       /*       <<                          */
				CData_Dstore(AS(CData,_this->m_idDat),nVal,nB*nXR+nR,nC);               /*       Store merged value          */
			}                                                                         /*     <<                            */

  /* Aftermath */                                                               /* --------------------------------- */
  return O_K;                                                                   /* Everything's ok                   */
}
Exemple #11
0
INT16 CGEN_PUBLIC CFBAproc::GenPitch(CData *idProso, CData *idPitch)
{
  INT32  i           = 0;
  INT32  j           = 0;
  INT32  nRecs       = 0;
  INT32  nLastSample = 0;
  INT16  bVoiced     = 0;
  INT32  nF0         = 0;
  INT32  nSamples    = 0;
  INT32  nNextPeak   = 0;
  INT32  nPm         = 0;

   // Validation
  if (idPitch == NULL)            return IERROR(this,ERR_NULLINST,0,0,0);
  if (idProso == NULL)            return IERROR(this,ERR_NULLINST,0,0,0);
  if (idProso->IsEmpty() == TRUE) return IERROR(idProso,DATA_EMPTY,idProso->m_lpInstanceName,0,0);
  if (idProso->GetNComps()!=3 ||
      !dlp_is_numeric_type_code(idProso->GetCompType(0)) ||
      !dlp_is_numeric_type_code(idProso->GetCompType(1)) ||
      !dlp_is_numeric_type_code(idProso->GetCompType(2))
      )
    return IERROR(idProso,FBA_BADINTO,idProso->m_lpInstanceName,0,0);

  // Initialization
  idPitch->Reset();
  idPitch->AddComp("pm", T_SHORT);
  idPitch->AddComp("v/uv",T_SHORT);
  nRecs = idProso->GetNRecs();

  // For every record in idProso
  for (i=0; i<nRecs; i++)
  {
    bVoiced     = (INT16)      idProso->Dfetch(i ,2 );              // unvoiced = 0
    nF0         = (INT32)  idProso->Dfetch(i ,1 );              // nF0 in hz
    nSamples    = (INT32)  idProso->Dfetch(i ,0 ) * m_nCrate ;  // duration in samples
    nPm         = (INT32)  (m_nSrate / nF0);
    nLastSample = nLastSample + nSamples;

    while (nLastSample > nNextPeak)
    {
      IFCHECK printf("\n Write %s pitch starting from %ld %ld samples long.",bVoiced==0?"unvoiced":"bVoiced",(long)nNextPeak,(long)nPm);
      idPitch->AddRecs(1,FBA_GRANY);
      idPitch->Dstore(nPm, j, 0);
      idPitch->Dstore(bVoiced, j, 1);
      j++;
      nNextPeak= nPm + nNextPeak;
    }
  }

  return O_K;
}
Exemple #12
0
/*
 * Manual page at function.def
 */
INT16 CGEN_PUBLIC CFunction::OnGet()
{
  // Delegate to running function                                               // ------------------------------------
  FNC_DELEGATE OnGet();                                                         // Use a weird macro (see function.def)

  // Initialize                                                                 // ------------------------------------
  CDlpObject* iCont = GetActiveInstance();                                      // Determine field container
  const char* lpsId = GetNextToken(TRUE);                                       // Determine field name

  // Validate                                                                   // ------------------------------------
  DLPASSERT(iCont);                                                             // Check set target
  if (!dlp_strlen(lpsId))                                                       // If no field name committed
    return IERROR(this,FNC_EXPECT,"field identifier after -get",0,0);           //   Error
  SWord* lpWrd = iCont->FindWord(lpsId,WL_TYPE_FIELD);                          // Find field in container
  if (!lpWrd)                                                                   // If not found
  {                                                                             // >>
    iCont = this;                                                               //   Use this instance as container
    lpWrd = FindWord(lpsId,WL_TYPE_FIELD);                                      //   And seek again
  }                                                                             // <<
  if (!lpWrd) return IERROR(this,ERR_NOTFIELD,lpsId,0,0);                       // If still not found --> Error

  // Push field value                                                           // ------------------------------------
  switch (lpWrd->ex.fld.nType)                                                  // Branch for field variable type
  {                                                                             // >>
    case T_BOOL    : { PushLogic   (      *(     BOOL*)lpWrd->lpData);  break; }// - Boolean
    case T_UCHAR   : { PushNumber  (CMPLX(*(    UINT8*)lpWrd->lpData)); break; }// - Unsigned character
    case T_CHAR    : { PushNumber  (CMPLX(*(     INT8*)lpWrd->lpData)); break; }// - Signed character
    case T_USHORT  : { PushNumber  (CMPLX(*(   UINT16*)lpWrd->lpData)); break; }// - Unsigned short integer
    case T_SHORT   : { PushNumber  (CMPLX(*(    INT16*)lpWrd->lpData)); break; }// - Signed short integer
    case T_UINT    : { PushNumber  (CMPLX(*(   UINT32*)lpWrd->lpData)); break; }// - Unsigned integer
    case T_INT     : { PushNumber  (CMPLX(*(    INT32*)lpWrd->lpData)); break; }// - Signed integer
    case T_ULONG   : { PushNumber  (CMPLX(*(   UINT64*)lpWrd->lpData)); break; }// - Unsigned long integer
    case T_LONG    : { PushNumber  (CMPLX(*(    INT64*)lpWrd->lpData)); break; }// - Signed long integer
    case T_FLOAT   : { PushNumber  (CMPLX(*(  FLOAT32*)lpWrd->lpData)); break; }// - Single precision floating point
    case T_DOUBLE  : { PushNumber  (CMPLX(*(  FLOAT64*)lpWrd->lpData)); break; }// - Double precision floating point
    case T_COMPLEX : { PushNumber  (      *(COMPLEX64*)lpWrd->lpData);  break; }// - Double precision complex floating point
    case T_INSTANCE: { PushInstance(*(CDlpObject**) lpWrd->lpData);     break; }// - Instance
    case T_TEXT    : /* Fall through */                                         // - Text (deprecated type!)
    case T_CSTRING : /* Fall through */                                         // - Constant string
    case T_STRING  : { PushString(*(char**)         lpWrd->lpData); break;     }// - String
    default        : {                                                          // - Other types
      if (lpWrd->ex.fld.nType > 0 && lpWrd->ex.fld.nType <= 256)                //     Character array?
        PushString((char*)lpWrd->lpData);                                       //       Push value
      else                                                                      //     Type unknown!
        DLPASSERT(FMSG("Unknown field type"));                                  //       Error
    }                                                                           //   <<
  }                                                                             // <<

  return O_K;                                                                   // Done.
}
Exemple #13
0
/*
 * Manual page at function.def
 */
BOOL CGEN_PUBLIC CFunction::Platform(const char* lpsPlatformId)
{
  if (dlp_strcmp(lpsPlatformId,"WIN32")==0)
  {
#if (defined __WIN32 && !defined __CYGWIN__)
    return TRUE;
#else
    return FALSE;
#endif
  }
  if (dlp_strcmp(lpsPlatformId,"LINUX")==0)
  {
#ifdef __LINUX
    return TRUE;
#else
    return FALSE;
#endif
  }
  if (dlp_strcmp(lpsPlatformId,"SPARC")==0)
  {
#ifdef __SPARC
    return TRUE;
#else
    return FALSE;
#endif
  }

  // Deprecated platform IDs
  if (dlp_strcmp(lpsPlatformId,"_WINDOWS")==0)
  {
    IERROR(this,ERR_OBSOLETEID,"_WINDOWS","WIN32",0);
#ifdef __WIN32
    return TRUE;
#else
    return FALSE;
#endif
  }
  if (dlp_strcmp(lpsPlatformId,"_LINUX")==0)
  {
    IERROR(this,ERR_OBSOLETEID,"_LINUX","LINUX",0);
#ifdef __LINUX
    return TRUE;
#else
    return FALSE;
#endif
  }

  return FALSE;
}
Exemple #14
0
/**
 * Converts the automaton weights to weights to another semiring.
 *
 * @param nSrType Semiring type (<code>FST_WSR_PROB</code>,
 *                <code>FST_WSR_LOG</code> or <code>FST_WSR_TROP</code>)
 * @return <code>O_K</code> if successfull, a (negative) error code otherwise
 */
INT16 CGEN_PUBLIC CFst_Wsr_Convert(CFst* _this, INT16 nSrType)
{
  INT16 nWsrt = FST_WSR_NONE;
  INT32  nIcW  = -1;
  INT32  nT    = 0;
  INT32  nXXT  = 0;
  INT32  nRlt  = 0;
  BYTE* lpW   = NULL;
  BYTE* lpW0  = NULL;

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

  /* Initialize */                                                              /* --------------------------------- */
  nWsrt = CFst_Wsr_GetType(_this,&nIcW);                                        /* Get current weight semiring type  */
  if (nWsrt==FST_WSR_NONE) return IERROR(_this,FST_UNWEIGHTED,0,0,0);           /* No weights, no service            */
  if (nWsrt==nSrType     ) return O_K;                                          /* Nothing to be done                */
  lpW0 = CData_XAddr(AS(CData,_this->td),0,nIcW);                               /* Get pointer to weight component   */
  nRlt = CData_GetRecLen(AS(CData,_this->td));                                  /* Get record length of trans. list  */
  nXXT = UD_XXT(_this);                                                         /* Get total number of transitions   */

  /* Convert weights */                                                         /* --------------------------------- */
  switch (nSrType)                                                              /* Branch for target weight sr. type */
  {                                                                             /* >>                                */
  case FST_WSR_PROB:                                                            /* Probability semiring              */
    /* TODO: Push log/tropical weights to the left!!! */                        /* X X X X X X X X X X X X X X X X X */
    IERROR(_this,FST_INTERNALW,"Probabilities may be >1",__FILE__,__LINE__);    /* Warn user!                        */
    for (nT=0,lpW=lpW0; nT<nXXT; nT++,lpW+=nRlt)                                /* Loop over all transitions         */
      *(FST_WTYPE*)lpW = exp(*(FST_WTYPE*)lpW*-1);                              /*   P = exp(-w)                     */
    CData_SetCname(AS(CData,_this->td),nIcW,NC_TD_PSR);                         /*   Rename weight component         */
    break;                                                                      /* ==                                */
  case FST_WSR_LOG:                                                             /* Log semiring                      */
    if (nWsrt==FST_WSR_PROB)                                                    /* Converting from probabilities     */
      for (nT=0,lpW=lpW0; nT<nXXT; nT++,lpW+=nRlt)                              /*   Loop over all transitions       */
        *(FST_WTYPE*)lpW = -1*log(*(FST_WTYPE*)lpW);                            /*     w = -log(P)                   */
    CData_SetCname(AS(CData,_this->td),nIcW,NC_TD_LSR);                         /*   Rename weight component         */
    break;                                                                      /* ==                                */
  case FST_WSR_TROP:                                                            /* Topical semiring                  */
    if (nWsrt==FST_WSR_PROB)                                                    /* Converting from probabilities     */
      for (nT=0,lpW=lpW0; nT<nXXT; nT++,lpW+=nRlt)                              /*   Loop over all transitions       */
        *(FST_WTYPE*)lpW = -1*log(*(FST_WTYPE*)lpW);                            /*     w = -log(P)                   */
    CData_SetCname(AS(CData,_this->td),nIcW,NC_TD_TSR);                         /*   Rename weight component         */
    break;                                                                      /* ==                                */
  default:                                                                      /* nSrType unknown                   */
    return IERROR(_this,FST_INVALID,"weight semiring type",0,0);                /*   Error                           */
  }                                                                             /* <<                                */
  return O_K;                                                                   /* All right                         */
}
Exemple #15
0
/**
 *  Expand/reduce number of pitch markers to fit new target sum of period length.
 *
 * @param idSrc        source object
 * @param idDst        target object
 * @param n            target length
 * @return O_K if sucessfull, not exec otherwise
 */
INT16 CGEN_PUBLIC CPMproc::ExpandPm(CData *idSrc, CData* idDst, INT32 n)
{
  if(CData_IsEmpty(idSrc) == TRUE) return NOT_EXEC;
  if(n <= 0)                       return NOT_EXEC;

  CREATEVIRTUAL(CData,idSrc,idDst);

  DLPASSERT(CData_GetNComps(idSrc) == 2);

  CData_Reset(idDst, TRUE);
  CData_Scopy(idDst,idSrc);

  INT32    nRecsNew = 0;
  INT32    nRecs    = (INT32)CData_GetNRecs(idSrc);
  INT16* pm_new = NULL;

  if(dlm_pm_expand((INT16*)CData_XAddr(idSrc,0,0), nRecs, &pm_new, &nRecsNew, n) != O_K) {
    return IERROR(this,ERR_NULLARG, "", NULL, NULL);
  }
  CData_Allocate(idDst,nRecsNew);
  dlp_memmove(CData_XAddr(idDst,0,0), pm_new, nRecsNew*2*sizeof(INT16));
  dlp_free(pm_new);
  CData_CopyDescr(idDst,idSrc);

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

  return(O_K);
}
Exemple #16
0
pnode_t create_link(void)
{
	pnode_t phead = NULL;
	FILE *fp;
	int ch;
	long pos;
	char word[WORD_LEN];

	fp = fopen(DICT_FILENAME, "r+");
	if (fp == NULL)
	{
		IERROR("open file '%s' error", DICT_FILENAME);
		exit(1);
	}

	while ((ch = getc(fp)) != EOF)
	{
		if (ch == '#')
		{
			pos = ftell(fp);
			fgets(word, WORD_LEN - 1, fp);

			phead = insert_to_link(phead, word, pos);
		}
	}

	fclose(fp);

	return phead;
}
Exemple #17
0
/**
 *  Expand/reduce number of pitch markers to new number.
 *
 * @param idSrc        source object
 * @param idDst        target object
 * @param n            target number of pitch markers
 * @return O_K if sucessfull, not exec otherwise
 */
INT16 CGEN_PUBLIC CPMproc::CompressPm(CData *idSrc, CData* idDst, INT32 n)
{
  if(CData_IsEmpty(idSrc) == TRUE) return NOT_EXEC;
  if(n <= 0)                       return NOT_EXEC;

  CREATEVIRTUAL(CData,idSrc,idDst);

  DLPASSERT(CData_GetNComps(idSrc) == 2);
  CData_Reset(idDst, TRUE);
  CData_Scopy(idDst,idSrc);
  CData_Allocate(idDst, n);

  if(dlm_pm_compress((INT16*)CData_XAddr(idSrc,0,0),
                     CData_GetNRecs(idSrc),
                     (INT16*)CData_XAddr(idDst,0,0),
                     CData_GetNRecs(idDst)) != O_K) {
    return IERROR(this,ERR_NULLARG, "", NULL, NULL);
  }
  CData_CopyDescr(idDst,idSrc);

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

  return(O_K);
}
Exemple #18
0
/**
 * Compute pooled histogram h from histogram.
 *
 * <p>Remark: In the moment, only for m_hmode = 1, 2 (histogram resampling needed !)</p>
 */
INT16 CGEN_PUBLIC CHistogram::Poole(CHistogram* h)
{
  if (h == NULL)
    return (NOT_EXEC);
  if (CheckHisto() != O_K)
    return (NOT_EXEC);

  if (m_hmode > 2)
    return IERROR(this,HIS_POOLE, 0,0,0);

  CHistogram_minmax_poole(m_minmax, h->m_minmax);

  /* MWX 2004-03-10: Replaced by CData_Aggregate -->
   data_aggrop (m_hist, h->m_hist,  NULL, 0, OP_SUM, 3, T_DOUBLE, 0);
   */
  CData_Aggregate_Int(h->m_hist, m_hist, NULL, CMPLX(0), OP_SUM);
  /* <-- */
  h->m_nhist = 1;
  h->m_bins = m_bins;
  h->m_hmode = m_hmode;
  h->m_hdim = m_hdim;
  h->m_calls = m_calls;
  h->m_count = 0;
  h->m_ssize = m_ssize;
  if (m_hmode == 1)
  {
    m_min = dfetch(m_minmax,0,0);
    m_max = dfetch(m_minmax,1,0);
  }

  return (O_K);
}
Exemple #19
0
/*
 * Manual page at process.def
 */
INT16 CGEN_PUBLIC CProcess::Wait()
{
  const SMic* pMic    = NULL;                                                   // Method invocation context of Wait()
  CFunction*  iCaller = NULL;                                                   // Function instance calling Wait()

  // Validate and initialize                                                    // ------------------------------------
  if (!((m_nState & PRC_RUNNING)|PRC_COMPLETE))                                 // Not running
    return IERROR(this,PRC_CANTWAIT,"not started",0,0);                         //   Forget it
  if (!(pMic = CDlpObject_MicGet(_this))) return -1;                            // Get method invocation context
  iCaller = (CFunction*)CDlpObject_OfKind("function",pMic->iCaller);            // Get calling CFunction
  if (!iCaller) return -1;                                                      // Must be a function!

  // Wait for job to be completed                                               // ------------------------------------
#ifdef USE_FORK
  if(!m_hThread && m_hPid){                                                     // If there is a child process by fork >>
    waitpid(m_hPid,NULL,0);                                                     //   Wait for child process
    m_nState &= ~PRC_RUNNING;                                                   //   Clear running flag
    m_nState |= PRC_COMPLETE;                                                   //   Set completed flag
  }else                                                                         // <<
#endif
  dlp_join_thread(m_hThread);                                                   // Wait for the watcher thread to end
  ReceiveData();                                                                // Receive transfer data

  // Aftermath                                                                  // ------------------------------------
  if (m_iDto)                                                                   // This job was a function call
    Unmarshal(m_iDto,iCaller);                                                  //   Unmarshal transfer data to caller
  else                                                                          // This job was a program call
    MIC_PUT_N(m_nRetVal);                                                       //   Push process return value

  return O_K;                                                                   // Ok
}
Exemple #20
0
/**
 * Check minmax data, return mode.
 */
INT16 CGEN_PROTECTED CHistogram::CheckMinmax()
{
  if (data_empty (m_minmax) == TRUE)
    return IERROR(this,HIS_EMPTY,0,0,0);

  if (data_chtype (m_minmax, T_DOUBLE) != TRUE)
    return IERROR(this,HIS_TYPE,0,0,0);

  if (data_nrec(m_minmax) == 2 && data_dim(m_minmax) == 1)
    return (1);
  if (data_nrec(m_minmax) == 2)
    return (2);
  if (data_nrec(m_minmax) > 2)
    return (3);

  return (-1);
}
Exemple #21
0
INT16 CGEN_PROTECTED CCgen::OnAutoinstance()
{
  char lpAutoname[L_INPUTLINE+1];
  GetNextDefToken(lpAutoname);

  if (m_bMainProject)
    return IERROR(this,ERR_INVALKEY,"AUTOINSTANCE:","MAIN:",0);
  if (m_nAncestor) return O_K;

  if (!dlp_strlen(lpAutoname))
    return IERROR(this,ERR_EXPECTIDAFTER,"name","AUTOINSTANCE:",0);

  dlp_strcpy(m_lpsAutoname,lpAutoname);
  m_nCSXXX |= CS_AUTOINSTANCE;

    return O_K;
}
Exemple #22
0
INT16 CGEN_PROTECTED CCgen::OnHfile()
{
  char lpName[L_INPUTLINE+1];
  GetNextDefToken(lpName);
  if (!dlp_strlen(lpName)) ERRORRET(ERR_EXPECTAFTER,"name","HFILE:",0,NOT_EXEC);

  switch(m_nCreating)
  {
  case CR_PROJECT:
    return IERROR(this,ERR_INVALSUBKEY,"PROJECT:","HFILE:",0);
  case CR_ERROR:
    return IERROR(this,ERR_INVALSUBKEY,"ERROR:","HFILE:",0);
  case CR_FIELD:
    return IERROR(this,ERR_INVALSUBKEY,"FIELD:","HFILE:",0);
  case CR_OPTION:
    return IERROR(this,ERR_INVALSUBKEY,"OPTION:","HFILE:",0);
  case CR_METHOD:
    return IERROR(this,ERR_INVALSUBKEY,"METHOD:","HFILE:",0);
  case CR_NOTE:
    return IERROR(this,ERR_INVALSUBKEY,"NOTE:","HFILE:",0);
  case CR_ICLS   : {
    SCGIcl* s = m_lpCreatingIcl; DLPASSERT(s);
    dlp_strcpy(s->lpHFile,lpName);
    break; }
  default:
    return IERROR(this,ERR_EXPGLOBALKEY,"HFILE:",0,0);
  }

  return O_K;
}
Exemple #23
0
INT16 CGEN_PROTECTED CCgen::OnOpath()
{
  char lpName[L_INPUTLINE+1];
  GetNextDefToken(lpName);
  if (!dlp_strlen(lpName)) ERRORRET(ERR_EXPECTAFTER,"name","OPATH:",0,NOT_EXEC);

  switch(m_nCreating)
  {
  case CR_PROJECT: {
    if (m_nAncestor) return O_K;
    dlp_convert_name(CN_XLATPATH,m_lpsOPath,lpName);
    break;}
  case CR_ERROR:
    return IERROR(this,ERR_INVALSUBKEY,"ERROR:","OPATH:",0);
  case CR_FIELD:
    return IERROR(this,ERR_INVALSUBKEY,"FIELD:","OPATH:",0);
  case CR_OPTION:
    return IERROR(this,ERR_INVALSUBKEY,"OPTION:","OPATH:",0);
  case CR_METHOD:
    return IERROR(this,ERR_INVALSUBKEY,"METHOD:","OPATH:",0);
  case CR_NOTE:
    return IERROR(this,ERR_INVALSUBKEY,"NOTE:","OPATH:",0);
  case CR_ICLS:
    return IERROR(this,ERR_INVALSUBKEY,"ICLS:","OPATH:",0);
  default:
    return IERROR(this,ERR_EXPGLOBALKEY,"OPATH:",0,0);
  }

  return O_K;
}
Exemple #24
0
INT16 CGEN_PUBLIC CFBAproc::AlignFramesToPitch(CData *idPitch, CData *idFea, CData* idNewFea) {
  CData* idAuxF  = NULL;
  INT32 nSamplesP = 0;
  INT32  nFea      = 0;
  INT32  nPer      = 0;
  INT32  i         = 0;
  INT32  j         = 0;

  if(m_nSync) return O_K;

  if(idFea == NULL)       return IERROR(this,ERR_NULLINST,0,0,0);
  if(idFea->IsEmpty())    return IERROR(idPitch,DATA_EMPTY,idPitch->m_lpInstanceName,0,0);

  if(idPitch == NULL)       return IERROR(this,ERR_NULLINST,0,0,0);
  if(idPitch->IsEmpty())    return IERROR(idPitch,DATA_EMPTY,idPitch->m_lpInstanceName,0,0);
  if(idPitch->GetNComps()!=2                            ||
     !dlp_is_numeric_type_code(idPitch->GetCompType(0)) ||
     !dlp_is_numeric_type_code(idPitch->GetCompType(1))) {
    return IERROR(this,FBA_BADARG,idPitch,"idPitch","contains invalid data.");
  }

  CREATEVIRTUAL(CData,idFea,idNewFea);
  ICREATEEX(CData,idAuxF  ,"~idAuxF"  ,NULL);

  if(idFea->m_lpTable->m_fsr <= 0.0) {
    idFea->m_lpTable->m_fsr = 1000.0 * (FLOAT64)m_nCrate / (FLOAT64)m_nSrate;
  }

  nFea = idFea->GetNRecs();

  for(i = 0, j = 0, nSamplesP = 0; i < idPitch->GetNRecs(); i++, nSamplesP+=nPer) {
    nPer = (INT32)idPitch->Dfetch(i,0);

    while((idFea->m_lpTable->m_fsr * (FLOAT64)(j+0.5)) < (1000.0 * (FLOAT64)nSamplesP / (FLOAT64)m_nSrate)) j++;

    j = (j>=nFea) ? nFea-1 : j;

    idAuxF->SelectRecs(idFea,j,1);
    idNewFea->Cat(idAuxF);
  }

  IDESTROY(idAuxF);
  DESTROYVIRTUAL(idFea, idNewFea);
  return O_K;
}
Exemple #25
0
/*
 * Manual page at fst_man.def
 */
INT16 CGEN_PUBLIC CFst_CopyUi(CFst* _this, CFst* itSrc, CData* idIndex, INT32 nPar)
{
  INT32 i  = 0;
  INT32 nU = 0;

  /* Validate */
  CHECK_THIS_RV(NOT_EXEC);
  CFst_Check(_this);
  CFst_Check(itSrc);

  if (idIndex)
  {
    if (CData_IsEmpty(idIndex)) return NOT_EXEC;
    if (nPar<0)
      for (i=0; i<CData_GetNComps(idIndex); i++)
        if (dlp_is_numeric_type_code(CData_GetCompType(idIndex,i)))
          { nPar=i; break; }

    if
    (
      nPar<0 || nPar>=CData_GetNComps(idIndex) ||
      !dlp_is_numeric_type_code(CData_GetCompType(idIndex,nPar))
    )
    {
      return IERROR(_this,FST_BADID,"component",nPar,0);
    }
  }

  /* Initialize */
  CREATEVIRTUAL(CFst,itSrc,_this);
  CFst_Reset(BASEINST(_this),TRUE);
  
  if (idIndex)
  {
    /* Loop over records of idIndex */
    for (i=0; i<CData_GetNRecs(idIndex); i++)
    {
      nU = (INT32)CData_Dfetch(idIndex,i,nPar);
      if (nU>=0 && nU<UD_XXU(itSrc)) {
        DLPASSERT(OK(CFst_CatEx(_this,itSrc,nU,1)))
      } else IERROR(_this,FST_BADID2,"unit",nU,0);
    }
  }
  else if (nPar<0)
Exemple #26
0
/**
 * Get scaling function coefficients
 *
 * @return O_K if successfull, NOT_EXEC otherwise
 */
INT16 CGEN_PUBLIC CFWTproc::GetCoef(CData *idCoef)
{
  INT16  di=GetDindex();
  const FLOAT64 *h;
  if(!di) return IERROR(this,ERR_INVALARG,"wvltype invalid",0,0);
  if(!(h=dlm_fwt_geth(di))) return NOT_EXEC;
  CData_Array(idCoef,T_DOUBLE,1,di);
  memcpy(CData_XAddr(idCoef,0,0),h,sizeof(FLOAT64)*di);
  return O_K;
}
Exemple #27
0
/*
 * Manual page at function.def
 */
INT16 CGEN_PROTECTED CFunction::OnType()
{
  FNC_DELEGATE OnType();
  const char* lpsTypecode = GetNextToken(TRUE);
  INT16       nTypecode   = dlp_get_type_code(lpsTypecode);
  if (nTypecode<=0)
    return IERROR(this,FNC_INVALID,"elementary type name",lpsTypecode,0);
  PushNumber(CMPLX(nTypecode));
  return O_K;
}
Exemple #28
0
/**
 * Synthesis
 *
 *
 * @return O_K if successfull, NOT_EXEC otherwise
 */
INT16 CGEN_PROTECTED CFWTproc::Synthesize(CData* idTrans, CData* idSignal)
{  
  INT32   nNrOfCoeff;   /* number of signal values */
  INT16  ret = NOT_EXEC;
  INT16  di=GetDindex();

  if(!di) return IERROR(this,ERR_INVALARG,"wvltype invalid",0,0);
  if (idTrans == NULL)    return IERROR(this,ERR_NULLINST,0,0,0);
  if (idTrans->IsEmpty())   return IERROR(idTrans,DATA_EMPTY,idTrans->m_lpInstanceName,0,0);
  if (idTrans->GetCompType(0)!=T_DOUBLE)
    return IERROR(idTrans,DATA_BADCOMPTYPE,0,idTrans->m_lpInstanceName,"double");

  // remove symbolic component
  if(dlp_is_symbolic_type_code(idTrans->GetCompType(idTrans->GetNComps()-1)))
  {
    idTrans->DeleteComps(idTrans->GetNComps()-1,1);
  }
  
  nNrOfCoeff = (INT32) idTrans->GetNComps();                                     /* get number of coefficients */
  // maybe the records containing the data
  if(nNrOfCoeff == 1)
  { 
    nNrOfCoeff = (INT32) idTrans->GetNRecs();                                    /* get number of coefficients */
  }
 
  /* allocate output data objects */
  idSignal->Reset(TRUE);
  idSignal->AddNcomps(T_DOUBLE, 1);
  idSignal->Alloc(nNrOfCoeff);
  idSignal->SetNRecs(nNrOfCoeff);

  if(!dlp_strncmp(m_lpsWvltype,"haar",4)) di=2;
  else if(m_lpsWvltype[0]=='d') di=atoi(m_lpsWvltype+1);
  else return NOT_EXEC;

  return dlm_fwt_dx_inv((FLOAT64*)idTrans->XAddr(0,0),
                           (FLOAT64*)idSignal->XAddr(0,0),
                           (INT32)nNrOfCoeff,
                           di,
                           (INT16)m_nLevel);

  return ret;
}
Exemple #29
0
void move_info(long pos, char *word, char *explain)
{
    pid_t pid;
    char tempfile[32];
	FILE *fp;
	int c;
    
    if ((fp = fopen(DICT_FILENAME, "r+")) == NULL)
		IERROR("Open file '%s' failed!", DICT_FILENAME);

	fseek(fp, pos, SEEK_SET);
	while ((c = getc(fp)) != EOF)
		if (c == '#')
			break;

	pos = ftell(fp) - 1;

    pid = getpid();
    x_memzero(tempfile, sizeof(tempfile));
    snprintf(tempfile, sizeof(tempfile), "/tmp/tmp_%d\n", pid);

	FILE *fp_temp = fopen(tempfile, "word+");
	if (fp_temp == NULL)
		IERROR("Open file '%s' failed!", tempfile);

	fwrite(word, 1, strlen(word), fp_temp);
	fwrite(explain, 1, strlen(explain), fp_temp);
	fseek(fp, pos, SEEK_SET);
	while ((c = getc(fp)) != EOF)
	{
		putc(c, fp_temp);
	}

	rewind(fp_temp);
	fseek(fp, pos, SEEK_SET);
	while ((c = getc(fp_temp)) != EOF)
	{
		putc(c, fp);
	}

	fclose(fp_temp);
	fclose(fp);
}
Exemple #30
0
/**
 * Get data initializer '{ ... }' from command line and store into token list
 * lpsInit.
 * <h3>Note</h3>
 * <p>You must setup the method invocation context <code>m_lpMic</code> (see 
 * <a href="dlpinst.html"><code class="link">CDlpInstance</code></a>) before
 * calling this method. Otherwise it will do noting.</p>
 *
 * @param lpsInit Pointer to character buffer to store initializer in. The
 *                tokens will be separated by nulls '\0', opening and closing
 *                curly braces will not be included! The token list will be
 *                terminated with a double null "\0\0".
 * @param nLen    Maximal number of characters to place on lpsInit (including
 *                the terminal double null)
 * @param bForce  If TRUE the method does not seek for the opening curly brace
 *                but starts reading initializers until it encounters a closing
 *                curly brace '}'. A leading opening curly brace will, however,
 *                be tolerated. If FALSE the method <i>expects</i> an opening
 *                curly brace and does not read any initializers if no leading
 *                opening brace is found.
 * @return The number of initializers read
 */
INT32 CGEN_PROTECTED CData_ReadInitializer
(
  CData* _this,
  char*  lpsInit,
  INT32   nLen,
  BOOL   bForce
)
{
  const char* lpsToken;                                                         /* Current token                     */
  INT32        nCnt;                                                             /* Token counter                     */
  INT32        nPos;                                                             /* Position in output buffer         */
  BOOL        bStor;                                                            /* Store next token                  */

  /* Initialize */                                                              /* --------------------------------- */
  if (!CDlpObject_MicGet(BASEINST(_this))) return 0;                            /* Need invocation context           */
  if (!lpsInit) return 0;                                                       /* Need output buffer                */
  dlp_memset(lpsInit,0,nLen);                                                   /* Clear output buffer               */

  /* Do initializers follow? */                                                 /* --------------------------------- */
  lpsToken = MIC_NEXTTOKEN_FORCE;                                                /* Ruthlessly get next token         */
  if (!lpsToken || dlp_strcmp(lpsToken,"{")!=0)                                 /* No or not the "{" token           */
  {                                                                             /* >>                                */
    if (bForce) IERROR(_this,DATA_NOTFOUND,"Constant initializer ","'{'",0);    /*   If there should be some-> error */
    if (lpsToken) MIC_REFUSETOKEN;                                              /*   Wrong token -> push it back     */
    return 0;                                                                   /*   Now get out'a here              */
  }                                                                             /* <<                                */

  /* Get 'em tokens */                                                          /* --------------------------------- */
  for (nCnt=0,nPos=0,bStor=TRUE; ; nCnt++)                                      /* Infinitely ...                    */
  {                                                                             /* >>                                */
    lpsToken = MIC_NEXTTOKEN_FORCE;                                             /*   Ruthlessly get next token       */
    if (!lpsToken) return IERROR(_this,DATA_HERESCAN,"}",0,0);                  /*   No more tokens -> forget it     */
    if (dlp_strcmp(lpsToken,"}")==0) break;                                     /*   End token -> get out'a here     */

    if (nLen<nPos+(INT32)dlp_strlen(lpsToken)+2) bStor = FALSE;                  /*   Cannot store more tokens :(     */
    if (!bStor) continue;                                                       /*   Ignore ALL following tokens     */

    dlp_strcpy(&lpsInit[nPos],lpsToken);                                        /*   Store token                     */
    nPos+=(INT32)dlp_strlen(&lpsInit[nPos])+1;                                   /*   Set next token pointer          */
  }                                                                             /* <<                                */

  return nCnt;                                                                  /* Return number of tokens read      */
}