11/*
22 * This file is part of OpenModelica.
33 *
4- * Copyright (c) 1998-2010, Link�pings University,
5- * Department of Computer and Information Science,
6- * SE-58183 Link�ping , Sweden.
4+ * Copyright (c) 1998-2010, Linköpings University,
5+ * Department of Computer and Information Science,
6+ * SE-58183 Linköping , Sweden.
77 *
88 * All rights reserved.
99 *
1414 *
1515 * The OpenModelica software and the Open Source Modelica
1616 * Consortium (OSMC) Public License (OSMC-PL) are obtained
17- * from Link�pings University, either from the above address,
17+ * from Linköpings University, either from the above address,
1818 * from the URL: http://www.ida.liu.se/projects/OpenModelica
1919 * and in the OpenModelica distribution.
2020 *
@@ -69,14 +69,14 @@ modelica_boolean sample(DATA *data, double start, double interval, int hindex)
6969 double retVal ;
7070 double tmp = 1 ;
7171 int tmpindex = data -> simulationInfo .curSampleTimeIx ;
72-
72+
7373 if (tmpindex < data -> simulationInfo .nSampleTimes ){
7474 while ((data -> simulationInfo .sampleTimes [tmpindex ]).activated == 1 ){
7575 if ((data -> simulationInfo .sampleTimes [tmpindex ]).zc_index == hindex )
7676 tmp = 0 ;
77-
77+
7878 tmpindex ++ ;
79-
79+
8080 if (tmpindex == data -> simulationInfo .nSampleTimes )
8181 break ;
8282 }
@@ -162,12 +162,12 @@ void initSample(DATA* data, double start, double stop)
162162 /* not used yet
163163 * long measure_start_time = clock();
164164 */
165-
165+
166166 /* This code will generate an array of time values when sample generates events.
167167 * The only problem is our backend does not generate this array.
168168 * Sample() and sample() also need to be changed, but this should be easy to fix.
169169 */
170-
170+
171171 int i ;
172172 /* double stop = 1.0; */
173173 double d ;
@@ -194,19 +194,19 @@ void initSample(DATA* data, double start, double stop)
194194
195195 for (i = 0 ; i < num_samples ; i ++ ){
196196 DEBUG_INFO2 (LOG_EVENTS , "Generate times for sample(%f, %f)" , data -> simulationInfo .rawSampleExps [i ].start , data -> simulationInfo .rawSampleExps [i ].interval );
197-
197+
198198 for (d = data -> simulationInfo .rawSampleExps [i ].start ; ix < max_events && d <= stop ; d += data -> simulationInfo .rawSampleExps [i ].interval ){
199199 (Samples [ix ]).events = d ;
200200 (Samples [ix ++ ]).zc_index = (data -> simulationInfo .rawSampleExps [i ]).zc_index ;
201-
201+
202202 DEBUG_INFO3 (LOG_EVENTS , "Generate sample(%f, %f, %d)" , d , data -> simulationInfo .rawSampleExps [i ].interval , (data -> simulationInfo .rawSampleExps [i ]).zc_index );
203203 }
204204 }
205-
205+
206206 /* Sort, filter out unique values */
207207 qsort (Samples , max_events , sizeof (SAMPLE_TIME ), compSample );
208208 nuniq = unique (Samples , max_events , sizeof (SAMPLE_TIME ), compSampleZC );
209-
209+
210210 DEBUG_INFO1 (LOG_INIT , "Number of sorted, unique sample events: %d" , nuniq );
211211 for (i = 0 ; i < nuniq ; i ++ )
212212 DEBUG_INFO_AL3 (LOG_INIT , "%f\t HelpVar[%d]=activated(%d)" , (Samples [i ]).events , (Samples [i ]).zc_index ,(Samples [i ]).activated );
@@ -227,8 +227,7 @@ void initSample(DATA* data, double start, double stop)
227227 * ! Function check if a sample expression should be activated
228228 *
229229 */
230- int
231- checkForSampleEvent (DATA * data , SOLVER_INFO * solverInfo )
230+ int checkForSampleEvent (DATA * data , SOLVER_INFO * solverInfo )
232231{
233232 double a = solverInfo -> currentTime + solverInfo -> currentStepSize ;
234233 int b = 0 ;
@@ -268,8 +267,7 @@ checkForSampleEvent(DATA *data, SOLVER_INFO* solverInfo)
268267 * ! Function activated sample expression
269268 *
270269 */
271- int
272- activateSampleEvents (DATA * data )
270+ int activateSampleEvents (DATA * data )
273271{
274272 if (data -> simulationInfo .curSampleTimeIx < data -> simulationInfo .nSampleTimes )
275273 {
@@ -305,8 +303,7 @@ activateSampleEvents(DATA *data)
305303 * ! Function deactivate, before activated sample expression
306304 *
307305 */
308- void
309- deactivateSampleEvents (DATA * data )
306+ void deactivateSampleEvents (DATA * data )
310307{
311308 int tmpindex = data -> simulationInfo .curSampleTimeIx ;
312309
@@ -321,8 +318,7 @@ deactivateSampleEvents(DATA *data)
321318 * ! Function deactivate, before activated sample expression in equations
322319 *
323320 */
324- void
325- deactivateSampleEventsandEquations (DATA * data )
321+ void deactivateSampleEventsandEquations (DATA * data )
326322{
327323 while ((data -> simulationInfo .sampleTimes [data -> simulationInfo .curSampleTimeIx ]).activated == 1 )
328324 {
@@ -341,8 +337,7 @@ deactivateSampleEventsandEquations(DATA *data)
341337 If a ZeroCrossing Function cause a sign change, root finding
342338 process will start
343339*/
344- int
345- CheckForNewEvent (DATA * simData , modelica_boolean * sampleactived , double * currentTime )
340+ int CheckForNewEvent (DATA * simData , modelica_boolean * sampleactived , double * currentTime )
346341{
347342 long i = 0 ;
348343 LIST * eventList = NULL ;
@@ -479,7 +474,7 @@ void FindRoot(DATA* simData, double *EventTime, LIST *eventList)
479474 LIST_NODE * it ;
480475 fortran_integer i = 0 ;
481476 static LIST * tmpEventList = NULL ;
482-
477+
483478 double * states_right = (double * ) malloc (simData -> modelData .nStates * sizeof (double ));
484479 double * states_left = (double * ) malloc (simData -> modelData .nStates * sizeof (double ));
485480
@@ -513,9 +508,10 @@ void FindRoot(DATA* simData, double *EventTime, LIST *eventList)
513508 double value = fabs (simData -> simulationInfo .zeroCrossings [* ((long * )listFirstData (eventList ))]);
514509 for (it = listFirstNode (eventList ); it ; it = listNextNode (it ))
515510 {
516- if (value > fabs (simData -> simulationInfo .zeroCrossings [* ((long * )listNodeData (it ))]))
511+ double fvalue = fabs (simData -> simulationInfo .zeroCrossings [* ((long * )listNodeData (it ))]);
512+ if (value > fvalue )
517513 {
518- value = fabs ( simData -> simulationInfo . zeroCrossings [ * (( long * ) listNodeData ( it ))]) ;
514+ value = fvalue ;
519515 }
520516 }
521517 DEBUG_INFO1 (LOG_ZEROCROSSINGS , "Minimum value: %f" , value );
@@ -652,12 +648,11 @@ double BiSection(DATA* simData, double* a, double* b, double* states_a,
652648 Check if at least one zerocrossing has change sign
653649 is used in BiSection
654650*/
655- int
656- CheckZeroCrossings (DATA * simData , LIST * tmpEventList , LIST * eventList )
651+ int CheckZeroCrossings (DATA * simData , LIST * tmpEventList , LIST * eventList )
657652{
658653
659654 LIST_NODE * it ;
660-
655+
661656 listClear (tmpEventList );
662657 for (it = listFirstNode (eventList ); it ; it = listNextNode (it ))
663658 {
@@ -690,8 +685,7 @@ CheckZeroCrossings(DATA *simData, LIST *tmpEventList, LIST *eventList)
690685}
691686
692687
693- void
694- SaveZeroCrossingsAfterEvent (DATA * simData )
688+ void SaveZeroCrossingsAfterEvent (DATA * simData )
695689{
696690 long i = 0 ;
697691
@@ -704,8 +698,7 @@ SaveZeroCrossingsAfterEvent(DATA* simData)
704698}
705699
706700
707- void
708- initializeZeroCrossings (DATA * simData )
701+ void initializeZeroCrossings (DATA * simData )
709702{
710703 long i = 0 ;
711704 for (i = 0 ; i < simData -> modelData .nZeroCrossings ; i ++ )
@@ -721,8 +714,7 @@ initializeZeroCrossings(DATA* simData)
721714 }
722715}
723716
724- void
725- correctDirectionZeroCrossings (DATA * simData )
717+ void correctDirectionZeroCrossings (DATA * simData )
726718{
727719 long i = 0 ;
728720 for (i = 0 ; i < simData -> modelData .nZeroCrossings ; i ++ )
0 commit comments