This commit is contained in:
2025-04-09 10:22:44 +02:00
commit 96ff5392c8
330 changed files with 28300 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
---
BasedOnStyle: LLVM
---
Language: Cpp
AllowShortFunctionsOnASingleLine: Empty
DerivePointerAlignment: false
PointerAlignment: Left
ColumnLimit: 120
TabWidth: 4
IndentWidth: 2
...
+23
View File
@@ -0,0 +1,23 @@
# debug: clangd --check=modules/iue-io/ccsv.h
# debug: clangd --check=task1.hpp
# debug: clangd --check=task1.test.cpp
InlayHints:
Enabled: No
ParameterNames: No
DeducedTypes: No
---
CompileFlags:
Add:
- -Wall
- -Wno-unused-function
- -Wno-unused-variable
---
If:
PathMatch: [.*\\.c, .*\\.h]
CompileFlags:
Add: [-std=c11]
---
If:
PathMatch: [.*\\.cpp, .*\\.hpp]
CompileFlags:
Add: [-std=c++20]
+16
View File
@@ -0,0 +1,16 @@
## source: https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.h text
*.hpp text
*.c text
*.cpp text
*.py text
*.ipynb text
*.md text
*.txt text
*.csv text
+364
View File
@@ -0,0 +1,364 @@
# custom
taskA
taskB
taskC
taskAref
taskBref
taskCref
build
doc
.cache
.vscode
.idea
# https://github.com/github/gitignore/blob/main/CMake.gitignore
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
# ttps://github.com/github/gitignore/blob/main/C.gitignore
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
# https://github.com/github/gitignore/blob/main/C%2B%2B.gitignore
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
# source: https://github.com/github/gitignore/blob/main/Python.gitignore
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# jetbrain IDEs: https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
# VSCODE source: https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
# Local History for Visual Studio Code
.history/
# Built Visual Studio Code Extensions
*.vsix
+4
View File
@@ -0,0 +1,4 @@
[submodule "modules"]
path = modules
url = https://sgit.iue.tuwien.ac.at/360050/modules
branch = main
+40
View File
@@ -0,0 +1,40 @@
cmake_minimum_required(VERSION 3.20)
# define project metadata
project(lab5 LANGUAGES C CXX
DESCRIPTION "lab5"
HOMEPAGE_URL "https://sgit.iue.tuwien.ac.at/360050/lab5")
# setting required language standards
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED True)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS OFF)
# misc settings
# generate a compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# make all symbols visible on windows (which is default on unix)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# find math library and link to all targets
find_library(MATH_LIBRARY m)
link_libraries(${MATH_LIBRARY})
# global includes
include_directories(modules)
# include own targets
add_executable(taskA taskA.c)
add_executable(taskB taskB.c)
add_executable(taskC taskC.c)
+25
View File
@@ -0,0 +1,25 @@
# Labor V: Abgabe (30min)
**Dieser Teil wird über [TUWEL, Labor V: Abgabe (30min)](https://tuwel.tuwien.ac.at/course/view.php?id=62042#coursecontentcollapse13)** abgewickelt.
# Labor V: Praxisteil (120min)
- **Fragen Sie frühzeitig nach, falls Unklarheiten bestehen**.
- Fragen Sie alles, was Ihnen im Rahmen der Lehrveranstaltung wichtig erscheint.
- Es gibt keine Einschränkungen für die Zusammenarbeit zwischen Studierenden beim Bearbeiten der untenstehenden Aufgaben.
- Sie haben das Labor erfolgreich absolviert, wenn Sie alle drei Teilaufgaben bei einem Betreuer **demonstriert** haben.
- Melden Sie sich bei einem Betreuer, sobald Sie sich in der Lage sehen alle drei Aufgaben zu demonstrieren.
---
Im heutigen Labor sollen Sie die folgenden drei Aufgabengebiete bearbeiten.
### A. Kommandozeilenoptionen
### B. Verwendung einer gegebenen Bibliothek zum Lesen/Schreiben von .csv-Dateien (C-Version)
### C. Vergleich von numerischen Daten
---
Details zu den Aufgaben finden Sie in [`main.ipynb`](main.ipynb).
+1
View File
@@ -0,0 +1 @@
-Imodules
+111
View File
@@ -0,0 +1,111 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## A. Kommandozeilenoptionen\n",
"\n",
"**Aufgabe (Details siehe [taskA.c](taskA.c)):**\n",
"- Implementieren Sie mithilfe der in [modules/iue-po/cpo.h](modules/iue-po/cpo.h) bereitgestellten Funktionalität ein Programm mit einer Kommandozeilen-Schnittstelle:\n",
" - Es gibt vier Argumente, die über die Befehlszeile übergeben werden können: \n",
" - erforderlich: ein ganzzahliger Wert (`opt1`)\n",
" - erforderlich: eine Fließkommazahl (`opt2`)\n",
" - optional: eine Zeichen (Typ `char`) (`opt3`), Standardwert `A`\n",
" - optional: Zeichenkette (`opt4`), Standardwert `\"empty\"`\n",
" - Gültige Aufrufe Ihres Programms können dann z.B. so aussehen:\n",
" ```shell\n",
" ./taskA -opt1 10 -opt2 1.5 \n",
" ./taskA -opt1 10 -opt2 1.5 -opt3 X -opt4 lab5\n",
" ./taskA -opt2 1.5 -opt3 Y -opt4 lab5 -opt1 10 \n",
" ```\n",
" - Geben Sie die übergebenen Werte zur Überprüfung in der Konsole aus.\n",
" - Falls ein notwendiges Argumente nicht übergeben wurde (oder nicht erfolgreich zum Zieltyp umgewandelt werden konnte), soll Ihr Programm mit einem Fehler abbrechen.\n",
"\n",
"**Hinweise:**\n",
"- In der Datei [modules/iue-po/cpo.test.c](modules/iue-po/cpo.test.c) befindet sich ein Test, der die erforderlichen Funktionen einsetzt:\n",
" - Sie können dieses Programm als Vorlage benutzen (kopieren und dann adaptieren)\n",
" \n",
"**Demonstration:**\n",
"- Rufen Sie Ihr Programm mit verschiedenen gültigen Kommandozeilen-Argumenten auf.\n",
"- Rufen Sie Ihr Programm mit verschiedenen invaliden Kommandozeilen-Argumenten auf.\n",
"- Diskutieren Sie: Wofür dienen die Parameter `argc` und `argv` der `main`-Funktion?"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## B. Verwendung einer gegebenen C-Bibliothek zum Lesen/Schreiben von .csv-Dateien\n",
"\n",
"**Aufgabe (Details siehe [taskB.c](taskB.c)):**\n",
"- Setzen Sie mithilfe der in [modules/iue-io/ccsv.h](modules/iue-io/ccsv.h) bereitgestellten Funktionalität folgende Schritte um:\n",
" - Erstellen Sie eine Tabelle mit numerischen Werten\n",
" - Abspeichern der Tabelle als .csv-Datei (`table1.csv`)\n",
" - Erneutes Einlesen der gespeicherten Tabelle aus der Datei (`table1.csv`)\n",
" - Manipulation der Werte (Skalieren mit Faktor `1.001`) und erneutes Abspeichern als .csv-Datei (`table2.csv`)\n",
"\n",
"**Hinweise:**\n",
"- In der Datei [modules/iue-io/ccsv.test.c](modules/iue-io/ccsv.test.c) befindet sich ein Test, der die erforderlichen Funktionen einsetzt:\n",
" - Sie können dieses Programm als Vorlage benutzen (kopieren und dann adaptieren)\n",
"\n",
"**Demonstration:**\n",
"- Demonstrieren Sie die Funktionalität Ihres Programms.\n",
"- Erklären Sie die Funktion `table_append_copy` (Zeile-für-Zeile); gehen Sie dabei vor allem auf die Bedeutung von `malloc` und `realloc` ein.\n",
" - Was ist der Unterschied zwischen `table_append_copy` und `table_append_move`?\n",
"- Erklären Sie die Funktion `table_clear` (Zeile-für-Zeile); gehen Sie dabei vor allem auf die Bedeutung von `free` ein.\n",
" - Wann und wozu sollte `table_clear` verwendet werden?"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## C. Kommandozeilengesteuertes Programm zum Vergleich von numerischen Daten\n",
"\n",
"**Aufgabe (Details siehe [taskC.c](taskC.c)):**\n",
"- Implementieren Sie ein Programm, dass \n",
" - zwei Tabellen von Fliesskommazahlen aus zwei `.csv`-Dateien einließt, und\n",
" - testet, ob die zwei Tabellen numerisch als gleich anzusehen sind (bei gegebener relativer Toleranz).\n",
"- Das Programm erhält alle Eingaben mittels Kommandozeilen-Parameter und soll schlussendlich so aufrufbar sein:\n",
" ```shell\n",
" ./taskC --first table1.csv --second table2.csv --tolerance 1e-5\n",
" ```\n",
" \n",
"**Hinweise:**\n",
"- Verwenden Sie `iuenum_isclose_tol` aus der Bibliothek [modules/iue-num/numerics.h](modules/iue-num/numerics.h) um die Elemente miteinander zu vergleichen.\n",
"- In der Datei [modules/iue-num/numerics.test.c](modules/iue-num/numerics.test.c) befindet sich eine beispielhafte Anwendung der Funktion `iuenum_isclose_tol`.\n",
"\n",
"**Demonstration:**\n",
"\n",
"- Demonstrieren Sie die Funktionalität Ihres Programms indem Sie die in Aufgabe 2 erzeugten Dateien vergleichen: welche Toleranz ist noetig, damit diese als gleich angesehen werden?\n",
"- Warum müssen numerische Werte meist 'ungefähr' verglichen werden, und nicht 'ganz exakt'?\n",
"- Wie viele signifikante Stellen haben Fließkommazahlen (`float`, `double`) in C/C++?"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
+3
View File
@@ -0,0 +1,3 @@
1.000000000000000036e-10;1.000000000000000000e+01;1.000000000000000000e+10;1.000000000000000016e+100
2.000000000000000073e-10;2.000000000000000000e+01;2.000000000000000000e+10;2.000000000000000032e+100
2.999999999999999980e-10;3.000000000000000000e+01;3.000000000000000000e+10;2.999999999999999853e+100
1 1.000000000000000036e-10 1.000000000000000000e+01 1.000000000000000000e+10 1.000000000000000016e+100
2 2.000000000000000073e-10 2.000000000000000000e+01 2.000000000000000000e+10 2.000000000000000032e+100
3 2.999999999999999980e-10 3.000000000000000000e+01 3.000000000000000000e+10 2.999999999999999853e+100
+3
View File
@@ -0,0 +1,3 @@
1e-10, 1e1, 1e10, 1e100
2e-10, 2e1, 2e10, 2e100
3e-10, 3e1, 3e10, 3e100
1 1e-10 1e1 1e10 1e100
2 2e-10 2e1 2e10 2e100
3 3e-10 3e1 3e10 3e100
+3
View File
@@ -0,0 +1,3 @@
1.000999999999999955e-10;1.000999999999999801e+01;1.000999999999999809e+10;1.000999999999999816e+100
2.001999999999999911e-10;2.001999999999999602e+01;2.001999999999999619e+10;2.001999999999999632e+100
3.002999999999999866e-10;3.002999999999999758e+01;3.002999999999999619e+10;3.002999999999999448e+100
1 1.000999999999999955e-10 1.000999999999999801e+01 1.000999999999999809e+10 1.000999999999999816e+100
2 2.001999999999999911e-10 2.001999999999999602e+01 2.001999999999999619e+10 2.001999999999999632e+100
3 3.002999999999999866e-10 3.002999999999999758e+01 3.002999999999999619e+10 3.002999999999999448e+100
+24
View File
@@ -0,0 +1,24 @@
#include <stdio.h>
#include <math.h>
struct Vec2d {
double x;
double y;
};
struct Vec2d getCoords(double Winkel) {
struct Vec2d erg;
erg.x = cos(Winkel);
erg.y = sin(Winkel);
return erg;
}
int main() {
double winkel[] = {0.0,45.0,90.0,135.0,180.0,360.0};
int max = sizeof(winkel)/sizeof(double);
for(int i=0;i < max;i++){
double winkel_rad=(winkel[i] * (0.0174533)); // double at end represents est of 1 degree in radian
struct Vec2d erg = getCoords(winkel_rad);
printf("Pos of %lf is x=%lf and y=%lf \n",winkel[i],erg.x,erg.y);
}
}
+46
View File
@@ -0,0 +1,46 @@
/// @file
/// @brief Task A
/// gcc -g -fsanitize=address -std=c11 taskA.c -Imodules -o taskA
/// ./taskA -opt1 10 -opt2 1.5 -opt3 X -opt4 lab5
#include "iue-po/cpo.h" // iuepo_get_*
#include <stdio.h> // printf
#include <stdlib.h> // EXIT_SUCCESS, EXIT_FAILURE
/// @todo Implement a main function supporting the following command line arguments:
/// -opt1 integer (required)
/// -opt2 double (required)
/// -opt3 char (optional, default is 'A')
/// -opt4 string (optional, default is "empty")
int main(int argc, char* argv[]) {
/// @todo Parse the command line arguments according to the specification above:
/// - have a look at modules/iue-io/cpo.test.h (you can use this as a starting point)
/// - If mandatory arguments are missing or cannot be parsed, the program aborts with an error.
/// @todo Print all passed command line arguments to the console
int opt1;
if (iuepo_get_int(argc, argv, "opt1", &opt1, IUEPO_REQUIRED) != EXIT_SUCCESS)
return EXIT_FAILURE;
double opt2;
if (iuepo_get_double(argc, argv, "opt2", &opt2, IUEPO_REQUIRED) != EXIT_SUCCESS)
return EXIT_FAILURE;
char opt3 = 'A';
if (iuepo_get_char(argc, argv, "opt3", &opt3, IUEPO_OPTIONAL) != EXIT_SUCCESS)
return EXIT_FAILURE;
char opt4[256] = "empty";
if (iuepo_get_string(argc, argv, "opt4", opt4, sizeof(opt4), IUEPO_OPTIONAL) != EXIT_SUCCESS)
return EXIT_FAILURE;
printf("'%i'\n", opt1);
printf("'%lf'\n", opt2);
printf("'%c'\n", opt3);
printf("'%s'\n", opt4);
return EXIT_SUCCESS;
}
+74
View File
@@ -0,0 +1,74 @@
/// @file
/// @brief Task B
/// gcc -g -fsanitize=address -std=c11 taskB.c -Imodules -o taskB && ./taskB
#include "iue-io/ccsv.h" // struct Table, table_append_copy, table_clear, iueio_savetxt, iueio_loadtxt
#include <stddef.h> // size_t
#include <stdio.h> // printf
int main() {
//writing Data manually
FILE *fpt;
fpt = fopen("table1m.csv","w+");
fprintf(fpt,"1e-10, 1e1, 1e10, 1e100\n");
fprintf(fpt,"2e-10, 2e1, 2e10, 2e100\n");
fprintf(fpt,"3e-10, 3e1, 3e10, 3e100\n");
fclose(fpt);
/// @todo use the functionality in 'iue-io/ccsv.h' to implement the following steps:
/// 1. create a table of type `struct Table` using the function
/// 'table_append_copy'
/// containing these values:
/// 1e-10, 1e1, 1e10, 1e100
/// 2e-10, 2e1, 2e10, 2e100
/// 3e-10, 3e1, 3e10, 3e100
/// 2. save the table as 'table1.csv' using the function 'iueio_savetxt')
/// - use ',' as separator
/// - use '#' as comment
/// 3. load the just saved table again using 'iueio_loadtxt'
/// 4. multiply each value in the table by 1.001
/// 5. store the modified table as 'table2.csv'
/// 6. use 'table_clear' appropriately at the end of your program
double mult=1.001;
{// write
struct Table table1 = {NULL, 0};
double data[4] = {1e-10, 1e1, 1e10, 1e100};
double data1[4] = {2e-10, 2e1, 2e10, 2e100};
double data2[4] = {3e-10, 3e1, 3e10, 3e100};
table_append_copy(&table1, data, 4);
table_append_copy(&table1, data1, 4);
table_append_copy(&table1, data2, 4);
iueio_savetxt("table1.csv", &table1, ';',"", '#');
table_clear(&table1);
}
{ // read && write
struct Table table2 = {NULL, 0};
struct Table table3 = {NULL, 0};
iueio_loadtxt("table1.csv", &table2, ';', '#');
for (size_t i = 0; i != table2.n; ++i) {
double data[4];
for (size_t j = 0; j != table2.rows[i].n; ++j)
data[j]=(table2.rows[i].values[j])*1.001;
table_append_copy(&table3, data, 4);
}
iueio_savetxt("table2.csv", &table3, ';',"", '#');
table_clear(&table2);
table_clear(&table3);
}
return 0;
}
+87
View File
@@ -0,0 +1,87 @@
/// @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);
}