From bbe24292e24f64cbbb03ec4a76008a2ebdaf64e8 Mon Sep 17 00:00:00 2001
From: Uwe Schulzweida <uwe.schulzweida@mpimet.mpg.de>
Date: Mon, 24 Apr 2023 20:11:39 +0200
Subject: [PATCH] percentiles_hist: fix problem with time constant data (bug
 fix)

---
 ChangeLog               | 6 +++++-
 src/cdo.cc              | 2 +-
 src/percentiles_hist.cc | 7 ++++---
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 867cc3574..4b3caa733 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,12 @@
-2023-04-21  Uwe Schulzweida
+2023-04-24  Uwe Schulzweida
 
 	* Using CDI library version 2.2.1
 	* Version 2.2.0 release
 
+2023-04-24  Uwe Schulzweida
+
+	* percentiles_hist: fix problem with time constant data (bug fix)
+
 2023-04-20  Uwe Schulzweida
 
 	* Vertstat: wrong result for non monotonic levels in GRIB format [Bug #11323]
diff --git a/src/cdo.cc b/src/cdo.cc
index 0aaf66e06..4e01a9204 100644
--- a/src/cdo.cc
+++ b/src/cdo.cc
@@ -487,7 +487,7 @@ static void
 define_compress(const std::string &argString)
 {
   const char *arg = argString.c_str();
-  size_t len = strlen(arg);
+  size_t len = argString.size();
 
   if (argString == "szip")
     {
diff --git a/src/percentiles_hist.cc b/src/percentiles_hist.cc
index 2d80b2368..db44953b6 100644
--- a/src/percentiles_hist.cc
+++ b/src/percentiles_hist.cc
@@ -58,8 +58,9 @@ histDefBounds(Histogram &hist, float a, float b)
 static inline int
 calc_bin(int nbins, float histMin, float histStep, float value)
 {
-  assert(histStep > 0.0f);
-  return std::min((int) ((value - histMin) / histStep), nbins - 1);
+  //assert(histStep > 0.0f);
+  //return std::min((int) ((value - histMin) / histStep), nbins - 1);
+  return (histStep > 0.0f) ? std::min((int) ((value - histMin) / histStep), nbins - 1) : 0;
 }
 
 template <typename T>
@@ -241,7 +242,7 @@ histGetPercentile(const Histogram &hist, double p)
 
       auto bin = hist.isUint32 ? histGetBin(hist.nbins, s, INT_PTR(hist.ptr)) : histGetBin(hist.nbins, s, SHR_PTR(hist.ptr));
 
-      assert(hist.step > 0.0f);
+      //assert(hist.step > 0.0f);
 
       return hist.min + bin * hist.step;
     }
-- 
GitLab