comparison FXAnalyse.c @ 24:b838371c7a91

Code cleanup and dead code removal
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 20 Jul 2012 17:38:15 +0200
parents 65e277fdf01f
children fde495ba28d2
comparison
equal deleted inserted replaced
23:65e277fdf01f 24:b838371c7a91
15 #include "DDS_Fox.h" 15 #include "DDS_Fox.h"
16 #include "muParserDLL.h" 16 #include "muParserDLL.h"
17 17
18 18
19 #define FXLINELENGTH 123 19 #define FXLINELENGTH 123
20 #define LOGFILEPATH "C:\\Femto\\Software\\FXQE80"
21
20 #define DDSBESCLOCK (200.e6) // 200MHz de clock pour la DDS de Besancon... 22 #define DDSBESCLOCK (200.e6) // 200MHz de clock pour la DDS de Besancon...
21
22
23 #define LOGFILEPATH "C:\\Femto\\Software\\FXQE80"
24 #define FREP_NORMAL_FORMULA "(0-15M+DDS-Ch1/200)/12+2M/3"
25 #define NUOL_NORMAL_FORMULA "(N*250M-194400G)+N*Math1-8*DDS1"
26 #define NUHG_NORMAL_FORMULA "(N*250M-282143G)+N*Math1-(DDS1-Ch2)"
27 #define NUSR_NORMAL_FORMULA "(N*250M-429228G)+N*Math1+(DDS2-Ch3)"
28 #define NU813_NORMAL_FORMULA "(N*766M-368554G)+N*Math1+000.000M"
29 #define NU1064_NORMAL_FORMULA "(N*766M-281630G)+(DDS_1064-Ch4)"
30
31 #define FACTORDDSBES 36*(8/770000) 23 #define FACTORDDSBES 36*(8/770000)
32 24
33 //============================================================================== 25 //==============================================================================
34 // Static global variables 26 // Static global variables
35 27
53 // Global variables 45 // Global variables
54 46
55 char * LogFileName ; 47 char * LogFileName ;
56 char ExtraMathFileName[MAX_PATHNAME_LEN] ; 48 char ExtraMathFileName[MAX_PATHNAME_LEN] ;
57 49
58 double utc = 0 ; 50 double utc = 0;
59 double mjd =0 ; 51 double mjd = 0;
60 52
61 double Ch1, Ch2, Ch3, Ch4 ; // le type long double est identique au double (8 octets) sous CVI !!! 53 double Ch1, Ch2, Ch3, Ch4 ; // le type long double est identique au double (8 octets) sous CVI !!!
62 double Math1, Math2, Math3, Math4, Math5; // N est en fait un entier en pratique... 54 double Math1, Math2, Math3, Math4, Math5; // N est en fait un entier en pratique...
63 double N1, N2, N3, N4 ; 55 double N1, N2, N3, N4 ;
64 56
71 muParserHandle_t MathParser1, MathParser2, MathParser3, MathParser4, MathParser5 ; 63 muParserHandle_t MathParser1, MathParser2, MathParser3, MathParser4, MathParser5 ;
72 64
73 volatile bool Acquiring = FALSE ; 65 volatile bool Acquiring = FALSE ;
74 66
75 long OldLogFilePtr = 0 ; 67 long OldLogFilePtr = 0 ;
76
77 double NuOpt=0.0;
78 double Ndiv=8.0; 68 double Ndiv=8.0;
79 69
80 /////////////////// 70 ///////////////////
81 //Pour les calculs des N 71 //Pour les calculs des N
82 72
101 double N_1=0.0, N_2=0.0, N_3=0.0; 91 double N_1=0.0, N_2=0.0, N_3=0.0;
102 double DeltaT_1=20.0, DeltakHz_1=500.0, t1_1=0.0, t2_1=0.0, t3_1=0.0, Frepplus_1=0.0, Frepminus_1=0.0; 92 double DeltaT_1=20.0, DeltakHz_1=500.0, t1_1=0.0, t2_1=0.0, t3_1=0.0, Frepplus_1=0.0, Frepminus_1=0.0;
103 double DeltaT_2=20.0, DeltakHz_2=500.0, t1_2=0.0, t2_2=0.0, t3_2=0.0, Frepplus_2=0.0, Frepminus_2=0.0; 93 double DeltaT_2=20.0, DeltakHz_2=500.0, t1_2=0.0, t2_2=0.0, t3_2=0.0, Frepplus_2=0.0, Frepminus_2=0.0;
104 double DeltaT_3=20.0, DeltakHz_3=500.0, t1_3=0.0, t2_3=0.0, t3_3=0.0, Frepplus_3=0.0, Frepminus_3=0.0; 94 double DeltaT_3=20.0, DeltakHz_3=500.0, t1_3=0.0, t2_3=0.0, t3_3=0.0, Frepplus_3=0.0, Frepminus_3=0.0;
105 95
106 96 int n_1=0, n_2=0, n_3=0;
107 int DeltaTMoy_1=3,n_1=0,DeltaTMoy_2=3,n_2=0,DeltaTMoy_3=3,n_3=0;
108 double Tmoy_1_1=0.0,Tmoy_2_1=0.0,Tmoy_1_2=0.0,Tmoy_2_2=0.0,Tmoy_1_3=0.0,Tmoy_2_3=0.0;
109 double Frequ_slope_1=0.0,Moy_slope_1=0.0,Slope_slope_1=0.0,Frequ_slope_2=0.0,Moy_slope_2=0.0,Slope_slope_2=0.0,Frequ_slope_3=0.0,Moy_slope_3=0.0,Slope_slope_3=0.0; 97 double Frequ_slope_1=0.0,Moy_slope_1=0.0,Slope_slope_1=0.0,Frequ_slope_2=0.0,Moy_slope_2=0.0,Slope_slope_2=0.0,Frequ_slope_3=0.0,Moy_slope_3=0.0,Slope_slope_3=0.0;
110 int N_slope_1=0,N_slope_2=0,N_slope_3=0; 98 int N_slope_1=0,N_slope_2=0,N_slope_3=0;
111 double Beat_slope_2=0.0 ,Moy_Beatslope_2=0.0,Slope_Beatslope_2=0.0; 99 double Beat_slope_2=0.0 ,Moy_Beatslope_2=0.0,Slope_Beatslope_2=0.0;
112 double Ch4_slope=0.0,Moy_Ch4slope_1=0.0,Slope_Ch4slope_1=0.0,Ch4Slope=0.0; 100 double Ch4_slope=0.0,Moy_Ch4slope_1=0.0,Slope_Ch4slope_1=0.0,Ch4Slope=0.0;
113 101
121 109
122 double Step1=800000.0,Step2=800000.0; 110 double Step1=800000.0,Step2=800000.0;
123 111
124 double Ch4Plus=0.0,Ch4Minus=0.0; 112 double Ch4Plus=0.0,Ch4Minus=0.0;
125 113
126 int NDEJAPASSE=0, nDDSChange=0, nstabilization=0; 114 int nDDSChange=0, nstabilization=0;
127 115
128 ////// 116 //////
129 //Pour les signes de fb 117 //Pour les signes de fb
130 118
131 double Frequencystep1=10000.0, tbegin1=0.0, Frepbefore1=0.0, Frequency1=0.0; 119 double Frequencystep1=10000.0, tbegin1=0.0, Frepbefore1=0.0, Frequency1=0.0;
146 volatile bool AutoStopSlopeCancellingIfDelock=TRUE; 134 volatile bool AutoStopSlopeCancellingIfDelock=TRUE;
147 volatile bool OnSlopeCancelling =FALSE; 135 volatile bool OnSlopeCancelling =FALSE;
148 double SlopeMath2=0.0; 136 double SlopeMath2=0.0;
149 double TimetoSlope=60.0; 137 double TimetoSlope=60.0;
150 double SlopeMeasuringTimeBegin=0.0; 138 double SlopeMeasuringTimeBegin=0.0;
151 char * OnOffMessage="OFF" ;
152 139
153 char DDSFoxName[255] = "DDS Fox Control" ; 140 char DDSFoxName[255] = "DDS Fox Control" ;
154 double DDSFoxClock=200000000; 141 double DDSFoxClock=200000000;
155 int DDSFoxSweepSign=0; 142 int DDSFoxSweepSign=0;
156 double DDSFoxFrequency=70000000.0; 143 double DDSFoxFrequency=70000000.0;
162 149
163 double Slope_Math2slope=0.0,Math2_slope=0.0,Moy_Math2slope=0.0; 150 double Slope_Math2slope=0.0,Math2_slope=0.0,Moy_Math2slope=0.0;
164 int N_Math2slope=0.0,nstabilisationSlopeMeasuring=0; 151 int N_Math2slope=0.0,nstabilisationSlopeMeasuring=0;
165 152
166 double LimitToDelock=5.0; 153 double LimitToDelock=5.0;
167 double SlopeCorrection=0.0; 154 double limitotakoff=70.0;
168 155
169 int ratio=10; //Recentre la frequence tous les ratios 156 int ratio=10; //Recentre la frequence tous les ratios
170 157
171 volatile bool FrequCorrec=FALSE,KeepFrequ=TRUE, KeepSlope=TRUE ; 158 volatile bool FrequCorrec=FALSE,KeepFrequ=TRUE, KeepSlope=TRUE ;
172 int Nratio=-1; 159 int Nratio=-1;
173 double MoyMath2 = 0.0, CenterFrequencyCh2 = 0.0; 160 double MoyMath2 = 0.0, CenterFrequencyCh2 = 0.0;
174 volatile bool CenterFrequencyCh2ToDetermine=FALSE; 161 volatile bool CenterFrequencyCh2ToDetermine=FALSE;
175 162
176 double limitotakoff=70.0; 163
177 164
178 enum { 165 enum {
179 SLOPE_REFERENCE_MICROWAVE = 0, 166 SLOPE_REFERENCE_MICROWAVE = 0,
180 SLOPE_REFERENCE_HG_CAVITY = 1, 167 SLOPE_REFERENCE_HG_CAVITY = 1,
181 }; 168 };
686 Ch1 = 1000*Ch1; 673 Ch1 = 1000*Ch1;
687 Ch2 = 1000*Ch2; 674 Ch2 = 1000*Ch2;
688 Ch3 = 1000*Ch3; 675 Ch3 = 1000*Ch3;
689 Ch4 = 1000*Ch4; 676 Ch4 = 1000*Ch4;
690 677
691 NuOpt=N1*(250000000+Math1)-Signe1*8*FrequDDS1 ;
692
693 SetCtrlVal(MainPanel, PANEL_FREQ1, Ch1) ; 678 SetCtrlVal(MainPanel, PANEL_FREQ1, Ch1) ;
694 SetCtrlVal(MainPanel, PANEL_FREQ2, Ch2) ; 679 SetCtrlVal(MainPanel, PANEL_FREQ2, Ch2) ;
695 SetCtrlVal(MainPanel, PANEL_FREQ3, Ch3) ; 680 SetCtrlVal(MainPanel, PANEL_FREQ3, Ch3) ;
696 SetCtrlVal(MainPanel, PANEL_FREQ4, Ch4) ; 681 SetCtrlVal(MainPanel, PANEL_FREQ4, Ch4) ;
697 SetCtrlVal(MainPanel, PANEL_SIGN1, Signe1); 682 SetCtrlVal(MainPanel, PANEL_SIGN1, Signe1);
702 SetCtrlVal(CalcN2Panel, CALCN2_N, N_2) ; 687 SetCtrlVal(CalcN2Panel, CALCN2_N, N_2) ;
703 SetCtrlVal(CalcN2Panel, CALCN2_SLOPE, Beatslope_2) ; 688 SetCtrlVal(CalcN2Panel, CALCN2_SLOPE, Beatslope_2) ;
704 SetCtrlVal(CalcN3Panel, CALCN3_N, N_3) ; 689 SetCtrlVal(CalcN3Panel, CALCN3_N, N_3) ;
705 SetCtrlVal(CalcN3Panel, CALCN3_SLOPE, Slope_3) ; 690 SetCtrlVal(CalcN3Panel, CALCN3_SLOPE, Slope_3) ;
706 SetCtrlVal(MainPanel, PANEL_SLOPETOCANCEL, SlopeMath2); 691 SetCtrlVal(MainPanel, PANEL_SLOPETOCANCEL, SlopeMath2);
707 /*SetCtrlVal(MainPanel, PANEL_SLOPECANCELONOFF, OnOffMessage); */
708 SetCtrlVal(MainPanel, PANEL_CENTERFREQUENCY, CenterFrequencyCh2); 692 SetCtrlVal(MainPanel, PANEL_CENTERFREQUENCY, CenterFrequencyCh2);
709 SetCtrlVal(MainPanel, PANEL_LED1, SlopeMeasuring); 693 SetCtrlVal(MainPanel, PANEL_LED1, SlopeMeasuring);
710 SetCtrlVal(MainPanel, PANEL_LED2, OnSlopeCancelling); 694 SetCtrlVal(MainPanel, PANEL_LED2, OnSlopeCancelling);
711 // Treat data 695 // Treat data
712 696
713 Math1 = mupEval(MathParser1) ; 697 Math1 = mupEval(MathParser1) ;
714 SetCtrlVal(MainPanel,PANEL_MATH1, Math1) ; 698 SetCtrlVal(MainPanel,PANEL_MATH1, Math1) ;
715 699
716 Math2 = mupEval(MathParser2) ; 700 Math2 = mupEval(MathParser2) ;
717 //Math2=NuOpt;
718 SetCtrlVal(MainPanel,PANEL_MATH2, Math2) ; 701 SetCtrlVal(MainPanel,PANEL_MATH2, Math2) ;
719 702
720 Math3 = mupEval(MathParser3) ; 703 Math3 = mupEval(MathParser3) ;
721 SetCtrlVal(MainPanel,PANEL_MATH3, Math3) ; 704 SetCtrlVal(MainPanel,PANEL_MATH3, Math3) ;
722 705
1380 { 1363 {
1381 CenterFrequencyCh2 = MoyMath2; 1364 CenterFrequencyCh2 = MoyMath2;
1382 CenterFrequencyCh2ToDetermine = FALSE; 1365 CenterFrequencyCh2ToDetermine = FALSE;
1383 } 1366 }
1384 1367
1385 OnOffMessage = "ON " ;
1386 OnSlopeCancelling = TRUE; 1368 OnSlopeCancelling = TRUE;
1387 1369
1388 FoxFrequ = ReadDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate); 1370 FoxFrequ = ReadDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate);
1389 1371
1390 if (Nratio == ratio) 1372 if (Nratio == ratio)
1449 } 1431 }
1450 1432
1451 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,ActualFrequ,ActualSlope,0); 1433 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,ActualFrequ,ActualSlope,0);
1452 1434
1453 SlopeMeasuring = FALSE; 1435 SlopeMeasuring = FALSE;
1454 OnOffMessage = "OFF " ;
1455 N_Math2slope = 0.0; 1436 N_Math2slope = 0.0;
1456 Math2_slope = 0.0; 1437 Math2_slope = 0.0;
1457 MoyMath2 = 0.0; 1438 MoyMath2 = 0.0;
1458 Moy_Math2slope = 0.0; 1439 Moy_Math2slope = 0.0;
1459 Slope_Math2slope = 0.0; 1440 Slope_Math2slope = 0.0;
1498 1479
1499 } 1480 }
1500 1481
1501 1482
1502 } 1483 }
1503
1504
1505
1506
1507 // Now, some special extra functions for some math value which have special 'default' meaning (like nu_Hg and nu_Sr)
1508
1509 /*GetPanelAttribute(CalcNHgPanel, ATTR_VISIBLE, &BoxChecked) ; // correct name for answer would be more
1510 if (BoxChecked) { // something like "&PanelOpened" here
1511 N_1 = 0; // evaluate Math2 for N=0 gives 282143G-/+320M
1512 GetCtrlVal(CalcNHgPanel, CALCNHG_TARGET, &Target) ;
1513 NCalc = (Target-mupEval(MathParser2))/(Math1+766e6) ;
1514 SetCtrlVal(CalcNHgPanel, CALCNHG_NHGCALC, (double) RoundRealToNearestInteger (NCalc) ) ;
1515 SetCtrlVal(CalcNHgPanel, CALCNHG_ERROR, NCalc-RoundRealToNearestInteger (NCalc) ) ;
1516 GetCtrlVal(MainPanel, PANEL_N_HG, &N_1) ; // Set N_1 back to value user defined in main panel
1517 }
1518
1519 GetPanelAttribute(CalcNSrPanel, ATTR_VISIBLE, &BoxChecked) ; // correct name for answer would be more
1520 if (BoxChecked) { // something like "&PanelOpened" here, but I reuse variable name for concision
1521 N2 = 0; // evaluate Math3 for N=0 gives 429228G-/+DDS2-/+Ch3
1522 GetCtrlVal(CalcNSrPanel, CALCN2_TARGET, &Target) ;
1523 NCalc = (Target-mupEval(MathParser3))/(Math1+766e6) ;
1524 SetCtrlVal(CalcNSrPanel, CALCN2_NSRCALC, (double) RoundRealToNearestInteger (NCalc) ) ;
1525 SetCtrlVal(CalcNSrPanel, CALCNSR_ERROR, NCalc-RoundRealToNearestInteger (NCalc) ) ;
1526 GetCtrlVal(MainPanel, PANEL_N_SR, &N2) ; // Set N_2 back to value user defined in main panel
1527 }
1528
1529 GetPanelAttribute(CalcN813Panel, ATTR_VISIBLE, &BoxChecked) ; // correct name for answer would be more
1530 if (BoxChecked) { // something like "&PanelOpened" here, but I reuse variable name for concision
1531 N3 = 0; // evaluate Math4 for N=0 gives ??????G-/+DDS_813-/+Ch4
1532 GetCtrlVal(CalcN813Panel, CALCN83_TARGET, &Target) ;
1533 NCalc = (Target-mupEval(MathParser4))/(Math1+766e6) ;
1534 SetCtrlVal(CalcN813Panel, CALCN813_N813CALC, (double) RoundRealToNearestInteger (NCalc) ) ;
1535 SetCtrlVal(CalcN813Panel, CALCN813_ERROR, NCalc-RoundRealToNearestInteger (NCalc) ) ;
1536 GetCtrlVal(MainPanel, PANEL_N_813, &N3) ; // Set N3 back to value user defined in main panel
1537 }*/
1538 1484
1539 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2AUTOSAV, &BoxChecked) ; // AutoSave OL 1485 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2AUTOSAV, &BoxChecked) ; // AutoSave OL
1540 if (BoxChecked) { 1486 if (BoxChecked) {
1541 SetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, TRUE) ; // so that it will try to write it (at next block) if it seems reasonnable, even though it was off before 1487 SetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, TRUE) ; // so that it will try to write it (at next block) if it seems reasonnable, even though it was off before
1542 } 1488 }
1543 1489
1544 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, &BoxChecked) ; // Save OL (Math2) 1490 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, &BoxChecked) ; // Save OL (Math2)
1545 if (BoxChecked) { 1491 if (BoxChecked) {
1546 /*GetCtrlVal(CalcNHgPanel, CALCNHG_TARGET, &Target) ;
1547 if (abs(Math2-Target)>1e4) { // write it only if it's vaguely plausible (here outlier>10kHz ie approx 10000sigma but not dedrift applied !!!)
1548 SetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, FALSE) ;
1549 break ;
1550 } ;*/
1551 FileOpt = OpenFile("z:\\MeasuresFifi1\\OptCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ; 1492 FileOpt = OpenFile("z:\\MeasuresFifi1\\OptCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ;
1552 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math2); 1493 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math2);
1553 WriteLine(FileOpt, ReportString, -1) ; 1494 WriteLine(FileOpt, ReportString, -1) ;
1554 CloseFile(FileOpt) ; 1495 CloseFile(FileOpt) ;
1555 FileOpt = OpenFile("C:\\Femto\\Results\\OptCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ; // a local backup for debugging 1496 FileOpt = OpenFile("C:\\Femto\\Results\\OptCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ; // a local backup for debugging
1556 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math2); 1497 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math2);
1557 WriteLine(FileOpt, ReportString, -1) ; 1498 WriteLine(FileOpt, ReportString, -1) ;
1558 CloseFile(FileOpt) ; 1499 CloseFile(FileOpt) ;
1559 } 1500 }
1560 1501
1561 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3AUTOSAV, &BoxChecked) ; // AutoSave Hg (Math3) 1502 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3AUTOSAV, &BoxChecked) ; // AutoSave Hg (Math3)
1562 if (BoxChecked) { 1503 if (BoxChecked) {
1563 SetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, TRUE) ; // so that it will try to write it (at next block) if it seems reasonnable, even though it was off before 1504 SetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, TRUE) ; // so that it will try to write it (at next block) if it seems reasonnable, even though it was off before
1564 } 1505 }
1565 1506
1566 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, &BoxChecked) ; // Save Hg 1507 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, &BoxChecked) ; // Save Hg
1567 1508
1568 if (BoxChecked) { 1509 if (BoxChecked) {
1569 /*GetCtrlVal(CalcNSrPanel, CALCN3_TARGET, &Target) ;
1570 if (abs(Math3-Target)>1.0e4) { // write it only if it's vaguely plausible (here outlier>10kHz ie approx 10000sigma but not dedrift applied !!!)
1571 SetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, FALSE) ; // otherwise uncheck the save box
1572 break ;
1573 } ;*/
1574 FileHg = OpenFile("z:\\MeasuresFifi1\\HgCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ; 1510 FileHg = OpenFile("z:\\MeasuresFifi1\\HgCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ;
1575 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math3); 1511 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math3);
1576 WriteLine(FileHg, ReportString, -1) ; 1512 WriteLine(FileHg, ReportString, -1) ;
1577 CloseFile(FileHg) ; 1513 CloseFile(FileHg) ;
1578 FileHg = OpenFile("C:\\Femto\\Results\\HgCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ; 1514 FileHg = OpenFile("C:\\Femto\\Results\\HgCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ;
1579 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math3); 1515 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math3);
1580 WriteLine(FileHg, ReportString, -1) ; 1516 WriteLine(FileHg, ReportString, -1) ;
1581 CloseFile(FileHg) ; 1517 CloseFile(FileHg) ;
1582 1518 }
1583 }
1584 1519
1585 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5SAVE, &BoxChecked) ; // Save ExtraMath (Math5) 1520 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5SAVE, &BoxChecked) ; // Save ExtraMath (Math5)
1586 if (BoxChecked) { 1521 if (BoxChecked) {
1587 FileExtraMath = OpenFile(ExtraMathFileName, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ; 1522 FileExtraMath = OpenFile(ExtraMathFileName, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ;
1588 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p7]", Date, Time, utc, Math5); 1523 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p7]", Date, Time, utc, Math5);
1589 WriteLine(FileExtraMath, ReportString, -1) ; 1524 WriteLine(FileExtraMath, ReportString, -1) ;
1590 CloseFile(FileExtraMath) ; 1525 CloseFile(FileExtraMath) ;
1591 } 1526 }
1592 1527
1593 // Special case to handle change of day at next second 1528 // Special case to handle change of day at next second
1594 //if ( LocalTime.tm_hour==23 && LocalTime.tm_min==59 && strtod(Sec,NULL)>59 ) {
1595 if ( LocalTime.tm_hour==23 && LocalTime.tm_min==59 && strtod(Sec,NULL)>=58 ) { 1529 if ( LocalTime.tm_hour==23 && LocalTime.tm_min==59 && strtod(Sec,NULL)>=58 ) {
1596 printf("Entering change of date substructure\r\n"); 1530 printf("Entering change of date substructure\r\n");
1597 printf("old file : %s %s %s \r\n",Date, Time, LogFileName); 1531 printf("old file : %s %s %s \r\n",Date, Time, LogFileName);
1598 Acquiring = FALSE ; 1532 Acquiring = FALSE ;
1599 do { 1533 do {
1841 } 1775 }
1842 1776
1843 int CVICALLBACK CB_ChangeMath (int panel, int control, int event, 1777 int CVICALLBACK CB_ChangeMath (int panel, int control, int event,
1844 void *callbackData, int eventData1, int eventData2) 1778 void *callbackData, int eventData1, int eventData2)
1845 { 1779 {
1846 1780 int len;
1847 char * MathString = " " ; 1781 char *string;
1848 // should be long enough for any reasonnable math expression...
1849 1782
1850 switch (event) 1783 switch (event)
1851 { 1784 {
1852 case EVENT_COMMIT: 1785 case EVENT_COMMIT:
1853 GetCtrlVal(panel, control, MathString) ; 1786 GetCtrlAttribute(panel, control, ATTR_STRING_TEXT_LENGTH, &len);
1854 if (control==PANEL_MATHSTRING1) { mupSetExpr(MathParser1, MathString) ; } 1787 string = (char *)malloc(sizeof(char) * (len + 1));
1855 if (control==PANEL_MATHSTRING2) { mupSetExpr(MathParser2, MathString) ; } 1788 GetCtrlVal(panel, control, string);
1856 if (control==PANEL_MATHSTRING3) { mupSetExpr(MathParser3, MathString) ; } 1789 switch (control) {
1857 if (control==PANEL_MATHSTRING4) { mupSetExpr(MathParser4, MathString) ; } 1790 case PANEL_MATHSTRING1:
1858 if (control==PANEL_MATHSTRING5) { mupSetExpr(MathParser5, MathString) ; } 1791 mupSetExpr(MathParser1, string);
1792 break;
1793 case PANEL_MATHSTRING2:
1794 mupSetExpr(MathParser2, string);
1795 break;
1796 case PANEL_MATHSTRING3:
1797 mupSetExpr(MathParser3, string);
1798 break;
1799 case PANEL_MATHSTRING4:
1800 mupSetExpr(MathParser4, string);
1801 break;
1802 case PANEL_MATHSTRING5:
1803 mupSetExpr(MathParser5, string);
1804 break;
1805 }
1806 free(string);
1859 break; 1807 break;
1860 } 1808 }
1861 return 0; 1809 return 0;
1862 } 1810 }
1863 1811
1874 break; 1822 break;
1875 } 1823 }
1876 return 0; 1824 return 0;
1877 } 1825 }
1878 1826
1827
1879 int CVICALLBACK CB_OnPlus275k (int panel, int control, int event, 1828 int CVICALLBACK CB_OnPlus275k (int panel, int control, int event,
1880 void *callbackData, int eventData1, int eventData2) 1829 void *callbackData, int eventData1, int eventData2)
1881 { 1830 {
1882 double Frequency ; 1831 double Frequency ;
1883 1832
1884 switch (event) 1833 switch (event)
1885 { 1834 {
1886 case EVENT_COMMIT: 1835 case EVENT_COMMIT:
1887 GetCtrlVal(MainPanel, PANEL_DDSFREPOUT, &Frequency) ; 1836 GetCtrlVal(MainPanel, PANEL_DDSFREPOUT, &Frequency);
1888 Frequency += 275000.0 ; 1837 Frequency += 275000.0;
1889 DDSBes_SetFrequency(&DDSBes, Frequency) ; 1838 DDSBes_SetFrequency(&DDSBes, Frequency);
1890 SetCtrlVal(MainPanel, PANEL_DDSFREPOUT, Frequency) ; 1839 SetCtrlVal(MainPanel, PANEL_DDSFREPOUT, Frequency);
1891 /*SetCtrlVal(MainPanel, PANEL_MATHSTRING1, FREP_NORMAL_FORMULA) ; 1840 break;
1892 mupSetExpr(MathParser1, FREP_NORMAL_FORMULA) ; 1841 }
1893 SetCtrlVal(MainPanel, PANEL_MATHSTRING2, NUHG_NORMAL_FORMULA) ; 1842 return 0;
1894 mupSetExpr(MathParser2, NUHG_NORMAL_FORMULA) ; 1843 }
1895 SetCtrlVal(MainPanel, PANEL_MATHSTRING4, NU813_NORMAL_FORMULA) ; 1844
1896 mupSetExpr(MathParser4, NU813_NORMAL_FORMULA) ;
1897 */
1898 break;
1899 }
1900 return 0;
1901 }
1902 1845
1903 int CVICALLBACK CB_OnMinus275k (int panel, int control, int event, 1846 int CVICALLBACK CB_OnMinus275k (int panel, int control, int event,
1904 void *callbackData, int eventData1, int eventData2) 1847 void *callbackData, int eventData1, int eventData2)
1905 { 1848 {
1906 double Frequency ; 1849 double Frequency ;
1907 1850
1908 switch (event) 1851 switch (event)
1909 { 1852 {
1910 case EVENT_COMMIT: 1853 case EVENT_COMMIT:
1911 GetCtrlVal(MainPanel, PANEL_DDSFREPOUT, &Frequency) ; 1854 GetCtrlVal(MainPanel, PANEL_DDSFREPOUT, &Frequency);
1912 Frequency -= 275000.0 ; 1855 Frequency -= 275000.0;
1913 DDSBes_SetFrequency(&DDSBes, Frequency) ; 1856 DDSBes_SetFrequency(&DDSBes, Frequency);
1914 SetCtrlVal(MainPanel, PANEL_DDSFREPOUT, Frequency) ; 1857 SetCtrlVal(MainPanel, PANEL_DDSFREPOUT, Frequency);
1915 /*SetCtrlVal(MainPanel, PANEL_MATHSTRING1, "0") ; 1858 break;
1916 mupSetExpr(MathParser1, "0") ; 1859 }
1917 SetCtrlVal(MainPanel, PANEL_MATHSTRING2, "0") ; 1860 return 0;
1918 mupSetExpr(MathParser2, "0") ; 1861 }
1919 SetCtrlVal(MainPanel, PANEL_MATHSTRING4, "0") ; 1862
1920 mupSetExpr(MathParser4, "0") ;
1921 */
1922 break;
1923 }
1924 return 0;
1925 }
1926 1863
1927 int CVICALLBACK CB_OnPlus10k (int panel, int control, int event, 1864 int CVICALLBACK CB_OnPlus10k (int panel, int control, int event,
1928 void *callbackData, int eventData1, int eventData2) 1865 void *callbackData, int eventData1, int eventData2)
1929 { 1866 {
1930 double Frequency ; 1867 double Frequency ;
1931 1868
1932 switch (event) 1869 switch (event)
1933 { 1870 {
1934 case EVENT_COMMIT: 1871 case EVENT_COMMIT:
1935 if (control==PANEL_PLUS10KDDS1) { 1872 switch (control)
1936 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency) ; 1873 {
1937 Frequency += 10000.0 ; 1874 case PANEL_PLUS10KDDS1:
1938 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency); 1875 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency);
1939 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency) ; 1876 Frequency += 10000.0;
1940 /*SetCtrlVal(MainPanel, PANEL_MATHSTRING3, NUHG_NORMAL_FORMULA) ; 1877 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency);
1941 mupSetExpr(MathParser3, NUHG_NORMAL_FORMULA) ; 1878 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency);
1942 */ 1879 break;
1880 case PANEL_PLUS10KDDS2:
1881 GetCtrlVal(MainPanel, PANEL_DDS2, &Frequency);
1882 Frequency += 10000.0;
1883 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, Frequency);
1884 SetCtrlVal(MainPanel, PANEL_DDS2, Frequency);
1885 break;
1886 case PANEL_PLUS10KDDS3:
1887 GetCtrlVal(MainPanel, PANEL_DDS3, &Frequency);
1888 Frequency += 10000.0;
1889 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, Frequency);
1890 SetCtrlVal(MainPanel, PANEL_DDS3, Frequency);
1891 break;
1892 case PANEL_PLUS10KDDS4:
1893 GetCtrlVal(MainPanel, PANEL_DDS4, &Frequency);
1894 Frequency += 10000.0;
1895 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, Frequency);
1896 SetCtrlVal(MainPanel, PANEL_DDS4, Frequency);
1897 break;
1943 } 1898 }
1944 if (control==PANEL_PLUS10KDDS2) { 1899 break;
1945 GetCtrlVal(MainPanel, PANEL_DDS2, &Frequency) ; 1900 }
1946 Frequency += 10000.0 ; 1901 return 0;
1947 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, Frequency); 1902 }
1948 SetCtrlVal(MainPanel, PANEL_DDS2, Frequency) ; 1903
1949 /*SetCtrlVal(MainPanel, PANEL_MATHSTRING3, NUSR_NORMAL_FORMULA) ; 1904
1950 mupSetExpr(MathParser3, NUSR_NORMAL_FORMULA) ; 1905 int CVICALLBACK CB_OnMinus10k (int panel, int control, int event,
1951 */ 1906 void *callbackData, int eventData1, int eventData2)
1907 {
1908 double Frequency;
1909
1910 switch (event)
1911 {
1912 case EVENT_COMMIT:
1913 switch (control)
1914 {
1915 case PANEL_MINUS10KDDS1:
1916 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency);
1917 Frequency -= 10000.0;
1918 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency);
1919 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency);
1920 break;
1921 case PANEL_MINUS10KDDS2:
1922 GetCtrlVal(MainPanel, PANEL_DDS2, &Frequency);
1923 Frequency -= 10000.0;
1924 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, Frequency);
1925 SetCtrlVal(MainPanel, PANEL_DDS2, Frequency);
1926 break;
1927 case PANEL_MINUS10KDDS3:
1928 GetCtrlVal(MainPanel, PANEL_DDS3, &Frequency);
1929 Frequency -= 10000.0;
1930 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, Frequency);
1931 SetCtrlVal(MainPanel, PANEL_DDS3, Frequency);
1932 break;
1933 case PANEL_MINUS10KDDS4:
1934 GetCtrlVal(MainPanel, PANEL_DDS4, &Frequency);
1935 Frequency -= 10000.0;
1936 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, Frequency);
1937 SetCtrlVal(MainPanel, PANEL_DDS4, Frequency);
1938 break;
1952 } 1939 }
1953 if (control==PANEL_PLUS10KDDS3) { 1940 break;
1954 GetCtrlVal(MainPanel, PANEL_DDS3, &Frequency) ; 1941 }
1955 Frequency += 10000.0 ; 1942 return 0;
1956 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, Frequency); 1943 }
1957 SetCtrlVal(MainPanel, PANEL_DDS3, Frequency) ;
1958 }
1959 if (control==PANEL_PLUS10KDDS4) {
1960 GetCtrlVal(MainPanel, PANEL_DDS4, &Frequency) ;
1961 Frequency += 10000.0 ;
1962 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, Frequency);
1963 SetCtrlVal(MainPanel, PANEL_DDS4, Frequency) ;
1964 }
1965 break;
1966 }
1967 return 0;
1968 }
1969
1970 int CVICALLBACK CB_OnMinus10k (int panel, int control, int event,
1971 void *callbackData, int eventData1, int eventData2)
1972 {
1973 double Frequency ;
1974
1975 switch (event)
1976 {
1977 case EVENT_COMMIT:
1978 if (control==PANEL_MINUS10KDDS1) {
1979 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency) ;
1980 Frequency -= 10000.0 ;
1981 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency);
1982 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency) ;
1983 /*SetCtrlVal(MainPanel, PANEL_MATHSTRING3, NUHG_NORMAL_FORMULA) ;
1984 mupSetExpr(MathParser3, NUHG_NORMAL_FORMULA) ;
1985 */
1986 }
1987 if (control==PANEL_MINUS10KDDS2) {
1988 GetCtrlVal(MainPanel, PANEL_DDS2, &Frequency) ;
1989 Frequency -= 10000.0 ;
1990 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, Frequency);
1991 SetCtrlVal(MainPanel, PANEL_DDS2, Frequency) ;
1992 /*SetCtrlVal(MainPanel, PANEL_MATHSTRING3, NUSR_NORMAL_FORMULA) ;
1993 mupSetExpr(MathParser3, NUSR_NORMAL_FORMULA) ;
1994 */
1995 }
1996 if (control==PANEL_MINUS10KDDS3) {
1997 GetCtrlVal(MainPanel, PANEL_DDS3, &Frequency) ;
1998 Frequency -= 10000.0 ;
1999 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, Frequency);
2000 SetCtrlVal(MainPanel, PANEL_DDS3, Frequency) ;
2001 }
2002 if (control==PANEL_MINUS10KDDS4) {
2003 GetCtrlVal(MainPanel, PANEL_DDS4, &Frequency) ;
2004 Frequency -= 10000.0 ;
2005 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, Frequency);
2006 SetCtrlVal(MainPanel, PANEL_DDS4, Frequency) ;
2007 }
2008 break;
2009 }
2010 return 0;
2011 }
2012
2013 1944
2014 1945
2015 1946
2016 int CVICALLBACK CB_OnSaveOpt (int panel, int control, int event, 1947 int CVICALLBACK CB_OnSaveOpt (int panel, int control, int event,
2017 void *callbackData, int eventData1, int eventData2) 1948 void *callbackData, int eventData1, int eventData2)
2157 break; 2088 break;
2158 } 2089 }
2159 return 0; 2090 return 0;
2160 } 2091 }
2161 2092
2162 /*int CVICALLBACK OnFSRStep (int panel, int control, int event,
2163 void *callbackData, int eventData1, int eventData2)
2164 {
2165 double Target, FSR ;
2166
2167 switch (event)
2168 {
2169 case EVENT_COMMIT:
2170 if (panel==CalcNHgPanel) {
2171 if (control==CALCNHG_MINUSFSR) {
2172 GetCtrlVal(CalcNHgPanel, CALCNHG_FSR, &FSR) ;
2173 GetCtrlVal(CalcNHgPanel, CALCNHG_TARGET, &Target) ;
2174 Target -= FSR ;
2175 SetCtrlVal(CalcNHgPanel, CALCNHG_TARGET, Target) ;
2176 }
2177 if (control==CALCNHG_PLUSFSR) {
2178 GetCtrlVal(CalcNHgPanel, CALCNHG_FSR, &FSR) ;
2179 GetCtrlVal(CalcNHgPanel, CALCNHG_TARGET, &Target) ;
2180 Target += FSR ;
2181 SetCtrlVal(CalcNHgPanel, CALCNHG_TARGET, Target) ;
2182 }
2183 }
2184 if (panel==CalcNSrPanel) {
2185 if (control==CALCNSR_MINUSFSR) {
2186 GetCtrlVal(CalcNSrPanel, CALCNSR_FSR, &FSR) ;
2187 GetCtrlVal(CalcNSrPanel, CALCNSR_TARGET, &Target) ;
2188 Target -= FSR ;
2189 SetCtrlVal(CalcNSrPanel, CALCNSR_TARGET, Target) ;
2190 }
2191 if (control==CALCNSR_PLUSFSR) {
2192 GetCtrlVal(CalcNSrPanel, CALCNSR_FSR, &FSR) ;
2193 GetCtrlVal(CalcNSrPanel, CALCNSR_TARGET, &Target) ;
2194 Target += FSR ;
2195 SetCtrlVal(CalcNSrPanel, CALCNSR_TARGET, Target) ;
2196 }
2197 }
2198 break;
2199 }
2200 return 0;
2201 } */
2202
2203 /*int CVICALLBACK OnExtrapolateTarget (int panel, int control, int event,
2204 void *callbackData, int eventData1, int eventData2)
2205 {
2206 bool BoxChecked = FALSE ;
2207 double extrapolFreq = 745967614;
2208 time_t utcTime ;
2209 double utc ;
2210
2211 switch (event)
2212 {
2213 case EVENT_COMMIT:
2214 GetCtrlVal(CalcNHgPanel, CALCNHG_EXTRAPOLATE, &BoxChecked) ;
2215 if (BoxChecked) {
2216 SetCtrlAttribute(CalcNHgPanel, CALCNHG_TARGET, ATTR_DIMMED, TRUE) ;
2217 SetCtrlAttribute(CalcNHgPanel, CALCNHG_OFFSETFREQ, ATTR_DIMMED, TRUE) ;
2218 SetCtrlAttribute(CalcNHgPanel, CALCNHG_PLUSFSR, ATTR_DIMMED, TRUE) ;
2219 SetCtrlAttribute(CalcNHgPanel, CALCNHG_MINUSFSR, ATTR_DIMMED, TRUE) ;
2220 utc = time(&utcTime) ;
2221 //extrapolFreq = 746127081 + 0.032*(utc-3491304000) ; // linear data extrapolation with slope from 18/08/2010-12/08/2010
2222 extrapolFreq = 746108328.707542 + 3.144737e-002 * (utc-3490779388.183) - 9.527612e-010 * (utc-3490779388.183) ; // quad extrapol from fit of data in HgCavity.txt 5/10/2010
2223
2224
2225 SetCtrlVal(CalcNHgPanel, CALCNHG_TARGET, extrapolFreq) ;
2226 }
2227 else {
2228 SetCtrlAttribute(CalcNHgPanel, CALCNHG_TARGET, ATTR_DIMMED, FALSE) ;
2229 SetCtrlAttribute(CalcNHgPanel, CALCNHG_OFFSETFREQ, ATTR_DIMMED, FALSE) ;
2230 SetCtrlAttribute(CalcNHgPanel, CALCNHG_PLUSFSR, ATTR_DIMMED, FALSE) ;
2231 SetCtrlAttribute(CalcNHgPanel, CALCNHG_MINUSFSR, ATTR_DIMMED, FALSE) ;
2232 }
2233 break;
2234 }
2235 return 0;
2236 } */
2237
2238 2093
2239 int CVICALLBACK OnChooseSaveFile (int panel, int control, int event, 2094 int CVICALLBACK OnChooseSaveFile (int panel, int control, int event,
2240 void *callbackData, int eventData1, int eventData2) 2095 void *callbackData, int eventData1, int eventData2)
2241 { 2096 {
2242 switch (event) 2097 switch (event)
2248 2103
2249 break; 2104 break;
2250 } 2105 }
2251 return 0; 2106 return 0;
2252 } 2107 }
2253
2254
2255 // Changements pour Calcul de N
2256
2257 2108
2258 2109
2259 int CVICALLBACK CB_OnNCalculus (int panel, int control, int event, 2110 int CVICALLBACK CB_OnNCalculus (int panel, int control, int event,
2260 void *callbackData, int eventData1, int eventData2) 2111 void *callbackData, int eventData1, int eventData2)
2261 { 2112 {
2643 OnSlopeCancelling =TRUE; } 2494 OnSlopeCancelling =TRUE; }
2644 else { ActualSlope= DDSFoxSweeprate; 2495 else { ActualSlope= DDSFoxSweeprate;
2645 OnSlopeCancelling =FALSE; } 2496 OnSlopeCancelling =FALSE; }
2646 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,ActualFrequ,ActualSlope,0); 2497 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,ActualFrequ,ActualSlope,0);
2647 SlopeMeasuring=FALSE; 2498 SlopeMeasuring=FALSE;
2648 OnOffMessage="OFF " ;
2649 N_Math2slope=0.0; 2499 N_Math2slope=0.0;
2650 Math2_slope=0.0; 2500 Math2_slope=0.0;
2651 Moy_Math2slope=0.0; 2501 Moy_Math2slope=0.0;
2652 Slope_Math2slope=0.0; 2502 Slope_Math2slope=0.0;
2653 MoyMath2=0.0; 2503 MoyMath2=0.0;