From dd171def160370481a8f24a4e218f79504fc050d Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Thu, 10 Sep 2020 10:17:54 +0200
Subject: [PATCH] [extractPointInformationFromPVDUsingPointID.py]

---
 ...ractPointInformationFromPVDUsingPointID.py | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 post/extractPointInformation/extractPointInformationFromPVDUsingPointID.py

diff --git a/post/extractPointInformation/extractPointInformationFromPVDUsingPointID.py b/post/extractPointInformation/extractPointInformationFromPVDUsingPointID.py
new file mode 100644
index 0000000..bb67f25
--- /dev/null
+++ b/post/extractPointInformation/extractPointInformationFromPVDUsingPointID.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+import sys
+from vtk import *
+from lxml import etree as ET
+
+def readVTU(filename):
+    reader = vtkXMLUnstructuredGridReader()
+    reader.SetFileName(filename)
+    reader.Update()
+    return reader.GetOutput()
+
+def extractBulkPointData(bulk_vtu, node_id, array_name):
+    point_data = bulk_vtu.GetPointData()
+    data_array = point_data.GetArray(array_name)
+    return data_array.GetTuple1(node_id)
+
+def readPVD(filename):
+    tree = ET.parse(filename)
+    root = tree.getroot()
+    ts_files = {}
+    ts_files['ts'] = []
+    ts_files['filename'] = []
+    for collection in root.getchildren():
+        for dataset in collection.getchildren():
+            ts_files['ts'].append(dataset.attrib['timestep'])
+            ts_files['filename'].append(dataset.attrib['file'])
+    return ts_files
+
+pvd = readPVD(sys.argv[1])
+node_id = int(sys.argv[2])
+array_name=sys.argv[3]
+
+for i in range(1, len(pvd['ts'])):
+    vtu = readVTU(pvd['filename'][i])
+    print(pvd['ts'][i] + ' ' + str(extractBulkPointData(vtu, node_id, array_name)))
-- 
GitLab