0

I would like to read and decodinga binary file in order to get values.

Below the code I use to read the file :

with open("modele_petite_zone.op2", "rb") as op2File :
for lines in op2File :
    byte = op2File.read()
    print(byte)

and here a part of what I have in output :

b'\xaf\xc9Dq\xdd\xa8\xc44\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x9e\xdd\x1f\x004\x08\x00\x00\x00\xb0\x97EHq\xccD{\xdc\xc3\xc44\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x9f\xdd\x1f\x004\x08\x00\x00\x00\xb0\x97E3S\xc1D{4\xbf\xc44\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa8\xdd\x1f\x004\x08\x00\x00\x00\xb0\x97E\xe1\xc2\xc2D\xc3\xed\xd7\xc44\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa9\xdd\x1f\x004\x08\x00\x00\x00\xb0\x97Ef\xb6\xb7D\xa4\xd8\xd1\xc44\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb2\xdd\x1f\x004\x08\x00\x00\x00\xb0\x97ER\x10\xb7DR\xc8\xea\xc44\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb5\xdd\x1f\x004\x08\x00\x00\x00\xb0\x97E\xa40\xacD\xec1\xe3\xc44\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\xdd\x1f\x004\x08\x00\x00\x00\xb0\x97E\xcd|\xa9D\x00@\xfc\xc44\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbd\xdd\x1f\x004\x08\x00\x00\x00\xb0\x97E\x1f\xed\x9eD\x1f\x15\xf3\xc44\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xec\x01\x00\x00\x04\x00\x00\x00\xfb\xff\xff\xff\x04\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x0c\x00\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00\x0c\x00\x00\x00\x04\x00\x00\x00\xfa\xff\xff\xff\x04\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\x08\x00\x00\x00GEOM3

What can I do to decoding the ouptut ?

Binary file can be downloaded here : https://www.dropbox.com/s/uimba2xojc55uii/modele_petite_zone.op2?dl=0

mnekkach
  • 191
  • 2
  • 11
  • do you mean https://stackoverflow.com/questions/4657416/difference-between-encoding-and-encryption – erik258 Dec 27 '18 at 17:38
  • ok so it is decoding and not decrypt. Thanks for the link and explanation between the difference. – mnekkach Dec 27 '18 at 17:58

1 Answers1

2

Binary format means that the saved file is not readable as text. However binary is not a standard that can be parsed easily, it only means that the data is saved as "data" (bits) instead of text. The actual format (or structure) can be open source or proprietary, meaning it might be parsable (if you know how to read the data) or near impossible to understand.

The op2 format seems to be known and have modules implemented that can parse the files (look here for the format description https://docs.plm.automation.siemens.com/tdoc/nxnastran/11/help/#uid:index_dmap:xid666580:id496821).

Checkout this module for parsing op2 files: https://pynastran-git.readthedocs.io/en/latest/index.html

Example:

from pyNastran.op2.op2 import OP2
model = OP2()
model.read_op2("modele_petite_zone.op2")
print(model.get_op2_stats())
SimonF
  • 1,855
  • 10
  • 23
  • I know pyNastran but I want to create my python script in order to use it in an other program. Actually I have a python script to reduce stiffness matrix and I get output value in a text file. I would like to perform my script and add an op2 file reader. – mnekkach Dec 27 '18 at 18:05
  • See the other link for an explanation of the format structure, it tells you how to read the op2 file – SimonF Dec 27 '18 at 18:07