From ce752b76d18ddb9eaf87744a477760cca8b4e5e7 Mon Sep 17 00:00:00 2001 From: akscholar <155985936+akscholar@users.noreply.github.com> Date: Thu, 24 Oct 2024 17:48:59 -0400 Subject: [PATCH 1/4] Update tabgen.c The column names are now manually created based on the amount of columns. --- src/kernel/tab/tabgen.c | 80 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 5 deletions(-) diff --git a/src/kernel/tab/tabgen.c b/src/kernel/tab/tabgen.c index 5d2119f3d..7e4e076cd 100644 --- a/src/kernel/tab/tabgen.c +++ b/src/kernel/tab/tabgen.c @@ -14,6 +14,7 @@ string defv[] = { "sep=s\n column separator (s=space t=tab c=comma v=vertical bar)", "addrow=f\n Add row number (1=first) as first column?", "VERSION=0.8\n 14-feb-2024 PJT", + "header=None\n Add a dummy header in a given style [ecsv, ipac]", NULL, }; @@ -34,6 +35,72 @@ local real linear(real c1, real c2) return count; } +string add_header(int nc, string header) +{ + char *result = malloc(100); + result[0] = '\0'; + int first = 1; + int arr_len = 0; + + strcat(result, "| "); + for (int i = 0; i < nc; i++) { + char col_num[100]; + if (!first) { + strcat(result, " | "); + } + sprintf(col_num, "col%d", (i+1)); + strcat(result, col_num); + first = 0; + arr_len++; + } + + strcat(result, " |"); + strcat(result, "\n"); + strcat(result, "| double"); + + for (int i = 1; i < arr_len; i++) { + strcat(result, " | double"); + } + + strcat(result, " |"); + + return result; + +} + +string add_header(string header) +{ + char *token; + char *result = malloc(100); + result[0] = '\0'; + int first = 1; + int arr_len = 0; + + token = strtok(header, ","); + + strcat(result, "| "); + while (token != NULL) { + if (!first) { + strcat(result, " | "); + } + strcat(result, token); + first = 0; + arr_len++; + token = strtok(NULL, ","); + } + + strcat(result, " |"); + strcat(result, "\n"); + strcat(result, "| double"); + + for (int i = 1; i < arr_len; i++) { + strcat(result, " | double"); + } + + strcat(result, " |"); + + return result; +} void nemo_main() { @@ -48,13 +115,15 @@ void nemo_main() string seps = getparam("sep"); bool Qrow = getbparam("addrow"); char sep[8]; + string header = getparam("header"); + + fprintf(ostr, "%s\n", add_header(header)); if (seps[0] == 'c') strcpy(sep,","); else if (seps[0] == 's') strcpy(sep," "); else if (seps[0] == 't') strcpy(sep,"\t"); else if (seps[0] == 'v') strcpy(sep,"|"); else strcpy(sep,seps); - dprintf(1,"seed=%d\n",seed); @@ -79,15 +148,16 @@ void nemo_main() int k=0; for (i=0; i0) fprintf(ostr, "%s", sep); - fprintf(ostr,fmt, my_random(0.0, 1.0)); + if (j>0) fprintf(ostr, "%s", sep); + fprintf(ostr,fmt, my_random(0.0, 1.0)); } fprintf(ostr,"\n"); } -} + +} \ No newline at end of file From 76aea70da50f9dd78150c87a3152b7fce6a870a4 Mon Sep 17 00:00:00 2001 From: akscholar <155985936+akscholar@users.noreply.github.com> Date: Thu, 24 Oct 2024 18:10:21 -0400 Subject: [PATCH 2/4] Update tabgen.c --- src/kernel/tab/tabgen.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/src/kernel/tab/tabgen.c b/src/kernel/tab/tabgen.c index 7e4e076cd..a10e622ab 100644 --- a/src/kernel/tab/tabgen.c +++ b/src/kernel/tab/tabgen.c @@ -68,40 +68,6 @@ string add_header(int nc, string header) } -string add_header(string header) -{ - char *token; - char *result = malloc(100); - result[0] = '\0'; - int first = 1; - int arr_len = 0; - - token = strtok(header, ","); - - strcat(result, "| "); - while (token != NULL) { - if (!first) { - strcat(result, " | "); - } - strcat(result, token); - first = 0; - arr_len++; - token = strtok(NULL, ","); - } - - strcat(result, " |"); - strcat(result, "\n"); - strcat(result, "| double"); - - for (int i = 1; i < arr_len; i++) { - strcat(result, " | double"); - } - - strcat(result, " |"); - - return result; -} - void nemo_main() { stream ostr = stropen(getparam("out"),"w"); From 0adfb485b16199f430ce0ec318728656693b372d Mon Sep 17 00:00:00 2001 From: akscholar <155985936+akscholar@users.noreply.github.com> Date: Fri, 25 Oct 2024 21:21:29 -0400 Subject: [PATCH 3/4] Update tabgen.c --- src/kernel/tab/tabgen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel/tab/tabgen.c b/src/kernel/tab/tabgen.c index a10e622ab..5afd9ba8e 100644 --- a/src/kernel/tab/tabgen.c +++ b/src/kernel/tab/tabgen.c @@ -37,7 +37,7 @@ local real linear(real c1, real c2) string add_header(int nc, string header) { - char *result = malloc(100); + char *result = malloc(101); result[0] = '\0'; int first = 1; int arr_len = 0; From d51562f6c564617bcbc60e04d4b4ca7ef537d4f8 Mon Sep 17 00:00:00 2001 From: akscholar <155985936+akscholar@users.noreply.github.com> Date: Sun, 10 Nov 2024 10:08:49 -0500 Subject: [PATCH 4/4] Update tabgen.c --- src/kernel/tab/tabgen.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/kernel/tab/tabgen.c b/src/kernel/tab/tabgen.c index 5afd9ba8e..661c64a3d 100644 --- a/src/kernel/tab/tabgen.c +++ b/src/kernel/tab/tabgen.c @@ -13,7 +13,7 @@ string defv[] = { "fmt=%g\n Format statement for output", "sep=s\n column separator (s=space t=tab c=comma v=vertical bar)", "addrow=f\n Add row number (1=first) as first column?", - "VERSION=0.8\n 14-feb-2024 PJT", + "VERSION=last", "header=None\n Add a dummy header in a given style [ecsv, ipac]", NULL, }; @@ -35,7 +35,7 @@ local real linear(real c1, real c2) return count; } -string add_header(int nc, string header) +string add_header(int nc) { char *result = malloc(101); result[0] = '\0'; @@ -83,7 +83,7 @@ void nemo_main() char sep[8]; string header = getparam("header"); - fprintf(ostr, "%s\n", add_header(header)); + fprintf(ostr, "%s\n", add_header(nc)); if (seps[0] == 'c') strcpy(sep,","); else if (seps[0] == 's') strcpy(sep," ");