changeset 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
files FXAnalyse.c FXAnalyse.h FXAnalyse.uir
diffstat 3 files changed, 115 insertions(+), 97 deletions(-) [+]
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) {
--- a/FXAnalyse.h	Thu Dec 12 17:21:15 2013 +0100
+++ b/FXAnalyse.h	Fri Dec 13 12:24:00 2013 +0100
@@ -39,10 +39,10 @@
 #define  PANEL_QUITBUTTON                 2       /* control type: command, callback function: QuitCallback */
 #define  PANEL_STARTBUTTON                3       /* control type: command, callback function: CB_OnStart */
 #define  PANEL_STOPBUTTON                 4       /* control type: command, callback function: CB_OnStop */
-#define  PANEL_FREQ4                      5       /* control type: numeric, callback function: (none) */
-#define  PANEL_FREQ3                      6       /* control type: numeric, callback function: (none) */
-#define  PANEL_FREQ2                      7       /* control type: numeric, callback function: (none) */
-#define  PANEL_FREQ1                      8       /* control type: numeric, callback function: (none) */
+#define  PANEL_CH4                        5       /* control type: numeric, callback function: (none) */
+#define  PANEL_CH3                        6       /* control type: numeric, callback function: (none) */
+#define  PANEL_CH2                        7       /* control type: numeric, callback function: (none) */
+#define  PANEL_CH1                        8       /* control type: numeric, callback function: (none) */
 #define  PANEL_CHECKBOX_MATH1ALLAN        9       /* control type: radioButton, callback function: CB_OnAllanPlot */
 #define  PANEL_CHECKBOX_FREQ4ALLAN        10      /* control type: radioButton, callback function: CB_OnAllanPlot */
 #define  PANEL_CHECKBOX_FREQ3ALLAN        11      /* control type: radioButton, callback function: CB_OnAllanPlot */
@@ -71,81 +71,79 @@
 #define  PANEL_DDS2STEP                   34      /* control type: ring, callback function: CB_ChangeDDSStep */
 #define  PANEL_CENTERFREQUENCY            35      /* control type: numeric, callback function: (none) */
 #define  PANEL_SLOPE_APPLIED              36      /* control type: numeric, callback function: CB_SetSlope */
-#define  PANEL_MATH4                      37      /* control type: numeric, callback function: (none) */
-#define  PANEL_MATH5                      38      /* control type: numeric, callback function: (none) */
-#define  PANEL_MATH3                      39      /* control type: numeric, callback function: (none) */
-#define  PANEL_CHECKBOX_MATH5PLOT         40      /* control type: radioButton, callback function: CB_OnFreqPlot */
-#define  PANEL_CHECKBOX_MATH4PLOT         41      /* control type: radioButton, callback function: CB_OnFreqPlot */
-#define  PANEL_CHECKBOX_MATH4ALLAN        42      /* control type: radioButton, callback function: CB_OnAllanPlot */
-#define  PANEL_DDS1STEP                   43      /* control type: ring, callback function: CB_ChangeDDSStep */
-#define  PANEL_TEXTMSG_15                 44      /* control type: textMsg, callback function: (none) */
-#define  PANEL_CHECKBOX_MATH5ALLAN        45      /* control type: radioButton, callback function: CB_OnAllanPlot */
-#define  PANEL_CHECKBOX_MATH3PLOT         46      /* control type: radioButton, callback function: CB_OnFreqPlot */
-#define  PANEL_CHECKBOX_MATH5SAVE         47      /* control type: radioButton, callback function: (none) */
-#define  PANEL_SR_LOGGER                  48      /* control type: radioButton, callback function: (none) */
-#define  PANEL_CHECKBOX_MATH4SAVE         49      /* control type: radioButton, callback function: (none) */
-#define  PANEL_CHECKBOX_MATH3ALLAN        50      /* control type: radioButton, callback function: CB_OnAllanPlot */
-#define  PANEL_MATHSTRING4                51      /* control type: string, callback function: CB_ChangeMath */
-#define  PANEL_MATH2                      52      /* control type: numeric, callback function: (none) */
-#define  PANEL_CHECKBOX_MATH2PLOT         53      /* control type: radioButton, callback function: CB_OnFreqPlot */
-#define  PANEL_CHECKBOX_MATH3SAVE         54      /* control type: radioButton, callback function: (none) */
-#define  PANEL_CHECKBOX_MATH2SAVE         55      /* control type: radioButton, callback function: (none) */
-#define  PANEL_CHECKBOX_MATH2ALLAN        56      /* control type: radioButton, callback function: CB_OnAllanPlot */
-#define  PANEL_MATHSTRING3                57      /* control type: string, callback function: CB_ChangeMath */
-#define  PANEL_MATH1                      58      /* control type: numeric, callback function: (none) */
-#define  PANEL_MATHSTRING1                59      /* control type: string, callback function: CB_ChangeMath */
-#define  PANEL_TEXTMSG_10                 60      /* control type: textMsg, callback function: (none) */
-#define  PANEL_MATHSTRING2                61      /* control type: string, callback function: CB_ChangeMath */
-#define  PANEL_TEXTMSG_16                 62      /* control type: textMsg, callback function: (none) */
-#define  PANEL_MINUS10KDDS1               63      /* control type: command, callback function: CB_OnMinus10k */
-#define  PANEL_MINUS10KDDS4               64      /* control type: command, callback function: CB_OnMinus10k */
-#define  PANEL_MINUS10KDDS3               65      /* control type: command, callback function: CB_OnMinus10k */
-#define  PANEL_MINUS10KDDS2               66      /* control type: command, callback function: CB_OnMinus10k */
-#define  PANEL_PLUS10KDDS4                67      /* control type: command, callback function: CB_OnPlus10k */
-#define  PANEL_PLUS10KDDS3                68      /* control type: command, callback function: CB_OnPlus10k */
-#define  PANEL_PLUS10KDDS1                69      /* control type: command, callback function: CB_OnPlus10k */
-#define  PANEL_PLUS10KDDS2                70      /* control type: command, callback function: CB_OnPlus10k */
-#define  PANEL_TEXTMSG_11                 71      /* control type: textMsg, callback function: (none) */
-#define  PANEL_MATHSTRING5                72      /* control type: textBox, callback function: CB_ChangeMath */
-#define  PANEL_UTC                        73      /* control type: numeric, callback function: (none) */
-#define  PANEL_TIME                       74      /* control type: string, callback function: (none) */
-#define  PANEL_DDS4                       75      /* control type: numeric, callback function: CB_ChangeDDSOut */
-#define  PANEL_DDS3                       76      /* control type: numeric, callback function: CB_ChangeDDSOut */
-#define  PANEL_N1CALCULUS                 77      /* control type: command, callback function: CB_OnNCalculus */
-#define  PANEL_FINDSIGN3                  78      /* control type: command, callback function: CB_OnFindSign */
-#define  PANEL_SIGN3                      79      /* control type: numeric, callback function: CB_Sign3 */
-#define  PANEL_FINDSIGN2                  80      /* control type: command, callback function: CB_OnFindSign */
-#define  PANEL_SIGN2                      81      /* control type: numeric, callback function: (none) */
-#define  PANEL_FINDSIGN1                  82      /* control type: command, callback function: CB_OnFindSign */
-#define  PANEL_SIGN1                      83      /* control type: numeric, callback function: (none) */
-#define  PANEL_FIND10K3                   84      /* control type: command, callback function: CB_OnFind275K */
-#define  PANEL_FIND275K2                  85      /* control type: command, callback function: CB_OnFind275K */
-#define  PANEL_RESETSLOPE                 86      /* control type: command, callback function: CB_OnResetSlope */
-#define  PANEL_CHECKBOX_STOPIFAUTODE      87      /* control type: radioButton, callback function: CB_OnStopSlopeCancellingOnUnlocked */
-#define  PANEL_CHECKBOX_RECENTER          88      /* control type: radioButton, callback function: CB_OnReCentering */
-#define  PANEL_CHECKBOX_KEEPSLOPE         89      /* control type: radioButton, callback function: CB_OnCROX */
-#define  PANEL_CHECKBOX_KEEP              90      /* control type: radioButton, callback function: CB_OnCROX */
-#define  PANEL_SLOPE_REFERENCE            91      /* control type: ring, callback function: CB_OnSlopeReference */
-#define  PANEL_ESTIMATE_N3                92      /* control type: command, callback function: CB_OnEstimateN */
-#define  PANEL_INVERT_SLOPE_SIGN          93      /* control type: radioButton, callback function: CB_InvertSlopeSign */
-#define  PANEL_MEASURE_SLOPE              94      /* control type: LED, callback function: CB_MeasureSlope */
-#define  PANEL_SLOPE_MEASURED             95      /* control type: numeric, callback function: (none) */
-#define  PANEL_RESET_DEDRIFT_DDS          96      /* control type: command, callback function: CB_ResetDedriftDDS */
-#define  PANEL_SAVE_RAW_DATA              97      /* control type: radioButton, callback function: (none) */
-#define  PANEL_SHOWLOG                    98      /* control type: radioButton, callback function: CB_ShowLog */
-#define  PANEL_SLOPEX2                    99      /* control type: radioButton, callback function: CB_SlopeX2 */
-#define  PANEL_SAVE_DDS_FREQS             100     /* control type: radioButton, callback function: (none) */
-#define  PANEL_DECORATION_2               101     /* control type: deco, callback function: (none) */
-#define  PANEL_DECORATION                 102     /* control type: deco, callback function: (none) */
-#define  PANEL_DECORATION_3               103     /* control type: deco, callback function: (none) */
-#define  PANEL_TEXTMSG_6                  104     /* control type: textMsg, callback function: (none) */
-#define  PANEL_TEXTMSG_7                  105     /* control type: textMsg, callback function: (none) */
-#define  PANEL_DECORATION_4               106     /* control type: deco, callback function: (none) */
-#define  PANEL_DECORATION_7               107     /* control type: deco, callback function: (none) */
-#define  PANEL_DECORATION_6               108     /* control type: deco, callback function: (none) */
-#define  PANEL_DECORATION_5               109     /* control type: deco, callback function: (none) */
-#define  PANEL_TEXTMSG_20                 110     /* control type: textMsg, callback function: (none) */
-#define  PANEL_TEXTMSG_19                 111     /* control type: textMsg, callback function: (none) */
+#define  PANEL_CHECKBOX_MATH5PLOT         37      /* control type: radioButton, callback function: CB_OnFreqPlot */
+#define  PANEL_CHECKBOX_MATH4PLOT         38      /* control type: radioButton, callback function: CB_OnFreqPlot */
+#define  PANEL_CHECKBOX_MATH4ALLAN        39      /* control type: radioButton, callback function: CB_OnAllanPlot */
+#define  PANEL_DDS1STEP                   40      /* control type: ring, callback function: CB_ChangeDDSStep */
+#define  PANEL_TEXTMSG_15                 41      /* control type: textMsg, callback function: (none) */
+#define  PANEL_CHECKBOX_MATH5ALLAN        42      /* control type: radioButton, callback function: CB_OnAllanPlot */
+#define  PANEL_CHECKBOX_MATH3PLOT         43      /* control type: radioButton, callback function: CB_OnFreqPlot */
+#define  PANEL_CHECKBOX_MATH5SAVE         44      /* control type: radioButton, callback function: (none) */
+#define  PANEL_SR_LOGGER                  45      /* control type: radioButton, callback function: (none) */
+#define  PANEL_CHECKBOX_MATH4SAVE         46      /* control type: radioButton, callback function: (none) */
+#define  PANEL_CHECKBOX_MATH3ALLAN        47      /* control type: radioButton, callback function: CB_OnAllanPlot */
+#define  PANEL_MATHSTRING4                48      /* control type: string, callback function: CB_ChangeMath */
+#define  PANEL_CHECKBOX_MATH2PLOT         49      /* control type: radioButton, callback function: CB_OnFreqPlot */
+#define  PANEL_CHECKBOX_MATH3SAVE         50      /* control type: radioButton, callback function: (none) */
+#define  PANEL_CHECKBOX_MATH2SAVE         51      /* control type: radioButton, callback function: (none) */
+#define  PANEL_CHECKBOX_MATH2ALLAN        52      /* control type: radioButton, callback function: CB_OnAllanPlot */
+#define  PANEL_MATHSTRING3                53      /* control type: string, callback function: CB_ChangeMath */
+#define  PANEL_MATHSTRING1                54      /* control type: string, callback function: CB_ChangeMath */
+#define  PANEL_MATHSTRING2                55      /* control type: string, callback function: CB_ChangeMath */
+#define  PANEL_TEXTMSG_16                 56      /* control type: textMsg, callback function: (none) */
+#define  PANEL_MINUS10KDDS1               57      /* control type: command, callback function: CB_OnMinus10k */
+#define  PANEL_MINUS10KDDS4               58      /* control type: command, callback function: CB_OnMinus10k */
+#define  PANEL_MINUS10KDDS3               59      /* control type: command, callback function: CB_OnMinus10k */
+#define  PANEL_MINUS10KDDS2               60      /* control type: command, callback function: CB_OnMinus10k */
+#define  PANEL_PLUS10KDDS4                61      /* control type: command, callback function: CB_OnPlus10k */
+#define  PANEL_PLUS10KDDS3                62      /* control type: command, callback function: CB_OnPlus10k */
+#define  PANEL_PLUS10KDDS1                63      /* control type: command, callback function: CB_OnPlus10k */
+#define  PANEL_PLUS10KDDS2                64      /* control type: command, callback function: CB_OnPlus10k */
+#define  PANEL_MATHSTRING5                65      /* control type: textBox, callback function: CB_ChangeMath */
+#define  PANEL_UTC                        66      /* control type: numeric, callback function: (none) */
+#define  PANEL_TIME                       67      /* control type: string, callback function: (none) */
+#define  PANEL_DDS4                       68      /* control type: numeric, callback function: CB_ChangeDDSOut */
+#define  PANEL_DDS3                       69      /* control type: numeric, callback function: CB_ChangeDDSOut */
+#define  PANEL_N1CALCULUS                 70      /* control type: command, callback function: CB_OnNCalculus */
+#define  PANEL_FINDSIGN3                  71      /* control type: command, callback function: CB_OnFindSign */
+#define  PANEL_SIGN3                      72      /* control type: numeric, callback function: CB_Sign3 */
+#define  PANEL_FINDSIGN2                  73      /* control type: command, callback function: CB_OnFindSign */
+#define  PANEL_SIGN2                      74      /* control type: numeric, callback function: (none) */
+#define  PANEL_FINDSIGN1                  75      /* control type: command, callback function: CB_OnFindSign */
+#define  PANEL_SIGN1                      76      /* control type: numeric, callback function: (none) */
+#define  PANEL_FIND10K3                   77      /* control type: command, callback function: CB_OnFind275K */
+#define  PANEL_FIND275K2                  78      /* control type: command, callback function: CB_OnFind275K */
+#define  PANEL_RESETSLOPE                 79      /* control type: command, callback function: CB_OnResetSlope */
+#define  PANEL_CHECKBOX_STOPIFAUTODE      80      /* control type: radioButton, callback function: CB_OnStopSlopeCancellingOnUnlocked */
+#define  PANEL_CHECKBOX_RECENTER          81      /* control type: radioButton, callback function: CB_OnReCentering */
+#define  PANEL_CHECKBOX_KEEPSLOPE         82      /* control type: radioButton, callback function: CB_OnCROX */
+#define  PANEL_CHECKBOX_KEEP              83      /* control type: radioButton, callback function: CB_OnCROX */
+#define  PANEL_SLOPE_REFERENCE            84      /* control type: ring, callback function: CB_OnSlopeReference */
+#define  PANEL_ESTIMATE_N3                85      /* control type: command, callback function: CB_OnEstimateN */
+#define  PANEL_INVERT_SLOPE_SIGN          86      /* control type: radioButton, callback function: CB_InvertSlopeSign */
+#define  PANEL_MEASURE_SLOPE              87      /* control type: LED, callback function: CB_MeasureSlope */
+#define  PANEL_SLOPE_MEASURED             88      /* control type: numeric, callback function: (none) */
+#define  PANEL_RESET_DEDRIFT_DDS          89      /* control type: command, callback function: CB_ResetDedriftDDS */
+#define  PANEL_SAVE_RAW_DATA              90      /* control type: radioButton, callback function: (none) */
+#define  PANEL_SHOWLOG                    91      /* control type: radioButton, callback function: CB_ShowLog */
+#define  PANEL_SLOPEX2                    92      /* control type: radioButton, callback function: CB_SlopeX2 */
+#define  PANEL_SAVE_DDS_FREQS             93      /* control type: radioButton, callback function: (none) */
+#define  PANEL_DECORATION_2               94      /* control type: deco, callback function: (none) */
+#define  PANEL_DECORATION                 95      /* control type: deco, callback function: (none) */
+#define  PANEL_DECORATION_3               96      /* control type: deco, callback function: (none) */
+#define  PANEL_TEXTMSG_6                  97      /* control type: textMsg, callback function: (none) */
+#define  PANEL_TEXTMSG_7                  98      /* control type: textMsg, callback function: (none) */
+#define  PANEL_DECORATION_4               99      /* control type: deco, callback function: (none) */
+#define  PANEL_DECORATION_7               100     /* control type: deco, callback function: (none) */
+#define  PANEL_DECORATION_6               101     /* control type: deco, callback function: (none) */
+#define  PANEL_DECORATION_5               102     /* control type: deco, callback function: (none) */
+#define  PANEL_TEXTMSG_20                 103     /* control type: textMsg, callback function: (none) */
+#define  PANEL_TEXTMSG_19                 104     /* control type: textMsg, callback function: (none) */
+#define  PANEL_MATH4                      105     /* control type: string, callback function: (none) */
+#define  PANEL_MATH5                      106     /* control type: string, callback function: (none) */
+#define  PANEL_MATH3                      107     /* control type: string, callback function: (none) */
+#define  PANEL_MATH2                      108     /* control type: string, callback function: (none) */
+#define  PANEL_MATH1                      109     /* control type: string, callback function: (none) */
 
 
      /* Control Arrays: */
Binary file FXAnalyse.uir has changed