123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #include "tseries.h"
- ts_timeseries *
- clip(ts_timeseries *ts, mi_datetime *start, mi_datetime *end, MI_FPARAM *fParam)
- {
- ts_tsdesc *tsdesc;
- ts_tsdesc *new_tsdesc;
- ts_tscan *tsscan;
- ts_tselem elem;
- mi_integer ret;
- mi_integer nelems;
- mi_integer off;
- mi_boolean isreg;
- ts_timeseries *new_ts;
- MI_TYPEID *ts_typeid;
- MI_CONNECTION *conn;
- conn = mi_open(NULL, NULL, NULL);
-
- ts_typeid = mi_fp_argtype(fParam, 0);
-
- tsdesc = ts_open(conn, ts, ts_typeid, 0);
-
- nelems = ts_nelems(tsdesc);
-
- isreg = !TS_IS_IRREGULAR(ts);
- new_ts = ts_create(conn,
- ts_get_calname(ts),
- start,
- ts_get_threshold(ts),
- isreg ? 0: TS_CREATE_IRR,
- ts_typeid,
- nelems,
- ts_get_containername(ts));
-
-
- new_tsdesc = ts_open(conn, new_ts, ts_typeid, 0);
-
- off = -1;
- tsscan = ts_begin_scan(tsdesc, 0, start, end);
- while ((ret = ts_next(tsscan, &elem)) != TS_SCAN_EOS) {
- off++;
- if (ret == TS_SCAN_NULL)
-
- continue;
-
- if (isreg)
- ts_put_nth_elem(new_tsdesc, elem, off);
- else
- ts_put_elem(new_tsdesc, elem, ts_current_timestamp(tsscan));
- }
-
- ts_end_scan(tsscan);
- ts_close(tsdesc);
- ts_close(new_tsdesc);
-
- return(new_ts);
- }
|