aboutsummaryrefslogtreecommitdiff
path: root/src/parse.c
diff options
context:
space:
mode:
authorjvech <jmvalenciae@unal.edu.co>2024-07-24 15:31:02 -0500
committerjvech <jmvalenciae@unal.edu.co>2024-07-24 15:31:02 -0500
commitd45581c0b067b9526ce88ba9d3a1bd861f4ff7cc (patch)
treea907346b2b282437537d7f4f6b138b3efddcce22 /src/parse.c
parentb9deaf6ec1ba587f2b81a63c75b696c6def33436 (diff)
add: file_read() and format integraded on main program
things implemented: - read output in false bug was solved. - Make generic rule added to build test executables - format option added to the CLI
Diffstat (limited to 'src/parse.c')
-rw-r--r--src/parse.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/parse.c b/src/parse.c
index 8d31da5..18668ec 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -152,20 +152,16 @@ void csv_read(
in_cols = ecalloc(n_in_cols, sizeof(size_t));
csv_keys2cols(in_cols, in_keys, n_in_cols);
- if (read_output) {
- out_cols = ecalloc(n_out_cols, sizeof(size_t));
- csv_keys2cols(out_cols, out_keys, n_out_cols);
- }
+ out_cols = ecalloc(n_out_cols, sizeof(size_t));
+ csv_keys2cols(out_cols, out_keys, n_out_cols);
input->shape[0] = 1;
input->shape[1] = n_in_cols;
input->data = ecalloc(input->shape[1], sizeof(double));
- if (read_output) {
- out->shape[0] = 1;
- out->shape[1] = n_out_cols;
- out->data = ecalloc(input->shape[1], sizeof(double));
- }
+ out->shape[0] = 1;
+ out->shape[1] = n_out_cols;
+ out->data = ecalloc(out->shape[1], sizeof(double));
fgets(line_buffer, 1024, fp);
for (line_ptr = line_buffer; *line_ptr != '\0'; line_ptr++) {
@@ -178,7 +174,9 @@ void csv_read(
csv_readline_values(num_buffer, num_buffer_length, line_buffer, 1, separator);
csv_columns_select(input->data + line * input->shape[1], num_buffer, in_cols, n_in_cols, num_buffer_length);
- if (read_output) csv_columns_select(out->data + line * out->shape[1], num_buffer, out_cols, n_out_cols, num_buffer_length);
+ if (read_output) {
+ csv_columns_select(out->data + line * out->shape[1], num_buffer, out_cols, n_out_cols, num_buffer_length);
+ }
for (line = 1; fgets(line_buffer, 1024, fp) != NULL; line++) {
csv_readline_values(num_buffer, num_buffer_length, line_buffer, line+1, separator);
@@ -187,9 +185,9 @@ void csv_read(
input->data = erealloc(input->data, input->shape[0] * input->shape[1] * sizeof(double));
csv_columns_select(input->data + line * input->shape[1], num_buffer, in_cols, n_in_cols, num_buffer_length);
+ out->shape[0]++;
+ out->data = erealloc(out->data, out->shape[0] * out->shape[1] * sizeof(double));
if (read_output) {
- out->shape[0]++;
- out->data = erealloc(out->data, out->shape[0] * out->shape[1] * sizeof(double));
csv_columns_select(out->data + line * out->shape[1], num_buffer, out_cols, n_out_cols, num_buffer_length);
}
}
Feel free to download, copy and edit any repo