@@ -65,10 +65,10 @@ def __init__(self, filename):
6565 self .filename = filename
6666
6767 # Store result retrieval items
68- self .nnod , self .numdof , self .neqv , self .rpointers , self .pointers = GetResultInfo (filename )
68+ self .nnod , self .numdof , self .neqv , self .rpointers , self .pointers , self . endian = GetResultInfo (filename )
6969
7070 # Number of results
71- self .nsets = len (self .rpointers )
71+ self .nsets = len (self .rpointers )
7272
7373 # Get indices to resort nodal results
7474 self .sidx = np .argsort (self .neqv )
@@ -96,11 +96,11 @@ def LoadCDB(self, filename):
9696
9797 # Import cdb
9898 cdb = CDB_Reader .Read (filename )
99- uGrid = cdb .ParseVTK ()
99+ self . uGrid = cdb .ParseVTK ()
100100
101101 # Extract surface mesh
102102 sfilter = vtk .vtkDataSetSurfaceFilter ()
103- sfilter .SetInputData (uGrid )
103+ sfilter .SetInputData (self . uGrid )
104104 sfilter .PassThroughPointIdsOn ()
105105 sfilter .PassThroughCellIdsOn ()
106106 sfilter .Update ()
@@ -193,11 +193,14 @@ def GetTimeValues(self):
193193 """
194194 # Load values if not already stored
195195 if not hasattr (self , 'tvalues' ):
196+
197+ # Format endian
198+
196199 # Seek to start of time result table
197200 f = open (self .filename , 'rb' )
198201
199202 f .seek (self .pointers ['ptrTIMl' ]* 4 + 8 )
200- self .tvalues = np .fromfile (f , dtype = np . double , count = self .nsets )
203+ self .tvalues = np .fromfile (f , self . endian + 'd' , self .nsets )
201204
202205 f .close ()
203206
@@ -235,12 +238,12 @@ def GetResult(self, rnum, nosort=False):
235238
236239 # Seek to result table and to get pointer to DOF results of result table
237240 f .seek ((self .rpointers [rnum ] + 12 )* 4 ) # item 12
238- ptrNSLl = np .fromfile (f , dtype = np . int32 , count = 1 )[0 ]
241+ ptrNSLl = np .fromfile (f , self . endian + 'i' , 1 )[0 ]
239242
240243 # Seek and read DOF results
241244 f .seek ((self .rpointers [rnum ] + ptrNSLl + 2 )* 4 )
242245 nitems = self .nnod * self .numdof
243- result = np .fromfile (f , dtype = np . double , count = nitems )
246+ result = np .fromfile (f , self . endian + 'd' , nitems )
244247
245248 f .close ()
246249
@@ -281,13 +284,31 @@ def GetResultInfo(filename):
281284
282285 pointers = {}
283286 f = open (filename , 'rb' )
287+
288+ # Check if big or small endian
289+ endian = '<'
290+ inttype = '<i'
291+ if np .fromfile (f , dtype = '<i' , count = 1 ) != 100 :
292+ # Check if big enos
293+ f .seek (0 )
294+ if np .fromfile (f , dtype = '>i' , count = 1 ) == 100 :
295+ endian = '>'
296+ inttype = '>i'
297+ # Otherwise, it's probably not a result file
298+ else :
299+ raise Exception ('Unable to determine endian type.\n \n ' + \
300+ 'File is possibly not a result file.' )
301+
302+
303+ # Read standard header
304+ # f.seek(0);header = np.fromfile(f, dtype='>i', count=100)
284305
285306 #======================
286307 # Read .RST FILE HEADER
287308 #======================
288309 # 100 is size of standard header, plus extras, 3 is location of pointer in table
289- f .seek (( 105 ) * 4 )
290- rheader = np .fromfile (f , dtype = np . int32 , count = 55 )
310+ f .seek (105 * 4 )
311+ rheader = np .fromfile (f , dtype = inttype , count = 55 )
291312
292313 # Number of nodes (item 3)
293314 nnod = rheader [2 ]
@@ -309,16 +330,16 @@ def GetResultInfo(filename):
309330
310331 # Read nodal equivalence table
311332 f .seek ((ptrNODl + 2 )* 4 ) # Start of pointer says size, then empty, then data
312- neqv = np .fromfile (f , dtype = np . int32 , count = nnod )
333+ neqv = np .fromfile (f , dtype = inttype , count = nnod )
313334 #neqv = np.frombuffer(f, dtype=np.int32, count=nnod)
314335
315336 # Read table of pointers to locations of results
316337 f .seek ((ptrDSIl + 2 )* 4 ) # Start of pointer says size, then empty, then data
317- rpointers = np .fromfile (f , dtype = np . int32 , count = nsets )
338+ rpointers = np .fromfile (f , dtype = inttype , count = nsets )
318339
319340 f .close ()
320341
321- return nnod , numdof , neqv , rpointers , pointers
342+ return nnod , numdof , neqv , rpointers , pointers , endian
322343
323344#==============================================================================
324345# Plotting (ideally in its own module)
0 commit comments