-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileIO.c
More file actions
500 lines (368 loc) · 18.2 KB
/
FileIO.c
File metadata and controls
500 lines (368 loc) · 18.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
#include "FileIO.h"
int openIniFile(Settings *settings)
{
//First the dclarations
IniText *iniSettings;
char *iniFileDir;
int *fileSuccessfullyOpened;
char exeDir[MAX_PATHNAME_LEN] = "";
int readFromFileFailed;
FILE *iniFileLocation;
//First let's make sure we have all parameters passed in.
if (!settings)
return -1;
iniSettings = &(settings->settingsHandle);
iniFileDir = settings->iniFile;
fileSuccessfullyOpened = &(settings->fileOpened);
//Next let's build the ini file directory and try to open the file.
GetProjectDir(exeDir);
MakePathname(exeDir, "config.ini", iniFileDir);
*iniSettings = Ini_New(0);
readFromFileFailed = Ini_ReadFromFile(*iniSettings, iniFileDir);
//Let's see if it failed and it's because the file doesn't exist, let's create it.
if (readFromFileFailed == -94 || readFromFileFailed == -5001)
{
//We'll use the standard method.
iniFileLocation = fopen(iniFileDir, "w");
//If it worked, let's close the file and try the op again.
if (iniFileLocation)
{
fclose(iniFileLocation);
readFromFileFailed = Ini_ReadFromFile(*iniSettings, iniFileDir);
}
}
if (!readFromFileFailed)
*fileSuccessfullyOpened = 1;
else
*fileSuccessfullyOpened = 0;
return readFromFileFailed;
}
int saveVNASettings(Settings *settings, int vnaPanelHandle)
{
IniText *settingsStorage;
char channel[256];
char key[19] = "Network Analyzer";
double value;
int ivalue;
unsigned short usvalue;
if ((vnaPanelHandle < 0) || (settings == NULL) || (settings->fileOpened == 0))
return -1;
settingsStorage = &(settings->settingsHandle);
GetCtrlVal(vnaPanelHandle, VNA_INPUT_PHYS_CHANNEL, channel);
Ini_PutString(*settingsStorage, key, "Input Channel", channel);
GetCtrlVal(vnaPanelHandle, VNA_INPUT_CONFIG, &ivalue);
Ini_PutDouble(*settingsStorage, key, "Input Terminal Configuration", ivalue);
GetCtrlVal(vnaPanelHandle, VNA_R_INPUT_PHYS_CHANNEL, channel);
Ini_PutString(*settingsStorage, key, "Reference Channel", channel);
GetCtrlVal(vnaPanelHandle, VNA_USE_REF_CHAN, &ivalue);
Ini_PutDouble(*settingsStorage, key, "Use Reference Channel", (double) ivalue);
GetCtrlVal(vnaPanelHandle, VNA_OUT_PHYS_CHANNEL, channel);
Ini_PutString(*settingsStorage, key, "Output Channel", channel);
GetCtrlVal(vnaPanelHandle, VNA_TRIG_PHYS_CHANNEL, channel);
Ini_PutString(*settingsStorage, key, "Trigger Channel", channel);
GetCtrlVal(vnaPanelHandle, VNA_USE_TRIG_CHAN, &ivalue);
Ini_PutDouble(*settingsStorage, key, "Use Trigger Channel", (double) ivalue);
GetCtrlVal(vnaPanelHandle, VNA_AVERAGES, &usvalue);
Ini_PutDouble(*settingsStorage, key, "Num Traces to Average", (double) usvalue);
GetCtrlVal(vnaPanelHandle, VNA_FIT_POS, &ivalue);
Ini_PutDouble(*settingsStorage, key, "Fit Start Pos", (double) ivalue);
GetCtrlVal(vnaPanelHandle, VNA_DELAY_TIME, &value);
Ini_PutDouble(*settingsStorage, key, "Delay Between Runs", value);
GetCtrlVal(vnaPanelHandle, VNA_GAIN, &value);
Ini_PutDouble(*settingsStorage, key, "Amp Gain", value);
GetCtrlVal(vnaPanelHandle, VNA_RATIO, &value);
Ini_PutDouble(*settingsStorage, key, "Divider Ratio", value);
GetCtrlVal(vnaPanelHandle, VNA_INPUT_VOLTAGE, &value);
Ini_PutDouble(*settingsStorage, key, "Input Voltage", value);
GetCtrlAttribute(vnaPanelHandle, VNA_INPUT_VOLTAGE, ATTR_MAX_VALUE, &value);
Ini_PutDouble(*settingsStorage, key, "Input Voltage Max", value);
GetCtrlVal(vnaPanelHandle, VNA_OUTPUT_VOLTAGE, &value);
Ini_PutDouble(*settingsStorage, key, "Output Voltage", value);
GetCtrlAttribute(vnaPanelHandle, VNA_OUTPUT_VOLTAGE, ATTR_MAX_VALUE, &value);
Ini_PutDouble(*settingsStorage, key, "Output Voltage Max", value);
GetCtrlVal(vnaPanelHandle, VNA_SIGNAL_START_FREQ, &value);
Ini_PutDouble(*settingsStorage, key, "Start Freq", value);
GetCtrlAttribute(vnaPanelHandle, VNA_SIGNAL_START_FREQ, ATTR_MAX_VALUE, &value);
Ini_PutDouble(*settingsStorage, key, "Start Freq Max", value);
GetCtrlVal(vnaPanelHandle, VNA_SIGNAL_STOP_FREQ, &value);
Ini_PutDouble(*settingsStorage, key, "Stop Freq", value);
GetCtrlAttribute(vnaPanelHandle, VNA_SIGNAL_STOP_FREQ, ATTR_MAX_VALUE, &value);
Ini_PutDouble(*settingsStorage, key, "Stop Freq Max", value);
GetCtrlVal(vnaPanelHandle, VNA_STEPS, &usvalue);
Ini_PutDouble(*settingsStorage, key, "Steps", usvalue);
GetCtrlVal(vnaPanelHandle, VNA_SIG_TYPE, &ivalue);
Ini_PutDouble(*settingsStorage, key, "Steps type", ivalue);
Ini_WriteToFile(*settingsStorage, settings->iniFile);
return 0;
}
int readVNASettings(Settings *settings, int vnaPanelHandle)
{
IniText *settingsStorage;
char *channel;
char key[19] = "Network Analyzer";
double value;
if ((vnaPanelHandle < 0) || (settings == NULL) || (settings->fileOpened == 0))
return -1;
settingsStorage = &(settings->settingsHandle);
if(Ini_GetPointerToString(*settingsStorage, key, "Input Channel", &channel) > 0)
SetCtrlVal(vnaPanelHandle, VNA_INPUT_PHYS_CHANNEL, channel);
if(Ini_GetDouble(*settingsStorage, key, "Input Terminal Configuration", &value) > 0)
SetCtrlVal(vnaPanelHandle, VNA_INPUT_CONFIG, (int) value);
if(Ini_GetPointerToString(*settingsStorage, key, "Reference Channel", &channel) > 0)
SetCtrlVal(vnaPanelHandle, VNA_R_INPUT_PHYS_CHANNEL, channel);
if(Ini_GetDouble(*settingsStorage, key, "Use Reference Channel", &value) > 0)
SetCtrlVal(vnaPanelHandle, VNA_USE_REF_CHAN, (int) value);
if(Ini_GetPointerToString(*settingsStorage, key, "Output Channel", &channel) > 0)
SetCtrlVal(vnaPanelHandle, VNA_OUT_PHYS_CHANNEL, channel);
if(Ini_GetPointerToString(*settingsStorage, key, "Trigger Channel", &channel) > 0)
SetCtrlVal(vnaPanelHandle, VNA_TRIG_PHYS_CHANNEL, channel);
if(Ini_GetDouble(*settingsStorage, key, "Use Trigger Channel", &value) > 0)
SetCtrlVal(vnaPanelHandle, VNA_USE_TRIG_CHAN, (int) value);
if(Ini_GetDouble(*settingsStorage, key, "Num Traces to Average", &value) > 0)
SetCtrlVal(vnaPanelHandle, VNA_AVERAGES, (int) value);
if(Ini_GetDouble(*settingsStorage, key, "Fit Start Pos", &value) > 0)
SetCtrlVal(vnaPanelHandle, VNA_FIT_POS, (int) value);
if(Ini_GetDouble(*settingsStorage, key, "Delay Between Runs", &value) > 0)
SetCtrlVal(vnaPanelHandle, VNA_DELAY_TIME, value);
if(Ini_GetDouble(*settingsStorage, key, "Amp Gain", &value) > 0)
SetCtrlVal(vnaPanelHandle, VNA_GAIN, value);
if(Ini_GetDouble(*settingsStorage, key, "Divider Ratio", &value) > 0)
SetCtrlVal(vnaPanelHandle, VNA_RATIO, value);
if(Ini_GetDouble(*settingsStorage, key, "Input Voltage", &value) > 0)
SetCtrlVal(vnaPanelHandle, VNA_INPUT_VOLTAGE, value);
if(Ini_GetDouble(*settingsStorage, key, "Input Voltage Max", &value) > 0)
SetCtrlAttribute(vnaPanelHandle, VNA_INPUT_VOLTAGE, ATTR_MAX_VALUE, value);
if(Ini_GetDouble(*settingsStorage, key, "Output Voltage", &value) > 0)
SetCtrlVal(vnaPanelHandle, VNA_OUTPUT_VOLTAGE, value);
if(Ini_GetDouble(*settingsStorage, key, "Output Voltage Max", &value) > 0)
SetCtrlAttribute(vnaPanelHandle, VNA_OUTPUT_VOLTAGE, ATTR_MAX_VALUE, value);
if(Ini_GetDouble(*settingsStorage, key, "Start Freq", &value) > 0)
SetCtrlVal(vnaPanelHandle, VNA_SIGNAL_START_FREQ, value);
if(Ini_GetDouble(*settingsStorage, key, "Start Freq Max", &value) > 0)
SetCtrlAttribute(vnaPanelHandle, VNA_SIGNAL_START_FREQ, ATTR_MAX_VALUE, value);
if(Ini_GetDouble(*settingsStorage, key, "Stop Freq", &value) > 0)
SetCtrlVal(vnaPanelHandle, VNA_SIGNAL_STOP_FREQ, value);
if(Ini_GetDouble(*settingsStorage, key, "Stop Freq Max", &value) > 0)
SetCtrlAttribute(vnaPanelHandle, VNA_SIGNAL_STOP_FREQ, ATTR_MAX_VALUE, value);
if(Ini_GetDouble(*settingsStorage, key, "Steps", &value) > 0)
SetCtrlVal(vnaPanelHandle, VNA_STEPS, (unsigned short) value);
if(Ini_GetDouble(*settingsStorage, key, "Steps type", &value) > 0)
SetCtrlVal(vnaPanelHandle, VNA_SIG_TYPE, (int) value);
return 0;
}
int saveSRSettings(Settings *settings, int vnaPanelHandle)
{
IniText *settingsStorage;
char channel[256];
char key[25] = "Static Response Analyzer";
double value;
int ivalue;
unsigned short usvalue;
if ((vnaPanelHandle < 0) || (settings == NULL) || (settings->fileOpened == 0))
return -1;
settingsStorage = &(settings->settingsHandle);
GetCtrlVal(vnaPanelHandle, STATIC_RES_INPUT_PHYS_CHANNEL, channel);
Ini_PutString(*settingsStorage, key, "Input Channel", channel);
GetCtrlVal(vnaPanelHandle, STATIC_RES_INPUT_CONFIG, &ivalue);
Ini_PutDouble(*settingsStorage, key, "Input Terminal Configuration", ivalue);
GetCtrlVal(vnaPanelHandle, STATIC_RES_R_INPUT_PHYS_CHANNEL, channel);
Ini_PutString(*settingsStorage, key, "Reference Channel", channel);
GetCtrlVal(vnaPanelHandle, STATIC_RES_OUT_PHYS_CHANNEL, channel);
Ini_PutString(*settingsStorage, key, "Output Channel", channel);
GetCtrlVal(vnaPanelHandle, STATIC_RES_SETTLE_TIME, &value);
Ini_PutDouble(*settingsStorage, key, "Settle Time", value);
GetCtrlVal(vnaPanelHandle, STATIC_RES_TRIG_PHYS_CHANNEL, channel);
Ini_PutString(*settingsStorage, key, "Trigger Channel", channel);
GetCtrlVal(vnaPanelHandle, STATIC_RES_USE_TRIG_CHAN, &ivalue);
Ini_PutDouble(*settingsStorage, key, "Use Trigger Channel", (double) ivalue);
GetCtrlVal(vnaPanelHandle, STATIC_RES_FIT_POS, &ivalue);
Ini_PutDouble(*settingsStorage, key, "Fit Start Pos", (double) ivalue);
GetCtrlVal(vnaPanelHandle, STATIC_RES_DELAY_TIME, &value);
Ini_PutDouble(*settingsStorage, key, "Delay Between Runs", value);
GetCtrlVal(vnaPanelHandle, STATIC_RES_INPUT_VOLTAGE, &value);
Ini_PutDouble(*settingsStorage, key, "Input Voltage", value);
GetCtrlAttribute(vnaPanelHandle, STATIC_RES_INPUT_VOLTAGE, ATTR_MAX_VALUE, &value);
Ini_PutDouble(*settingsStorage, key, "Input Voltage Max", value);
GetCtrlVal(vnaPanelHandle, STATIC_RES_GAIN, &value);
Ini_PutDouble(*settingsStorage, key, "Amp Gain", value);
GetCtrlVal(vnaPanelHandle, STATIC_RES_RATIO, &value);
Ini_PutDouble(*settingsStorage, key, "Divider Ratio", value);
GetCtrlVal(vnaPanelHandle, STATIC_RES_SIGNAL_START_V, &value);
Ini_PutDouble(*settingsStorage, key, "Start Voltage", value);
GetCtrlAttribute(vnaPanelHandle, STATIC_RES_SIGNAL_START_V, ATTR_MAX_VALUE, &value);
Ini_PutDouble(*settingsStorage, key, "Start Voltage Max", value);
GetCtrlVal(vnaPanelHandle, STATIC_RES_SIGNAL_STOP_V, &value);
Ini_PutDouble(*settingsStorage, key, "Stop Voltage", value);
GetCtrlAttribute(vnaPanelHandle, STATIC_RES_SIGNAL_STOP_V, ATTR_MAX_VALUE, &value);
Ini_PutDouble(*settingsStorage, key, "Stop Voltage Max", value);
GetCtrlVal(vnaPanelHandle, STATIC_RES_STEPS, &usvalue);
Ini_PutDouble(*settingsStorage, key, "Steps", usvalue);
GetCtrlVal(vnaPanelHandle, STATIC_RES_OUTPUT_FREQ, &value);
Ini_PutDouble(*settingsStorage, key, "Signal Frequency", value);
GetCtrlAttribute(vnaPanelHandle, STATIC_RES_OUTPUT_FREQ, ATTR_MAX_VALUE, &value);
Ini_PutDouble(*settingsStorage, key, "Signal Frequency Max", value);
Ini_WriteToFile(*settingsStorage, settings->iniFile);
return 0;
}
int readSRSettings(Settings *settings, int vnaPanelHandle)
{
IniText *settingsStorage;
char *channel;
char key[25] = "Static Response Analyzer";
double value;
if ((vnaPanelHandle < 0) || (settings == NULL) || (settings->fileOpened == 0))
return -1;
settingsStorage = &(settings->settingsHandle);
if(Ini_GetPointerToString(*settingsStorage, key, "Input Channel", &channel) > 0)
SetCtrlVal(vnaPanelHandle, STATIC_RES_INPUT_PHYS_CHANNEL, channel);
if(Ini_GetDouble(*settingsStorage, key, "Input Terminal Configuration", &value) > 0)
SetCtrlVal(vnaPanelHandle, STATIC_RES_INPUT_CONFIG, (int) value);
if(Ini_GetPointerToString(*settingsStorage, key, "Reference Channel", &channel) > 0)
SetCtrlVal(vnaPanelHandle, STATIC_RES_R_INPUT_PHYS_CHANNEL, channel);
if(Ini_GetPointerToString(*settingsStorage, key, "Output Channel", &channel) > 0)
SetCtrlVal(vnaPanelHandle, STATIC_RES_OUT_PHYS_CHANNEL, channel);
if(Ini_GetDouble(*settingsStorage, key, "Settle Time", &value) > 0)
SetCtrlVal(vnaPanelHandle, STATIC_RES_SETTLE_TIME, value);
if(Ini_GetPointerToString(*settingsStorage, key, "Trigger Channel", &channel) > 0)
SetCtrlVal(vnaPanelHandle, STATIC_RES_TRIG_PHYS_CHANNEL, channel);
if(Ini_GetDouble(*settingsStorage, key, "Use Trigger Channel", &value) > 0)
SetCtrlVal(vnaPanelHandle, STATIC_RES_USE_TRIG_CHAN, (int) value);
if(Ini_GetDouble(*settingsStorage, key, "Fit Start Pos", &value) > 0)
SetCtrlVal(vnaPanelHandle, STATIC_RES_FIT_POS, (int) value);
if(Ini_GetDouble(*settingsStorage, key, "Delay Between Runs", &value) > 0)
SetCtrlVal(vnaPanelHandle, STATIC_RES_DELAY_TIME, value);
if(Ini_GetDouble(*settingsStorage, key, "Amp Gain", &value) > 0)
SetCtrlVal(vnaPanelHandle, STATIC_RES_GAIN, value);
if(Ini_GetDouble(*settingsStorage, key, "Divider Ratio", &value) > 0)
SetCtrlVal(vnaPanelHandle, STATIC_RES_RATIO, value);
if(Ini_GetDouble(*settingsStorage, key, "Input Voltage", &value) > 0)
SetCtrlVal(vnaPanelHandle, STATIC_RES_INPUT_VOLTAGE, value);
if(Ini_GetDouble(*settingsStorage, key, "Input Voltage Max", &value) > 0)
SetCtrlAttribute(vnaPanelHandle, STATIC_RES_INPUT_VOLTAGE, ATTR_MAX_VALUE, value);
if(Ini_GetDouble(*settingsStorage, key, "Start Voltage", &value) > 0)
SetCtrlVal(vnaPanelHandle, STATIC_RES_SIGNAL_START_V, value);
if(Ini_GetDouble(*settingsStorage, key, "Start Voltage Max", &value) > 0)
SetCtrlAttribute(vnaPanelHandle, STATIC_RES_SIGNAL_START_V, ATTR_MAX_VALUE, value);
if(Ini_GetDouble(*settingsStorage, key, "Stop Voltage", &value) > 0)
SetCtrlVal(vnaPanelHandle, STATIC_RES_SIGNAL_STOP_V, value);
if(Ini_GetDouble(*settingsStorage, key, "Stop Voltage Max", &value) > 0)
SetCtrlAttribute(vnaPanelHandle, STATIC_RES_SIGNAL_STOP_V, ATTR_MAX_VALUE, value);
if(Ini_GetDouble(*settingsStorage, key, "Steps", &value) > 0)
SetCtrlVal(vnaPanelHandle, STATIC_RES_STEPS, (unsigned short) value);
if(Ini_GetDouble(*settingsStorage, key, "Signal Frequency", &value) > 0)
SetCtrlVal(vnaPanelHandle, STATIC_RES_OUTPUT_FREQ, value);
if(Ini_GetDouble(*settingsStorage, key, "Signal Frequency Max", &value) > 0)
SetCtrlAttribute(vnaPanelHandle, STATIC_RES_OUTPUT_FREQ, ATTR_MAX_VALUE, value);
return 0;
}
void saveInstrumentData(int isRunning, int dataPoints, double *freqData, double *voutData, double *magData, double *phaseData)
{
FILE* file;
char filepath[MAX_PATHNAME_LEN] = "";
int dialogReturn;
int i;
//First we need to make sure that the VNA isn't running. If it is let's get out of here.
if (!isRunning)
{
//Next let's make sure there is data to save.
if (dataPoints > 0)
{
//Now let's select a file and make sure no errors occur.
if((dialogReturn = FileSelectPopup("", "*.dat", "*.dat; *.txt; *.csv", "Save VNA Data", VAL_SAVE_BUTTON, 0, 0, 1, 1, filepath)) > 0)
{
//Now let's open the file,,
file = fopen(filepath, "w");
//Make sure it was actually opened
if (file != NULL)
{
//And write the headers and data to the file
fprintf(file, "Frequency\tVoltage Out\tVoltage In\tPhase\n");
for (i = 0; i < dataPoints; i++)
fprintf(file, "%f\t%f\t%f\t%f\n", freqData[i], voutData[i], magData[i], phaseData[i]);
//And then close it.
fclose(file);
}
else
{
MessagePopup("Error", "Could not open file to write data. Aborting.");
}
}
}
else
{
MessagePopup("Error", "No data to save!");
}
}
else
{
MessagePopup("Error", "Cannot save data while instrument is running.\nPlease cancel current operation or wait for it to complete.");
}
}
int ReadCalFromFile (uint64_t inSerial, uint64_t outDevSerial, char calDir[MAX_PATHNAME_LEN], Calibration *cal)
{
char filename[MAX_PATHNAME_LEN];
char file[MAX_PATHNAME_LEN];
char outSerial[50];
IniText ini;
//First let's init everything.
if ((ini = Ini_New(0)) == 0)
return -1;
//If so let's format our file names.
sprintf(outSerial, "%d", (int)outDevSerial);
sprintf(filename, "%d.ini", (int)inSerial);
sprintf(file, "%s\\%s", calDir, filename);
if (Ini_ReadFromFile(ini, file) < 0)
{
Ini_Dispose(ini);
return -1;
}
if(Ini_GetDouble(ini, outSerial, "am", &cal->am) <= 0) return -1;
if(Ini_GetDouble(ini, outSerial, "bm", &cal->bm) <= 0) return -1;
if(Ini_GetDouble(ini, outSerial, "cm", &cal->cm) <= 0) return -1;
if(Ini_GetDouble(ini, outSerial, "dm", &cal->dm) <= 0) return -1;
if(Ini_GetDouble(ini, outSerial, "ap", &cal->ap) <= 0) return -1;
if(Ini_GetDouble(ini, outSerial, "bp", &cal->bp) <= 0) return -1;
if(Ini_GetDouble(ini, outSerial, "cp", &cal->cp) <= 0) return -1;
if(Ini_GetDouble(ini, outSerial, "dp", &cal->dp) <= 0) return -1;
cal->serial = inSerial;
cal->outSerial = outDevSerial;
cal->completed = 1;
cal->refCal = 0;
Ini_Dispose(ini);
return 0;
}
int WriteCalToFile (char calDir[MAX_PATHNAME_LEN], Calibration *calRun)
{
//Declarations
char filename[MAX_PATHNAME_LEN];
char file[MAX_PATHNAME_LEN];
char outSerial[50];
IniText ini;
//first things first let's set it up
ini = Ini_New(0);
//If we couldn't get the ini container let's exit.
if (ini == 0)
return -1;
//Let's see if we've been given a complete calibration
if (calRun->completed)
{
//If so let's format our file names.
sprintf(outSerial, "%d", calRun->outSerial);
sprintf(filename, "%d.ini", calRun->serial);
sprintf(file, "%s\\%s", calDir, filename);
//And then store our variables
if(Ini_PutDouble(ini, outSerial, "am", calRun->am) < 0) return -1;
if(Ini_PutDouble(ini, outSerial, "bm", calRun->bm) < 0) return -1;
if(Ini_PutDouble(ini, outSerial, "cm", calRun->cm) < 0) return -1;
if(Ini_PutDouble(ini, outSerial, "dm", calRun->dm) < 0) return -1;
if(Ini_PutDouble(ini, outSerial, "ap", calRun->ap) < 0) return -1;
if(Ini_PutDouble(ini, outSerial, "bp", calRun->bp) < 0) return -1;
if(Ini_PutDouble(ini, outSerial, "cp", calRun->cp) < 0) return -1;
if(Ini_PutDouble(ini, outSerial, "dp", calRun->dp) < 0) return -1;
if(Ini_WriteToFile(ini, file) < 0) return -1;
}
else
return -1;
Ini_Dispose(ini);
return 0;
}