1 /* TA-LIB Copyright (c) 1999-2007, Mario Fortier
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or
5  * without modification, are permitted provided that the following
6  * conditions are met:
7  *
8  * - Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  *
11  * - Redistributions in binary form must reproduce the above copyright
12  *   notice, this list of conditions and the following disclaimer in
13  *   the documentation and/or other materials provided with the
14  *   distribution.
15  *
16  * - Neither name of author nor the names of its contributors
17  *   may be used to endorse or promote products derived from this
18  *   software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /* List of contributors:
35  *
36  *  Initial  Name/description
37  *  -------------------------------------------------------------------
38  *  MF       Mario Fortier
39  *
40  * Change history:
41  *
42  *  MMDDYY BY     Description
43  *  -------------------------------------------------------------------
44  *  021807 MF     Initial Version
45  */
46 
47 /**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/
48 /* All code within this section is automatically
49  * generated by gen_code. Any modification will be lost
50  * next time gen_code is run.
51  */
52 /* Generated */
53 /* Generated */ #if defined( _MANAGED )
54 /* Generated */    #include "TA-Lib-Core.h"
55 /* Generated */    #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError)
56 /* Generated */    namespace TicTacTec { namespace TA { namespace Library {
57 /* Generated */ #elif defined( _JAVA )
58 /* Generated */    #include "ta_defs.h"
59 /* Generated */    #include "ta_java_defs.h"
60 /* Generated */    #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError)
61 /* Generated */ #else
62 /* Generated */    #include <string.h>
63 /* Generated */    #include <math.h>
64 /* Generated */    #include "ta_func.h"
65 /* Generated */ #endif
66 /* Generated */
67 /* Generated */ #ifndef TA_UTILITY_H
68 /* Generated */    #include "ta_utility.h"
69 /* Generated */ #endif
70 /* Generated */
71 /* Generated */ #ifndef TA_MEMORY_H
72 /* Generated */    #include "ta_memory.h"
73 /* Generated */ #endif
74 /* Generated */
75 /* Generated */ #define TA_PREFIX(x) TA_##x
76 /* Generated */ #define INPUT_TYPE   double
77 /* Generated */
78 /* Generated */ #if defined( _MANAGED )
MovingAverageVariablePeriodLookback(int optInMinPeriod,int optInMaxPeriod,MAType optInMAType)79 /* Generated */ int Core::MovingAverageVariablePeriodLookback( int           optInMinPeriod, /* From 2 to 100000 */
80 /* Generated */                                              int           optInMaxPeriod, /* From 2 to 100000 */
81 /* Generated */                                              MAType        optInMAType ) /* Generated */
82 /* Generated */ #elif defined( _JAVA )
83 /* Generated */ public int movingAverageVariablePeriodLookback( int           optInMinPeriod, /* From 2 to 100000 */
84 /* Generated */                                               int           optInMaxPeriod, /* From 2 to 100000 */
85 /* Generated */                                               MAType        optInMAType ) /* Generated */
86 /* Generated */ #else
87 /* Generated */ int TA_MAVP_Lookback( int           optInMinPeriod, /* From 2 to 100000 */
88 /* Generated */                     int           optInMaxPeriod, /* From 2 to 100000 */
89 /* Generated */                     TA_MAType     optInMAType ) /* Generated */
90 /* Generated */ #endif
91 /**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/
92 {
93    /* insert local variable here */
94 
95 /**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
96 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
97 /* Generated */    /* min/max are checked for optInMinPeriod. */
98 /* Generated */    if( (int)optInMinPeriod == TA_INTEGER_DEFAULT )
99 /* Generated */       optInMinPeriod = 2;
100 /* Generated */    else if( ((int)optInMinPeriod < 2) || ((int)optInMinPeriod > 100000) )
101 /* Generated */       return -1;
102 /* Generated */
103 /* Generated */    /* min/max are checked for optInMaxPeriod. */
104 /* Generated */    if( (int)optInMaxPeriod == TA_INTEGER_DEFAULT )
105 /* Generated */       optInMaxPeriod = 30;
106 /* Generated */    else if( ((int)optInMaxPeriod < 2) || ((int)optInMaxPeriod > 100000) )
107 /* Generated */       return -1;
108 /* Generated */
109 /* Generated */    #if !defined(_MANAGED) && !defined(_JAVA)
110 /* Generated */    if( (int)optInMAType == TA_INTEGER_DEFAULT )
111 /* Generated */       optInMAType = (TA_MAType)0;
112 /* Generated */    else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) )
113 /* Generated */       return -1;
114 /* Generated */
115 /* Generated */    #endif /* !defined(_MANAGED) && !defined(_JAVA)*/
116 /* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */
117 /**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
118 
119    return LOOKBACK_CALL(MA)(optInMaxPeriod, optInMAType);
120 }
121 
122 /**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
123 /*
124  * TA_MAVP - Moving average with variable period
125  *
126  * Input  = double, double
127  * Output = double
128  *
129  * Optional Parameters
130  * -------------------
131  * optInMinPeriod:(From 2 to 100000)
132  *    Value less than minimum will be changed to Minimum period
133  *
134  * optInMaxPeriod:(From 2 to 100000)
135  *    Value higher than maximum will be changed to Maximum period
136  *
137  * optInMAType:
138  *    Type of Moving Average
139  *
140  *
141  */
142 /* Generated */
143 /* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY )
144 /* Generated */ enum class Core::RetCode Core::MovingAverageVariablePeriod( int    startIdx,
145 /* Generated */                                                             int    endIdx,
146 /* Generated */                                                             SubArray^    inReal,
147 /* Generated */                                                             SubArray^    inPeriods,
148 /* Generated */                                                             int           optInMinPeriod, /* From 2 to 100000 */
149 /* Generated */                                                             int           optInMaxPeriod, /* From 2 to 100000 */
150 /* Generated */                                                             MAType        optInMAType,
151 /* Generated */                                                             [Out]int%    outBegIdx,
152 /* Generated */                                                             [Out]int%    outNBElement,
153 /* Generated */                                                             cli::array<double>^  outReal )
154 /* Generated */ #elif defined( _MANAGED )
155 /* Generated */ enum class Core::RetCode Core::MovingAverageVariablePeriod( int    startIdx,
156 /* Generated */                                                             int    endIdx,
157 /* Generated */                                                             cli::array<double>^ inReal,
158 /* Generated */                                                             cli::array<double>^ inPeriods,
159 /* Generated */                                                             int           optInMinPeriod, /* From 2 to 100000 */
160 /* Generated */                                                             int           optInMaxPeriod, /* From 2 to 100000 */
161 /* Generated */                                                             MAType        optInMAType,
162 /* Generated */                                                             [Out]int%    outBegIdx,
163 /* Generated */                                                             [Out]int%    outNBElement,
164 /* Generated */                                                             cli::array<double>^  outReal )
165 /* Generated */ #elif defined( _JAVA )
166 /* Generated */ public RetCode movingAverageVariablePeriod( int    startIdx,
167 /* Generated */                                             int    endIdx,
168 /* Generated */                                             double       inReal[],
169 /* Generated */                                             double       inPeriods[],
170 /* Generated */                                             int           optInMinPeriod, /* From 2 to 100000 */
171 /* Generated */                                             int           optInMaxPeriod, /* From 2 to 100000 */
172 /* Generated */                                             MAType        optInMAType,
173 /* Generated */                                             MInteger     outBegIdx,
174 /* Generated */                                             MInteger     outNBElement,
175 /* Generated */                                             double        outReal[] )
176 /* Generated */ #else
177 /* Generated */ TA_RetCode TA_MAVP( int    startIdx,
178 /* Generated */                     int    endIdx,
179 /* Generated */                     const double inReal[],
180 /* Generated */                     const double inPeriods[],
181 /* Generated */                     int           optInMinPeriod, /* From 2 to 100000 */
182 /* Generated */                     int           optInMaxPeriod, /* From 2 to 100000 */
183 /* Generated */                     TA_MAType     optInMAType,
184 /* Generated */                     int          *outBegIdx,
185 /* Generated */                     int          *outNBElement,
186 /* Generated */                     double        outReal[] )
187 /* Generated */ #endif
188 /**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
189 {
190    /* insert local variable here */
191    int i, j, lookbackTotal, outputSize, tempInt, curPeriod;
192    ARRAY_INT_REF(localPeriodArray);
193    ARRAY_REF(localOutputArray);
194    VALUE_HANDLE_INT(localBegIdx);
195    VALUE_HANDLE_INT(localNbElement);
196    ENUM_DECLARATION(RetCode) retCode;
197 
198 /**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
199 /* Generated */
200 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
201 /* Generated */
202 /* Generated */    /* Validate the requested output range. */
203 /* Generated */    if( startIdx < 0 )
204 /* Generated */       return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
205 /* Generated */    if( (endIdx < 0) || (endIdx < startIdx))
206 /* Generated */       return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
207 /* Generated */
208 /* Generated */    #if !defined(_JAVA)
209 /* Generated */    if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
210 /* Generated */    if( !inPeriods ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
211 /* Generated */    #endif /* !defined(_JAVA)*/
212 /* Generated */    /* min/max are checked for optInMinPeriod. */
213 /* Generated */    if( (int)optInMinPeriod == TA_INTEGER_DEFAULT )
214 /* Generated */       optInMinPeriod = 2;
215 /* Generated */    else if( ((int)optInMinPeriod < 2) || ((int)optInMinPeriod > 100000) )
216 /* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
217 /* Generated */
218 /* Generated */    /* min/max are checked for optInMaxPeriod. */
219 /* Generated */    if( (int)optInMaxPeriod == TA_INTEGER_DEFAULT )
220 /* Generated */       optInMaxPeriod = 30;
221 /* Generated */    else if( ((int)optInMaxPeriod < 2) || ((int)optInMaxPeriod > 100000) )
222 /* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
223 /* Generated */
224 /* Generated */    #if !defined(_MANAGED) && !defined(_JAVA)
225 /* Generated */    if( (int)optInMAType == TA_INTEGER_DEFAULT )
226 /* Generated */       optInMAType = (TA_MAType)0;
227 /* Generated */    else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) )
228 /* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
229 /* Generated */
230 /* Generated */    #endif /* !defined(_MANAGED) && !defined(_JAVA)*/
231 /* Generated */    #if !defined(_JAVA)
232 /* Generated */    if( !outReal )
233 /* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
234 /* Generated */
235 /* Generated */    #endif /* !defined(_JAVA) */
236 /* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */
237 /* Generated */
238 /**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
239 
240    /* Insert TA function code here. */
241 
242    /* Identify the minimum number of price bar needed
243     * to calculate at least one output.
244     */
245    lookbackTotal = LOOKBACK_CALL(MA)(optInMaxPeriod,optInMAType);
246 
247    /* Move up the start index if there is not
248     * enough initial data.
249     */
250    if( startIdx < lookbackTotal )
251       startIdx = lookbackTotal;
252 
253    /* Make sure there is still something to evaluate. */
254    if( startIdx > endIdx )
255    {
256       VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
257       VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
258       return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
259    }
260 
261    /* Calculate exact output size */
262    if( lookbackTotal > startIdx )
263       tempInt = lookbackTotal;
264    else
265 	  tempInt = startIdx;
266    if( tempInt > endIdx )
267    {
268 	  /* No output */
269       VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
270       VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
271       return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
272    }
273    outputSize = endIdx - tempInt + 1;
274 
275    /* Allocate intermediate local buffer. */
276    ARRAY_ALLOC(localOutputArray,outputSize);
277    ARRAY_INT_ALLOC(localPeriodArray,outputSize);
278 
279    /* Copy caller array of period into local buffer.
280     * At the same time, truncate to min/max.
281 	*/
282    for( i=0; i < outputSize; i++ )
283    {
284       tempInt = (int)(inPeriods[startIdx+i]);
285 	  if( tempInt < optInMinPeriod )
286 		  tempInt = optInMinPeriod;
287 	  else if( tempInt > optInMaxPeriod )
288           tempInt = optInMaxPeriod;
289       localPeriodArray[i] = tempInt;
290    }
291 
292    /* Process each element of the input.
293     * For each possible period value, the MA is calculated
294 	* only once.
295 	* The outReal is then fill up for all element with
296 	* the same period.
297 	* A local flag (value 0) is set in localPeriodArray
298 	* to avoid doing a second time the same calculation.
299 	*/
300    for( i=0; i < outputSize; i++ )
301    {
302 	   curPeriod = localPeriodArray[i];
303 	   if( curPeriod != 0 )
304 	   {
305            /* TODO: This portion of the function can be slightly speed
306             *       optimized by making the function without unstable period
307 	        *       start their calculation at 'startIdx+i' instead of startIdx.
308 	        */
309 
310 		   /* Calculation of the MA required. */
311 		   retCode = FUNCTION_CALL(MA)( startIdx, endIdx, inReal,
312 			                            curPeriod, optInMAType,
313 									    VALUE_HANDLE_OUT(localBegIdx),VALUE_HANDLE_OUT(localNbElement),localOutputArray );
314 
315            if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) )
316 		   {
317               ARRAY_FREE(localOutputArray);
318 			  ARRAY_INT_FREE(localPeriodArray);
319               VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
320               VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
321               return retCode;
322 	       }
323 
324 		   outReal[i] = localOutputArray[i];
325 		   for( j=i+1; j < outputSize; j++ )
326 		   {
327 			   if( localPeriodArray[j] == curPeriod )
328 			   {
329 				   localPeriodArray[j] = 0; /* Flag to avoid recalculation */
330 				   outReal[j] = localOutputArray[j];
331 			   }
332 		   }
333 	   }
334    }
335 
336    ARRAY_FREE(localOutputArray);
337    ARRAY_INT_FREE(localPeriodArray);
338 
339    /* Done. Inform the caller of the success. */
340    VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
341    VALUE_HANDLE_DEREF(outNBElement) = outputSize;
342    return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
343 }
344 
345 /**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
346 /* Generated */
347 /* Generated */ #define  USE_SINGLE_PRECISION_INPUT
348 /* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )
349 /* Generated */    #undef   TA_PREFIX
350 /* Generated */    #define  TA_PREFIX(x) TA_S_##x
351 /* Generated */ #endif
352 /* Generated */ #undef   INPUT_TYPE
353 /* Generated */ #define  INPUT_TYPE float
354 /* Generated */ #if defined( _MANAGED )
355 /* Generated */ enum class Core::RetCode Core::MovingAverageVariablePeriod( int    startIdx,
356 /* Generated */                                                             int    endIdx,
357 /* Generated */                                                             cli::array<float>^ inReal,
358 /* Generated */                                                             cli::array<float>^ inPeriods,
359 /* Generated */                                                             int           optInMinPeriod, /* From 2 to 100000 */
360 /* Generated */                                                             int           optInMaxPeriod, /* From 2 to 100000 */
361 /* Generated */                                                             MAType        optInMAType,
362 /* Generated */                                                             [Out]int%    outBegIdx,
363 /* Generated */                                                             [Out]int%    outNBElement,
364 /* Generated */                                                             cli::array<double>^  outReal )
365 /* Generated */ #elif defined( _JAVA )
366 /* Generated */ public RetCode movingAverageVariablePeriod( int    startIdx,
367 /* Generated */                                             int    endIdx,
368 /* Generated */                                             float        inReal[],
369 /* Generated */                                             float        inPeriods[],
370 /* Generated */                                             int           optInMinPeriod, /* From 2 to 100000 */
371 /* Generated */                                             int           optInMaxPeriod, /* From 2 to 100000 */
372 /* Generated */                                             MAType        optInMAType,
373 /* Generated */                                             MInteger     outBegIdx,
374 /* Generated */                                             MInteger     outNBElement,
375 /* Generated */                                             double        outReal[] )
376 /* Generated */ #else
377 /* Generated */ TA_RetCode TA_S_MAVP( int    startIdx,
378 /* Generated */                       int    endIdx,
379 /* Generated */                       const float  inReal[],
380 /* Generated */                       const float  inPeriods[],
381 /* Generated */                       int           optInMinPeriod, /* From 2 to 100000 */
382 /* Generated */                       int           optInMaxPeriod, /* From 2 to 100000 */
383 /* Generated */                       TA_MAType     optInMAType,
384 /* Generated */                       int          *outBegIdx,
385 /* Generated */                       int          *outNBElement,
386 /* Generated */                       double        outReal[] )
387 /* Generated */ #endif
388 /* Generated */ {
389 /* Generated */    int i, j, lookbackTotal, outputSize, tempInt, curPeriod;
390 /* Generated */    ARRAY_INT_REF(localPeriodArray);
391 /* Generated */    ARRAY_REF(localOutputArray);
392 /* Generated */    VALUE_HANDLE_INT(localBegIdx);
393 /* Generated */    VALUE_HANDLE_INT(localNbElement);
394 /* Generated */    ENUM_DECLARATION(RetCode) retCode;
395 /* Generated */  #ifndef TA_FUNC_NO_RANGE_CHECK
396 /* Generated */     if( startIdx < 0 )
397 /* Generated */        return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
398 /* Generated */     if( (endIdx < 0) || (endIdx < startIdx))
399 /* Generated */        return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
400 /* Generated */     #if !defined(_JAVA)
401 /* Generated */     if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
402 /* Generated */     if( !inPeriods ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
403 /* Generated */     #endif
404 /* Generated */     if( (int)optInMinPeriod == TA_INTEGER_DEFAULT )
405 /* Generated */        optInMinPeriod = 2;
406 /* Generated */     else if( ((int)optInMinPeriod < 2) || ((int)optInMinPeriod > 100000) )
407 /* Generated */        return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
408 /* Generated */     if( (int)optInMaxPeriod == TA_INTEGER_DEFAULT )
409 /* Generated */        optInMaxPeriod = 30;
410 /* Generated */     else if( ((int)optInMaxPeriod < 2) || ((int)optInMaxPeriod > 100000) )
411 /* Generated */        return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
412 /* Generated */     #if !defined(_MANAGED) && !defined(_JAVA)
413 /* Generated */     if( (int)optInMAType == TA_INTEGER_DEFAULT )
414 /* Generated */        optInMAType = (TA_MAType)0;
415 /* Generated */     else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) )
416 /* Generated */        return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
417 /* Generated */     #endif
418 /* Generated */     #if !defined(_JAVA)
419 /* Generated */     if( !outReal )
420 /* Generated */        return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
421 /* Generated */     #endif
422 /* Generated */  #endif
423 /* Generated */    lookbackTotal = LOOKBACK_CALL(MA)(optInMaxPeriod,optInMAType);
424 /* Generated */    if( startIdx < lookbackTotal )
425 /* Generated */       startIdx = lookbackTotal;
426 /* Generated */    if( startIdx > endIdx )
427 /* Generated */    {
428 /* Generated */       VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
429 /* Generated */       VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
430 /* Generated */       return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
431 /* Generated */    }
432 /* Generated */    if( lookbackTotal > startIdx )
433 /* Generated */       tempInt = lookbackTotal;
434 /* Generated */    else
435 /* Generated */ 	  tempInt = startIdx;
436 /* Generated */    if( tempInt > endIdx )
437 /* Generated */    {
438 /* Generated */       VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
439 /* Generated */       VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
440 /* Generated */       return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
441 /* Generated */    }
442 /* Generated */    outputSize = endIdx - tempInt + 1;
443 /* Generated */    ARRAY_ALLOC(localOutputArray,outputSize);
444 /* Generated */    ARRAY_INT_ALLOC(localPeriodArray,outputSize);
445 /* Generated */    for( i=0; i < outputSize; i++ )
446 /* Generated */    {
447 /* Generated */       tempInt = (int)(inPeriods[startIdx+i]);
448 /* Generated */ 	  if( tempInt < optInMinPeriod )
449 /* Generated */ 		  tempInt = optInMinPeriod;
450 /* Generated */ 	  else if( tempInt > optInMaxPeriod )
451 /* Generated */           tempInt = optInMaxPeriod;
452 /* Generated */       localPeriodArray[i] = tempInt;
453 /* Generated */    }
454 /* Generated */    for( i=0; i < outputSize; i++ )
455 /* Generated */    {
456 /* Generated */ 	   curPeriod = localPeriodArray[i];
457 /* Generated */ 	   if( curPeriod != 0 )
458 /* Generated */ 	   {
459 /* Generated */ 		   retCode = FUNCTION_CALL(MA)( startIdx, endIdx, inReal,
460 /* Generated */ 			                            curPeriod, optInMAType,
461 /* Generated */ 									    VALUE_HANDLE_OUT(localBegIdx),VALUE_HANDLE_OUT(localNbElement),localOutputArray );
462 /* Generated */            if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) )
463 /* Generated */ 		   {
464 /* Generated */               ARRAY_FREE(localOutputArray);
465 /* Generated */ 			  ARRAY_INT_FREE(localPeriodArray);
466 /* Generated */               VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
467 /* Generated */               VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
468 /* Generated */               return retCode;
469 /* Generated */ 	       }
470 /* Generated */ 		   outReal[i] = localOutputArray[i];
471 /* Generated */ 		   for( j=i+1; j < outputSize; j++ )
472 /* Generated */ 		   {
473 /* Generated */ 			   if( localPeriodArray[j] == curPeriod )
474 /* Generated */ 			   {
475 /* Generated */ 				   localPeriodArray[j] = 0;
476 /* Generated */ 				   outReal[j] = localOutputArray[j];
477 /* Generated */ 			   }
478 /* Generated */ 		   }
479 /* Generated */ 	   }
480 /* Generated */    }
481 /* Generated */    ARRAY_FREE(localOutputArray);
482 /* Generated */    ARRAY_INT_FREE(localPeriodArray);
483 /* Generated */    VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
484 /* Generated */    VALUE_HANDLE_DEREF(outNBElement) = outputSize;
485 /* Generated */    return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
486 /* Generated */ }
487 /* Generated */
488 /* Generated */ #if defined( _MANAGED )
489 /* Generated */ }}} // Close namespace TicTacTec.TA.Lib
490 /* Generated */ #endif
491 /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
492 
493