use opaque pointers
[sddekit.git] / include / sk_out.h
blobe689699d2a8647063a694caaebd986192f833eb9
1 /* Apache 2.0 INS-AMU 2015 */
3 #ifndef SK_OUT_H
4 #define SK_OUT_H
6 #include <stdio.h>
8 #include "sk_util.h"
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
14 /** SK_DEFOUT aids in creating a new output definition.
15 * See ::sk_out for details of the generated output callback signature.
17 * \param name name of output callback being defined.
19 #define SK_DEFOUT(name) int name(void * restrict data,\
20 double t,\
21 int nx, double * restrict x,\
22 int nc, double * restrict c)
24 /**
25 * Callback signature expected by solver framework for output callbacks.
26 * Use #SK_DEFOUT to declare or define a new output callback.
28 * \param data user data for output function such as simulation length.
29 * \param t current time.
30 * \param nx number of state variables.
31 * \param x state variable vector.
32 * \param nc number of coupling terms.
33 * \param c coupling term vector.
34 * \return 1 if the solver should continue, 0 to stop solver.
36 typedef SK_DEFOUT((*sk_out));
38 typedef struct sk_out_file_data sk_out_file_data;
40 /**
41 * Allocate memory for file output.
43 sk_out_file_data *sk_out_file_alloc();
45 /**
46 * Initialize file output from a file name.
48 int sk_out_file_from_fname(sk_out_file_data *d, char *fname);
50 /**
51 * Initialize file output from stdout or stderr.
53 int sk_out_file_from_std(sk_out_file_data *d, FILE *std);
55 /**
56 * Query whether file output is on stdout stderr.
58 int sk_out_file_is_std(sk_out_file_data *d);
60 /**
61 * Get file pointer.
63 FILE *sk_out_file_get_fd(sk_out_file_data *d);
65 /**
66 * Free memory allocated for file output.
68 void sk_out_file_free(sk_out_file_data *d);
70 /**
71 * Callback implementing file output.
73 SK_DEFOUT(sk_out_file);
75 /* auto-allocating array */
76 typedef struct sk_out_mem_data sk_out_mem_data;
78 /**
79 * Get number of state variables in memory buffer.
81 int sk_out_mem_get_nx(sk_out_mem_data *d);
83 /**
84 * Get number of coupling variables in memory buffer.
86 int sk_out_mem_get_nc(sk_out_mem_data *d);
88 /**
89 * Get number of samples in memory buffer.
91 int sk_out_mem_get_n_sample(sk_out_mem_data *d);
93 /**
94 * Get capacity in number of samples in memory buffer.
96 int sk_out_mem_get_capacity(sk_out_mem_data *d);
98 /**
99 * Get state variable buffer.
101 double *sk_out_mem_get_xs(sk_out_mem_data *d);
104 * Get coupling variable buffer.
106 double *sk_out_mem_get_cs(sk_out_mem_data *d);
109 * Allocate memory for output memory buffer.
111 sk_out_mem_data *sk_out_mem_alloc();
114 * Initialize output memory buffer.
116 int sk_out_mem_init(sk_out_mem_data *d);
119 * Free memory allocated to output memory buffer.
121 void sk_out_mem_free(sk_out_mem_data *d);
124 * Callback implementing output memory buffer.
126 SK_DEFOUT(sk_out_mem);
128 /* split n-ways */
129 typedef struct sk_out_tee_data sk_out_tee_data;
132 * Allocate output splitter.
134 sk_out_tee_data *sk_out_tee_alloc();
137 * Initialize output splitter.
139 * \param d splitter instance
140 * \param nout number of outputs to distribute to
142 int sk_out_tee_init(sk_out_tee_data *d, int nout);
145 * Get number of outputs for splitter.
147 int sk_out_tee_get_nout(sk_out_tee_data *d);
150 * Get NULL status of out data array.
152 int sk_out_tee_outd_is_null();
155 * Get NULL status of out callback array.
157 int sk_out_tee_outs_is_null();
160 * Set i'th output of splitter.
162 * \param d splitter instance
163 * \param i output index
164 * \param out i'th output callback
165 * \param data i'th output user data
167 int sk_out_tee_set_out(sk_out_tee_data *d, int i, sk_out out, void *data);
170 * Get i'th output callback.
172 sk_out sk_out_tee_get_out_i(sk_out_tee_data *d, int i);
175 * Get i'th output user data.
177 void *sk_out_tee_get_outd_i(sk_out_tee_data *d, int i);
180 * Free memory allocated to splitter output.
182 void sk_out_tee_free(sk_out_tee_data *d);
185 * Callback implementing output splitter.
187 SK_DEFOUT(sk_out_tee);
189 /* TODO general temporal filter */
191 /* temporal average */
192 typedef struct sk_out_tavg_data sk_out_tavg_data;
195 * Allocate memory for temporal average output.
197 sk_out_tavg_data *sk_out_tavg_alloc();
200 * Initialize temporal average output.
202 int sk_out_tavg_init(sk_out_tavg_data *d, int len, sk_out out, void *outd);
205 * Get len of temporal average output.
207 int sk_out_tavg_get_len(sk_out_tavg_data *d);
210 * Get pos of temporal average output.
212 int sk_out_tavg_get_pos(sk_out_tavg_data *d);
215 * Get t of temporal average output.
217 double sk_out_tavg_get_t(sk_out_tavg_data *d);
220 * Get out of temporal average output.
222 sk_out sk_out_tavg_get_out(sk_out_tavg_data *d);
225 * Get outd of temporal average output.
227 void *sk_out_tavg_get_outd(sk_out_tavg_data *d);
230 * Get x of temporal average output.
232 double *sk_out_tavg_get_x(sk_out_tavg_data *d);
235 * Get c of temporal average output.
237 double *sk_out_tavg_get_c(sk_out_tavg_data *d);
240 * Free memory allocated to temporal average output.
242 void sk_out_tavg_free(sk_out_tavg_data *d);
245 * Callback implementing temporal average output.
247 SK_DEFOUT(sk_out_tavg);
249 /* spatial filter (bank) */
250 typedef struct sk_out_sfilt_data sk_out_sfilt_data;
253 * Allocate memory for spatial filter output.
255 sk_out_sfilt_data *sk_out_sfilt_alloc();
258 * Initialize spatial filter output.
260 int sk_out_sfilt_init(sk_out_sfilt_data *d, int nfilt, int filtlen,
261 double *xfilts, double *cfilts, sk_out out, void *outd);
264 * Get nfilt of spatial filter output.
266 int sk_out_sfilt_get_nfilt(sk_out_sfilt_data *d);
269 * Get filtlen of spatial filter output.
271 int sk_out_sfilt_get_filtlen(sk_out_sfilt_data *d);
274 * Get xfilts of spatial filter output.
276 double *sk_out_sfilt_get_xfilts(sk_out_sfilt_data *d);
279 * Get cfilts of spatial filter output.
281 double *sk_out_sfilt_get_cfilts(sk_out_sfilt_data *d);
284 * Get x of spatial filter output.
286 double *sk_out_sfilt_get_x(sk_out_sfilt_data *d);
289 * Get c of spatial filter output.
291 double *sk_out_sfilt_get_c(sk_out_sfilt_data *d);
294 * Get out of spatial filter output.
296 sk_out sk_out_sfilt_get_out(sk_out_sfilt_data *d);
299 * Get outd of spatial filter output.
301 void *sk_out_sfilt_get_outd(sk_out_sfilt_data *d);
304 * Free memory allocated to spatial filter output.
306 void sk_out_sfilt_free(sk_out_sfilt_data *d);
309 * Callback implementing spatial filter monitor.
311 SK_DEFOUT(sk_out_sfilt);
313 #ifdef __cplusplus
314 }; /* extern "C" */
315 #endif
317 #endif