diff Allan.c @ 136:7b9cf3d4346e

Code cleanup
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Wed, 22 Jan 2014 12:29:58 +0100
parents 77539f2597b1
children 792ac7151f0f
line wrap: on
line diff
--- a/Allan.c	Wed Jan 22 12:29:38 2014 +0100
+++ b/Allan.c	Wed Jan 22 12:29:58 2014 +0100
@@ -46,17 +46,14 @@
 	int N = 1 + Instance->BlocksNumber[0];
 	double Mean = Instance->Mean;
 	double Drift = Instance->Drift;
-	double Normalizer = Instance->normalization;
 	
 	/* compute drift rate */
-	if (N > 1) {
+	if (N > 1)
 		Instance->Drift = (Drift * (N - 2) + 6 * (Freq - Mean) / N) / (N + 1);
-		SetCtrlVal(Instance->AllanPanel, ALLANPANEL_DRIFT, Instance->Drift/Normalizer);
-	}
 	Instance->Mean = (Mean * (N - 1) + Freq) / N; 
 	
 	/* compute allan deviation */
-	for (int i = 0; i < ALLAN_MAXPOINTSNUMBER; i++) {
+	for (int i = 0; i < ALLAN_NUM_DATAPOINTS; i++) {
 		Instance->CurrentAverage[i] = (Instance->CurrentAverage[i]*Instance->NbCurrentAverage[i] + Freq)
 											/(Instance->NbCurrentAverage[i]+1);
 		Instance->NbCurrentAverage[i] +=1;
@@ -101,20 +98,21 @@
 static void Allan_Display(Allan_Data *Instance)
 {
 	int i, N;
-	double X[ALLAN_MAXPOINTSNUMBER];
-	double Y[ALLAN_MAXPOINTSNUMBER];
+	double X[ALLAN_NUM_DATAPOINTS];
+	double Y[ALLAN_NUM_DATAPOINTS];
 	double Normalizer = Instance->normalization;
 	double DriftTau, FirstFreq, LastFreq, Error;
 	int dedrift;
 	
 	GetCtrlVal(Instance->AllanPanel, ALLANPANEL_DEDRIFT, &dedrift);
+	SetCtrlVal(Instance->AllanPanel, ALLANPANEL_DRIFT, Instance->Drift);
 	
-	for (i = 0; i < ALLAN_MAXPOINTSNUMBER; i++) {
+	for (i = 0; i < ALLAN_NUM_DATAPOINTS; i++) {
 		X[i] = pow(2, i);
 		if (dedrift) {
 			DriftTau = Instance->Drift * X[i];
 			N = Instance->BlocksNumber[i];
-			if (N>=2) { // if enough data to calculate AVAR for tau = 2^i*tau0, and therefore, AllanVar[i] is meaningful
+			if (N > 1) { // if enough data to calculate AVAR for tau = 2^i*tau0, and therefore, AllanVar[i] is meaningful
 				FirstFreq = Instance->FirstMean[i];
 				LastFreq = Instance->LastMean[i];
 				Y[i] = sqrt(Instance->AllanVar[i]+DriftTau*(DriftTau/2-(LastFreq-FirstFreq)/(N-1)))/Normalizer;
@@ -129,10 +127,10 @@
 	}
 	
 	DeleteGraphPlot(Instance->AllanPanel, ALLANPANEL_ALLANPLOT, -1, VAL_IMMEDIATE_DRAW); 
-	PlotXY(Instance->AllanPanel, ALLANPANEL_ALLANPLOT, X, Y, ALLAN_MAXPOINTSNUMBER,
+	PlotXY(Instance->AllanPanel, ALLANPANEL_ALLANPLOT, X, Y, ALLAN_NUM_DATAPOINTS,
 			VAL_DOUBLE, VAL_DOUBLE, VAL_SCATTER, VAL_SOLID_SQUARE, VAL_SOLID, 1, DATAPOINT_COLOR);
 	
-	for (i = 0; i < ALLAN_MAXPOINTSNUMBER; i++) {
+	for (i = 0; i < ALLAN_NUM_DATAPOINTS; i++) {
 		Error = 1/sqrt(Instance->BlocksNumber[i]);
 		PlotLine(Instance->AllanPanel, ALLANPANEL_ALLANPLOT, X[i], Y[i]*(1-Error), X[i], Y[i]*(1+Error), ERRORBAR_COLOR);
 	}
@@ -162,12 +160,12 @@
 	switch (event)
 	{
 		case EVENT_COMMIT:
-			int YMin, YMax;
-			GetCtrlVal(panel, ALLANPANEL_MIN, &YMin);
-			GetCtrlVal(panel, ALLANPANEL_MAX, &YMax);
-			if (YMin < YMax) {
-				SetAxisScalingMode(panel, ALLANPANEL_ALLANPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, pow(10,(double)YMin), pow(10,(double)YMax) );
-				SetCtrlVal(panel, ALLANPANEL_CHECKBOX_AUTOSCALE, FALSE); 
+			int pmin, pmax;
+			GetCtrlVal(panel, ALLANPANEL_MIN, &pmin);
+			GetCtrlVal(panel, ALLANPANEL_MAX, &pmax);
+			if (pmin < pmax) {
+				SetAxisScalingMode(panel, ALLANPANEL_ALLANPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, pow(10, pmin), pow(10, pmax));
+				SetCtrlVal(panel, ALLANPANEL_CHECKBOX_AUTOSCALE, FALSE);
 			}
 			break;
 	}	
@@ -183,7 +181,7 @@
 		case EVENT_COMMIT:
 			Allan_Data *data;
 			GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &data);
-			GetCtrlVal(panel, control, &(data->normalization));
+			GetCtrlVal(panel, control, &(data->autoscale));
 			Allan_Display(data);
 			break;
 	}