Such binary files consist of two records: description whose length is 32 bytes and data whose length is determined by the description. The rest of the bytes are of special use described below or ignored.
Description record consists of four groups of bytes:
integer[4]
list(integer[4])
whose format is determined by the codeFormat identifier for version 1 is equal to 1760568055 and is unique with alternative byte orderings taken into account (-148705176).
Format code consists of 4 bytes defined as follows:
The dimensions list depends on the shape:
[n]
gives its size[n,m]
, where n/m
is the row/column dimension[n]
gives the number of rows or columns (it is square)[n1,n2,n3,...]
gives the array dimensionsAdditional bytes are used as follows:
list(byte)
describes datatypes for the list elements: 0/128+1,2,4,8 means integer/float of size 1,2,4,8Finally, data record gives the elements one by one in the order prescribed by the shape. For shape 13, vector of varying dimensions (described by code) is followed by linearized records corresponding to the fixed secondary dimension.
Code for reading/writing such binary files: Maple – BasicTools[ReadBIN/WriteBIN], Python – BasicTools.ReadBIN/WriteBIN from MolMod package, Fortran – see readdump for example
Test samples:
file=bin.evl
code=[2,8,1,1]
dims=[31]
data=[-522.788480,-521.586832,-281.447629,...,46.626176]
elements: [1]=-522.788480, sum=-1086.285092
file=bin.evc
code=[2,8,22,1]
dims=[31,31]
data=[0.000047,-0.000188,-0.000145,...,-0.092279]
elements: [1,1]=0.000047, [2,1]=-0.000188, [1,2]=0.000218, sum=19.433223
file=bin.s1e
code=[2,8,3,1]
dims=[31]
data=[1.000000,0.219059,1.000000,...,1.000000]
elements: [1,1]=1.000000, [1,2]=[2,1]=0.219059, [2,2]=1.000000, sum=66.308944