changeset 76:5e0c314528bf

Refactor data writing to disk. Implement dayly chunking to separate files
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 30 Nov 2012 17:42:02 +0100
parents 6aae1ebf397f
children 87af2fbc2321
files FXAnalyse.c FXAnalyse.h FXAnalyse.uir
diffstat 3 files changed, 60 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/FXAnalyse.c	Thu Nov 29 13:16:32 2012 +0100
+++ b/FXAnalyse.c	Fri Nov 30 17:42:02 2012 +0100
@@ -17,6 +17,7 @@
 
 #define FXLINELENGTH 123
 #define LOGFILEPATH "C:\\Femto\\Software\\FXQE80"
+#define DATAFOLDER "Z:\\Measures-2012"
 
 #define DEDRIFT_DDS_FREQUENCY 70000000
 
@@ -200,6 +201,21 @@
 }
 
 
+void writeData(char *folder, char *name, char *id, char *date, char *time, double utc, double value)
+{
+	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);
+	
+	int fd = OpenFile(name, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII);
+	Fmt(line, "%s\t%s\t%f[p3]\t%f[p3]", date, time, utc, value);
+	WriteLine(fd, line, -1);
+	CloseFile(fd);
+}
+
+
 int main (int argc, char *argv[])
 {
 	double frequency;
@@ -482,7 +498,7 @@
 int CVICALLBACK CB_OnTimer (int panel, int control, int event,
 		void *callbackData, int eventData1, int eventData2)
 {
-	int LogFile, FileOpt, FileHg, FileExtraMath;
+	int LogFile;
 	long LogFileSize;
 	char LineBuffer[FXLINELENGTH+10] = "\r\n_1 ";
 	
@@ -498,7 +514,6 @@
 	char Sec[] = "00.000";
 	struct tm LocalTime ;
 	time_t utcTime;
-	char * ReportString = "dd.mm.yy\t00:00:00\t3481610838.000\t0000000000000.00000000";
 
 	int BoxChecked = FALSE; 
 	
@@ -1277,36 +1292,29 @@
 					}
 				}
 				
-				GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, &BoxChecked);			   // Save OL (Math2)
-				if (BoxChecked) {
-					FileOpt = OpenFile("z:\\MeasuresFifi1\\OptCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII);
-					Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math2);
-					WriteLine(FileOpt, ReportString, -1);
-					CloseFile(FileOpt);
-					FileOpt = OpenFile("C:\\Femto\\Results\\OptCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII);   // a local backup for debugging
-					Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math2);
-					WriteLine(FileOpt, ReportString, -1);
-					CloseFile(FileOpt);
+				int save;
+				// run id derived from current date in the form YYMMDD
+				char id[7];
+				snprintf(id, sizeof(id), "%2s%2s%2s", ShortYear, Month, Day);
+				
+				// write LO frequency (Math2) to disk
+				GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, &save);
+				if (save) {
+					writeData(DATAFOLDER, "OptCavity", id, Date, Time, utc, Math2);
+					writeData("C:\\Femto\\Results", "OptCavity", id, Date, Time, utc, Math2);
 				}
 				
-				GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, &BoxChecked);			   // Save Hg
-				if (BoxChecked) {
-					FileHg = OpenFile("z:\\MeasuresFifi1\\HgCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII);
-					Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math3);
-					WriteLine(FileHg, ReportString, -1);
-					CloseFile(FileHg);
-					FileHg = OpenFile("C:\\Femto\\Results\\HgCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII);
-					Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math3);
-					WriteLine(FileHg, ReportString, -1);
-					CloseFile(FileHg);
+				// write Hg frequency (Math3) to disk
+				GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, &save);
+				if (save) {
+					writeData(DATAFOLDER, "HgCavity", id, Date, Time, utc, Math3);
+					writeData("C:\\Femto\\Results", "HgCavity", id, Date, Time, utc, Math3);
 				}
 				
-				GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5SAVE, &BoxChecked);				// Save ExtraMath (Math5)
-				if (BoxChecked) {
-					FileExtraMath = OpenFile(ExtraMathFileName, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII);
-					Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p7]", Date, Time, utc, Math5);
-					WriteLine(FileExtraMath, ReportString, -1);
-					CloseFile(FileExtraMath);
+				// write ExtraMath (Math5) to disk
+				GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5SAVE, &save);
+				if (save) {
+					writeData(DATAFOLDER, "ExtraMath", id, Date, Time, utc, Math5);
 				}
 				
 				// Special case to handle change of day at next second
@@ -1681,22 +1689,6 @@
 }
 
 
-int CVICALLBACK OnChooseSaveFile (int panel, int control, int event,
-		void *callbackData, int eventData1, int eventData2)
-{
-	switch (event)
-		{
-		case EVENT_COMMIT:
-
-			FileSelectPopup("D:\\Manip Femto", "*.txt", "*.txt", "Selection of the ExtraMath saving file", VAL_SAVE_BUTTON, 0, 0, 0, FALSE, ExtraMathFileName) ;
-			SetCtrlAttribute(MainPanel, PANEL_CHECKBOX_MATH5SAVE, ATTR_DIMMED, FALSE) ;
-			
-			break;
-		}
-	return 0;
-}
-
-
 int CVICALLBACK CB_OnNCalculus (int panel, int control, int event,
 		void *callbackData, int eventData1, int eventData2)
 {
--- a/FXAnalyse.h	Thu Nov 29 13:16:32 2012 +0100
+++ b/FXAnalyse.h	Fri Nov 30 17:42:02 2012 +0100
@@ -147,31 +147,30 @@
 #define  PANEL_UTC                        93      /* control type: numeric, callback function: (none) */
 #define  PANEL_TIME                       94      /* control type: string, callback function: (none) */
 #define  PANEL_DATE                       95      /* control type: string, callback function: (none) */
-#define  PANEL_CHOOSESAVEFILE             96      /* control type: command, callback function: OnChooseSaveFile */
-#define  PANEL_SPLITTER_14                97      /* control type: splitter, callback function: (none) */
-#define  PANEL_SPLITTER_13                98      /* control type: splitter, callback function: (none) */
-#define  PANEL_DDS4                       99      /* control type: numeric, callback function: CB_ChangeDDSOut */
-#define  PANEL_SPLITTER_2                 100     /* control type: splitter, callback function: (none) */
-#define  PANEL_DDS3                       101     /* control type: numeric, callback function: CB_ChangeDDSOut */
-#define  PANEL_N1CALCULUS                 102     /* control type: command, callback function: CB_OnNCalculus */
-#define  PANEL_FINDSIGN3                  103     /* control type: command, callback function: CB_OnFindSign */
-#define  PANEL_SIGN3                      104     /* control type: numeric, callback function: (none) */
-#define  PANEL_FINDSIGN2                  105     /* control type: command, callback function: CB_OnFindSign */
-#define  PANEL_SIGN2                      106     /* control type: numeric, callback function: (none) */
-#define  PANEL_FINDSIGN1                  107     /* control type: command, callback function: CB_OnFindSign */
-#define  PANEL_SIGN1                      108     /* control type: numeric, callback function: (none) */
-#define  PANEL_FIND10K3                   109     /* control type: command, callback function: CB_OnFind275K */
-#define  PANEL_FIND275K2                  110     /* control type: command, callback function: CB_OnFind275K */
-#define  PANEL_RESETSLOPE                 111     /* control type: command, callback function: CB_OnResetSlope */
-#define  PANEL_CHECKBOX_STOPIFAUTODE      112     /* control type: radioButton, callback function: CB_OnStopSlopeCancellingOnUnlocked */
-#define  PANEL_CHECKBOX_RECENTER          113     /* control type: radioButton, callback function: CB_OnReCentering */
-#define  PANEL_CHECKBOX_KEEPSLOPE         114     /* control type: radioButton, callback function: CB_OnCROX */
-#define  PANEL_CHECKBOX_KEEP              115     /* control type: radioButton, callback function: CB_OnCROX */
-#define  PANEL_SLOPE_REFERENCE            116     /* control type: ring, callback function: CB_OnSlopeReference */
-#define  PANEL_ESTIMATE_N3                117     /* control type: command, callback function: CB_OnEstimateN */
-#define  PANEL_INVERT_SLOPE_SIGN          118     /* control type: radioButton, callback function: CB_InvertSlopeSign */
-#define  PANEL_MEASURE_SLOPE              119     /* control type: LED, callback function: CB_MeasureSlope */
-#define  PANEL_SLOPE_MEASURED             120     /* control type: numeric, callback function: (none) */
+#define  PANEL_SPLITTER_14                96      /* control type: splitter, callback function: (none) */
+#define  PANEL_SPLITTER_13                97      /* control type: splitter, callback function: (none) */
+#define  PANEL_DDS4                       98      /* control type: numeric, callback function: CB_ChangeDDSOut */
+#define  PANEL_SPLITTER_2                 99      /* control type: splitter, callback function: (none) */
+#define  PANEL_DDS3                       100     /* control type: numeric, callback function: CB_ChangeDDSOut */
+#define  PANEL_N1CALCULUS                 101     /* control type: command, callback function: CB_OnNCalculus */
+#define  PANEL_FINDSIGN3                  102     /* control type: command, callback function: CB_OnFindSign */
+#define  PANEL_SIGN3                      103     /* control type: numeric, callback function: (none) */
+#define  PANEL_FINDSIGN2                  104     /* control type: command, callback function: CB_OnFindSign */
+#define  PANEL_SIGN2                      105     /* control type: numeric, callback function: (none) */
+#define  PANEL_FINDSIGN1                  106     /* control type: command, callback function: CB_OnFindSign */
+#define  PANEL_SIGN1                      107     /* control type: numeric, callback function: (none) */
+#define  PANEL_FIND10K3                   108     /* control type: command, callback function: CB_OnFind275K */
+#define  PANEL_FIND275K2                  109     /* control type: command, callback function: CB_OnFind275K */
+#define  PANEL_RESETSLOPE                 110     /* control type: command, callback function: CB_OnResetSlope */
+#define  PANEL_CHECKBOX_STOPIFAUTODE      111     /* control type: radioButton, callback function: CB_OnStopSlopeCancellingOnUnlocked */
+#define  PANEL_CHECKBOX_RECENTER          112     /* control type: radioButton, callback function: CB_OnReCentering */
+#define  PANEL_CHECKBOX_KEEPSLOPE         113     /* control type: radioButton, callback function: CB_OnCROX */
+#define  PANEL_CHECKBOX_KEEP              114     /* control type: radioButton, callback function: CB_OnCROX */
+#define  PANEL_SLOPE_REFERENCE            115     /* control type: ring, callback function: CB_OnSlopeReference */
+#define  PANEL_ESTIMATE_N3                116     /* control type: command, callback function: CB_OnEstimateN */
+#define  PANEL_INVERT_SLOPE_SIGN          117     /* control type: radioButton, callback function: CB_InvertSlopeSign */
+#define  PANEL_MEASURE_SLOPE              118     /* control type: LED, callback function: CB_MeasureSlope */
+#define  PANEL_SLOPE_MEASURED             119     /* control type: numeric, callback function: (none) */
 
 
      /* Menu Bars, Menus, and Menu Items: */
@@ -216,7 +215,6 @@
 int  CVICALLBACK CB_OnStopSlopeCancellingOnUnlocked(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
 int  CVICALLBACK CB_OnTimer(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
 int  CVICALLBACK CB_SetSlope(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
-int  CVICALLBACK OnChooseSaveFile(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
 int  CVICALLBACK QuitCallback(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
 
 
Binary file FXAnalyse.uir has changed