$ ./OceanHDX_Calib -h
./OceanHDX_Calib [-H=host] [-Pport] [-Aavg|-auto] [-Iintg] [-F] [-SR=val] [-HG1] [-C=model|-C{0,1,2,3}=val]: perform a calibration of a OceanHDX spectrometer with a HG-1/HG-2 mercury calibration source
	-H=host Hostname or IP address (default 192.168.0.4)
	-Pport  Port number (default 57357)
	-Aavg   Hardware averages avg scans (default 1, recommanded higher value)
	-Iintg  Integration time in ms (default 1000)
	-auto   Auto-adjust integration time (recommanded)
	-F      Improve peak search by using a parabola fit (small increase in precision)
	-SR=val Search range on each side of a peak, in nm (default 4.0nm)
	-HG1    Use HG-1 calibration source (default is to use HG-2)
	-C=UV-VIS       Set hardcoded wavelength coefficients into the spectro and exit: I=0 C1=0 C2=0 C3=0
	-C=VIS-NIR      Set hardcoded wavelength coefficients into the spectro and exit: I=344.229 C1=0.362076 C2=-4.50373e-05 C3=3.10282e-09
	-C=XR   Set hardcoded wavelength coefficients into the spectro and exit: I=193.018 C1=0.557475 C2=-6.31192e-05 C3=4.1691e-09
	-C0=val Set wavelength coefficients I to 'val' and exit
	-C1=val Set wavelength coefficients C1x to 'val' and exit
	-C2=val Set wavelength coefficients C2x² to 'val' and exit
	-C3=val Set wavelength coefficients C3x³ to 'val' and exit



$ ./OceanHDX_Calib -auto -A100 -F -SR=7
	Socket created for OceanHDX
	OceanHDX connected

	Get main serial number
	Serial: HDX00441

	Get payload of length N: 20
	PASSED

	Get wavelength coefficient count: 4
	4 wavelengths coefficients: 193.018 0.557475 -6.31192e-05 4.1691e-09

Integration: 6..16000ms in steps of 1ms

	Set scans to average: 100
	Set integration time (μs): 6000
	Clear all buffered spectra

Searching for optimal integration rate: 6ms
	Get and send default spectrum immediately
Saving pixels to file 20191205_171231_Spectrum_HDX00441-A100-I6.csv
	Max value is 24119, you should be able to raise the integration from 6ms to ~16ms
Number of calibration peaks to search for: 29

Current spectrometer wavelength range: 193.018..1105.446nm, resolution: 0.557..0.352nm
Looking for peaks among 29 Hg-Ar peaks (29 within range):
Index: Intensities	TrueWL/CloseWL/InterpWL, ExpectedIdx/Relative/Interp
 0:                               17622 24119 21446  5882  1999  1626  1538  1512  1513  1502  1480  1478  1477  1454  1455  1452  1448  1444  1441  1434  1438  1465  1489  1494  1443                               253.652/253.582/247.707nm, 110/-11/99.2
 1:                          1510  1874  2129  1846  1388  1319  1315  1310  1313  1321  1345  1418  1502  1464  1344  1315  1314  1310  1313  1316  1312  1313  1315  1317  1319  1311  1319                         296.728/296.688/290.794nm, 190/-11/179.0
 2:                          1345  1418  1502  1464  1344  1315  1314  1310  1313  1316  1312  1313  1315  1317  1319  1311  1319  1328  1343  1452  1855  2914  4213  4133  2456  1457  1336                         302.150/302.022/307.046nm, 200/+9/209.4
 3:                          2914  4213  4133  2456  1457  1336  1325  1317  1318  1318  1319  1317  1320  1317  1319  1316  1315  1314  1310  1315  1313  1317  1314  1313  1315  1311  1309                         313.155/313.182/307.046nm, 221/-12/209.4
 4:                          1333  1380  1402  1330  1307  1300  1300  1299  1299  1308  1302  1302  1302  1303  1303  1307  1302  1304  1302  1301  1299  1299  1305  1307  1301  1301  1304                         334.148/334.293/328.367nm, 261/-11/249.7
 5:                          2033  3600  5022  3217  1933  1639  1370  1322  1313  1316  1320  1319  1320  1316  1317  1318  1320  1312  1319  1319  1321  1323  1322  1321  1321  1324  1312                         365.015/365.083/359.343nm, 320/-11/308.9
 6:                          1643  2711  3759  2663  1530  1340  1337  1394  1481  1423  1337  1317  1313  1314  1312  1312  1313  1315  1314  1312  1319  1317  1320  1323  1328  1322  1314                         404.656/404.648/399.033nm, 397/-11/386.0
 7:                          1337  1394  1481  1423  1337  1317  1313  1314  1312  1312  1313  1315  1314  1312  1319  1317  1320  1323  1328  1322  1314  1314  1315  1318  1318  1318  1329                         407.783/407.702/402.151nm, 403/-11/392.1
 8:                          3033  6620  7334  3291  1963  1504  1398  1365  1354  1348  1343  1345  1339  1339  1339  1337  1336  1331  1333  1333  1331  1329  1328  1326  1336  1330  1326                         435.833/436.004/430.297nm, 459/-11/447.7
 9:                    2713  4276  7232 10947  7810  2332  1442  1346  1328  1325  1316  1318  1317  1323  1316  1319  1318  1317  1318  1329  1329  1328  1317  1318  1318  1318  1325  1320  1313                   546.074/546.134/540.901nm, 684/-11/673.0
10:                    1476  1685  2036  2723  2604  1816  1894  2385  2903  1938  1384  1321  1308  1305  1309  1306  1303  1308  1311  1300  1309  1307  1305  1307  1307  1312  1306  1306  1307                   576.960/576.909/574.016nm, 749/-6/742.8
11:                    1816  1894  2385  2903  1938  1384  1321  1308  1305  1309  1306  1303  1308  1311  1300  1309  1307  1305  1307  1307  1312  1306  1306  1307  1306  1306  1305  1308  1306                   579.066/579.257/574.016nm, 754/-11/742.8
12:              1381  1512  2010  3584  5765  4138  1951  1414  1337  1326  1316  1315  1313  1310  1309  1310  1311  1309  1319  1323  1314  1317  1318  1330  1375  1512  1913  2553  2134  1501  1343             696.543/696.418/691.575nm, 1011/-11/1000.1
13:              1330  1375  1512  1913  2553  2134  1501  1343  1324  1317  1314  1314  1317  1315  1314  1315  1311  1316  1316  1320  1337  1383  1484  1455  1345  1310  1311  1313  1311  1311  1309             706.722/706.572/701.768nm, 1034/-11/1023.1
14:              1320  1337  1383  1484  1455  1345  1310  1311  1313  1311  1311  1309  1310  1309  1313  1311  1317  1317  1314  1314  1314  1316  1313  1316  1314  1308  1312  1318  1333  1393  1534             714.704/714.920/721.018nm, 1053/+15/1066.9
15:        1318  1333  1393  1534  1923  2631  2073  1452  1336  1320  1315  1314  1311  1308  1315  1315  1311  1309  1310  1306  1313  1310  1317  1326  1331  1336  1356  1417  1578  1986  3182  4012  2111       727.294/727.156/733.594nm, 1081/+15/1095.8
16:        1356  1417  1578  1986  3182  4012  2111  1434  1351  1331  1327  1324  1321  1320  1321  1317  1322  1321  1316  1320  1319  1327  1327  1335  1346  1359  1367  1396  1455  1623  2059  3401  7332       738.393/738.449/745.572nm, 1107/+16/1123.5
17:        1455  1623  2059  3401  7332  7247  3930  4554  2603  1577  1427  1386  1372  1362  1351  1350  1339  1336  1338  1336  1338  1344  1346  1356  1363  1369  1382  1396  1421  1456  1533  1715  2222       750.387/750.536/745.572nm, 1135/-12/1123.5
18:        1533  1715  2222  3462  8313 17958  8514  2592  1745  1548  1477  1447  1426  1411  1401  1393  1383  1382  1387  1398  1421  1463  1585  1883  2640  5713 10070  4311  1863  1522  1437  1416  1399       763.511/763.401/758.697nm, 1165/-11/1154.0
19:        1463  1585  1883  2640  5713 10070  4311  1863  1522  1437  1416  1399  1385  1374  1379  1383  1375  1361  1362  1356  1351  1347  1353  1357  1338  1333  1332  1320  1317  1319  1328  1336  1339       772.376/772.355/767.641nm, 1186/-11/1174.9
20:        1379  1424  1528  1878  3268  5074  2538  1546  1428  1403  1392  1395  1398  1409  1430  1478  1601  2062  3725  4928  4169  4594  2240  1527  1444  1416  1402  1389  1385  1376  1378  1383  1382       794.818/794.764/790.099nm, 1239/-11/1227.9
21:        1430  1478  1601  2062  3725  4928  4169  4594  2240  1527  1444  1416  1402  1389  1385  1376  1378  1383  1382  1391  1395  1413  1440  1471  1537  1680  2082  3594  6658  4735  7342 11303  4218       800.616/800.638/806.852nm, 1253/+15/1267.9
22:        2082  3594  6658  4735  7342 11303  4218  1895  1623  1528  1495  1469  1454  1434  1418  1405  1391  1375  1368  1365  1364  1361  1362  1363  1362  1365  1363  1359  1356  1361  1362  1370  1379       811.531/811.498/806.852nm, 1279/-11/1267.9
23:        1474  1571  1831  2678  6336  8368  3119  1718  1525  1468  1442  1427  1409  1393  1386  1378  1374  1376  1373  1364  1363  1360  1365  1370  1364  1366  1365  1368  1373  1381  1382  1384  1396       826.452/826.431/821.789nm, 1315/-11/1303.8
24:  2310  4948  5596  2572  2653  5994  6802  2515  1660  1535  1480  1457  1434  1411  1404  1395  1390  1384  1373  1369  1371  1368  1368  1370  1380  1395  1429  1550  2100  3703  2910  1591  1413  1381  1361 842.465/842.471/837.821nm, 1354/-11/1342.7
25:  1380  1395  1429  1550  2100  3703  2910  1591  1413  1381  1361  1352  1349  1341  1334  1336  1326  1325  1325  1319  1316  1321  1317  1316  1314  1317  1323  1323  1323  1321  1325  1330  1332  1328  1328 852.144/852.272/847.447nm, 1378/-12/1366.2
26:  1332  1335  1339  1357  1433  1665  1625  1378  1337  1332  1319  1312  1309  1308  1302  1305  1303  1305  1310  1307  1307  1305  1309  1306  1308  1308  1308  1307  1307  1305  1305  1308  1311  1308  1304 866.794/866.874/862.163nm, 1414/-12/1402.4
27:  1556  1640  1895  2800  4995  8194 12044  3761  2091  1778  1662  1594  1559  1522  1495  1471  1454  1442  1429  1414  1405  1398  1396  1392  1407  1395  1395  1412  1463  1703  1948  2742  2997  1715  1467 912.297/912.344/907.934nm, 1528/-11/1516.8
28:  1395  1412  1463  1703  1948  2742  2997  1715  1467  1411  1385  1378  1366  1354  1348  1343  1337  1335  1328  1329  1325  1325  1329  1338  1323  1319  1316  1317  1315  1317  1324  1327  1324  1323  1327 922.450/922.552/918.109nm, 1554/-11/1542.7

Input list of indices to exclude from computation, separated by [Space], and press [Enter]: 2 10 14 15 16 21

Regression analysis table:
Index	TrueWL	Pix	Pix²	Pix³
0	253.652	  99.2	   9842.3	    976442.6
1	296.728	 179.0	  32031.7	   5732838.0
3	313.155	 209.4	  43865.9	   9187370.9
4	334.148	 249.7	  62367.1	  15575186.0
5	365.015	 308.9	  95444.3	  29486633.9
6	404.656	 386.0	 148987.4	  57507452.5
7	407.783	 392.1	 153742.4	  60282399.0
8	435.833	 447.7	 200390.6	  89704874.3
9	546.074	 673.0	 452985.8	 304878530.8
11	579.066	 742.8	 551825.1	 409922863.0
12	696.543	1000.1	1000145.5	1000218240.7
13	706.722	1023.1	1046742.5	1070926796.6
17	750.387	1123.5	1262204.7	1418060256.4
18	763.511	1154.0	1331728.2	1536821297.8
19	772.376	1174.9	1380462.2	1621947375.9
20	794.818	1227.9	1507777.5	1851424082.7
22	811.531	1267.9	1607465.4	2038038827.4
23	826.452	1303.8	1699839.9	2216215700.2
24	842.465	1342.7	1802732.1	2420453708.1
25	852.144	1366.2	1866417.8	2549842230.3
26	866.794	1402.4	1966593.8	2757858559.7
27	912.297	1516.8	2300734.8	3489794341.7
28	922.450	1542.7	2379818.1	3671264253.1

Best fit    : λ = 199.336 +0.555099.p -6.16338e-05.p² +3.67981e-09.p³
Previous was: λ = 193.018 +0.557475.p -6.31192e-05.p² +4.16910e-09.p³
Covariance matrix:
[ +9.74391e-03, -4.72315e-05, +5.79530e-08, -2.07419e-11  
  -4.72315e-05, +2.60593e-07, -3.38221e-10, +1.25280e-13  
  +5.79530e-08, -3.38221e-10, +4.58967e-13, -1.75906e-16  
  -2.07419e-11, +1.25280e-13, -1.75906e-16, +6.92967e-20 ]
Chi² = 0.12857
R² = 0.999999943 (correlation coefficient)
Would you like to validate those results and write them to the spectro's firmware (you can always revert with -C) ? [y/N] : Y
	Setting wavelengths coefficients: I=199.336 C1=0.555099 C2=-6.16338e-05 C3=3.67981e-09
Your spectrometer is now calibrated !
Running this again with reduced -SR and increased -A may slightly improve the precision.

================== OCEAN HDX SPECTRO CLOSED ==================



$ ./OceanHDX_Calib -auto -A100 -F -SR=1
	Socket created for OceanHDX
	OceanHDX connected

	Get main serial number
	Serial: HDX00441

	Get payload of length N: 20
	PASSED

	Get wavelength coefficient count: 4
	4 wavelengths coefficients: 199.336 0.555099 -6.16338e-05 3.67981e-09

Integration: 6..16000ms in steps of 1ms

	Set scans to average: 100
	Set integration time (μs): 6000
	Clear all buffered spectra

Searching for optimal integration rate: 6ms
	Get and send default spectrum immediately
Saving pixels to file 20191205_171309_Spectrum_HDX00441-A100-I6.csv
	Max value is 24108, you should be able to raise the integration from 6ms to ~16ms
Number of calibration peaks to search for: 29

Current spectrometer wavelength range: 199.336..1108.927nm, resolution: 0.555..0.349nm
Looking for peaks among 29 Hg-Ar peaks (29 within range):
Index: Intensities	TrueWL/CloseWL/InterpWL, ExpectedIdx/Relative/Interp
 0:       17609 24108 21495       253.652/253.690/253.806nm, 99/+0/99.2
 1:        1870  2131  1848       296.728/296.745/296.734nm, 179/+0/179.0
 2:        1420  1502  1466       302.150/302.072/302.176nm, 189/+0/189.2
 3:        4207  4139  2467       313.155/313.222/312.931nm, 210/-1/209.5
 4:        1380  1403  1331       334.148/334.316/334.180nm, 250/+0/249.7
 5:        3596  5019  3224       365.015/365.085/365.055nm, 309/+0/308.9
 6:        2710  3758  2665       404.656/404.632/404.627nm, 386/+0/386.0
 7:        1395  1480  1426       407.783/407.685/407.742nm, 392/+0/392.1
 8:        6621  7348  3303       435.833/435.981/435.806nm, 448/+0/447.7
 9:  4277  7230 10950  7834  2336 546.074/546.123/546.144nm, 673/+0/673.0
10:  1684  2035  2720  2601  1818 576.960/576.909/577.074nm, 738/+0/738.4
11:  1894  2386  2909  1940  1386 579.066/579.258/579.188nm, 743/+0/742.9
12:  2006  3578  5768  4134  1955 696.543/696.480/696.512nm, 1000/+0/1000.1
13:  1513  1911  2552  2132  1502 706.722/706.640/706.685nm, 1023/+0/1023.1
14:  1338  1384  1485  1458  1345 714.704/714.553/714.680nm, 1041/+0/1041.3
15:  1534  1923  2629  2076  1453 727.294/727.235/727.261nm, 1070/+0/1070.1
16:  1984  3184  4013  2115  1435 738.393/738.533/738.448nm, 1096/+0/1095.8
17:  2061  3397  7323  7252  3931 750.387/750.195/750.402nm, 1123/+0/1123.5
18:  3459  8300 17949  8532  2594 763.511/763.496/763.498nm, 1154/+0/1154.0
19:  2637  5701 10067  4318  1864 772.376/772.453/772.424nm, 1175/+0/1174.9
20:  1880  3264  5076  2532  1548 794.818/794.868/794.833nm, 1228/+0/1227.9
21:  2067  3717  4936  4162  4604 800.616/800.744/800.791nm, 1242/+0/1242.1
22:  4723  7327 11311  4229  1897 811.531/811.607/811.548nm, 1268/+0/1267.9
23:  2681  6323  8375  3119  1717 826.452/826.541/826.450nm, 1304/+0/1303.8
24:  2652  5986  6810  2516  1666 842.465/842.581/842.442nm, 1343/+0/1342.7
25:  1551  2098  3698  2913  1590 852.144/851.974/852.043nm, 1366/+0/1366.2
26:  1433  1666  1626  1381  1338 866.794/866.981/866.720nm, 1403/-1/1402.4
27:  4983  8176 12048  3764  2092 912.297/912.430/912.358nm, 1517/+0/1516.8
28:  1948  2740  2999  1717  1468 922.450/922.630/922.501nm, 1543/+0/1542.7
Input list of indices to exclude from computation, separated by [Space], and press [Enter]: 
Regression analysis table:
Index	TrueWL	Pix	Pix²	Pix³
0	253.652	  99.2	   9843.3	    976582.3
1	296.728	 179.0	  32033.8	   5733395.6
2	302.150	 189.2	  35794.7	   6772178.3
3	313.155	 209.5	  43869.4	   9188459.1
4	334.148	 249.7	  62371.1	  15576694.6
5	365.015	 308.9	  95445.3	  29487075.7
6	404.656	 386.0	 148987.9	  57507758.7
7	407.783	 392.1	 153751.4	  60287708.2
8	435.833	 447.7	 200392.6	  89706228.4
9	546.074	 673.0	 452988.5	 304881249.3
10	576.960	 738.4	 545163.7	 402522674.2
11	579.066	 742.9	 551826.9	 409924922.8
12	696.543	1000.1	1000145.4	1000218112.1
13	706.722	1023.1	1046742.1	1070926179.0
14	714.704	1041.3	1084282.9	1129051936.6
15	727.294	1070.1	1145030.0	1225251712.8
16	738.393	1095.8	1200786.4	1315826536.7
17	750.387	1123.5	1262212.3	1418073138.6
18	763.511	1154.0	1331730.0	1536824571.1
19	772.376	1174.9	1380464.3	1621951237.1
20	794.818	1227.9	1507777.6	1851424266.3
21	800.616	1242.1	1542841.3	1916381173.4
22	811.531	1267.9	1607469.0	2038045725.1
23	826.452	1303.8	1699844.3	2216224398.1
24	842.465	1342.7	1802738.6	2420466761.1
25	852.144	1366.2	1866422.8	2549852464.8
26	866.794	1402.4	1966595.3	2757861737.8
27	912.297	1516.8	2300738.4	3489802689.3
28	922.450	1542.7	2379824.8	3671279710.5

Best fit    : λ = 199.332 +0.555087.p -6.16574e-05.p² +3.7003e-09.p³
Previous was: λ = 199.336 +0.555099.p -6.16338e-05.p² +3.67981e-09.p³
Covariance matrix:
[ +8.41864e-03, -4.14183e-05, +5.13726e-08, -1.85614e-11  
  -4.14183e-05, +2.32044e-07, -3.03446e-10, +1.13137e-13  
  +5.13726e-08, -3.03446e-10, +4.12219e-13, -1.58272e-16  
  -1.85614e-11, +1.13137e-13, -1.58272e-16, +6.22784e-20 ]
Chi² = 0.171712
R² = 0.999999934 (correlation coefficient)
Would you like to validate those results and write them to the spectro's firmware (you can always revert with -C) ? [y/N] : Y
	Setting wavelengths coefficients: I=199.332 C1=0.555087 C2=-6.16574e-05 C3=3.7003e-09
Your spectrometer is now calibrated !
Running this again with reduced -SR and increased -A may slightly improve the precision.
================== OCEAN HDX SPECTRO CLOSED ==================
$