Mercurial > hg > fxanalyse
annotate Plot.c @ 248:eaac96094640
Minor style improvements
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Mon, 04 May 2015 17:46:52 +0200 |
parents | a3494d2806ee |
children |
rev | line source |
---|---|
0 | 1 #include <ansi_c.h> |
2 #include <userint.h> | |
3 | |
144 | 4 #include "utils.h" |
135 | 5 #include "FXPlot.h" |
6 #include "Plot.h" | |
0 | 7 |
218
a3494d2806ee
Change plot lines color to red
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
144
diff
changeset
|
8 #define PLOT_LINE_COLOR VAL_RED |
a3494d2806ee
Change plot lines color to red
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
144
diff
changeset
|
9 |
135 | 10 void Plot_InitPanel(Plot_Data *Instance, const char *title, double ymin, double ymax, int parent, int control) |
11 { | |
0 | 12 if ((Instance->PlotPanel = LoadPanel (0, "FXPlot.uir", PLOTPANEL)) < 0) |
135 | 13 return; |
14 | |
15 SetPanelAttribute(Instance->PlotPanel, ATTR_TITLE, title); | |
16 SetPanelAttribute(Instance->PlotPanel, ATTR_CALLBACK_DATA, (void *)Instance); | |
134
bd28161e5ac2
Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
21
diff
changeset
|
17 Instance->active = TRUE; |
bd28161e5ac2
Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
21
diff
changeset
|
18 Instance->parent = parent; |
bd28161e5ac2
Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
21
diff
changeset
|
19 Instance->control = control; |
135 | 20 Instance->IndexPoint = 0; |
21 Instance->Mean = 0; | |
0 | 22 Instance->Slope = 0; |
135 | 23 Instance->ADev = 0; |
24 Instance->Frequencies = calloc(MAXPOINTSNUMBER, sizeof(double)); | |
25 DisplayPanel(Instance->PlotPanel); | |
26 | |
27 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MIN, ymin); | |
28 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MAX, ymax); | |
29 | |
30 if ((ymin != 0.0) && (ymax != 0.0)) { | |
31 /* manual scaling */ | |
32 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MIN, ymin); | |
33 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MAX, ymax); | |
34 SetAxisScalingMode(Instance->PlotPanel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, ymin, ymax); | |
35 } else { | |
36 /* auto scaling */ | |
37 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_CHECKBOX_AUTOSCALE, TRUE); | |
38 SetAxisScalingMode(Instance->PlotPanel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_AUTOSCALE, 0, 0); | |
0 | 39 } |
135 | 40 } |
0 | 41 |
42 | |
135 | 43 void Plot_ClosePanel(Plot_Data * Instance) |
44 { | |
134
bd28161e5ac2
Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
21
diff
changeset
|
45 Instance->active = FALSE; |
bd28161e5ac2
Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
21
diff
changeset
|
46 free(Instance->Frequencies); |
bd28161e5ac2
Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
21
diff
changeset
|
47 SetCtrlVal(Instance->parent, Instance->control, FALSE); |
135 | 48 DiscardPanel(Instance->PlotPanel); |
49 } | |
50 | |
0 | 51 |
135 | 52 void Plot_AddFrequency(Plot_Data * Instance, double Freq) |
53 { | |
54 double Drift = 0; | |
55 int DeDrift; | |
56 int N = 0; | |
0 | 57 |
135 | 58 double Mean = Instance->Mean; |
59 double Slope = Instance->Slope; | |
60 double ADev = Instance->ADev; | |
61 | |
62 /* Correct Freq with drift (feed forward) if dedrift is on */ | |
63 GetCtrlVal(Instance->PlotPanel, PLOTPANEL_CHECKBOX_DEDRIFT, &DeDrift); | |
64 if (DeDrift) { | |
65 GetCtrlVal(Instance->PlotPanel, PLOTPANEL_DEDRIFT, &Drift); | |
66 Freq -= ((double) Instance->IndexPoint)*Drift; | |
67 } | |
68 | |
69 /* Add Freq to graph plot */ | |
70 Instance->Frequencies[Instance->IndexPoint++] = Freq; | |
71 N = Instance->IndexPoint; | |
72 | |
73 if (N > 1) { | |
74 /* adev and slope computation need at least 2 data points */ | |
75 Instance->Slope = (Slope*(N-2) + 6*(Freq-Mean)/N)/(N+1); | |
76 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_SLOPE, Instance->Slope); | |
77 Instance->ADev = sqrt( ( ADev*ADev*(N-2) + 0.5*pow(Freq-Instance->Frequencies[N-2],2) ) / (N-1)); | |
78 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_ADEV, Instance->ADev); | |
79 } | |
80 Instance->Mean = (Mean*(N-1)+Freq)/N; | |
81 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MEAN, Instance->Mean); | |
0 | 82 |
135 | 83 /* if too many points recorded restart */ |
84 if (N > MAXPOINTSNUMBER - 2) { | |
85 Instance->IndexPoint = 0; | |
86 Instance->Mean = 0; | |
87 Instance->Slope = 0; | |
88 Instance->ADev = 0; | |
89 SetCtrlVal(Instance->PlotPanel,PLOTPANEL_MEAN, 0.0); | |
90 SetCtrlVal(Instance->PlotPanel,PLOTPANEL_SLOPE, 0.0); | |
91 SetCtrlVal(Instance->PlotPanel,PLOTPANEL_ADEV, 0.0); | |
92 } | |
93 | |
94 DeleteGraphPlot(Instance->PlotPanel, PLOTPANEL_FREQPLOT, -1, VAL_IMMEDIATE_DRAW); | |
95 PlotY(Instance->PlotPanel, PLOTPANEL_FREQPLOT, Instance->Frequencies, Instance->IndexPoint, | |
218
a3494d2806ee
Change plot lines color to red
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
144
diff
changeset
|
96 VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, PLOT_LINE_COLOR); |
0 | 97 |
135 | 98 int autoscale; |
99 GetCtrlVal(Instance->PlotPanel, PLOTPANEL_CHECKBOX_AUTOSCALE, &autoscale); | |
100 if (autoscale) { | |
101 /* update plot limits */ | |
102 double ymin, ymax; | |
103 GetAxisScalingMode(Instance->PlotPanel, PLOTPANEL_FREQPLOT,VAL_LEFT_YAXIS, NULL, &ymin, &ymax); | |
104 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MIN, ymin); | |
105 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MAX, ymax); | |
106 /* adjust control limits */ | |
107 SetCtrlAttribute(Instance->PlotPanel, PLOTPANEL_MIN, ATTR_MAX_VALUE, ymax); | |
108 SetCtrlAttribute(Instance->PlotPanel, PLOTPANEL_MAX, ATTR_MIN_VALUE, ymin); | |
109 } | |
110 } | |
111 | |
112 | |
113 /* callbacks */ | |
114 | |
115 int CVICALLBACK CB_PlotEvent(int panel, int event, | |
116 void *callbackData, int eventData1, int eventData2) | |
117 { | |
0 | 118 switch (event) |
119 { | |
135 | 120 case EVENT_CLOSE: |
121 Plot_Data *data; | |
122 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &data); | |
123 Plot_ClosePanel(data); | |
124 break; | |
0 | 125 |
135 | 126 case EVENT_KEYPRESS: |
127 int keycode = GetKeyPressEventVirtualKey(eventData2); | |
128 int index; | |
129 double step; | |
130 switch (keycode) | |
131 { | |
132 case 2304: /* right arrow */ | |
133 GetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, &index); | |
134 if (index < 10) { | |
135 SetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, ++index); | |
136 GetCtrlVal(panel, PLOTPANEL_SCALINGSTEP, &step); | |
137 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_INCR_VALUE, step); | |
138 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_INCR_VALUE, step); | |
139 } | |
140 break; | |
141 case 2048: /* left arrow */ | |
142 GetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, &index); | |
143 if (index > 0) { | |
144 SetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, --index); | |
145 GetCtrlVal(panel, PLOTPANEL_SCALINGSTEP, &step); | |
146 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_INCR_VALUE, step); | |
147 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_INCR_VALUE, step); | |
148 } | |
149 break; | |
150 } | |
0 | 151 break; |
152 } | |
153 return 0; | |
154 } | |
155 | |
135 | 156 |
157 int CVICALLBACK Plot_CB_ChangeYLim (int panel, int control, int event, | |
0 | 158 void *callbackData, int eventData1, int eventData2) |
159 { | |
135 | 160 double ymin, ymax; |
0 | 161 |
162 switch (event) | |
135 | 163 { |
0 | 164 case EVENT_COMMIT: |
135 | 165 GetCtrlVal(panel, PLOTPANEL_MIN, &ymin); |
166 GetCtrlVal(panel, PLOTPANEL_MAX, &ymax); | |
167 /* adjust control limits */ | |
168 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_MAX_VALUE, ymax); | |
169 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_MIN_VALUE, ymin); | |
170 /* disable autoscaling */ | |
171 SetCtrlVal(panel, PLOTPANEL_CHECKBOX_AUTOSCALE, FALSE); | |
172 SetAxisScalingMode(panel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, ymin, ymax); | |
0 | 173 break; |
135 | 174 } |
0 | 175 return 0; |
176 } | |
177 | |
178 | |
179 int CVICALLBACK Plot_CB_ChangeAutoScale (int panel, int control, int event, | |
180 void *callbackData, int eventData1, int eventData2) | |
181 { | |
135 | 182 int autoscale = FALSE; |
183 double ymin, ymax; | |
0 | 184 |
185 switch (event) | |
135 | 186 { |
0 | 187 case EVENT_COMMIT: |
135 | 188 GetCtrlVal(panel, PLOTPANEL_CHECKBOX_AUTOSCALE, &autoscale); |
189 if (autoscale) { | |
190 SetAxisScalingMode(panel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_AUTOSCALE, 0, 0); | |
191 GetAxisScalingMode(panel, PLOTPANEL_FREQPLOT,VAL_LEFT_YAXIS, NULL, &ymin, &ymax); | |
192 SetCtrlVal(panel, PLOTPANEL_MIN, ymin); | |
193 SetCtrlVal(panel, PLOTPANEL_MAX, ymax); | |
194 /* adjust control limits */ | |
195 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_MAX_VALUE, ymax); | |
196 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_MIN_VALUE, ymin); | |
197 } else { | |
198 GetCtrlVal(panel, PLOTPANEL_MIN, &ymin); | |
199 GetCtrlVal(panel, PLOTPANEL_MAX, &ymax); | |
200 SetAxisScalingMode(panel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, ymin, ymax); | |
201 } | |
0 | 202 break; |
135 | 203 } |
0 | 204 return 0; |
205 } | |
206 | |
135 | 207 |
0 | 208 int CVICALLBACK Plot_CB_ChangeScalingStep(int panel, int control, int event, |
209 void *callbackData, int eventData1, int eventData2) | |
210 { | |
135 | 211 double step; |
0 | 212 |
213 switch (event) | |
135 | 214 { |
0 | 215 case EVENT_COMMIT: |
135 | 216 GetCtrlVal(panel, PLOTPANEL_SCALINGSTEP, &step); |
217 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_INCR_VALUE, step); | |
218 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_INCR_VALUE, step); | |
0 | 219 break; |
135 | 220 } |
0 | 221 return 0; |
222 } | |
223 | |
224 | |
225 int CVICALLBACK Plot_CB_Reset (int panel, int control, int event, | |
226 void *callbackData, int eventData1, int eventData2) | |
227 { | |
135 | 228 Plot_Data *data; |
0 | 229 switch (event) |
135 | 230 { |
0 | 231 case EVENT_COMMIT: |
135 | 232 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &data); |
233 data->IndexPoint = 0; | |
234 data->Mean = 0; | |
235 data->Slope = 0; | |
236 data->ADev = 0; | |
0 | 237 break; |
135 | 238 } |
0 | 239 return 0; |
240 } | |
241 | |
242 | |
243 int CVICALLBACK Plot_CB_GetDrift (int panel, int control, int event, | |
244 void *callbackData, int eventData1, int eventData2) | |
245 { | |
135 | 246 Plot_Data *data; |
247 int dedrift; | |
248 double drift; | |
0 | 249 |
250 switch (event) | |
135 | 251 { |
0 | 252 case EVENT_COMMIT: |
135 | 253 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &data); |
254 GetCtrlVal(panel, PLOTPANEL_CHECKBOX_DEDRIFT, &dedrift); | |
255 if (dedrift) { | |
256 GetCtrlVal(panel, PLOTPANEL_DEDRIFT, &drift); | |
257 drift += data->Slope; | |
258 SetCtrlVal(panel, PLOTPANEL_DEDRIFT, drift); | |
259 data->IndexPoint = 0; | |
260 data->Mean = 0; | |
261 data->Slope = 0; | |
262 data->ADev = 0; | |
263 } else | |
264 SetCtrlVal(panel,PLOTPANEL_DEDRIFT, data->Slope); | |
0 | 265 break; |
135 | 266 } |
0 | 267 return 0; |
268 } | |
269 | |
135 | 270 |
0 | 271 int CVICALLBACK Plot_CB_ChangeDrift (int panel, int control, int event, |
272 void *callbackData, int eventData1, int eventData2) | |
273 { | |
135 | 274 int dedrift; |
275 Plot_Data *data; | |
0 | 276 |
277 switch (event) | |
135 | 278 { |
0 | 279 case EVENT_COMMIT: |
135 | 280 GetCtrlVal(panel, PLOTPANEL_CHECKBOX_DEDRIFT, &dedrift); |
281 if (dedrift) { | |
282 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &data); | |
283 data->IndexPoint = 0; | |
284 data->Mean = 0; | |
285 data->Slope = 0; | |
286 data->ADev = 0; | |
287 } | |
0 | 288 break; |
135 | 289 } |
0 | 290 return 0; |
291 } | |
292 |