From 2f9ec3641cd0587898e1ca4d1c27996c81100d5b Mon Sep 17 00:00:00 2001
From: Giovanni La Mura <giovanni.lamura@inaf.it>
Date: Wed, 21 May 2025 10:51:47 +0200
Subject: [PATCH] Force CLUSTER to choose among the maximum allowed order and
 the recommended order

---
 src/cluster/cluster.cpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/cluster/cluster.cpp b/src/cluster/cluster.cpp
index de8a046..be3ce3c 100644
--- a/src/cluster/cluster.cpp
+++ b/src/cluster/cluster.cpp
@@ -732,6 +732,8 @@ int cluster_jxi488_cycle(int jxi488, ScattererConfiguration *sconf, GeometryConf
     output->vec_xi[jindex - 1] = xi;
   }
   // Dynamic order check
+  const int max_li = gconf->li;
+  const int max_le = gconf->le;
   const double alamb = 2.0 * pi / cid->vk;
   double size_par_li = 2.0 * pi * sqrt(exdc) * sconf->get_max_radius() / alamb;
   int recommended_li = 4 + (int)ceil(size_par_li + 4.05 * pow(size_par_li, 1.0 / 3.0));
@@ -758,14 +760,14 @@ int cluster_jxi488_cycle(int jxi488, ScattererConfiguration *sconf, GeometryConf
 	+ to_string(recommended_le) + " for scale iteration " + to_string(jxi488) + ".\n";
       logger->log(message, LOG_INFO);
     }
-    if (recommended_li < cid->c1->li || recommended_le < cid->c1->le) {
-      int new_li = (recommended_li < cid->c1->li) ? recommended_li : cid->c1->li;
-      int new_le = (recommended_le < cid->c1->le) ? recommended_le : cid->c1->le;
+    if (recommended_li < max_li || recommended_le < max_le) {
+      int new_li = (recommended_li < max_li) ? recommended_li : max_li;
+      int new_le = (recommended_le < max_le) ? recommended_le : max_le;
       cid->update_orders(sconf->_rcf, new_li, new_le);
       is_first_scale = true;
       jaw = 1;
+      cid->refinemode = 2;
     }
-    cid->refinemode = 2;
   }
   int li = cid->c1->li;
   int le = cid->c1->le;
-- 
GitLab