Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aesha tabgen 5 #160

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions src/kernel/tab/tabgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ 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,
};

Expand All @@ -34,6 +35,38 @@ local real linear(real c1, real c2)
return count;
}

string add_header(int nc)
{
char *result = malloc(101);
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;

}

void nemo_main()
{
Expand All @@ -48,13 +81,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(nc));

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);

Expand All @@ -79,15 +114,16 @@ void nemo_main()
int k=0;
for (i=0; i<nr; i++)
for (j=0; j<nc; j++)
x[k++] = my_random(0.0,1.0);
x[k++] = my_random(0.0,1.0);
} else
// output to file as well
for (i=0; i<nr; i++) {
if (Qrow) fprintf(ostr,"%d ", i+1);
for (j=0; j<nc; j++) {
if (j>0) 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");
}
}

}