Ejemplo n.º 1
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);
}
Ejemplo n.º 2
0
/**
 * Prepare histogram data.
 *
 * @param x  first data
 * @param wv weight data
 * @return max. index value or -1, if index empty
 */
INT32 CGEN_PROTECTED CHistogram::Prepare(CData* x, CData* wv)
{
  INT32 imax = 1, i, n;

  if (m_hist == NULL)
    m_hist = data_create("hist");

  m_nhist = data_nblock(m_hist);

  if (data_empty(m_indexlist) != TRUE)
  {
    imax = CHistogram_max_index(m_indexlist, 0) + 1;
    if (imax > m_nhist)
      m_nhist = imax;
  }

  if (data_empty(wv) != TRUE)
  {
    imax = data_ndim(wv);
    if (imax > m_nhist)
      m_nhist = imax;
  }

  if (m_nhist == 0)
    m_nhist = 1;

  if (data_empty(m_hist) != TRUE)
  {
    data_realloc (m_hist, m_nhist * m_bins);
    set_data_nrec (m_hist, m_nhist * m_bins);
    m_hdim = data_dim(m_hist);
  } else
  {
    data_reset(m_hist);
    n = data_dim(x);
    m_hdim = 0;
    for (i = 0; i < n; i++)
      if (comp_type(x,i) > 256 && i != m_icomp)
      {
        comp_def(m_hist, comp_text(x,i),T_DOUBLE);
        m_hdim++;
      }
    data_arr_alloc (m_hist, m_bins * m_nhist);
  }

  set_data_descr(m_hist, DESCR1, (FLOAT64)m_hmode);
  set_data_descr(m_hist, DESCR2, (FLOAT64)m_bins);

  set_data_nblock(m_hist, m_nhist);

  return (m_nhist);
}
Ejemplo n.º 3
0
/**
 * Check consistency between histogram and minmax data.
 */
INT16 CGEN_PROTECTED CHistogram::CheckConsist()
{
  INT16 ierr, mode;
  INT32 nhist;

  mode = HIS_MODE;
  nhist = data_nblock(m_hist);

  mode = CheckMinmax();
  if (mode == -1)
    return (NOT_EXEC);

  if ((ierr = CheckHisto()) != O_K)
    return (ierr);

  switch (mode)
  {
  case 1:
    if (data_nrec(m_minmax) != 2 || data_dim (m_minmax) != 1)
      return IERROR(this,HIS_INCONS,0,0,0);
    break;

  case 2:
    if (data_nrec(m_minmax) != 2)
      return IERROR(this,HIS_INCONS,0,0,0);
    if (data_dim(m_minmax) != data_dim(m_hist))
      return IERROR(this,HIS_INCONS,0,0,0);
    break;

  case 3:
    if (data_nrec(m_minmax) < 2 * nhist)
      return IERROR(this,HIS_INCONS,0,0,0);
    if (data_dim(m_minmax) != data_dim(m_hist))
      return IERROR(this,HIS_INCONS,0,0,0);
    break;

  default:
    return IERROR(this,HIS_INCONS,0,0,0);
  }

  return (O_K);
}
Ejemplo n.º 4
0
/**
 * Reorganize histogram.
 *
 * <p>Remarks</p>
 * <ul>
 *   <li>If (exist == NULL), the number of histogram blocks is set to nind,
 *       by adding empty blocks or removing blocks from the end.</li>
 *   <li>If (exist != NULL), histogram blocks may selected as follows:
 *       exist(i,0) == 0: block i is deleted;
 *       exist(i,0) >  0: block i is preserved</li>
 *   <li> Only preserved blocks will be available after reorganization! The
 *        index correspondence may be changed by this operation!nind is not used
 *        in this case.</li>
 * </ul>
 *
 * @param exist  -  index existing flag sequence (may be NULL)
 * @param nind   -  index number
 * @return O_K if ok, NOT_EXEC if not executed
 */
INT16 CGEN_PUBLIC CHistogram::ReorgEx(CData* exist, INT32 nind)
  {
  INT32 n, ifree, i, imax, rl;
  CData* h;

  if (CheckHisto() != O_K)
    return (NOT_EXEC);

  /* --- change only histogram number */
  if (exist == NULL)
  {
    if (nind > 0 && nind != data_nblock(m_hist))
    {
      data_realloc (m_hist, nind * m_bins);
      set_data_nblock(m_hist, nind);
      set_data_nrec (m_hist, nind * m_bins);
      return (O_K);
    } else
      return (NOT_EXEC);
  }

  /* --- reorganize according to exist */
  if (exist != NULL)
  {
    imax = data_nrec(exist);

    n = 0;
    for (i = 0; i < imax; i++)
    {
      if (dfetch (exist,i,0) > 0.0)
        n++;
    }

    if (n == imax)
      return (O_K);

    h = data_create("h");
    data_copy (m_hist,h);

    rl = BytesPerBlock();
    data_realloc (m_hist, n * m_bins);

    ifree = 0;

    for (i = 0; i < imax; i++)
    {
      if (dfetch (exist,i,0) > 0.0)
      {
        dl_memmove ( xaddr(m_hist,ifree,0),xaddr(h,i*m_bins,0), rl);
        ifree += m_bins;
      }
    }

    if (m_hmode == 3)
    {
      data_copy (m_hist,h);
      rl = 2 * data_reclen(m_minmax);
      data_realloc (m_minmax, n * 2);

      ifree = 0;

      for (i = 0; i < imax; i++)
      {
        if (dfetch (exist,i,0) > 0.0)
        {
          dl_memmove ( xaddr(m_minmax,ifree,0),xaddr(h,2*i,0), rl);
          ifree += 2;
        }
      }
    }

    data_destroy(h);

    set_data_nblock(m_hist, n);
    return (O_K);
  }

  return (O_K);
}