diff FXAnalyse.c @ 269:3f395eab72eb

Whitespace
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 10 Jul 2015 13:40:36 +0200
parents ec4462c7f8b7
children a451d4618dbf
line wrap: on
line diff
--- a/FXAnalyse.c	Thu Jul 09 23:11:00 2015 +0200
+++ b/FXAnalyse.c	Fri Jul 10 13:40:36 2015 +0200
@@ -3,17 +3,17 @@
 #include <utility.h>
 #include <ansi_c.h>
 #include <lowlvlio.h>
-#include <cvirte.h>		
+#include <cvirte.h>
 #include <userint.h>
 #include <formatio.h>
 #include <inifile.h>
 #include <string.h>
 
-#include "FXAnalyse.h" 
+#include "FXAnalyse.h"
 #include "Plot.h"
 #include "Allan.h"
 #include "ad9912.h"
-#include "ad9956.h" 
+#include "ad9956.h"
 #include "muParserDLL.h"
 #include "utils.h"
 #include "stat.h"
@@ -55,23 +55,23 @@
 void *zmqsocket;
 
 // utility function to send data through ZMQ socket framed by an envelope
-// see "Pub-Sub Message Envelopes" in chapter 2 "Sockets and Patterns" 
+// see "Pub-Sub Message Envelopes" in chapter 2 "Sockets and Patterns"
 // of "ZMQ The Guide" http://zguide.zeromq.org/page:all#toc49
 int zmq_xpub(void *socket, char *envelope, void *data, size_t len)
 {
 	int r;
-	
+
 	r = zmq_send(socket, envelope, strlen(envelope), ZMQ_SNDMORE);
 	if (r < 0)
 		return zmq_errno();
-	
+
 	r = zmq_send(socket, data, len, 0);
 	if (r < 0)
 		return zmq_errno();
 
 	return 0;
 }
-	
+
 
 struct event ev;
 double utc;
@@ -227,32 +227,32 @@
 static int ad9956_set_w(struct ad9956 *d, double f, double s)
 {
 	int r;
-	
+
 	r = ad9956_sweep_stop(d);
 	if (r) {
 		logmessage(ERROR, "ad9956 sweep stop error=%d", -r);
 		return r;
 	}
-	
+
 	r = ad9956_set_frequency(d, f);
 	if (r) {
 		logmessage(ERROR, "ad9956 set frequency error=%d", -r);
 		return r;
 	}
-	
+
 	r = ad9956_set_sweep_rate(d, s);
 	if (r) {
 		logmessage(ERROR, "ad9956 set sweep rate error=%d", -r);
 		return r;
 	}
-	
+
 	r = ad9956_sweep_start(d);
 	if (r) {
 		logmessage(ERROR, "ad9956 sweep start error=%d", -r);
 		return r;
 	}
 
-	return 0;	
+	return 0;
 }
 
 
@@ -285,10 +285,10 @@
 double f_rep_slope, f_beat_slope;
 double f_rep_plus, f_rep_minus;
 double f_beat_plus, f_beat_minus;
-	
+
 double f0_DDS[4] = { 110000000.0, 0.0, 0.0, 0.0 };
 double df_DDS3 = 0.0;
-	
+
 int nobs = 0;
 int settling = 0;
 
@@ -299,25 +299,25 @@
 // repetition rate given by:
 //
 //   abs(delta_f_rep) = Ndiv * delta_f_lock / N1
-// 
+//
 // where Ndiv = 8 and N1 ~= 8 x 10^5 obtaining that
-// 
+//
 //   abs(delta_f_rep) ~= delta_f_lock / 10^5
 //
 // For the determination of the comb locking beatnote sign we detect
 // the sign of delta_f_rep caused by a positive delta_f_lock. f_rep is
 // measured should be small enough to do not exceed the 200x PLL
 // bandwidth but still be clearly identified.
-// 
+//
 // For the optical beatnotes we detect the sign of delta_f_beat caused
 // by a positive delta_f_lock thus we need to take into account the
 // sign of the comb locking beatnote.  The optical beatnote frequency
 // change is given by
-// 
+//
 //   abs(delta_f_beat) = abs(delta_f_rep) * Nx
-// 
+//
 // where Nx ~= 10^6 obtaining that
-// 
+//
 //   abs(delta_f_beat) ~= delta_f_lock * 10
 //
 // this need to do not exceed the beatnote filters bandwidth.  Given
@@ -390,7 +390,7 @@
 void dedrift_update_enable()
 {
 	logmsg("dedrift: automatic slope update enabled");
-	
+
 	dedrift.enabled = TRUE;
 	dedrift.t0 = utc;
 	stat_zero(&dedrift.stat);
@@ -442,7 +442,7 @@
 
 
 void dedrift_update(double f)
-{	
+{
 	if (! dedrift.enabled)
 		return;
 
@@ -451,7 +451,7 @@
 	if (dedrift.badcount) {
 		// bad data point detected
 		logmsg("dedrift: bad data point detected");
-		
+
 		// too many consecutive bad data points detected
 		if (dedrift.safety && (dedrift.badcount > dedrift.badcountmax)) {
 			logmsg("dedrift: maximum number of consecutive bad data points exceeded");
@@ -462,28 +462,28 @@
 	// check if the previous check disabled slope update
 	if (! dedrift.enabled)
 		return;
-	
+
 	// update display
 	SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, dedrift.stat.slope);
-	
+
 	// update applied slope
 	if ((utc - dedrift.t0) > dedrift.interval) {
-			
+
 		// target frequency
 		if (dedrift.f0 == 0.0)
 			dedrift.f0 = dedrift.stat.mean;
-		
+
 		// compute correction
 		double dt = utc - dedrift.t0;
 		double corr = dedrift.stat.slope \
 			+ dedrift.proportional * ((dedrift.stat.mean - dedrift.f0) / dt + 0.5 * dedrift.stat.slope);
-		
+
 		// update
 		dedrift.applied += dedrift.sign * corr * (dedrift.x2 ? 2 : 1);
 		ad9956_set_sweep_rate_w(&ad9956, dedrift.applied);
 		SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied);
 		logmsg("dedrift: update correction=%+3e slope=%+3e", corr, dedrift.applied);
-		
+
 		// start over. keep track of the last updated data point to
 		// avoid gaps in the detectrion of bad data points based on
 		// threshold on the difference between current data point and
@@ -518,7 +518,7 @@
 {
 	if (! recenter.active)
 		return FALSE;
-	
+
 	for (int i = 0; i < NBEATNOTES; i++)
 		if (recenter.enabled[i])
 			return TRUE;
@@ -531,13 +531,13 @@
 {
 	if (! recenter_enabled())
 		return;
-	
+
 	rollmean_accumulate(&rollmean_ch2, Ch2);
 	rollmean_accumulate(&rollmean_ch3, Ch3);
 	rollmean_accumulate(&rollmean_ch4, Ch4);
-			
+
 	if ((utc - recenter.t0) > recenter.interval) {
-		
+
 		if (recenter.enabled[LO]) {
 			// adjust DDS2 frequency to keep Ch4 reading at 275 kHz
 			double freq = ad9912.frequency[1];
@@ -551,7 +551,7 @@
 				logmsg("recenter ch4 to 275 kHz: DDS2 adjustment=%+3e", adj);
 			}
 		}
-				
+
 		if (recenter.enabled[HG]) {
 			// adjust DDS3 frequency to keep Ch2 reading at 10 kHz
 			double freq = ad9912.frequency[2];
@@ -565,7 +565,7 @@
 				logmsg("recenter Hg beatnote (ch2) to 10 kHz: DDS3 adjustment=%+3e", adj);
 			}
 		}
-			
+
 		if (recenter.enabled[SR]) {
 			// adjust DDS4 frequency to keep Ch3 reading at 10 kHz
 			double freq = ad9912.frequency[3];
@@ -579,7 +579,7 @@
 				logmsg("recenter Sr beatnote (ch3) to 10 kHz: DDS4 adjustment=%+3e", adj);
 			}
 		}
-				
+
 		recenter.t0 = utc;
 		rollmean_zero(&rollmean_ch2);
 		rollmean_zero(&rollmean_ch3);
@@ -621,36 +621,36 @@
 };
 
 
-static void write_data(const char *folder, const char *name, const char *id, 
+static void write_data(const char *folder, const char *name, const char *id,
 		const char *timestr, double utc, double *v, int nchan)
 {
 	int i, fd, len;
 	char line[1024];
 	char filename[FILENAME_MAX];
-	
+
 	// construct filename in the form folder\\id-name.txt
 	snprintf(filename, sizeof(filename), "%s\\%s-%s.txt", folder, id, name);
-	
+
 	fd = open(filename, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR|S_IRGRP);
 	if (fd < 0) {
 		logmessage(ERROR, "open data file %s: %s", filename, strerror(errno));
 		return;
 	}
-	
+
 	// timestamp
 	len = snprintf(line, sizeof(line), "%s\t%.3f", timestr, utc);
 
 	// data channels
 	for (i = 0; i < nchan; i++)
 		len += snprintf(line + len, sizeof(line) - len, "\t%.16e", v[i]);
-	
+
 	// newline
 	line[len++] = '\r';
 	line[len++] = '\n';
-			
+
 	// write to file
 	write(fd, line, len);
-	
+
 	close(fd);
 }
 
@@ -674,11 +674,11 @@
 static void * muParserNew()
 {
 	void *parser = mupCreate();
-	
+
 	mupDefineOprtChars(parser, "abcdefghijklmnopqrstuvwxyzµ"
                         	   "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                         	   "+-*^/?<>=#!$%&|~'_");
-	
+
 	mupDefineVar(parser, "Ch1", &Ch1);
 	mupDefineVar(parser, "Ch2", &Ch2);
 	mupDefineVar(parser, "Ch3", &Ch3);
@@ -694,7 +694,7 @@
 	mupDefineVar(parser, "Sign2", &Sign2);
 	mupDefineVar(parser, "Sign3", &Sign3);
 	mupDefineVar(parser, "Ndiv", &Ndiv);
-	
+
 	mupDefinePostfixOprt(parser, "P", &Peta,  1);
 	mupDefinePostfixOprt(parser, "T", &Tera,  1);
 	mupDefinePostfixOprt(parser, "G", &Giga,  1);
@@ -706,7 +706,7 @@
 	mupDefinePostfixOprt(parser, "n", &nano,  1);
 	mupDefinePostfixOprt(parser, "p", &pico,  1);
 	mupDefinePostfixOprt(parser, "f", &femto, 1);
-	
+
 	return parser;
 }
 
@@ -732,7 +732,7 @@
 
 	// logging
 	logger_init(&onerror);
-	
+
 	// load configuration file
 	char path[MAX_PATHNAME_LEN];
 	GetIniFilePath(path);
@@ -745,7 +745,7 @@
 		nchan = 4;
 	// update number of channels to save to disk
 	datafiles[0].nchan = nchan;
-	
+
 	// data folder
 	rv = Ini_GetStringCopy(configuration, "data", "folder", &datafolder);
 	if (rv > 0) {
@@ -755,7 +755,7 @@
 		// do not allow to start the acquisition
 		SetCtrlAttribute(MainPanel, PANEL_STARTBUTTON, ATTR_DIMMED, TRUE);
 	}
-	
+
 	// ad9956 configuration parameters
 	rv = Ini_GetStringIntoBuffer(configuration, "AD9956", "host", host, sizeof(host));
 	if (! rv)
@@ -763,13 +763,13 @@
 	rv = Ini_GetDouble(configuration, "AD9956", "clock", &clock);
 	if (! rv)
 		return -1;
-	
+
 	// initialize AD9956 dedrift DDS
 	rv = ad9956_init(&ad9956, host, clock);
 	if (rv)
 		logmessage(ERROR, "ad9956 init erorr=%d", -rv);
 	ad9956_set_w(&ad9956, dedrift.fDDS, dedrift.applied);
-	
+
 	// AD9912 configuration parameters
 	rv = Ini_GetStringIntoBuffer(configuration, "AD9912", "host", host, sizeof(host));
 	if (! rv)
@@ -777,12 +777,12 @@
 	rv = Ini_GetDouble(configuration, "AD9912", "clock", &clock);
 	if (! rv)
 		return -1;
-	
+
 	// initialize AD9912 DDS box
 	rv = ad9912_init(&ad9912, host, clock);
 	if (rv)
 		logmessage(ERROR, "ad9912 init erorr=%d", -rv);
-	
+
 	// try to read back current frequency from DDS
 	for (i = 0; i < 4; i++) {
 		rv = ad9912_get_frequency(&ad9912, i, &frequency);
@@ -806,13 +806,13 @@
 	if (rv)
 		logmessage(ERROR, "cannot bind ZMQ socket '%s': %s", socket, zmq_strerror(zmq_errno()));
 	free(socket);
-	
+
 	// dispose configuration
 	Ini_Dispose(configuration);
 
 	// Sr data logger
 	sr_datalogger_init(&datalogger);
-	
+
 	GetCtrlVal(MainPanel, PANEL_N1, &N1);
 	GetCtrlVal(MainPanel, PANEL_N2, &N2);
 	GetCtrlVal(MainPanel, PANEL_N3, &N3);
@@ -820,25 +820,25 @@
 	MathParser1 = muParserNew();
 	GetCtrlVal(MainPanel, PANEL_MATHSTRING1, expr);
 	mupSetExpr(MathParser1, expr);
-	
+
 	MathParser2 = muParserNew();
 	mupDefineVar(MathParser2, "Math1", &Math1);
 	GetCtrlVal(MainPanel, PANEL_MATHSTRING2, expr);
 	mupSetExpr(MathParser2, expr);
-	
+
 	MathParser3 = muParserNew();
 	mupDefineVar(MathParser3, "Math1", &Math1);
 	mupDefineVar(MathParser3, "Math2", &Math2);
 	GetCtrlVal(MainPanel, PANEL_MATHSTRING3, expr);
 	mupSetExpr(MathParser3, expr);
-	
+
 	MathParser4 = muParserNew();
 	mupDefineVar(MathParser4, "Math1", &Math1);
 	mupDefineVar(MathParser4, "Math2", &Math2);
 	mupDefineVar(MathParser4, "Math3", &Math3);
 	GetCtrlVal(MainPanel, PANEL_MATHSTRING4, expr);
 	mupSetExpr(MathParser4, expr);
-	
+
 	MathParser5 = muParserNew();
 	mupDefineVar(MathParser5, "Math1", &Math1);
 	mupDefineVar(MathParser5, "Math2", &Math2);
@@ -846,18 +846,18 @@
 	mupDefineVar(MathParser5, "Math4", &Math4);
 	GetCtrlVal(MainPanel, PANEL_MATHSTRING5, expr);
 	mupSetExpr(MathParser5, expr);
-	
+
 	// data queue
 	CmtNewTSQ(128, sizeof(struct event), 0, &dataQueue);
 
 	// register callback to execute when data will be in the data queue
 	CmtInstallTSQCallback(dataQueue, EVENT_TSQ_ITEMS_IN_QUEUE, 1,
 		DataAvailableCB, NULL, CmtGetCurrentThreadID(), NULL);
-	
+
 	DisplayPanel(MainPanel);
-	
+
 	RunUserInterface();
-	
+
 	DiscardPanel(MainPanel);
 	return 0;
 }
@@ -879,7 +879,7 @@
 {
 	int control, index;
 	double step;
-	
+
 #define do_arrow(__DDS, __STEP)										\
 	do {															\
 		GetCtrlIndex(panel, __STEP, &index);						\
@@ -889,14 +889,14 @@
 			SetCtrlIndex(panel, __STEP, index - 1);					\
 		GetCtrlVal(panel, __STEP, &step);							\
 		SetCtrlAttribute(panel, __DDS, ATTR_INCR_VALUE, step);  	\
-	} while (0) 
-	
+	} while (0)
+
 	switch (event) {
 		case EVENT_KEYPRESS:
 			/* key code */
 			switch (eventData1) {
 				case VAL_RIGHT_ARROW_VKEY:
-				case VAL_LEFT_ARROW_VKEY:					
+				case VAL_LEFT_ARROW_VKEY:
 					control = GetActiveCtrl(panel);
 					switch (control) {
 						case PANEL_DDS1:
@@ -947,7 +947,7 @@
 			logmsg("start");
 			SetCtrlAttribute(panel, PANEL_STARTBUTTON, ATTR_DIMMED, TRUE);
 			acquiring = 1;
-			
+
 			// start data provider thread
 			CmtScheduleThreadPoolFunctionAdv(
 				DEFAULT_THREAD_POOL_HANDLE, DataProvider, NULL,
@@ -965,7 +965,7 @@
 		case EVENT_COMMIT:
 			if (! acquiring)
 				break;
-			
+
 			logmsg("stop");
 			acquiring = 0;
 
@@ -977,7 +977,7 @@
 				DEFAULT_THREAD_POOL_HANDLE, dataProviderThread);
 
 			SetCtrlAttribute(panel, PANEL_STARTBUTTON, ATTR_DIMMED, FALSE);
-			
+
 			break;
 	}
 	return 0;
@@ -987,17 +987,17 @@
 		int value, void *callbackData)
 {
 	int read;
-	
+
 	switch (event) {
 		case EVENT_TSQ_ITEMS_IN_QUEUE:
 			// read data from the data queue
 			while (value > 0) {
-				
+
 				read = CmtReadTSQData(queueHandle, &ev, 1, TSQ_INFINITE_TIMEOUT, 0);
 				if (read != 1)
 					logmsg("Error!");
 				value = value - read;
-				
+
 				// unpack event
 				utc = ev.time.tv_sec + ev.time.tv_usec * 1e-6;
 
@@ -1005,7 +1005,7 @@
 				SetCtrlVal(MainPanel, PANEL_UTC, utc);
 				SetCtrlVal(MainPanel, PANEL_CH1, Ch1);
 				SetCtrlVal(MainPanel, PANEL_CH2, Ch2);
-				SetCtrlVal(MainPanel, PANEL_CH3, Ch3);  
+				SetCtrlVal(MainPanel, PANEL_CH3, Ch3);
 				SetCtrlVal(MainPanel, PANEL_CH4, Ch4);
 
 				// compute
@@ -1014,9 +1014,9 @@
 				Math3 = mupEval(MathParser3);
 				Math4 = mupEval(MathParser4);
 				Math5 = mupEval(MathParser5);
-				
+
 				// update display.  numeric controllers do not format values
-				// with a thousands separator: use string controllers and a 
+				// with a thousands separator: use string controllers and a
 				// custom formatting function
 				char buffer[256];
 				SetCtrlVal(MainPanel, PANEL_MATH1, thousands(buffer, sizeof(buffer), "%.6f", Math1));
@@ -1032,128 +1032,128 @@
 				// update allan deviation plots
 				for (struct adev *adev = adevs; adev->data; adev++)
 					adev_update(adev);
-				
+
 				// N measurement
 
 				switch (n_measurement[LO]) {
-					
+
 					case N_MEASUREMENT_NONE:
 						// not measuring
 						break;
-					
+
 					case N_MEASUREMENT_INIT:
 						// initialization step
-						
+
 						// set DDS1 to nominal frequency
 						ad9912_set_frequency_w(&ad9912, 0, f0_DDS[0]);
 						SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
-						
+
 						// record current DDS frequencies
 						f0_DDS[1] = ad9912.frequency[1];
-						
+
 						t1 = utc;
 						t2 = t3 = 0.0;
 						nobs = 0;
 						stat_zero(&stat_math1);
 						f_rep_plus = f_rep_minus = 0.0;
-						
+
 						// next step
 						n_measurement[LO] += 1;
 						break;
-						
+
 					case N_MEASUREMENT_SLOPE:
 						// slope measurement
-						
+
 						stat_accumulate(&stat_math1, Math1);
-						
+
 						if ((utc - t1) > slope_time[LO]) {
 							f_rep_slope = stat_math1.slope;
-							
+
 							// frep positive step
 							ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] + delta_f_lock[LO], FREP_STEP_SIZE);
 							SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
-							
+
 							// allow counter to settle
 							settling = 3;
-							
+
 							// next step
 							n_measurement[LO] += 1;
 						}
 						break;
-						
+
 					case N_MEASUREMENT_ADJUST_FREQ_PLUS:
 					case N_MEASUREMENT_ADJUST_FREQ_MINUS:
 						// adjust DDS frequency to keep beatnote within the bandpass filter
-						
+
 						if (settling-- > 0)
 							break;
-						
+
 						double fDDS2 = ad9912.frequency[1];
 						ad9912_set_frequency_w(&ad9912, 1, fDDS2 + 275000 - Ch4);
 						SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
-						
+
 						// allow counter to settle
 						settling = 3;
-						
+
 						// next step
 						n_measurement[LO] += 1;
-						break;								
-						
+						break;
+
 					case N_MEASUREMENT_FREP_PLUS:
 						// frep positive step
-						
+
 						if (settling-- > 0)
 							break;
-						
+
 						if (t2 == 0.0)
 							t2 = utc;
-						
+
 						f_rep_plus += Math1 - f_rep_slope * (utc - t2);
 						nobs += 1;
-						
+
 						if ((utc - t2) > integration_time[LO]) {
 							f_rep_plus = f_rep_plus / nobs;
 							nobs = 0;
-							
+
 							// frep negative step
 							ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] - delta_f_lock[LO], FREP_STEP_SIZE);
 							SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
-							
+
 							// allow counter to settle
 							settling = 3;
-							
+
 							// next step
 							n_measurement[LO] += 1;
 						}
 						break;
-						
+
 					case N_MEASUREMENT_FREP_MINUS:
 						// frep negative step
-						
+
 						if (settling-- > 0)
 							break;
-						
+
 						if (t3 == 0.0)
 							t3 = utc;
-						
+
 						f_rep_minus += Math1 - f_rep_slope * (utc - t2);
 						nobs += 1;
-						
+
 						if ((utc - t3) > integration_time[LO]) {
 							f_rep_minus = f_rep_minus / nobs;
 							nobs = 0;
-							
+
 							// compute N1
 							double delta_f_rep = f_rep_minus - f_rep_plus;
 							double measured = Sign1 * 2 * Ndiv * delta_f_lock[LO] / delta_f_rep;
 							SetCtrlVal(CalcNPanel, CALCN_N, measured);
-							
+
 							// back to nominal frep
 							ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE);
 							ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]);
 							SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
 							SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
-							
+
 							// done
 							n_measurement[LO] = N_MEASUREMENT_NONE;
 						}
@@ -1165,18 +1165,18 @@
 					case N_MEASUREMENT_NONE:
 						// not measuring
 						break;
-					
+
 					case N_MEASUREMENT_INIT:
 						// initialization step
-						
+
 						// set DDS1 to nominal frequency
 						ad9912_set_frequency_w(&ad9912, 0, f0_DDS[0]);
 						SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
-						
+
 						// record current DDS frequencies
 						f0_DDS[1] = ad9912.frequency[1];
 						f0_DDS[2] = ad9912.frequency[2];
-						
+
 						t1 = utc;
 						t2 = t3 = 0.0;
 						nobs = 0;
@@ -1184,35 +1184,35 @@
 						stat_zero(&stat_ch2);
 						f_rep_plus = f_rep_minus = 0.0;
 						f_beat_plus = f_beat_minus = 0.0;
-						
+
 						// next step
 						n_measurement[HG] += 1;
 						break;
-						
+
 					case N_MEASUREMENT_SLOPE:
 						// slope measurement
-						
+
 						stat_accumulate(&stat_math1, Math1);
 						stat_accumulate(&stat_ch2, Ch2);
 
 						if ((utc - t1) > slope_time[HG]) {
 							f_rep_slope = stat_math1.slope;
 							f_beat_slope = stat_ch2.slope;
-							
+
 							// frep positive step
 							double fDDS1 = f0_DDS[0] + delta_f_lock[HG];
 							ad9912_ramp_frequency_w(&ad9912, 0, fDDS1, FREP_STEP_SIZE);
 							SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
-							
+
 							// adjust DDS3 to keep beatnote within the bandpass filter. prediction
 							double fDDS3 = f0_DDS[2] + Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock[HG];
 							df_DDS3 = fDDS3 - ad9912.frequency[2];
 							ad9912_set_frequency_w(&ad9912, 2, fDDS3);
 							SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
-						
+
 							// allow counter to settle
 							settling = 3;
-							
+
 							// next step
 							n_measurement[HG] += 1;
 						}
@@ -1221,14 +1221,14 @@
 					case N_MEASUREMENT_ADJUST_FREQ_PLUS:
 					case N_MEASUREMENT_ADJUST_FREQ_MINUS:
 						// adjust DDS frequency to keep beatnote within the bandpass filter
-						
+
 						if (settling-- > 0)
 							break;
-						
+
 						double fDDS2 = ad9912.frequency[1] + 275000 - Ch4;
 						ad9912_set_frequency_w(&ad9912, 1, fDDS2);
 						SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
-						
+
 						double fDDS3 = ad9912.frequency[2] + 10000 - Ch2;
 						df_DDS3 = df_DDS3 + 10000 - Ch2;
 						ad9912_set_frequency_w(&ad9912, 2, fDDS3);
@@ -1240,10 +1240,10 @@
 						// next step
 						n_measurement[HG] += 1;
 						break;
-						
+
 					case N_MEASUREMENT_FREP_PLUS:
 						// frep positive step
-						
+
 						if (settling-- > 0)
 							break;
 
@@ -1253,7 +1253,7 @@
 						f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2);
 						f_beat_plus += Ch2 - f_beat_slope * (utc - t2);
 						nobs += 1;
-						
+
 						if ((utc - t2) > integration_time[HG]) {
 							f_rep_plus = f_rep_plus / nobs;
 							f_beat_plus = f_beat_plus / nobs;
@@ -1263,7 +1263,7 @@
 							double fDDS1 = f0_DDS[0] - delta_f_lock[HG];
 							ad9912_ramp_frequency_w(&ad9912, 0, fDDS1, FREP_STEP_SIZE);
 							SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
-							
+
 							// adjust DDS3 to keep beatnote within the bandpass filter. prediction
 							double fDDS3 = f0_DDS[2] - Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock[HG];
 							df_DDS3 = fDDS3 - ad9912.frequency[2];
@@ -1272,18 +1272,18 @@
 
 							// allow counter to settle
 							settling = 3;
-							
+
 							// next step
 							n_measurement[HG] += 1;
 						}
 						break;
-						
+
 					case N_MEASUREMENT_FREP_MINUS:
 						// frep negative step
-						
+
 						if (settling-- > 0)
 							break;
-						
+
 						if (t3 == 0.0)
 							t3 = utc;
 
@@ -1300,13 +1300,13 @@
 							double delta_f_rep_m = f_rep_minus - f_rep_plus;
 							double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock[HG] / N1;
 							double delta = delta_f_rep_m - delta_f_rep;
-							
+
 							logmsg("delta frep: measured=%e expected=%e difference=%e rel=%e",
 								delta_f_rep_m, delta_f_rep, delta, delta / delta_f_rep);
-							
+
 							double measured = -Sign2 * (df_DDS3 + f_beat_minus - f_beat_plus) / delta_f_rep;
 							SetCtrlVal(CalcNPanel, CALCN_N, measured);
-							
+
 							// back to nominal frequency
 							ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE);
 							ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]);
@@ -1314,30 +1314,30 @@
 							SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
 							SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
 							SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
-							
+
 							// done
 							n_measurement[HG] = N_MEASUREMENT_NONE;
 						}
 						break;
 				}
-				
+
 				switch (n_measurement[SR]) {
-					
+
 					case N_MEASUREMENT_NONE:
 						// not measuring N3
 						break;
-						
+
 					case N_MEASUREMENT_INIT:
 						// init
-						
+
 						// set DDS1 to nominal frequency
 						ad9912_set_frequency_w(&ad9912, 0, f0_DDS[0]);
 						SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
-						
+
 						// record current DDS frequencies
 						f0_DDS[1] = ad9912.frequency[1];
 						f0_DDS[3] = ad9912.frequency[3];
-						
+
 						t1 = utc;
 						t2 = t3 = 0.0;
 						nobs = 0;
@@ -1345,40 +1345,40 @@
 						stat_zero(&stat_ch3);
 						f_rep_plus = f_rep_minus = 0.0;
 						f_beat_plus = f_beat_minus = 0.0;
-						
+
 						// next step
 						n_measurement[SR] += 1;
 						break;
-						
+
 					case N_MEASUREMENT_SLOPE:
 						// slope measurement
-						
+
 						if (settling-- > 0)
 							break;
-						
+
 						stat_accumulate(&stat_math1, Math1);
 						stat_accumulate(&stat_ch3, Ch3);
-						
+
 						if (utc - t1 > slope_time[SR]) {
 							// slope measurement
 							f_rep_slope = stat_math1.slope;
 							f_beat_slope = stat_ch3.slope;
-							
+
 							logmsg("f_rep_slope=%e Hz/s", f_rep_slope);
 							logmsg("f_beat_slope=%e Hz/s", f_rep_slope);
-							
+
 							// frep positive step
 							ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] + delta_f_lock[SR], FREP_STEP_SIZE);
 							SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
-							
+
 							// adjust DDS3 to keep beatnote within the bandpass filter
 							double fDDS4 = f0_DDS[3] + Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock[SR];
 							ad9912_set_frequency_w(&ad9912, 3, fDDS4);
 							SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]);
-							
+
 							// allow counter to settle
 							settling = 3;
-							
+
 							// next step
 							n_measurement[SR] += 1;
 						}
@@ -1390,37 +1390,37 @@
 
 						if (settling-- > 0)
 							break;
-						
+
 						// adjust DDS frequency to keep 55 MHz tracker oscillator locked
 						double fDDS2 = ad9912.frequency[1] + 275000 - Ch4;
 						ad9912_set_frequency_w(&ad9912, 1, fDDS2);
 						SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
-						
+
 						// allow counter to settle
 						settling = 3;
-						
+
 						// next step
 						n_measurement[SR] += 1;
-						break;						
-						
+						break;
+
 					case N_MEASUREMENT_FREP_PLUS:
 						// frep positive step
-						
+
 						if (settling-- > 0)
 							break;
 
 						if (t2 == 0.0)
 							t2 = utc;
-						
+
 						f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2);
 						f_beat_plus += Ch3 - f_beat_slope * (utc - t2);
 						nobs += 1;
-						
+
 						if (utc - t2 > integration_time[SR]) {
 							f_rep_plus = f_rep_plus / nobs;
 							f_beat_plus = f_beat_plus / nobs;
 							nobs = 0;
-							
+
 							// frep negative step
 							ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] - delta_f_lock[SR], FREP_STEP_SIZE);
 							SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
@@ -1429,53 +1429,53 @@
 							double fDDS4 = f0_DDS[3] - Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock[SR];
 							ad9912_set_frequency_w(&ad9912, 3, fDDS4);
 							SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]);
-							
+
 							// allow counter to settle
 							settling = 3;
-							
+
 							// next step
 							n_measurement[SR] += 1;
 						}
 						break;
-					
+
 					case N_MEASUREMENT_FREP_MINUS:
 						// frep negative step
-						
+
 						if (settling-- > 0)
 							break;
-						
+
 						if (t3 == 0.0)
 							t3 = utc;
-						
+
 						f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t2);
 						f_beat_minus += Ch3 - f_beat_slope * (utc - t2);
 						nobs += 1;
-						
+
 						if (utc - t3 > integration_time[SR]) {
 							f_rep_minus = f_rep_minus / nobs;
 							f_beat_minus = f_beat_minus / nobs;
 							nobs = 0;
-							
+
 							// check delta frep
 							double delta_f_rep_m = f_rep_minus - f_rep_plus;
 							double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock[SR] / N1;
 							double delta = delta_f_rep_m - delta_f_rep;
-							
+
 							logmsg("delta frep: measured=%e expected=%e difference=%e rel=%e",
 								delta_f_rep_m, delta_f_rep, delta, delta / delta_f_rep);
-							
+
 							// compute N3
 							double delta_f_beat = f_beat_minus - f_beat_plus + 2.0 * Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock[SR];
 							double delta_f_beat_expected = delta_f_rep * N3;
-							
+
 							logmsg("delta fbeat: measured=%e expected=%e difference=%e",
 								delta_f_beat, delta_f_beat_expected, delta_f_beat - delta_f_beat_expected);
-							
+
 							double measured = delta_f_beat / delta_f_rep;
 							SetCtrlVal(CalcNPanel, CALCN_N, measured);
-							
+
 							logmsg("measured N3=%.3f", measured);
-							
+
 							// back to nominal frep
 							ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE);
 							ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]);
@@ -1483,19 +1483,19 @@
 							SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
 							SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
 							SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]);
-							
+
 							// done
 							n_measurement[SR] = N_MEASUREMENT_NONE;
 						}
 						break;
 				}
-				
-				// beatnote sign determination				
-				if ((beatsign.measure != NONE) && 
+
+				// beatnote sign determination
+				if ((beatsign.measure != NONE) &&
 				    (utc > beatsign.t0 + 2.0)) {
 
-					int f_beat_sign, f_rep_sign = 0; 
-					
+					int f_beat_sign, f_rep_sign = 0;
+
 					switch (beatsign.measure) {
 					case LO:
 						f_rep_sign = (Math1 > beatsign.f_rep_zero) ? -1 : 1;
@@ -1522,15 +1522,15 @@
 
 					// measurement done
 					beatsign.measure = NONE;
-						
+
 					// in the case of the optical beatnotes sign measurement
 					// we induce fairly small steps in f_rep therefore it is
-					// good to check that we get the sign of the comb locking 
+					// good to check that we get the sign of the comb locking
 					// beatnote right in those cases
 					if (f_rep_sign != Sign1)
 						logmessage(ERROR, "merasured f_rep_sign does not agree with previous determination!");
 				}
-				
+
 				// select dedrift reference
 				double f = 0.0;
 				switch (dedrift.reference) {
@@ -1544,7 +1544,7 @@
 
 				// dedrift
 				dedrift_update(f);
-								
+
 				// recenter
 				recenter_update();
 
@@ -1561,23 +1561,23 @@
 				snprintf(timestr + len, sizeof(timestr) - len, ".%03d", msec);
 				// display local time
 				SetCtrlVal(MainPanel, PANEL_TIME, timestr);
-				
+
 				// run id derived from current date in the form YYMMDD
 				char id[7];
 				strftime(id, sizeof(id), "%y%m%d", time);
-				
+
 				// write datafiles
 				for (struct datafile *d = datafiles; d->data; d++)
 					datafile_append(d, id, timestr);
-				
+
 				// send Sr frequency (Math4) to Sr data logger
 				sr_datalogger_send(&datalogger, utc, Math4);
-				
+
 				// publish data through ZMQ
 				int r = zmq_xpub(zmqsocket, "RAW", &ev, sizeof(ev));
 				if (r)
 					logmessage(ERROR, "cannot send data through ZMQ socket: %s", zmq_strerror(r));
-			}		
+			}
 			break;
 	}
 }
@@ -1612,7 +1612,7 @@
 	return 0;
 }
 
-int  CVICALLBACK CB_ChangeDDSOut (int panel, int control, int event, 
+int  CVICALLBACK CB_ChangeDDSOut (int panel, int control, int event,
 		 void *callbackData, int eventData1, int eventData2)
 {
 	switch (event) {
@@ -1642,7 +1642,7 @@
 	return 0;
 }
 
-int  CVICALLBACK CB_ChangeDDSStep (int panel, int control, int event, 
+int  CVICALLBACK CB_ChangeDDSStep (int panel, int control, int event,
 		 void *callbackData, int eventData1, int eventData2)
 {
 	switch (event)
@@ -1675,7 +1675,7 @@
 {
 	int len;
 	char *string;
-		
+
 	switch (event)
 	{
 		case EVENT_COMMIT:
@@ -1751,7 +1751,7 @@
 					N3 = round(measured);
 					SetCtrlVal(MainPanel, PANEL_N3, N3);
 					break;
-			} 
+			}
 			break;
 	}
 	return 0;
@@ -1761,7 +1761,7 @@
 		void *callbackData, int eventData1, int eventData2)
 {
 	int visible;
-	
+
 	switch (event) {
 		case EVENT_COMMIT:
 			switch (control) {
@@ -1787,7 +1787,7 @@
 						SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock[HG] / 1000.0);
 						SetCtrlVal(CalcNPanel, CALCN_N, 0.0);
 						DisplayPanel(CalcNPanel);
-					} 
+					}
 					break;
 				case PANEL_N3CALCULUS:
 					GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible);
@@ -1812,7 +1812,7 @@
 {
 	void *v;
 	int measuring;
-	
+
 	switch (event) {
 		case EVENT_COMMIT:
 			GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &v);
@@ -1853,7 +1853,7 @@
 {
 	void *v;
 	int measuring;
-	
+
 	switch (event) {
 		case EVENT_COMMIT:
 			HidePanel(CalcNPanel);
@@ -1878,19 +1878,19 @@
 					ad9912_set_frequency_w(&ad9912, 3, f0_DDS[3]);
 					break;
 			}
-			
+
 			// update DDS frequencies display
 			SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
 			SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
 			SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
 			SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]);
-			
+
 			break;
 	}
 	return 0;
 }
 
-int  CVICALLBACK CB_OnFindSign (int panel, int control, int event, 
+int  CVICALLBACK CB_OnFindSign (int panel, int control, int event,
 		void *callbackData, int eventData1, int eventData2)
 {
 	double step = 0.0;
@@ -1928,7 +1928,7 @@
 	return 0;
 }
 
-int  CVICALLBACK CB_AdjustDDSFreq (int panel, int control, int event, 
+int  CVICALLBACK CB_AdjustDDSFreq (int panel, int control, int event,
 		 void *callbackData, int eventData1, int eventData2)
 {
 	double frequency;
@@ -1958,7 +1958,7 @@
 	return 0;
 }
 
-int  CVICALLBACK CB_OnChangeNdiv (int panel, int control, int event, 
+int  CVICALLBACK CB_OnChangeNdiv (int panel, int control, int event,
 		 void *callbackData, int eventData1, int eventData2)
 {
 	switch (event)
@@ -1973,7 +1973,7 @@
 	return 0;
 }
 
-int  CVICALLBACK CB_MeasureSlope (int panel, int control, int event, 
+int  CVICALLBACK CB_MeasureSlope (int panel, int control, int event,
 		 void *callbackData, int eventData1, int eventData2)
 {
 	int enable;
@@ -1982,18 +1982,18 @@
 		case EVENT_COMMIT:
 			GetCtrlVal(panel, control, &enable);
 			enable ? dedrift_update_enable() : dedrift_update_disable();
-			break;			
+			break;
 	}
 	return 0;
 }
 
-int  CVICALLBACK CB_OnResetSlope (int panel, int control, int event, 
+int  CVICALLBACK CB_OnResetSlope (int panel, int control, int event,
 		void *callbackData, int eventData1, int eventData2)
 {
 	switch (event)
 	{
 		case EVENT_COMMIT:
-			dedrift.applied = 0.0; 
+			dedrift.applied = 0.0;
 			SetCtrlVal(panel, PANEL_SLOPE_APPLIED, dedrift.applied);
 			ad9956_set_w(&ad9956, dedrift.fDDS, dedrift.applied);
 			logmsg("dedrift: reset");
@@ -2001,20 +2001,20 @@
 	}
 	return 0;
 }
-  
-int  CVICALLBACK CB_ChangeSlopeTime (int panel, int control, int event, 
+
+int  CVICALLBACK CB_ChangeSlopeTime (int panel, int control, int event,
 		void *callbackData, int eventData1, int eventData2)
 {
 	switch (event)
 	{
 		case EVENT_COMMIT:
-			GetCtrlVal(MainPanel, PANEL_SLOPETIME, &dedrift.interval); 
+			GetCtrlVal(MainPanel, PANEL_SLOPETIME, &dedrift.interval);
 			break;
 	}
 	return 0;
 }
 
-int  CVICALLBACK CB_OnDedriftSettingsChange (int panel, int control, int event, 
+int  CVICALLBACK CB_OnDedriftSettingsChange (int panel, int control, int event,
 		 void *callbackData, int eventData1, int eventData2)
 {
 	switch (event)
@@ -2044,7 +2044,7 @@
 	return 0;
 }
 
-int  CVICALLBACK CB_RecenterEnable (int panel, int control, int event, 
+int  CVICALLBACK CB_RecenterEnable (int panel, int control, int event,
 		 void *callbackData, int eventData1, int eventData2)
 {
 	switch (event)
@@ -2060,7 +2060,7 @@
 	return 0;
 }
 
-int  CVICALLBACK CB_OnStopSlopeCancellingOnUnlocked (int panel, int control, int event, 
+int  CVICALLBACK CB_OnStopSlopeCancellingOnUnlocked (int panel, int control, int event,
 		 void *callbackData, int eventData1, int eventData2)
 {
 	switch (event)
@@ -2117,7 +2117,7 @@
 	switch (event)
 	{
 		case EVENT_COMMIT:
-			// stop slope measurement and reset slope 
+			// stop slope measurement and reset slope
 			dedrift.enabled = FALSE;
 			SetCtrlVal(panel, PANEL_MEASURE_SLOPE, 0);
 			dedrift.applied = 0.0;
@@ -2293,21 +2293,21 @@
 
 
 //
-// N estimate 
+// N estimate
 //
 
 static void estimateN (void)
 {
 	double nu, fbeat, frep, N;
 	int sign;
-	
+
 	GetCtrlVal(EstimateNPanel, ESTIMATEN_FREQUENCY, &nu);
 	GetCtrlVal(EstimateNPanel, ESTIMATEN_FREP, &frep);
 	GetCtrlVal(EstimateNPanel, ESTIMATEN_FBEAT, &fbeat);
 	GetCtrlVal(EstimateNPanel, ESTIMATEN_SIGN, &sign);
-		
+
 	N = (nu * 1.0e12 - sign * fbeat) / frep;
-	
+
 	SetCtrlVal(EstimateNPanel, ESTIMATEN_N, N);
 }
 
@@ -2315,7 +2315,7 @@
 		void *callbackData, int eventData1, int eventData2)
 {
 	int visible;
-	
+
 	switch (event)
 	{
 		case EVENT_COMMIT:
@@ -2336,7 +2336,7 @@
 					SetCtrlVal(EstimateNPanel, ESTIMATEN_FDDS, Ch2);
 					// f_beat
 					SetCtrlVal(EstimateNPanel, ESTIMATEN_FBEAT, ad9912.frequency[2] - Ch2);
-					
+
 					SetPanelAttribute(EstimateNPanel, ATTR_TITLE, "Estimate N_Hg");
 					SetPanelAttribute(EstimateNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(HG));
 					break;
@@ -2357,12 +2357,12 @@
 					SetPanelAttribute(EstimateNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(SR));
 					break;
 			}
-			
+
 			// display dialog
 			GetPanelAttribute(EstimateNPanel, ATTR_VISIBLE , &visible);
 			if (! visible)
 				DisplayPanel(EstimateNPanel);
-			
+
 			// compute
 			estimateN();
 			break;
@@ -2374,7 +2374,7 @@
 		void *callbackData, int eventData1, int eventData2)
 {
 	double wavelenght, frequency;
-	
+
 	switch (event)
 	{
 		case EVENT_COMMIT:
@@ -2391,7 +2391,7 @@
 		void *callbackData, int eventData1, int eventData2)
 {
 	double wavelenght, frequency;
-	
+
 	switch (event)
 	{
 		case EVENT_COMMIT:
@@ -2420,7 +2420,7 @@
 		void *callbackData, int eventData1, int eventData2)
 {
 	int visible;
-	
+
 	switch (event)
 	{
 		case EVENT_COMMIT:
@@ -2438,7 +2438,7 @@
 	void *v;
 	double n;
 	int estimate = 0;
-	
+
 	switch (event)
 	{
 		case EVENT_COMMIT:
@@ -2461,4 +2461,3 @@
 	}
 	return 0;
 }
-