From e9a8f4df01b4eb7c94e41cadde0194072ee9c32e Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Thu, 11 Aug 2016 08:20:56 +0200
Subject: [PATCH] [A/U/SimpleMeshCreation] Impl. scaling.

---
 .../createMeshElemPropertiesFromASCRaster.cpp | 38 +++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/Applications/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp b/Applications/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp
index 2eb67ed1ef4..5aec7fbe54c 100644
--- a/Applications/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp
+++ b/Applications/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp
@@ -36,6 +36,17 @@
 #include "MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.h"
 #include "MeshLib/MeshEnums.h"
 
+void scaleMeshPropertyVector(MeshLib::Mesh & mesh,
+                             std::string const& property_name,
+                             double factor)
+{
+    boost::optional<MeshLib::PropertyVector<double> &> pv(
+        mesh.getProperties().getPropertyVector<double>(property_name));
+
+    for (auto & v : *pv)
+        v *= factor;
+}
+
 int main(int argc, char* argv[])
 {
     ApplicationsLib::LogogSetup logo_setup;
@@ -98,6 +109,17 @@ int main(int argc, char* argv[])
                                           "file name");
     cmd.add(mesh_arg);
 
+    std::vector<std::string> allowed_units{ "mm/a", "mm/month", "m/s" };
+    TCLAP::ValuesConstraint<std::string> allowed_units_constraints{
+        allowed_units};
+    TCLAP::ValueArg<std::string> unit_arg("u",
+                                          "input-unit",
+                                          "input unit of the data",
+                                          true,
+                                          "m/s",
+                                          &allowed_units_constraints);
+    cmd.add(unit_arg);
+
     cmd.parse(argc, argv);
 
     // read mesh
@@ -148,6 +170,22 @@ int main(int argc, char* argv[])
         src_mesh.get(), property_arg.getValue());
     mesh_interpolation.setPropertiesForMesh(dest_mesh.get());
 
+    double scale(1.0);
+    if (unit_arg.getValue() == "m/s")
+    {
+        scale = 1.0;
+    }
+    else if (unit_arg.getValue() == "mm/a")
+    {
+        scale = 1e-3 / (365.25 * 86400);
+    }
+    else if (unit_arg.getValue() == "mm/month")
+    {
+        scale = 1e-3 * (12.0 / (365.25 * 86400));
+    }
+
+    scaleMeshPropertyVector(*dest_mesh, property_arg.getValue(), scale);
+
     if (!out_mesh_arg.getValue().empty())
     {
         MeshLib::IO::writeMeshToFile(*dest_mesh, out_mesh_arg.getValue());
-- 
GitLab