From aaf2185f62cfe8cbb4af58520721aa8cada7f8e5 Mon Sep 17 00:00:00 2001
From: Ger van Diepen <diepen@astron.nl>
Date: Mon, 31 Jan 2011 14:45:31 +0000
Subject: [PATCH] bug 1638: Write new phase center if needed

---
 CEP/DP3/DPPP/include/DPPP/MSWriter.h |  3 +++
 CEP/DP3/DPPP/src/MSWriter.cc         | 17 +++++++++++++++++
 CEP/DP3/DPPP/src/PhaseShift.cc       |  2 +-
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/CEP/DP3/DPPP/include/DPPP/MSWriter.h b/CEP/DP3/DPPP/include/DPPP/MSWriter.h
index 1d0c843f6b8..47f8700368a 100644
--- a/CEP/DP3/DPPP/include/DPPP/MSWriter.h
+++ b/CEP/DP3/DPPP/include/DPPP/MSWriter.h
@@ -103,6 +103,9 @@ namespace LOFAR {
       // Update the OBSERVATION table with the correct start and end time.
       void updateObs (const string& outName);
 
+      // Update the FIELD table with the new phase center.
+      void updateField (const string& outName, const DPInfo& info);
+
       // Write the data, flags, etc.
       void writeData (casa::Table& out, const DPBuffer& buf);
 
diff --git a/CEP/DP3/DPPP/src/MSWriter.cc b/CEP/DP3/DPPP/src/MSWriter.cc
index 8451ac17c09..0c343dde38a 100644
--- a/CEP/DP3/DPPP/src/MSWriter.cc
+++ b/CEP/DP3/DPPP/src/MSWriter.cc
@@ -34,6 +34,8 @@
 #include <tables/Tables/SetupNewTab.h>
 #include <tables/Tables/ArrColDesc.h>
 #include <tables/Tables/StandardStMan.h>
+#include <measures/TableMeasures/ArrayMeasColumn.h>
+#include <measures/Measures/MCDirection.h>
 #include <casa/Arrays/ArrayMath.h>
 #include <casa/Containers/Record.h>
 #include <casa/OS/Path.h>
@@ -349,6 +351,10 @@ namespace LOFAR {
       updateSpw (outName, info);
       // Adjust the OBSERVATION table as needed.
       updateObs (outName);
+      // ADjust the FIELD table as needed.
+      if (! info.phaseCenterIsOriginal()) {
+        updateField (outName, info);
+      }
     }
 
     void MSWriter::updateSpw (const string& outName, const DPInfo& info)
@@ -437,6 +443,17 @@ namespace LOFAR {
       }
     }
 
+    void MSWriter::updateField (const string& outName, const DPInfo& info)
+    {
+      Table outField = Table(outName + "/FIELD", Table::Update);
+      // Set phase center.
+      ArrayMeasColumn<MDirection> delayCol (outField, "DELAY_DIR");
+      ArrayMeasColumn<MDirection> phaseCol (outField, "PHASE_DIR");
+      Vector<MDirection> dir(1, info.phaseCenter());
+      delayCol.put (0, dir);
+      phaseCol.put (0, dir);
+    }
+
     void MSWriter::writeHistory (Table& ms, const ParameterSet& parset)
     {
       Table histtab(ms.keywordSet().asTable("HISTORY"));
diff --git a/CEP/DP3/DPPP/src/PhaseShift.cc b/CEP/DP3/DPPP/src/PhaseShift.cc
index e0cbd4e5c51..7c1583b773e 100644
--- a/CEP/DP3/DPPP/src/PhaseShift.cc
+++ b/CEP/DP3/DPPP/src/PhaseShift.cc
@@ -69,7 +69,7 @@ namespace LOFAR {
     void PhaseShift::show (std::ostream& os) const
     {
       os << "PhaseShift " << itsName << std::endl;
-      os << "  center:         " << itsCenter << std::endl;
+      os << "  phasecenter:    " << itsCenter << std::endl;
     }
 
     void PhaseShift::showTimings (std::ostream& os, double duration) const
-- 
GitLab