From f919f645ad3709eda19a7c8766da5fe2c030424d Mon Sep 17 00:00:00 2001
From: Tammo Jan Dijkema <dijkema@astron.nl>
Date: Tue, 17 May 2016 18:48:31 +0000
Subject: [PATCH] Task #9439: ApplyCal sanity checks

---
 CEP/DP3/DPPP/src/ApplyCal.cc | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/CEP/DP3/DPPP/src/ApplyCal.cc b/CEP/DP3/DPPP/src/ApplyCal.cc
index b0394aafe9e..d91db36ae9b 100644
--- a/CEP/DP3/DPPP/src/ApplyCal.cc
+++ b/CEP/DP3/DPPP/src/ApplyCal.cc
@@ -185,6 +185,23 @@ namespace LOFAR {
 
       initDataArrays();
       itsFlagCounter.init(getInfo());
+
+      // Check that channels are evenly spaced
+      if (info().nchan()>1) {
+        Vector<Double> upFreq = info().chanFreqs()(
+                                  Slicer(IPosition(1,1),
+                                         IPosition(1,info().nchan()-1)));
+        Vector<Double> lowFreq = info().chanFreqs()(
+                                  Slicer(IPosition(1,0),
+                                         IPosition(1,info().nchan()-1)));
+        Double freqstep0=upFreq(0)-lowFreq(0);
+        // Compare up to 1kHz accuracy
+        bool regularChannels=allNearAbs(upFreq-lowFreq, freqstep0, 1.e3) &&
+                             allNearAbs(info().chanWidths(),
+                                        info().chanWidths()(0), 1.e3);
+        ASSERTSTR(regularChannels, 
+                  "ApplyCal requires evenly spaced channels.");
+      }
     }
 
     void ApplyCal::show (std::ostream& os) const
@@ -278,9 +295,11 @@ namespace LOFAR {
 
       uint numFreqs         (info().chanFreqs().size());
       double freqInterval  (info().chanWidths()[0]);
+      if (numFreqs>1) { // Handle data with evenly spaced gaps between channels
+        freqInterval = info().chanFreqs()[1]-info().chanFreqs()[0];
+      }
       double minFreq       (info().chanFreqs()[0]-0.5*freqInterval);
       double maxFreq (info().chanFreqs()[numFreqs-1]+0.5*freqInterval);
-
       itsLastTime = bufStartTime + itsTimeSlotsPerParmUpdate * itsTimeInterval;
       uint numTimes = itsTimeSlotsPerParmUpdate;
 
-- 
GitLab