/** * 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); }
/** * 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); }