[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
9.2 MSH binary file format
The binary file format is similar to the ASCII format described above:
$MeshFormat version-number file-type data-size one-binary $EndMeshFormat $Nodes number-of-nodes nodes-binary $EndNodes $Elements number-of-elements element-header-binary elements-binary element-header-binary elements-binary … $EndElements [ all other sections are identical to ASCII, except that node-number, elm-number, number-of-nodes-per-element and values are written in binary format ] |
where
-
version-number
is a real number equal to 2.1.
-
file-type
is an integer equal to 1.
-
data-size
has the same meaning as in the ASCII file format. Currently only data-size = sizeof(double) is supported.
-
one-binary
is an integer of value 1 written in binary form. This integer is used for detecting if the computer on which the binary file was written and the computer on which the file is read are of the same type (little or big endian).
Here is a pseudo C code to write one-binary:
int one = 1; fwrite(&one, sizeof(int), 1, file);
-
number-of-nodes
has the same meaning as in the ASCII file format.
-
nodes-binary
is the list of nodes in binary form, i.e., a array of number-of-nodes * (4 + 3 * data-size) bytes. For each node, the first 4 bytes contain the node number and the next (3 * data-size) bytes contain the three floating point coordinates.
Here is a pseudo C code to write nodes-binary:
for(i = 0; i < number_of_nodes; i++){ fwrite(&num_i, sizeof(int), 1, file); double xyz[3] = {node_i_x, node_i_y, node_i_z}; fwrite(&xyz, sizeof(double), 3, file); }
-
number-of-elements
has the same meaning as in the ASCII file format.
-
element-header-binary
is a list of 3 integers in binary form, i.e., an array of (3 * 4) bytes: the first four bytes contain the type of the elements that follow (same as elm-type in the ASCII format), the next four contain the number of elements that follow, and the last four contain the number of tags per element (same as number-of-tags in the ASCII format).
Here is a pseudo C code to write element-header-binary:
int header[3] = {elm_type, num_elm_follow, num_tags}; fwrite(&header, sizeof(int), 3, file);
-
elements-binary
is a list of elements in binary form, i.e., an array of “number of elements that follow” * (4 + number-of-tags * 4 + #node-number-list * 4) bytes. For each element, the first four bytes contain the element number, the next (number-of-tags * 4) contain the tags, and the last (#node-number-list * 4) contain the node indices.
Here is a pseudo C code to write elements-binary for triangles with the 3 standard tags (the physical and elementary regions, and the mesh partition):
for(i = 0; i < number_of_triangles; i++){ int data[7] = {num_i, physical, elementary, partition, node_i_1, node_i_2, node_i_3}; fwrite(data, sizeof(int), 7, file); }
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |