diff FXAnalyse.c @ 124:bdfc61a8ebee

Add thousands separator to important numeric displays
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 13 Dec 2013 12:24:00 +0100
parents 35861fe64d14
children 37535873ee83
line wrap: on
line diff
--- a/FXAnalyse.c	Thu Dec 12 17:21:15 2013 +0100
+++ b/FXAnalyse.c	Fri Dec 13 12:24:00 2013 +0100
@@ -159,6 +159,25 @@
 static int LoggingPanel;
 
 
+// format and add thousands separator */
+char * thousands(char *buffer, int len, char *fmt, double val)
+{
+	int c = snprintf(buffer, len, fmt, val);
+	char *p  = strchr(buffer, '.');
+	int n = buffer + c - p;
+	while (p > (buffer + 3)) {
+		// shift by 3 digits
+		p -= 3;
+		n += 4;
+		// make space for separator
+		memmove(p + 1, p, n);
+		// insert thousand separator
+		*p = ' ';
+	}
+	return buffer;
+}
+
+
 struct stat {
 	int samples;
 	double mean;
@@ -615,7 +634,7 @@
 	
 	switch (ev) {
 		case EVENT_TSQ_ITEMS_IN_QUEUE:
-			/* read data from the data queue */
+			// read data from the data queue
 			while (value > 0) {
 				
 				read = CmtReadTSQData(queueHandle, &event, 1, TSQ_INFINITE_TIMEOUT, 0);
@@ -628,33 +647,34 @@
 				Ch2 = event.data[1];
 				Ch3 = event.data[2];
 				Ch4 = event.data[3];
-				
+
+				// update display
 				SetCtrlVal(MainPanel, PANEL_UTC, utc);
-				SetCtrlVal(MainPanel, PANEL_FREQ1, Ch1);
-				SetCtrlVal(MainPanel, PANEL_FREQ2, Ch2);
-				SetCtrlVal(MainPanel, PANEL_FREQ3, Ch3);  
-				SetCtrlVal(MainPanel, PANEL_FREQ4, Ch4);
+				SetCtrlVal(MainPanel, PANEL_CH1, Ch1);
+				SetCtrlVal(MainPanel, PANEL_CH2, Ch2);
+				SetCtrlVal(MainPanel, PANEL_CH3, Ch3);  
+				SetCtrlVal(MainPanel, PANEL_CH4, Ch4);
 
 				SetCtrlVal(MainPanel, PANEL_CENTERFREQUENCY, CenterFrequencyCh2);
 				
-				// Treat data
-				
+				// compute
 				Math1 = mupEval(MathParser1);
-				SetCtrlVal(MainPanel,PANEL_MATH1, Math1);
-				
 				Math2 = mupEval(MathParser2);
-				SetCtrlVal(MainPanel,PANEL_MATH2, Math2);
-				
 				Math3 = mupEval(MathParser3);
-				SetCtrlVal(MainPanel,PANEL_MATH3, Math3);
-				
 				Math4 = mupEval(MathParser4);
-				SetCtrlVal(MainPanel,PANEL_MATH4, Math4);
+				Math5 = mupEval(MathParser5);
 				
-				Math5 = mupEval(MathParser5);
-				SetCtrlVal(MainPanel,PANEL_MATH5, Math5);
+				// update display.  numeric controllers do not format values
+				// with a thousands separator: use string controllers and a 
+				// custom formatting function
+				char buffer[256];
+				SetCtrlVal(MainPanel,PANEL_MATH1, thousands(buffer, sizeof(buffer), "%.3f", Math1));
+				SetCtrlVal(MainPanel,PANEL_MATH2, thousands(buffer, sizeof(buffer), "%.3f", Math2));
+				SetCtrlVal(MainPanel,PANEL_MATH3, thousands(buffer, sizeof(buffer), "%.3f", Math3));
+				SetCtrlVal(MainPanel,PANEL_MATH4, thousands(buffer, sizeof(buffer), "%.3f", Math4));
+				SetCtrlVal(MainPanel,PANEL_MATH5, thousands(buffer, sizeof(buffer), "%.3f", Math5));
 				
-				// Plot Data and calculus if required
+				// plot
 				
 				GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ1PLOT, &BoxChecked);
 				if (BoxChecked) {