-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest-c.c
117 lines (103 loc) · 2.78 KB
/
test-c.c
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
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include "../../scatdb/scatdb.h"
void printError() {
#define BUFLEN 1024
//const int buflen = 1024;
char buffer[BUFLEN];
SDBR_err_msg(BUFLEN, buffer);
printf("Error message:\n%s", buffer);
#undef BUFLEN
}
int main(int argc, char** argv) {
int retval = 0;
SDBR_HANDLE hdb = 0, hdbFiltA = 0, hdbFiltB = 0;
float *summaryTable = 0, *pfTable = 0;
printf("Calling SDBR_start\n");
bool resb= SDBR_start(argc, argv);
if (!resb) {
printf("Library startup failed!\n");
printError();
retval = 1;
goto freeObjs;
}
// Load the database
printf("Loading the database.\n");
hdb = SDBR_loadDB(0);
if (!hdb) {
printf("Cannot load database!\n");
printError();
retval = 2;
goto freeObjs;
}
// Count the number of lines in the database
uint64_t numEntries = SDBR_getNumRows(hdb);
printf("The database has %" PRIu64 " rows.\n", numEntries);
// Filter the database based on flake type
const char* fts = "3,4,5,6,20";
hdbFiltA = SDBR_filterIntByString(hdb, SDBR_FLAKETYPE, fts);
if (!hdbFiltA) {
printError();
retval = 4;
goto freeObjs;
}
// Filter the database based on frequency
hdbFiltB = SDBR_filterFloatByRange(hdbFiltA, SDBR_FREQUENCY_GHZ, 13.f, 14.f);
if (!hdbFiltB) {
printError();
retval = 4;
goto freeObjs;
}
// Summarize the database
// Get the size of the summary table
uint64_t statsNumFloats = 0, statsNumBytes = 0, count = 0;
SDBR_getStatsTableSize(&statsNumFloats, &statsNumBytes);
summaryTable = malloc((size_t) statsNumBytes);
if (!summaryTable) {
printf("Malloc error.\n");
retval = 5;
goto freeObjs;
}
if (!SDBR_getStats(hdbFiltB, summaryTable, statsNumBytes, &count)) {
printf("Error retreiving stats.\n");
printError();
retval = 6;
goto freeObjs;
}
printf("There are %" PRIu64 " points used to calculate the statistics.\n\n", count);
for (int i=0; i<SDBR_NUM_DATA_ENTRIES_STATS; ++i) {
printf("\t%s", SDBR_stringifyStatsColumn(i));
}
printf("\n");
int k=0;
for (int j=0; j<SDBR_NUM_DATA_ENTRIES_FLOATS; ++j) {
printf("%s", SDBR_stringifyFloatsColumn(j));
for (int i=0; i<SDBR_NUM_DATA_ENTRIES_STATS; ++i) {
printf("\t%e", summaryTable[k]);
++k;
}
printf("\n");
}
// Get the phase function of the very first filtered entry.
// ... and display it
// Write the database
printf("Writing the database to outdb.csv\n");
resb = SDBR_writeDBtext(hdb, "outdb.csv");
if (!resb) {
printf("Cannot write database to outdb.csv!\n");
printError();
retval = 3;
goto freeObjs;
}
freeObjs:
// Close handles
printf("Closing handles.\n");
if (hdb) SDBR_free(hdb);
if (hdbFiltA) SDBR_free(hdbFiltA);
if (hdbFiltB) SDBR_free(hdbFiltB);
if (summaryTable) free(summaryTable);
if (pfTable) free(pfTable);
printf("Finished with return code %d.\n", retval);
return retval;
}