From 189ed8f8ea9a331e7f4154bdf4edccc1400b0fc3 Mon Sep 17 00:00:00 2001 From: Torsten Sommer Date: Tue, 23 Jul 2024 15:04:43 +0200 Subject: [PATCH 1/2] Handle single line input files fixes #534 --- fmusim/FMIStaticInput.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/fmusim/FMIStaticInput.c b/fmusim/FMIStaticInput.c index 68fa8f4a..fdf35e07 100644 --- a/fmusim/FMIStaticInput.c +++ b/fmusim/FMIStaticInput.c @@ -239,27 +239,13 @@ FMIStatus FMIApplyInput(FMIInstance* instance, const FMIStaticInput* input, doub size_t row = 0; - for (size_t i = 1; i < input->nRows; i++) { - - const double t = input->time[i]; + while (row < input->nRows - 1) { - if (t >= time) { + if (afterEvent ? input->time[row + 1] > time : input->time[row] >= time) { break; } - row = i; - } - - if (afterEvent) { - - while (row < input->nRows - 2) { - - if (input->time[row + 1] > time) { - break; - } - - row++; - } + row++; } const size_t j = row * input->nVariables + i; From aa95cab554d977336aff1f1367d8fc2845d99153 Mon Sep 17 00:00:00 2001 From: Torsten Sommer Date: Wed, 24 Jul 2024 09:52:47 +0200 Subject: [PATCH 2/2] Compare time to input->time[row+1] for pre-event --- fmusim/FMIStaticInput.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fmusim/FMIStaticInput.c b/fmusim/FMIStaticInput.c index fdf35e07..0d99a73b 100644 --- a/fmusim/FMIStaticInput.c +++ b/fmusim/FMIStaticInput.c @@ -241,7 +241,9 @@ FMIStatus FMIApplyInput(FMIInstance* instance, const FMIStaticInput* input, doub while (row < input->nRows - 1) { - if (afterEvent ? input->time[row + 1] > time : input->time[row] >= time) { + const double nextTime = input->time[row + 1]; + + if (afterEvent ? nextTime > time : nextTime >= time) { break; }