1### Author: Kenneth Leiter 2### E-mail: kenneth.leiter@us.army.mil 3### 4### A simple python test that writes ints and floats to XdmfArrays and then tries to read them. Compares the 5### values for equality and tests the accuracy of some convenience functions 6 7 8import Xdmf 9from Xdmf import * 10 11if __name__ == '__main__': 12 13## 14## First Part = XDMF_INT64_TYPE Array 15## 16 intArray = Xdmf.XdmfArray() 17 18 intArray.SetNumberType(Xdmf.XDMF_INT64_TYPE) 19 assert(intArray.GetNumberType() == Xdmf.XDMF_INT64_TYPE) 20 intArray.SetShapeFromString("3 3") 21 assert(intArray.GetShapeAsString() == "3 3") 22 assert(intArray.GetNumberOfElements() == 9) 23 toWrite = [0, 1, 3, 4, 500, -5000, 500000, 9223372036854775807, -9223372036854775807] 24 i = 0; 25 for element in toWrite: 26 intArray.SetValueFromInt64(i,element) 27 i += 1 28 29 i = 0; 30 for element in toWrite: 31 assert(intArray.GetValueAsInt64(i) == element) 32 i += 1 33 34 assert (intArray.GetMaxAsInt64() == 9223372036854775807) 35 assert (intArray.GetMinAsInt64() == -9223372036854775807) 36 37## 38## Second Part = XDMF_FLOAT64_TYPE Array 39## 40 floatArray = Xdmf.XdmfArray() 41 42 floatArray.SetNumberType(Xdmf.XDMF_FLOAT64_TYPE) 43 assert(floatArray.GetNumberType() == Xdmf.XDMF_FLOAT64_TYPE) 44 floatArray.SetShapeFromString("2 2 2") 45 assert(floatArray.GetShapeAsString() == "2 2 2") 46 assert(floatArray.GetNumberOfElements() == 8) 47 toWrite = [0, -1, 1100.256, 1.1, 1000.50 , 5.6234567, -60.2, 60.25659] 48 i = 0; 49 for element in toWrite: 50 floatArray.SetValueFromFloat64(i,element) 51 i += 1 52 53 i = 0; 54 for element in toWrite: 55 assert(floatArray.GetValueAsFloat64(i) == element) 56 i += 1 57 58 assert (floatArray.GetMaxAsFloat64() == 1100.256) 59 assert (floatArray.GetMinAsFloat64() == -60.2)