/usr/share/doc/python-xdmf/examples/XdmfDataStructureTest2.py is in python-xdmf 2.1.dfsg.1-11+b2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | #!/bin/env python
from Xdmf import *
PointsTxt = """<?xml version="1.0" ?>
<!DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []>
<Xdmf>
<Domain>
<Grid Name="Shot Points">
<Topology Type="PolyVertex" NodesPerElement="1" NumberOfElements="5" >
</Topology>
<Geometry Type="XYZ">
<DataStructure Format="XML" DataType="Float" Precision="8"
Dimensions="3 2 5 3">
10.0 0.0 0.0
10.0 1.0 0.0
10.0 2.0 0.0
10.0 3.0 0.0
10.0 4.0 0.0
10.0 0.0 1.0
10.0 1.0 1.0
10.0 2.0 1.0
10.0 3.0 1.0
10.0 4.0 1.0
10.0 0.0 0.0
10.0 1.0 0.0
10.0 2.0 0.0
10.0 3.0 0.0
10.0 4.0 0.0
10.0 0.0 1.0
10.0 1.0 1.0
10.0 2.0 1.0
10.0 3.0 1.0
10.0 4.0 1.0
10.0 0.0 0.0
10.0 1.0 0.0
10.0 2.0 0.0
10.0 3.0 0.0
10.0 4.0 0.0
10.0 0.0 1.0
10.0 1.0 1.0
10.0 2.0 1.0
10.0 3.0 1.0
10.0 4.0 1.0
</DataStructure>
<DataStructure Reference="/Xdmf/Domain/Grid[@Name='Shot Points']/Geometry/DataStructure[1]"/>
<DataStructure Reference="XML">
/Xdmf/Domain/Grid[@Name="Shot Points"]/Geometry/DataStructure[2]
</DataStructure>
<DataStructure Reference="/Xdmf/Domain/Grid[@Name='Shot Points']/Geometry/DataStructure[1]/../DataStructure[2]"/>
</Geometry>
</Grid>
</Domain>
</Xdmf>
"""
fd = open('Points.xmf', 'w')
fd.write(PointsTxt)
fd.close()
########
dom = XdmfDOM()
dom.Parse('Points.xmf')
dm = dom.FindElement('Domain')
g = dom.FindElement('Grid', 0, dm)
geo = dom.FindElement('Geometry', 0, g)
dse = dom.FindElement('DataStructure', 0, geo)
ds = XdmfDataStructure()
ds.DebugOn()
ds.SetDOM(dom)
ds.SetElement(dse)
ds.UpdateInformation()
ds.Update()
print 'Values = ', ds.GetDataValues()
dsre = dom.FindElement('DataStructure', 1, geo)
dsr = XdmfDataStructure()
dsr.SetDOM(dom)
dsr.DebugOn()
# This will clear the reference and cause I/O
dsr.SetElement(dsre)
dsr.UpdateInformation()
dsr.Update()
if(dsr.GetIsReference()) :
print 'Getting Values'
print 'Values = ', dsr.GetDataValues()
else :
print 'This is not a reference'
dsre = dom.FindElement('DataStructure', 3, geo)
dsr = XdmfDataStructure()
dsr.SetDOM(dom)
dsr.DebugOn()
# This will clear the reference and cause I/O
dsr.SetElement(dsre)
# Cause an potential dangling reference
# dsr.SetCopyReferenceData(0)
print "UI"
dsr.UpdateInformation()
print "U"
dsr.Update()
# Cause an dangling reference by deleting refernced object
# ds = 0
if(dsr.GetIsReference()) :
print 'Getting Values'
print 'Values = ', dsr.GetDataValues()
else :
print 'This is not a reference'
|