Program Listing for File cmb_timeseries.h

Return to documentation for file (include/cmb_timeseries.h)

/*
 * Copyright (c) Asbjørn M. Bonvik 1994, 1995, 2025-26.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef CIMBA_CMB_TIMESERIES_H
#define CIMBA_CMB_TIMESERIES_H

#include "cmb_dataset.h"
#include "cmb_wtdsummary.h"

struct cmb_timeseries {
    struct cmb_dataset ds;
    double *ta;
    double *wa;
};

extern struct cmb_timeseries *cmb_timeseries_create(void);

extern void cmb_timeseries_initialize(struct cmb_timeseries *tsp);

extern void cmb_timeseries_reset(struct cmb_timeseries *tsp);

extern void cmb_timeseries_terminate(struct cmb_timeseries *tsp);

extern void cmb_timeseries_destroy(struct cmb_timeseries *tsp);


extern uint64_t cmb_timeseries_copy(struct cmb_timeseries *tgt,
                                    const struct cmb_timeseries *src);

extern uint64_t cmb_timeseries_add(struct cmb_timeseries *tsp,
                                   double x,
                                   double t);

extern uint64_t cmb_timeseries_finalize(struct cmb_timeseries *tsp, double t);

extern void cmb_timeseries_sort_x(struct cmb_timeseries *tsp);

extern void cmb_timeseries_sort_t(struct cmb_timeseries *tsp);

extern uint64_t cmb_timeseries_summarize(const struct cmb_timeseries *tsp,
                                         struct cmb_wtdsummary *wsp);

[[maybe_unused]]
static inline uint64_t cmb_timeseries_count(const struct cmb_timeseries *tsp)
{
    cmb_assert_release(tsp != NULL);

    return cmb_dataset_count((struct cmb_dataset *)tsp);
}

[[maybe_unused]]
static inline double cmb_timeseries_min(const struct cmb_timeseries *tsp)
{
    cmb_assert_release(tsp != NULL);

    return cmb_dataset_min((struct cmb_dataset *)tsp);
}

[[maybe_unused]]
static inline double cmb_timeseries_max(const struct cmb_timeseries *tsp)
{
    cmb_assert_release(tsp != NULL);

    return cmb_dataset_max((struct cmb_dataset *)tsp);
}

extern double cmb_timeseries_median(const struct cmb_timeseries *tsp);

extern void cmb_timeseries_fivenum_print(const struct cmb_timeseries *tsp,
                                         FILE *fp,
                                         bool lead_ins);

extern void cmb_timeseries_histogram_print(const struct cmb_timeseries *tsp,
                                           FILE *fp,
                                           uint16_t num_bins,
                                           double low_lim,
                                           double high_lim);

extern void cmb_timeseries_print(const struct cmb_timeseries *tsp, FILE *fp);

[[maybe_unused]]
static inline void cmb_timeseries_ACF(const struct cmb_timeseries *tsp,
                                      const uint16_t n,
                                      double *acf)
{
    cmb_assert_release(tsp != NULL);

    cmb_dataset_ACF((struct cmb_dataset *)tsp, n, acf);
}

[[maybe_unused]]
static inline void cmb_timeseries_PACF(const struct cmb_timeseries *tsp,
                                       const uint16_t n,
                                       double *pacf,
                                       double *acf)
{
    cmb_assert_release(tsp != NULL);

    cmb_dataset_PACF((struct cmb_dataset *)tsp, n, pacf, acf);
}

[[maybe_unused]]
static inline void cmb_timeseries_correlogram_print(const struct cmb_timeseries *tsp,
                                                    FILE *fp,
                                                    const uint16_t n,
                                                    double *acf)
{
    cmb_assert_release(tsp != NULL);

    cmb_dataset_correlogram_print((struct cmb_dataset *)tsp, fp, n, acf);
}

#endif /* CIMBA_CMB_TIMESERIES_H */