[Gmsh] How to write $ElementData as msh binary file?

蔡园武 yuanwucai at gmail.com
Tue Aug 30 15:47:50 CEST 2011


Hello, everyone!
I've been using msh ASCII format, but now I need to output hundreds of
$ElementData into a msh file, so ASCII file can be really big.
I tried to write the data in binary format, but can't work it out. Gmsh read
my sample binary data file with one $ElementData, but ate lots of ram and
showed wrong.
I don't know where is the problem. If anyone can help me, please answer.
Thank you!

My part of code written in C to output $ElementData:

    FILE* file = fopen("outfile.msh","wb");
    fprintf(file, "$MeshFormat\n");
    fprintf(file, "2.2 1 8\n");
    int one = 1;
    fwrite(&one, sizeof(int), 1, file);
    fprintf(file, "\n");
    fprintf(file, "$EndMeshFormat\n");
    fprintf(file, "$ElementData\n");
    fprintf(file, "1");
    fprintf(file, "\"tag\"\n");
    fprintf(file, "1\n0.0\n3\n0\n1\n%i\n",NElem);
    for (int i=0; i<NElem; i++) {
      int one = i + 1;
      fwrite(&one, sizeof(int), 1, file);
      fprintf(file, " ");
      double two = EDA[i];
      fwrite(&two, sizeof(double), 1, file);
      fprintf(file, "\n");
    }
    fprintf(file, "$EndElementData");


-- 
Cai Yuanwu  蔡园武
Dept. of Engineering Mechanics,
Dalian University of Technology,
Dalian 116024, China
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.geuz.org/pipermail/gmsh/attachments/20110830/4487ef04/attachment.html>