123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- /*
- * Licensed Materials - Property of HCL
- *
- * IBM Informix DataBlade Module
- * (C) Copyright International Business Machines Corporation 2002.
- * (c) Copyright HCL Technologies Ltd. 2017. All Rights Reserved.
- *
- * COPYRIGHT LICENSE:
- * This information contains sample application programs in source language,
- * which illustrate programming techniques on various operating platforms.
- * You may copy, modify, and distribute these sample programs in any form
- * without payment to IBM, for the purposes of developing, using, marketing
- * or distributing application programs conforming to the application
- * programming interface for the operating platform for which the sample
- * programs are written. These examples have not been thoroughly tested under
- * all conditions. IBM, therefore, cannot guarantee or imply reliability,
- * serviceability, or function of these programs. You may copy, modify, and
- * distribute these sample programs in any form without payment to IBM for
- * the purposes of developing, using, marketing, or distributing application
- * programs conforming to IBM's application programming interfaces.
- * Each copy or any portion of these sample programs or any derivative work,
- * must include a copyright notice as follows:
- * © (your company name) (year). Portions of this code are derived from
- * IBM Corp. Sample Programs. © Copyright IBM Corp. (enter the year or
- * years). All rights reserved.
- *
- */
- #include "tseries.h"
- /*
- * Example code for clipping a timeseries
- */
- 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);
- /* get the type info for the input timeseries */
- ts_typeid = mi_fp_argtype(fParam, 0);
- /* open the input timeseries */
- tsdesc = ts_open(conn, ts, ts_typeid, 0);
- /*
- * not really needed, figure out how many elements
- * could possibly be in result timeseries. This guess
- * will likely be way too big. Might be better just
- * to use 0.
- */
- nelems = ts_nelems(tsdesc);
- /*
- * create the new timeseries. Make it look like
- * the original timeseries - regularity, calendar, container
- */
- 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));
-
- /* open the output timeseries */
- new_tsdesc = ts_open(conn, new_ts, ts_typeid, 0);
- /* start scanning the input timeseries between the given dates */
- 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)
- /* just skip null elements */
- continue;
- /* add the data */
- if (isreg)
- ts_put_nth_elem(new_tsdesc, elem, off);
- else
- ts_put_elem(new_tsdesc, elem, ts_current_timestamp(tsscan));
- }
- /* clean up */
- ts_end_scan(tsscan);
- ts_close(tsdesc);
- ts_close(new_tsdesc);
- /* return the result timeseries */
- return(new_ts);
- }
|