]> Devoid-pointer.net GitWeb - libHPCS.git/commitdiff
Add some extra debugging output
authorMichal Malý <madcatxster@gmail.com>
Tue, 24 Jul 2018 23:42:03 +0000 (01:42 +0200)
committerMichal Malý <madcatxster@gmail.com>
Tue, 24 Jul 2018 23:42:03 +0000 (01:42 +0200)
src/libHPCS.c
src/test_tool.c

index 17107d6f63450394d16b315261523241a28f48fe..76028e417e96ec9d85bd73e6542f5e6a9d5376a5 100644 (file)
@@ -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:
index 7c9d4e045a907bf19ee9c63413f816cbd83b63ba..3061ec22ae8b420637804146370bc3e73b581961 100644 (file)
@@ -4,7 +4,7 @@
 #include <string.h>
 #include <libHPCS.h>
 
-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");