87 lines
3.1 KiB
C
87 lines
3.1 KiB
C
/// @file
|
|
/// @brief Task C
|
|
/// compile: gcc -g -fsanitize=address -std=c11 taskC.c -Imodules -o taskC -lm
|
|
/// call: ./taskC -first table1.csv -second table2.csv -tolerance 1e-5
|
|
|
|
#include "iue-io/ccsv.h" // struct Table, table_*, iueio_savetxt, iueio_loadtxt
|
|
#include "iue-num/numerics.h" // iuenum_isclose_tol
|
|
#include "iue-po/cpo.h" // // iuepo_get_*
|
|
|
|
#include <stddef.h> // size_t
|
|
#include <stdio.h> // printf
|
|
#include <stdlib.h> // EXIT_FAILURE|EXIT_SUCCESS
|
|
|
|
/// @todo Implement a program according to the following specification:
|
|
/// 1. The program receives three mandatory command line arguments:
|
|
/// --first filepath of first .csv-file with numeric data
|
|
/// --second filepath of second .csv-file with numeric data
|
|
/// --tolerance relative tolerance (floating point value)
|
|
/// and two optional arguments:
|
|
/// --delimiter delimiter character used in the .csv-files, default ','
|
|
/// --comment comment character used in the .csv-files, default '#'
|
|
/// 2. The program reads both .csv files and
|
|
/// - checks if the tables are of identical dimensions, and
|
|
/// - compares the entries element-wise using 'iuenum_isclose'
|
|
/// using the relative tolerance provided as argument.
|
|
/// 3. The program returns
|
|
/// - EXIT_SUCCESS if the tables are of identical size and numerically
|
|
/// identical, or
|
|
/// - EXIT_FAILURE if the tables are not of identical size or not numerically
|
|
/// identical, additionally a message is printen before exiting providing
|
|
/// an hint, e.g.
|
|
/// - "tables dimension differ" or
|
|
/// - "element (i,j) differs"
|
|
int main(int argc, char* argv[]) {
|
|
|
|
char in[256];
|
|
if (iuepo_get_string(argc, argv, "first", in, sizeof(in), IUEPO_REQUIRED) != EXIT_SUCCESS)
|
|
return EXIT_FAILURE;
|
|
|
|
char in2[256];
|
|
if (iuepo_get_string(argc, argv, "second", in2, sizeof(in2), IUEPO_REQUIRED) != EXIT_SUCCESS)
|
|
return EXIT_FAILURE;
|
|
|
|
double tol;
|
|
if (iuepo_get_double(argc, argv, "tolerance", &tol, IUEPO_REQUIRED) != EXIT_SUCCESS)
|
|
return EXIT_FAILURE;
|
|
|
|
char delim = ',';
|
|
if (iuepo_get_char(argc, argv, "delimiter", &delim, IUEPO_OPTIONAL) != EXIT_SUCCESS)
|
|
return EXIT_FAILURE;
|
|
|
|
char comment = '#';
|
|
if (iuepo_get_char(argc, argv, "comment", &comment, IUEPO_OPTIONAL) != EXIT_SUCCESS)
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------
|
|
|
|
struct Table table1 = {NULL, 0};
|
|
struct Table table2 = {NULL, 0};
|
|
|
|
iueio_loadtxt(in, &table1, delim, comment);
|
|
iueio_loadtxt(in2, &table2, delim, comment);
|
|
|
|
if(!(table1.n == table2.n)){
|
|
table_clear(&table1);
|
|
table_clear(&table2);
|
|
printf("Sizes do not Match\n");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
for (size_t r = 0; r != table1.n; ++r) {
|
|
assert(table1.rows[r].n == table2.rows[r].n);
|
|
for (size_t c = 0; c != table1.rows[r].n; ++c) {
|
|
if(!iuenum_isclose_tol(table1.rows[r].values[c], table2.rows[r].values[c],0.0,tol)){
|
|
table_clear(&table1);
|
|
table_clear(&table2);
|
|
printf("Values not within tolerance\n");
|
|
return EXIT_FAILURE;
|
|
}
|
|
}
|
|
}
|
|
|
|
table_clear(&table1);
|
|
table_clear(&table2);
|
|
|
|
} |