annotate Allan.c @ 134:bd28161e5ac2

Major code cleanup
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Wed, 22 Jan 2014 12:29:28 +0100
parents 0e9f95525a8f
children 77539f2597b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
1 #include <ansi_c.h>
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
2 #include <userint.h>
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
3
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
4 #include "YLCStuff.h"
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
5
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
6 #include "FXAllan.h" // Auto generated panel definitions and protypes
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
7 #include "Allan.h" // My own .h file, containing prototypes and definitions for the class Allan...
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
8
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
9
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
10
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
11 // ******************* Member functions : constructor and destructor *************************
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
12
134
bd28161e5ac2 Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
13 int Allan_InitPanel(Allan_Data * Instance, const char * title, double Normalizer, int parent, int control) {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
14
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
15 int i ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
16
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
17 if ((Instance->AllanPanel = LoadPanel (0, "FXAllan.uir", ALLANPANEL)) < 0)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
18 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
19 SetPanelAttribute(Instance->AllanPanel, ATTR_TITLE, title) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
20 SetPanelAttribute (Instance->AllanPanel, ATTR_CALLBACK_DATA, (void *)Instance); // the panel callback therefore knows which data structure it is associated to
134
bd28161e5ac2 Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
21 Instance->active = TRUE;
bd28161e5ac2 Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
22 Instance->parent = parent;
bd28161e5ac2 Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
23 Instance->control = control;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
24 for (i=0 ; i<ALLAN_MAXPOINTSNUMBER ; i++) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
25 Instance->AllanVar[i] = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
26 Instance->LastMean[i] = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
27 Instance->BlocksNumber[i] = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
28 Instance->CurrentAverage[i] = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
29 Instance->NbCurrentAverage[i] = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
30 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
31 Instance->Drift = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
32 DisplayPanel (Instance->AllanPanel);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
33 SetCtrlVal(Instance->AllanPanel, ALLANPANEL_NORMALIZER, Normalizer) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
34 return 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
35 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
36
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
37
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
38
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
39 int Allan_ClosePanel(Allan_Data * Instance) {
134
bd28161e5ac2 Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
40 Instance->active = FALSE;
bd28161e5ac2 Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 103
diff changeset
41 SetCtrlVal(Instance->parent, Instance->control, FALSE);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
42 DiscardPanel (Instance->AllanPanel);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
43 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
44 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
45
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
46
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
47
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
48 // ******************** Member functions, callbacks (private) *******************************
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
49
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
50
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
51 int CVICALLBACK Allan_CB_Reset(int panel, int control, int event,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
52 void *callbackData, int eventData1, int eventData2)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
53 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
54 Allan_Data * Instance = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
55
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
56 switch(event) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
57
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
58 case EVENT_COMMIT:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
59 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &Instance);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
60 Allan_Reset(Instance) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
61 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
62
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
63 case EVENT_RIGHT_CLICK:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
64
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
65 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
66 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
67
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
68 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
69 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
70
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
71 int CVICALLBACK Allan_CB_ChangeMax (int panel, int control, int event,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
72 void *callbackData, int eventData1, int eventData2)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
73 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
74 int YMin, YMax ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
75
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
76 switch (event)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
77 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
78 case EVENT_COMMIT:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
79 GetCtrlVal(panel, ALLANPANEL_MIN, &YMin) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
80 GetCtrlVal(panel, ALLANPANEL_MAX, &YMax) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
81 if (YMin<YMax) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
82 SetAxisScalingMode(panel, ALLANPANEL_ALLANPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, pow(10,(double)YMin), pow(10,(double)YMax) ) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
83 SetCtrlVal(panel, ALLANPANEL_CHECKBOX_AUTOSCALE, FALSE) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
84 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
85 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
86
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
87 case EVENT_RIGHT_CLICK:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
88
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
89 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
90 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
91 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
92 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
93
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
94 int CVICALLBACK Allan_CB_ChangeMin (int panel, int control, int event,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
95 void *callbackData, int eventData1, int eventData2)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
96 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
97 int YMin, YMax ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
98
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
99 switch (event)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
100 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
101 case EVENT_COMMIT:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
102 GetCtrlVal(panel, ALLANPANEL_MIN, &YMin) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
103 GetCtrlVal(panel, ALLANPANEL_MAX, &YMax) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
104 if (YMin<YMax ) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
105 SetAxisScalingMode(panel, ALLANPANEL_ALLANPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, pow(10,(double)YMin), pow(10,(double)YMax) ) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
106 SetCtrlVal(panel, ALLANPANEL_CHECKBOX_AUTOSCALE, FALSE) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
107 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
108 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
109
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
110 case EVENT_RIGHT_CLICK:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
111
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
112 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
113 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
114 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
115 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
116
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
117
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
118 int CVICALLBACK Allan_CB_ChangeAutoScale (int panel, int control, int event,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
119 void *callbackData, int eventData1, int eventData2)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
120 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
121 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
122 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
123
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
124
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
125 int CVICALLBACK Allan_CB_ChangeNormalizer (int panel, int control, int event,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
126 void *callbackData, int eventData1, int eventData2)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
127 { /*
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
128 bool AutoScale = FALSE;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
129 int NotCare = 20000000 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
130 double YMin = 10000000 , YMax = 64000000 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
131
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
132 switch (event)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
133 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
134 case EVENT_COMMIT:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
135 GetCtrlVal(panel, ALLANPANEL_CHECKBOX_AUTOSCALE, &AutoScale) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
136 if (AutoScale) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
137 SetAxisScalingMode(panel, ALLANPANEL_ALLANPLOT, VAL_LEFT_YAXIS, VAL_AUTOSCALE, YMin, YMax) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
138 GetAxisScalingMode(panel, ALLANPANEL_ALLANPLOT,VAL_LEFT_YAXIS, &NotCare, &YMin, &YMax ) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
139 SetCtrlVal(panel, ALLANPANEL_MIN, YMin);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
140 SetCtrlVal(panel, ALLANPANEL_MAX, YMax);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
141 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
142 else {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
143 GetCtrlVal(panel, ALLANPANEL_MIN, &YMin);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
144 GetCtrlVal(panel, ALLANPANEL_MAX, &YMax);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
145 SetAxisScalingMode(panel, ALLANPANEL_ALLANPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, YMin, YMax) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
146 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
147 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
148 case EVENT_RIGHT_CLICK:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
149
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
150 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
151 } */
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
152 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
153 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
154
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
155
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
156
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
157 // ******************** Member functions, public *****************************************
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
158
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
159 int Allan_Reset(Allan_Data * Instance) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
160
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
161 int i ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
162
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
163 for (i=0 ; i<ALLAN_MAXPOINTSNUMBER ; i++) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
164 Instance->AllanVar[i] = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
165 Instance->LastMean[i] = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
166 Instance->BlocksNumber[i] = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
167 Instance->CurrentAverage[i] = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
168 Instance->NbCurrentAverage[i] = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
169 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
170
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
171 return 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
172
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
173 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
174
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
175
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
176 int Allan_AddFrequency(Allan_Data * Instance, double Freq) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
177
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
178 int i, N;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
179 double CurrentMean, LastMean, Drift, Mean, Normalizer ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
180
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
181 N = Instance->BlocksNumber[0]+1 ; // the total number of points used, usefull to calculate drift rate
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
182 Mean = Instance->Mean ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
183 Drift = Instance->Drift ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
184
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
185 GetCtrlVal(Instance->AllanPanel, ALLANPANEL_NORMALIZER, &Normalizer);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
186
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
187 if (N > 1) { // Drift measure needs at least 2 values !
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
188 Instance->Drift = (Drift*(N-2) + 6*(Freq-Mean)/N)/(N+1) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
189 SetCtrlVal(Instance->AllanPanel, ALLANPANEL_DRIFT, Instance->Drift/Normalizer ) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
190 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
191
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
192 // update mean value (usefull to calculate drift rate with linear regression incremental algorithm...)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
193 Instance->Mean = (Mean*(N-1)+Freq)/N ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
194
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
195
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
196 for (i=0 ; i<ALLAN_MAXPOINTSNUMBER ; i++) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
197 Instance->CurrentAverage[i] = (Instance->CurrentAverage[i]*Instance->NbCurrentAverage[i] + Freq)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
198 /(Instance->NbCurrentAverage[i]+1) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
199 Instance->NbCurrentAverage[i] +=1 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
200
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
201 if (Instance->NbCurrentAverage[i] >= pow(2,i) ) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
202
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
203 CurrentMean = Instance->CurrentAverage[i];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
204 LastMean = Instance->LastMean[i] ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
205 N = Instance->BlocksNumber[i] ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
206 N++ ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
207 Instance->CurrentAverage[i] = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
208 Instance->NbCurrentAverage[i] = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
209 if (N>1) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
210 Instance->AllanVar[i] = (Instance->AllanVar[i]*(N-2)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
211 +0.5*pow(CurrentMean-LastMean,2))/(N-1) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
212 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
213 else { // ie if N=1, which is realized for the first completed block
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
214 Instance->FirstMean[i] = CurrentMean ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
215 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
216 Instance->LastMean[i] = CurrentMean ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
217 Instance->BlocksNumber[i] = N ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
218 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
219 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
220
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
221 Allan_Display(Instance, VAL_WHITE, VAL_BLUE) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
222
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
223 return 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
224 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
225
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
226 int Allan_Display (Allan_Data * Instance, int ColorPt, int ColorErrorBar){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
227
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
228 int PointsNumber = ALLAN_MAXPOINTSNUMBER ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
229 int i, N ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
230 double X[ALLAN_MAXPOINTSNUMBER] ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
231 double Y[ALLAN_MAXPOINTSNUMBER] ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
232 double Normalizer, DriftTau, FirstFreq, LastFreq, Error ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
233 bool DeDrift ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
234
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
235 GetCtrlVal(Instance->AllanPanel, ALLANPANEL_NORMALIZER, &Normalizer) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
236 GetCtrlVal(Instance->AllanPanel, ALLANPANEL_DEDRIFT, &DeDrift) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
237
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
238 for (i=0 ; i<PointsNumber ; i++) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
239 X[i] = pow(2,i) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
240 if (!DeDrift) { Y[i] = sqrt(Instance->AllanVar[i])/Normalizer ;}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
241 else {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
242 DriftTau = Instance->Drift*X[i] ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
243 N = Instance->BlocksNumber[i] ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
244 if (N>=2) { // if enough data to calculate AVAR for tau = 2^i*tau0, and therefore, AllanVar[i] is meaningful
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
245 FirstFreq = Instance->FirstMean[i] ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
246 LastFreq = Instance->LastMean[i] ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
247 Y[i] = sqrt(Instance->AllanVar[i]+DriftTau*(DriftTau/2-(LastFreq-FirstFreq)/(N-1)))/Normalizer ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
248 // Not totaly sure it works... to be checked thoroughly
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
249 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
250 else { Y[i] = 0 ; } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
251 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
252 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
253
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
254 DeleteGraphPlot(Instance->AllanPanel, ALLANPANEL_ALLANPLOT, -1, VAL_IMMEDIATE_DRAW) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
255 PlotXY (Instance->AllanPanel, ALLANPANEL_ALLANPLOT, X, Y, PointsNumber,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
256 VAL_DOUBLE, VAL_DOUBLE, VAL_SCATTER, VAL_SOLID_SQUARE, VAL_SOLID, 1, ColorPt);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
257
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
258 for (i=0 ; i<PointsNumber ; i++) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
259 Error = 1/sqrt(Instance->BlocksNumber[i]) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
260 PlotLine (Instance->AllanPanel, ALLANPANEL_ALLANPLOT, X[i], Y[i]*(1-Error), X[i], Y[i]*(1+Error), ColorErrorBar);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
261 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
262
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
263
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
264 return 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
265 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
266
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
267 int Allan_DisplayErrorBars (Allan_Data * Instance, int color){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
268
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
269 int i;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
270 double X[ALLAN_MAXPOINTSNUMBER] ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
271 double Val, Error, Normalizer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
272
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
273 GetCtrlVal(Instance->AllanPanel, ALLANPANEL_NORMALIZER, &Normalizer) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
274 for (i=0 ; i<ALLAN_MAXPOINTSNUMBER ; i++) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
275 X[i] = pow(2,i) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
276 Val = sqrt(Instance->AllanVar[i])/Normalizer ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
277 Error = 1/sqrt(Instance->BlocksNumber[i]) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
278 PlotLine (Instance->AllanPanel, ALLANPANEL_ALLANPLOT, X[i], Val*(1-Error), X[i], Val*(1+Error), color);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
279 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
280
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
281 return 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
282 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
283
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
284 int CVICALLBACK CB_GeneralAllanPanel (int panel, int event, void *callbackData,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
285 int eventData1, int eventData2)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
286 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
287 Allan_Data * Instance = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
288
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
289
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
290 switch (event)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
291 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
292 case EVENT_GOT_FOCUS:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
293
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
294 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
295 case EVENT_LOST_FOCUS:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
296
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
297 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
298 case EVENT_CLOSE:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
299 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &Instance);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
300 Allan_ClosePanel(Instance) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
301
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
302 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
303 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
304 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
305 }