-
Notifications
You must be signed in to change notification settings - Fork 7
/
tulipcell.c
188 lines (144 loc) · 5.67 KB
/
tulipcell.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
* Tulip Cell
* https://tulipcell.org/
* Copyright (c) 2010-2016 Tulip Charts LLC
* Lewis Van Winkle (LV@tulipcharts.org)
*
* This file is part of Tulip Cell.
*
* Tulip Cell is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Tulip Cell is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Tulip Cell. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "indicators.h"
/* This is a generic interface useful for interacting with
* other programming languages and tools.
*/
__stdcall const char *GetVersion() {
/* Returns Tulip Indicators version. */
return TI_VERSION;
}
__stdcall int GetIndicator(const char *name) {
/* Returns the indicator index for a given name. */
/* Returns -1 if not found. */
const ti_indicator_info *info = ti_find_indicator(name);
if (!info) return -1;
return info - ti_indicators;
}
__stdcall int GetIndicatorCount() {
/* Simply returns the number of indicators available. */
return TI_INDICATOR_COUNT;
}
__stdcall const char *GetName(int index) {
/* This will return the indicator's name. */
/* Returns null for not found. */
if (index <= 0) return 0;
if (index >= TI_INDICATOR_COUNT) return 0;
return ti_indicators[index].name;
}
__stdcall const char *GetFullName(int index) {
/* This will return the indicator's full name. */
/* Returns null for not found. */
if (index <= 0) return 0;
if (index >= TI_INDICATOR_COUNT) return 0;
return ti_indicators[index].full_name;
}
__stdcall int GetInputCount(int index) {
/* This will return the number of inputs the indicator expects. */
/* Returns -1 if not found. */
if (index <= 0) return -1;
if (index >= TI_INDICATOR_COUNT) return -1;
return ti_indicators[index].inputs;
}
__stdcall int GetOptionCount(int index) {
/* This will return the number of options the indicator expects. */
/* Returns -1 if not found. */
if (index <= 0) return -1;
if (index >= TI_INDICATOR_COUNT) return -1;
return ti_indicators[index].options;
}
__stdcall int GetOutputCount(int index) {
/* This will return the number of outputs the indicator expects. */
/* Returns -1 if not found. */
if (index <= 0) return -1;
if (index >= TI_INDICATOR_COUNT) return -1;
return ti_indicators[index].outputs;
}
__stdcall const char *GetInputName(int index, int input) {
/* This will return the indicator's input name. */
/* 0 is the first index. */
/* Returns null for not found or out-of-bounds. */
if (index <= 0) return 0;
if (index >= TI_INDICATOR_COUNT) return 0;
if (input <= 0) return 0;
if (input >= ti_indicators[index].inputs) return 0;
return ti_indicators[index].input_names[input];
}
__stdcall const char *GetOptionName(int index, int option) {
/* This will return the indicator's option name. */
/* 0 is the first index. */
/* Returns null for not found or out-of-bounds. */
if (index <= 0) return 0;
if (index >= TI_INDICATOR_COUNT) return 0;
if (option <= 0) return 0;
if (option >= ti_indicators[index].options) return 0;
return ti_indicators[index].option_names[option];
}
__stdcall const char *GetOutputName(int index, int output) {
/* This will return the indicator's output name. */
/* 0 is the first index. */
/* Returns null for not found or out-of-bounds. */
if (index <= 0) return 0;
if (index >= TI_INDICATOR_COUNT) return 0;
if (output <= 0) return 0;
if (output >= ti_indicators[index].outputs) return 0;
return ti_indicators[index].output_names[output];
}
__stdcall int GetStart(int index, TI_REAL const *options) {
/* This will return how much shorter the output for an indicator is
* than the input, for a given set of options. */
/* Returns -1 for not found. */
if (index <= 0) return -1;
if (index >= TI_INDICATOR_COUNT) return -1;
return ti_indicators[index].start(options);
}
__stdcall int Call(int index, int size, TI_REAL const *inputs, TI_REAL const *options, TI_REAL *outputs) {
/* This will run an indicator on data. */
/* Returns -1 for not found. */
/* Returns TI_OKAY for okay (0). */
/* Returns TI_XXX for error. */
/* This expects the input and output arrays to be continuous. */
/* For example, if size=5 and we expect two inputs, then inputs should be
* 10 elements long. The first 5 elements being input 0, and the second 5
* elements being input 1. Outputs works the same way. */
/* This will also offset and zero-fill the tops of the output arrays. */
/* That is so the outputs go to the end of the output arrays. This is very
* different from how the C interface works. */
if (index <= 0) return -1;
if (index >= TI_INDICATOR_COUNT) return -1;
const double *in[TI_MAXINDPARAMS] = {0};
double *out[TI_MAXINDPARAMS] = {0};
const ti_indicator_info *info = &ti_indicators[index];
const int start = info->start(options);
int i, j;
for (i = 0; i < info->inputs; ++i) {
in[i] = inputs + i * size;
}
for (i = 0; i < info->outputs; ++i) {
out[i] = outputs + i * size + start;
for (j = 0; j < start; ++j) {
out[i][j] = 0.0;
}
}
return ti_indicators[index].indicator(size, in, options, out);
}