Mercurial > hg > fxanalyse
comparison FXAnalyse.c @ 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 | 3aa1f1c18961 |
comparison
equal
deleted
inserted
replaced
75:6aae1ebf397f | 76:5e0c314528bf |
---|---|
15 #include "DDS_Fox.h" | 15 #include "DDS_Fox.h" |
16 #include "muParserDLL.h" | 16 #include "muParserDLL.h" |
17 | 17 |
18 #define FXLINELENGTH 123 | 18 #define FXLINELENGTH 123 |
19 #define LOGFILEPATH "C:\\Femto\\Software\\FXQE80" | 19 #define LOGFILEPATH "C:\\Femto\\Software\\FXQE80" |
20 #define DATAFOLDER "Z:\\Measures-2012" | |
20 | 21 |
21 #define DEDRIFT_DDS_FREQUENCY 70000000 | 22 #define DEDRIFT_DDS_FREQUENCY 70000000 |
22 | 23 |
23 // panel handling stuff | 24 // panel handling stuff |
24 static PanelHandle MainPanel ; | 25 static PanelHandle MainPanel ; |
195 mupDefinePostfixOprt(parser, "n", &nano, 1); | 196 mupDefinePostfixOprt(parser, "n", &nano, 1); |
196 mupDefinePostfixOprt(parser, "p", &pico, 1); | 197 mupDefinePostfixOprt(parser, "p", &pico, 1); |
197 mupDefinePostfixOprt(parser, "f", &femto, 1); | 198 mupDefinePostfixOprt(parser, "f", &femto, 1); |
198 | 199 |
199 return parser; | 200 return parser; |
201 } | |
202 | |
203 | |
204 void writeData(char *folder, char *name, char *id, char *date, char *time, double utc, double value) | |
205 { | |
206 char line[1024]; | |
207 char filename[FILENAME_MAX]; | |
208 | |
209 // construct filename in the form folder\\id-name.txt | |
210 snprintf(filename, sizeof(filename), "%s\\%s-%s.txt", folder, id, name); | |
211 | |
212 int fd = OpenFile(name, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII); | |
213 Fmt(line, "%s\t%s\t%f[p3]\t%f[p3]", date, time, utc, value); | |
214 WriteLine(fd, line, -1); | |
215 CloseFile(fd); | |
200 } | 216 } |
201 | 217 |
202 | 218 |
203 int main (int argc, char *argv[]) | 219 int main (int argc, char *argv[]) |
204 { | 220 { |
480 } | 496 } |
481 | 497 |
482 int CVICALLBACK CB_OnTimer (int panel, int control, int event, | 498 int CVICALLBACK CB_OnTimer (int panel, int control, int event, |
483 void *callbackData, int eventData1, int eventData2) | 499 void *callbackData, int eventData1, int eventData2) |
484 { | 500 { |
485 int LogFile, FileOpt, FileHg, FileExtraMath; | 501 int LogFile; |
486 long LogFileSize; | 502 long LogFileSize; |
487 char LineBuffer[FXLINELENGTH+10] = "\r\n_1 "; | 503 char LineBuffer[FXLINELENGTH+10] = "\r\n_1 "; |
488 | 504 |
489 char TimeTag[] = "100103 000000.000"; // K+K time tag meaning here 2010 january the 3rd at 00:00:00.000 | 505 char TimeTag[] = "100103 000000.000"; // K+K time tag meaning here 2010 january the 3rd at 00:00:00.000 |
490 char Date[] = "03/01/2010" ; | 506 char Date[] = "03/01/2010" ; |
496 char Hour[] = "00"; | 512 char Hour[] = "00"; |
497 char Min[] = "00" ; | 513 char Min[] = "00" ; |
498 char Sec[] = "00.000"; | 514 char Sec[] = "00.000"; |
499 struct tm LocalTime ; | 515 struct tm LocalTime ; |
500 time_t utcTime; | 516 time_t utcTime; |
501 char * ReportString = "dd.mm.yy\t00:00:00\t3481610838.000\t0000000000000.00000000"; | |
502 | 517 |
503 int BoxChecked = FALSE; | 518 int BoxChecked = FALSE; |
504 | 519 |
505 switch (event) { | 520 switch (event) { |
506 case EVENT_TIMER_TICK: | 521 case EVENT_TIMER_TICK: |
1275 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, frequency); | 1290 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, frequency); |
1276 CenteringTimeBegin10K = utc; | 1291 CenteringTimeBegin10K = utc; |
1277 } | 1292 } |
1278 } | 1293 } |
1279 | 1294 |
1280 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, &BoxChecked); // Save OL (Math2) | 1295 int save; |
1281 if (BoxChecked) { | 1296 // run id derived from current date in the form YYMMDD |
1282 FileOpt = OpenFile("z:\\MeasuresFifi1\\OptCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII); | 1297 char id[7]; |
1283 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math2); | 1298 snprintf(id, sizeof(id), "%2s%2s%2s", ShortYear, Month, Day); |
1284 WriteLine(FileOpt, ReportString, -1); | 1299 |
1285 CloseFile(FileOpt); | 1300 // write LO frequency (Math2) to disk |
1286 FileOpt = OpenFile("C:\\Femto\\Results\\OptCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII); // a local backup for debugging | 1301 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, &save); |
1287 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math2); | 1302 if (save) { |
1288 WriteLine(FileOpt, ReportString, -1); | 1303 writeData(DATAFOLDER, "OptCavity", id, Date, Time, utc, Math2); |
1289 CloseFile(FileOpt); | 1304 writeData("C:\\Femto\\Results", "OptCavity", id, Date, Time, utc, Math2); |
1290 } | 1305 } |
1291 | 1306 |
1292 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, &BoxChecked); // Save Hg | 1307 // write Hg frequency (Math3) to disk |
1293 if (BoxChecked) { | 1308 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, &save); |
1294 FileHg = OpenFile("z:\\MeasuresFifi1\\HgCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII); | 1309 if (save) { |
1295 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math3); | 1310 writeData(DATAFOLDER, "HgCavity", id, Date, Time, utc, Math3); |
1296 WriteLine(FileHg, ReportString, -1); | 1311 writeData("C:\\Femto\\Results", "HgCavity", id, Date, Time, utc, Math3); |
1297 CloseFile(FileHg); | 1312 } |
1298 FileHg = OpenFile("C:\\Femto\\Results\\HgCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII); | 1313 |
1299 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math3); | 1314 // write ExtraMath (Math5) to disk |
1300 WriteLine(FileHg, ReportString, -1); | 1315 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5SAVE, &save); |
1301 CloseFile(FileHg); | 1316 if (save) { |
1302 } | 1317 writeData(DATAFOLDER, "ExtraMath", id, Date, Time, utc, Math5); |
1303 | |
1304 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5SAVE, &BoxChecked); // Save ExtraMath (Math5) | |
1305 if (BoxChecked) { | |
1306 FileExtraMath = OpenFile(ExtraMathFileName, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII); | |
1307 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p7]", Date, Time, utc, Math5); | |
1308 WriteLine(FileExtraMath, ReportString, -1); | |
1309 CloseFile(FileExtraMath); | |
1310 } | 1318 } |
1311 | 1319 |
1312 // Special case to handle change of day at next second | 1320 // Special case to handle change of day at next second |
1313 if ( LocalTime.tm_hour==23 && LocalTime.tm_min==59 && strtod(Sec,NULL)>=58 ) { | 1321 if ( LocalTime.tm_hour==23 && LocalTime.tm_min==59 && strtod(Sec,NULL)>=58 ) { |
1314 Acquiring = FALSE; | 1322 Acquiring = FALSE; |
1679 } | 1687 } |
1680 return 0; | 1688 return 0; |
1681 } | 1689 } |
1682 | 1690 |
1683 | 1691 |
1684 int CVICALLBACK OnChooseSaveFile (int panel, int control, int event, | |
1685 void *callbackData, int eventData1, int eventData2) | |
1686 { | |
1687 switch (event) | |
1688 { | |
1689 case EVENT_COMMIT: | |
1690 | |
1691 FileSelectPopup("D:\\Manip Femto", "*.txt", "*.txt", "Selection of the ExtraMath saving file", VAL_SAVE_BUTTON, 0, 0, 0, FALSE, ExtraMathFileName) ; | |
1692 SetCtrlAttribute(MainPanel, PANEL_CHECKBOX_MATH5SAVE, ATTR_DIMMED, FALSE) ; | |
1693 | |
1694 break; | |
1695 } | |
1696 return 0; | |
1697 } | |
1698 | |
1699 | |
1700 int CVICALLBACK CB_OnNCalculus (int panel, int control, int event, | 1692 int CVICALLBACK CB_OnNCalculus (int panel, int control, int event, |
1701 void *callbackData, int eventData1, int eventData2) | 1693 void *callbackData, int eventData1, int eventData2) |
1702 { | 1694 { |
1703 | 1695 |
1704 int PanelIsVisible, PanelTop, PanelLeft, PanelWidth ; | 1696 int PanelIsVisible, PanelTop, PanelLeft, PanelWidth ; |