-
Notifications
You must be signed in to change notification settings - Fork 32
Using libsierraecg
Christopher edited this page Aug 16, 2014
·
1 revision
Using the libsierraecg C/C++ library requires more work than the other language bindings, however, it is relatively straightforward. Public methods exist to read an ECG from a file and to preprocess the XML.
libsierraecg uses libxml2, and compiles on Windows, Linux, and Mac OS X. In order to ensure libxml2 is used properly, users must call sierraecg_init
and sierraecg_cleanup
prior to and after they use the library.
#include <sierraecg.h>
int main(int argc, char* argv[])
{
/* local variables ... */
/* Allow the library to initialize */
if (sierraecg_init()) abort();
/* use the library routines sierraecg_*() */
/* Allow the library to cleanup its dependencies */
sierraecg_cleanup();
return 0;
}
Preprocessing Sierra ECG XML files requires only one call to sierraecg_decompress
:
#include <sierraecg.h>
int main(int argc, char* argv[])
{
char output[260];
int i;
/* Allow the library to initialize */
if (sierraecg_init()) abort();
for (i = 1; i < argc; ++i) {
memset(output, 0, sizeof(output));
sprintf(output, "%s.decoded.xml", argv[i]);
/* sierraecg_decompress(input, output) */
if (sierraecg_decompress(argv[i], output)) {
fprintf(stderr, "Errors preprocessing Sierra ECG file: %s\n",
argv[i]);
}
}
/* Allow the library to cleanup its dependencies */
sierraecg_cleanup();
return 0;
}
Extracting lead data from a Sierra ECG XML file is done like so:
#include <sierraecg.h>
int main(int argc, char* argv[])
{
int i;
/* Allow the library to initialize */
if (sierraecg_init()) abort();
for (i = 1; i < argc; ++i) {
ecg_t ecg;
/* sierraecg_read(input, ecg data) */
if (sierraecg_read(argv[i], &ecg)) {
fprintf(stderr, "Errors parsing Sierra ECG file: %s\n",
argv[i]);
}
else {
/*
* ecg.version(char[8]): Version, i.e. 1.03 or 1.04
* ecg.leads(lead_t[16]): Retrieved lead data
* ecg.valid(size_t): How many valid leads were read
*/
int lead;
for (lead = 0; lead < valid; ++lead) {
/*
* lead.name(char*): e.g. I, II, III
* lead.samples(short[]): Lead sample data
* lead.count(size_t): Number of samples
* lead.duration(size_t): Total msec of the recording
*/
fprintf(stdout, "Lead %s (%d samples, %d ms)\n",
ecg.leads[lead].name,
ecg.leads[lead].count,
ecg.leads[lead].duration);
}
/* cleanup the ECG itself */
sierraecg_free(&ecg);
}
}
/* Allow the library to cleanup its dependencies */
sierraecg_cleanup();
return 0;
}