From: Michal MalĂ˝ Date: Tue, 24 Jul 2018 23:42:03 +0000 (+0200) Subject: Add some extra debugging output X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=566b6e85413a51127b60af56b332963241c85d4a;p=libHPCS.git Add some extra debugging output --- diff --git a/src/libHPCS.c b/src/libHPCS.c index 17107d6..76028e4 100644 --- a/src/libHPCS.c +++ b/src/libHPCS.c @@ -176,6 +176,7 @@ enum HPCS_RetCode hpcs_read_mdata(const char* filename, struct HPCS_MeasuredData ret = HPCS_E_PARSE_ERROR; goto out; } + PR_DEBUGF("Signal step: %g, shift: %g\n", signal_step, signal_shift); pret = read_scans_start(datafile, &scans_start); if (pret != PARSE_OK) { @@ -991,7 +992,6 @@ static enum HPCS_ParseCode read_signal(FILE* datafile, struct HPCS_TVPair** pair PR_DEBUGF("Error reading stream, r=%lu\n", r); return PARSE_E_CANT_READ; } - segments_read++; /* Expand storage if there is more data than we can store */ if (alloc_size == data_segments_read) { @@ -1012,9 +1012,13 @@ static enum HPCS_ParseCode read_signal(FILE* datafile, struct HPCS_TVPair** pair dret = check_for_marker(raw, &next_marker_idx); switch (dret) { case DCHECK_GOT_MARKER: - PR_DEBUGF("Got marker at 0x%lx\n", segments_read - 1); + PR_DEBUGF("Got marker at segment %lu, byte 0x%lx\n", segments_read, 2 * segments_read); continue; case DCHECK_NO_MARKER: +#ifndef NDEBUG + if (segments_read == next_marker_idx) + PR_DEBUGF("Warning - marker expected but not found at segment %lu", segments_read); +#endif /* Check for a sudden jump of value */ if (raw[0] == BIN_MARKER_JUMP && raw[1] == BIN_MARKER_END) { char lraw[4]; @@ -1040,6 +1044,7 @@ static enum HPCS_ParseCode read_signal(FILE* datafile, struct HPCS_TVPair** pair } (*pairs)[data_segments_read].value = value; + segments_read++; data_segments_read++; break; default: diff --git a/src/test_tool.c b/src/test_tool.c index 7c9d4e0..3061ec2 100644 --- a/src/test_tool.c +++ b/src/test_tool.c @@ -4,7 +4,7 @@ #include #include -static int read_data(const char* path) +static int read_data(const char* path, int raw_output) { struct HPCS_MeasuredData* mdata; enum HPCS_RetCode hret; @@ -33,8 +33,12 @@ static int read_data(const char* path) mdata->y_units, mdata->sampling_rate); - for (di = 0; di < mdata->data_count; di++) - printf("Time: %.17lg, Value: %.17lg\n", mdata->data[di].time, mdata->data[di].value); + for (di = 0; di < mdata->data_count; di++) { + if (raw_output) + printf("%.17lg; %.17lg\n", mdata->data[di].time, mdata->data[di].value); + else + printf("Time: %.17lg; Value: %.17lg\n", mdata->data[di].time, mdata->data[di].value); + } hpcs_free_mdata(mdata); @@ -106,21 +110,26 @@ static int read_info(const char* path) int main(int argc, char** argv) { + const char* sel; + if (argc < 3) { printf("Not enough arguments\n"); printf("Usage: test_tool MODE FILE\n"); printf("MODE: d - read data file\n" + " r - read data file - raw output\n" " i - method info\n" " h - read header only\n" "FILE: path\n"); return EXIT_FAILURE; } - if (strcmp(argv[1], "d") == 0) - return read_data(argv[2]); - else if (strcmp(argv[1], "h") == 0) + sel = argv[1]; + + if (strcmp(sel, "d") == 0 || strcmp(sel, "r") == 0) + return read_data(argv[2], strcmp(sel, "r") == 0); + else if (strcmp(sel, "h") == 0) return read_header(argv[2]); - else if (strcmp(argv[1], "i") == 0) + else if (strcmp(sel, "i") == 0) return read_info(argv[2]); else { printf("Invalid mode argument\n");