changeset 136:7b9cf3d4346e

Code cleanup
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Wed, 22 Jan 2014 12:29:58 +0100
parents 77539f2597b1
children 792ac7151f0f
files Allan.c Allan.h FXAnalyse.c Plot.h
diffstat 4 files changed, 88 insertions(+), 82 deletions(-) [+]
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;
 	}
--- a/Allan.h	Wed Jan 22 12:29:38 2014 +0100
+++ b/Allan.h	Wed Jan 22 12:29:58 2014 +0100
@@ -1,30 +1,32 @@
-#include "YLCStuff.h"
+#ifndef __FXANALISE_ALLAN_H__
+#define __FXANALISE_ALLAN_H__
 
-#define ALLAN_MAXPOINTSNUMBER 13			// can compute Allan dev for tau from 1s to 2^13 s =8192 s ~ 2h15' < 10000 s
-
-
-// Allan_Data : the data of crypto class Allan
+/**
+ * The Allan deviation is computed at 2^(N tau0) seconds integration times
+ * with N ranging from 0 to ALLAN_NUM_DATAPOINTS - 1.  Setting this parameter
+ * to 14 allows to compute the allan deviation up to 2^13 = 8192 seconds. */
+#define ALLAN_NUM_DATAPOINTS 14
 
 typedef struct {
-	PanelHandle AllanPanel ;					// le handle sur le graphe
-	double AllanVar[ALLAN_MAXPOINTSNUMBER] ;	// the values of variances for each tau = 2^n.tau_0 (with n from 0 to ALLAN_MAXPOINTSNUMBER)
-	double FirstMean[ALLAN_MAXPOINTSNUMBER] ;   // the means of the first block of 2^n data for which averaging was completed
-	double LastMean[ALLAN_MAXPOINTSNUMBER] ;    // the means of the last block of 2^n data for which averaging was completed
-	int BlocksNumber[ALLAN_MAXPOINTSNUMBER] ;	// the number of blocks of 2^n data (averaged) used for computing AVAR(2^ntau)       
-	double CurrentAverage[ALLAN_MAXPOINTSNUMBER] ;  // the sum of the last p data points retrieved (with p<2^2n). used for averaging as soon as p=2^n
-	int NbCurrentAverage[ALLAN_MAXPOINTSNUMBER] ;	// number of data point being summed in CurrentAverage (from 0 up to 2^n)
-	double Drift, Mean ; // the drift rate of the data (in Hz/s), and the mean value (in Hz) : only usefull for dedrifting...
+	int AllanPanel;									/* display panel handle */
+	double X[ALLAN_NUM_DATAPOINTS];
+	double AllanVar[ALLAN_NUM_DATAPOINTS];			/* Allan variance computed at tau = 2^(N tau0) */
+	double FirstMean[ALLAN_NUM_DATAPOINTS];			/* mean of the first block of 2^N data for which averaging was completed */
+	double LastMean[ALLAN_NUM_DATAPOINTS];			/* mean of the last block of 2^N data for which averaging was completed */
+	int BlocksNumber[ALLAN_NUM_DATAPOINTS];			/* number of 2^N data points blocks used for computing AVAR(2^(N tau0)) */
+	double CurrentAverage[ALLAN_NUM_DATAPOINTS];  	/* sum of the last P data points retrieved. P < 2^N */
+	int NbCurrentAverage[ALLAN_NUM_DATAPOINTS];		/* number of data point being summed in CurrentAverage */
+	double Drift;									/* frequency drift rate [Hz/s] */
+	double Mean;									/* mean frequency [Hz] */
 	double normalization;
 	int autoscale;
-	int active;
-	int parent;
-	int control;
-} Allan_Data ;
-
+	int active;										/* active */
+	int parent;										/* panel containig the activation control */
+	int control;									/* activation control handle */
+} Allan_Data;
 
-// The functions of crypto class Allan
+void Allan_InitPanel(Allan_Data *data, const char * title, double Normalizer, int parent, int control);
+void Allan_ClosePanel(Allan_Data *data);
+void Allan_AddFrequency(Allan_Data * data, double Freq);
 
-void Allan_InitPanel(Allan_Data * Instance, const char * title, double Normalizer, int parent, int control) ;
-void Allan_ClosePanel(Allan_Data * Instance) ;
-void Allan_AddFrequency(Allan_Data * Instance, double Freq) ;
-
+#endif
--- a/FXAnalyse.c	Wed Jan 22 12:29:38 2014 +0100
+++ b/FXAnalyse.c	Wed Jan 22 12:29:58 2014 +0100
@@ -77,7 +77,7 @@
 	}
 
 
-int adev_toggle(struct adev *adev)
+static int adev_toggle(struct adev *adev)
 {
 	if (adev->allan.active)
 		Allan_ClosePanel(&(adev->allan));
@@ -88,7 +88,7 @@
 }
 
 
-void adev_update(struct adev *adev)
+static inline void adev_update(struct adev *adev)
 {
 	if (adev->allan.active)
 		Allan_AddFrequency(&(adev->allan), *(adev->data));
@@ -129,7 +129,7 @@
 	}
 
 
-int plot_toggle(struct plot *plot)
+static int plot_toggle(struct plot *plot)
 {
 	if (plot->plot.active)
 		Plot_ClosePanel(&(plot->plot));
@@ -140,7 +140,7 @@
 }
 
 
-void plot_update(struct plot *plot)
+static inline void plot_update(struct plot *plot)
 {
 	if (plot->plot.active)
 		Plot_AddFrequency(&(plot->plot), *(plot->data));
@@ -1353,10 +1353,7 @@
 				if (recenter.enabled)
 				{
 					if (recenter.t0 == 0.0) {
-						recenter.t0 = utc;
-						rollmean_zero(&rollmean_ch2, ROLLMEAN_N_OBS);
-						rollmean_zero(&rollmean_ch3, ROLLMEAN_N_OBS);
-						rollmean_zero(&rollmean_ch4, ROLLMEAN_N_OBS);
+
 					}
 					
 					rollmean_accumulate(&rollmean_ch2, Ch2);
@@ -1503,12 +1500,10 @@
 int  CVICALLBACK CB_ChangeDDSOut (int panel, int control, int event, 
 		 void *callbackData, int eventData1, int eventData2)
 {
-	double frequency ;
-	
 	switch (event) {
 		case EVENT_COMMIT:
+			double frequency;
 			GetCtrlVal(MainPanel, control, &frequency);
-			
 			switch (control) {
 				case PANEL_DDS1:
 					DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, frequency);
@@ -1523,6 +1518,7 @@
 					DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, frequency);
 					break;
 			}
+			break;
 	}
 	return 0;
 }
@@ -1530,22 +1526,28 @@
 int  CVICALLBACK CB_ChangeDDSStep (int panel, int control, int event, 
 		 void *callbackData, int eventData1, int eventData2)
 {
-	double Step ;
-	
 	switch (event)
-		{
+	{
 		case EVENT_COMMIT:
-			GetCtrlVal(MainPanel, control, &Step);
-			if (control==PANEL_DDS1STEP)   { SetCtrlAttribute(panel, PANEL_DDS1,   ATTR_INCR_VALUE, Step); }   
-			if (control==PANEL_DDS2STEP)   { SetCtrlAttribute(panel, PANEL_DDS2,   ATTR_INCR_VALUE, Step); }
-			if (control==PANEL_DDS3STEP)   { SetCtrlAttribute(panel, PANEL_DDS3,   ATTR_INCR_VALUE, Step); }   
-			if (control==PANEL_DDS4STEP)   { SetCtrlAttribute(panel, PANEL_DDS4,   ATTR_INCR_VALUE, Step); } 
+			double step;
+			GetCtrlVal(panel, control, &step);
+			switch (control)
+			{
+				case PANEL_DDS1STEP:
+					SetCtrlAttribute(panel, PANEL_DDS1, ATTR_INCR_VALUE, step);
+					break;
+				case PANEL_DDS2STEP:
+					SetCtrlAttribute(panel, PANEL_DDS2, ATTR_INCR_VALUE, step);
+					break;
+				case PANEL_DDS3STEP:
+					SetCtrlAttribute(panel, PANEL_DDS3, ATTR_INCR_VALUE, step);
+					break;
+				case PANEL_DDS4STEP:
+					SetCtrlAttribute(panel, PANEL_DDS4, ATTR_INCR_VALUE, step);
+					break;
+			}
 			break;
-		case EVENT_RIGHT_CLICK:
-
-			break;
-			
-		}
+	}
 	return 0;
 }
 
@@ -1589,13 +1591,22 @@
 {
 
 	switch (event)
-		{
+	{
 		case EVENT_COMMIT:
-			if (control==PANEL_N1CHOICE) GetCtrlVal(MainPanel, control, &N1) ;
-			if (control==PANEL_N2CHOICE) GetCtrlVal(MainPanel, control, &N2) ;
-			if (control==PANEL_N3CHOICE) GetCtrlVal(MainPanel, control, &N3) ;
+			switch (control)
+			{
+				case PANEL_N1CHOICE:
+					GetCtrlVal(panel, control, &N1);
+					break;
+				case PANEL_N2CHOICE:
+					GetCtrlVal(panel, control, &N2);
+					break;
+				case PANEL_N3CHOICE:
+					GetCtrlVal(panel, control, &N3);
+					break;
+			}
 			break;
-		}
+	}
 	return 0;
 }
 
@@ -1987,17 +1998,10 @@
 	{
 		case EVENT_COMMIT:
 			switch (control) {
-				
-				case PANEL_CHECKBOX_CORRFREQU:
-					// enable frequency correction
-				   	// GetCtrlVal(MainPanel, PANEL_CHECKBOX_CORRFREQU, &FrequCorrec);
-					break;
-			
 				case PANEL_CHECKBOX_KEEP:
 					// keep current dedrifting frequency when dedrifting is disabled
 				   	GetCtrlVal(MainPanel, PANEL_CHECKBOX_KEEP, &dedrift.keep_freq);
 					break;
-					
 				case PANEL_CHECKBOX_KEEPSLOPE:
 					// keep current dedrifting slope when dedrifting is disabled
 				   	GetCtrlVal(MainPanel, PANEL_CHECKBOX_KEEPSLOPE, &dedrift.keep_slope);
@@ -2017,7 +2021,10 @@
 	{
 		case EVENT_COMMIT:
 			GetCtrlVal(panel, control, &recenter.enabled);
-			recenter.t0 = 0.0;
+			recenter.t0 = utc;
+			rollmean_zero(&rollmean_ch2, ROLLMEAN_N_OBS);
+			rollmean_zero(&rollmean_ch3, ROLLMEAN_N_OBS);
+			rollmean_zero(&rollmean_ch4, ROLLMEAN_N_OBS);
  			break;
 	}
 	return 0;
@@ -2065,9 +2072,8 @@
 			{
 				case PANEL_ESTIMATE_N3:
 					GetPanelAttribute(EstimateN3Panel, ATTR_VISIBLE , &visible);
-					if (! visible) {
+					if (! visible)
 						DisplayPanel(EstimateN3Panel);
-					}
 					// set current frep
 					SetCtrlVal(EstimateN3Panel, ESTIMATEN3_FREP, 250e6 + Math1);
 					// default wavelenght for Sr cavity
--- a/Plot.h	Wed Jan 22 12:29:38 2014 +0100
+++ b/Plot.h	Wed Jan 22 12:29:58 2014 +0100
@@ -1,5 +1,5 @@
-#ifndef __FXANALIZE_PLOT_H__
-#define __FXANALIZE_PLOT_H__
+#ifndef __FXANALISE_PLOT_H__
+#define __FXANALISE_PLOT_H__
 
 #define MAXPOINTSNUMBER 10000