Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Initial revision
[simgrid.git] / src / nws_portability / Forecast / last_value.c
1 /* $Id$ */
2
3 #include <unistd.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <math.h>
7 #include <string.h>
8 #include <strings.h>
9
10 #include "fbuff.h"
11 #include "last_value.h"
12
13 struct last_value_state
14 {
15         fbuff series;                   /* the series so far */
16         fbuff time_stamps;              /* the time stamps */
17         double value;
18 };
19
20 /*
21  * init local state.  can save a copy of the pointer to the
22  * series and time stamps, if desired
23  */
24 char *
25 InitLastValue(fbuff series, fbuff time_stamps, char *params)
26 {
27         struct last_value_state *state;
28         
29         state = (struct last_value_state *)
30                 malloc(sizeof(struct last_value_state));
31         
32         if(state == NULL)
33         {
34                 return(NULL);
35         }
36         
37         /*
38          * all functions take a forcb
39          */
40         state->series = series;
41         state->time_stamps = time_stamps;
42         
43         return((char *)state);
44 }
45
46 void
47 FreeLastValue(char *state)
48 {
49         free(state);
50         return;
51 }
52
53 void
54 UpdateLastValue(char *state,
55                 double ts,
56                 double value)
57 {
58         /*
59          * no op -- will just grab it from series
60          */
61         return;
62 }
63
64 int
65 ForcLastValue(char *state, double *v)
66 {
67         double val;
68         struct last_value_state *s = (struct last_value_state *)state;
69         
70         if(!IS_EMPTY(s->series))
71         {
72                 val = F_VAL(s->series,F_FIRST(s->series));
73                 *v = val;
74                 return(1);
75         }
76         else
77         {
78                 *v = 0.0;
79                 return(0);
80         }
81 }
82
83