From f2db3420129c149c8fbc112dfb14f086153e73b2 Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@cnes.fr>
Date: Tue, 16 Jan 2018 14:51:24 +0100
Subject: [PATCH] BUG: Fix export of deburst metadata that has been broken by
 previous revamp of saveState/loadState of ossimSarSensorModel

---
 .../test/otbSarDeburstFilterTest.cxx           | 18 +++++++++++++++++-
 .../src/ossim/ossimSarSensorModel.cpp          | 17 +++++++++++------
 .../src/ossim/ossimSentinel1Model.cpp          |  5 +----
 3 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/Modules/Radiometry/SARCalibration/test/otbSarDeburstFilterTest.cxx b/Modules/Radiometry/SARCalibration/test/otbSarDeburstFilterTest.cxx
index 5d0f320c83..d221088626 100644
--- a/Modules/Radiometry/SARCalibration/test/otbSarDeburstFilterTest.cxx
+++ b/Modules/Radiometry/SARCalibration/test/otbSarDeburstFilterTest.cxx
@@ -40,7 +40,23 @@ int otbSarDeburstFilterTest(int itkNotUsed(argc), char * argv[])
   writer->SetInput(filter->GetOutput());
   writer->SetFileName(argv[2]);
   writer->Update();
-  
+
+  // check that there is now a single burst in data
+  reader = ReaderType::New();
+  reader->SetFileName(argv[2]);
+  reader->UpdateOutputInformation();
+
+  unsigned int nb_bursts = atoi(reader->GetOutput()->GetImageKeywordlist().GetMetadataByKey("support_data.geom.bursts.number").c_str());
+
+  if(nb_bursts != 1)
+    {
+    std::cerr<<"Error: more than 1 burst ("<<nb_bursts<<" bursts) found in output metadata."<<std::endl;
+    }
+  else
+    {
+    std::cout<<"Metadata have a single burst as expected."<<std::endl;
+    }
+
   return EXIT_SUCCESS;
 }
 
diff --git a/Modules/ThirdParty/OssimPlugins/src/ossim/ossimSarSensorModel.cpp b/Modules/ThirdParty/OssimPlugins/src/ossim/ossimSarSensorModel.cpp
index 46381857ea..e8e5a6ef82 100644
--- a/Modules/ThirdParty/OssimPlugins/src/ossim/ossimSarSensorModel.cpp
+++ b/Modules/ThirdParty/OssimPlugins/src/ossim/ossimSarSensorModel.cpp
@@ -1218,13 +1218,18 @@ namespace ossimplugins
      static const char MODULE[] = "ossimplugins::ossimSarSensorModel::saveState";
      SCOPED_LOG(traceDebug, MODULE);
 
-     kwl.add(prefix,
-             ossimKeywordNames::TYPE_KW,
-             "ossimSarSensorModel",
-             true);
-
-     add(kwl, SUPPORT_DATA_PREFIX + "product_type", theProductType.ToString().data());
+     // Prevent override of subclasses TYPE_KW
+     
+     if(!kwl.hasKey(ossimKeywordNames::TYPE_KW))
+       {
+       kwl.add(prefix,
+               ossimKeywordNames::TYPE_KW,
+               "ossimSarSensorModel",
+               true);
+       }
 
+     std::string product_type = theProductType.ToString().data();
+     add(kwl, SUPPORT_DATA_PREFIX + "product_type", product_type);
      add(kwl, SUPPORT_DATA_PREFIX, "slant_range_to_first_pixel", theNearRangeTime      );
      add(kwl, SUPPORT_DATA_PREFIX, "range_sampling_rate"       , theRangeSamplingRate  );
      add(kwl, SUPPORT_DATA_PREFIX, "range_spacing"             , theRangeResolution    );
diff --git a/Modules/ThirdParty/OssimPlugins/src/ossim/ossimSentinel1Model.cpp b/Modules/ThirdParty/OssimPlugins/src/ossim/ossimSentinel1Model.cpp
index 17d764ceb1..3cc96023f4 100644
--- a/Modules/ThirdParty/OssimPlugins/src/ossim/ossimSentinel1Model.cpp
+++ b/Modules/ThirdParty/OssimPlugins/src/ossim/ossimSentinel1Model.cpp
@@ -150,11 +150,8 @@ namespace ossimplugins
 
       kwl.addList(theManifestKwl, true);
       kwl.addList(theProductKwl,  true);
-
-      const unsigned int k_version = 2;
-      add(kwl, HEADER_PREFIX, "version", k_version);
       
-      return ossimSensorModel::saveState(kwl, prefix);
+      return ossimSarSensorModel::saveState(kwl, prefix);
    }
 
 
-- 
GitLab