Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when exporting am meshes #231

Open
SAFedorov opened this issue Jun 4, 2022 · 3 comments
Open

Error when exporting am meshes #231

SAFedorov opened this issue Jun 4, 2022 · 3 comments

Comments

@SAFedorov
Copy link

Hello,
There appears to be a bug when exporting meshes in .am format. It can be reproduced in the following script:

mesh Th = square(10, 10);
savemesh(Th, "square.am");
mesh Th2=readmesh("square.am");
plot(Th2);

As you can see, it creates a mesh, saves it into an am file, and tries to read it out and plot. However, when executing it I get the following error:

Fatal Error Input FortranUnFormattedFile
 Erreur  read Record number = 2
 read position  in file 320 < 4672 =  end on record
 position in the record = 300 length of record = 4652
 file = square.am
 Fatal error in the mesh generator 900
  current line = 3
Meshing error: Bamg
 number : 900,
Meshing error: Bamg
 number : 900,
 err code 5 ,  mpirank 0

When using the text am_fmt, there is no problem. My small investigation showed that the content of the exported .am file looks strange --- in the block (number 2) listing the triangle vertex indices, some indices have nonsensically large integer values, while many are ok, in agreement with what I find if creating a formatted file for the mesh .am_fmt.
The freefem version I use is 4.9 on Windows.

@SAFedorov
Copy link
Author

Hello again,
It looks like the problem arises because of extra carriage return symbols inserted in the binary file. The analysis of the content of the .am file generated by the script in my previous message suggests that every byte that happened to correspond to the '\n' symbol is replaced by two bytes, '\r\n'. This also leads to some bytes at the end of the file being lost, because the lengths of the Fortran sections are calculated without accounting for the extra '\r' bytes. My understanding is that the problem can occur because the output file is always open in textual format (in this line), even when saving a mesh in the binary am format.

If anyone is curious, I attach the notebook that examines the am file content.
am_investigation.zip

@frederichecht
Copy link
Contributor

frederichecht commented Jun 19, 2022 via email

@frederichecht
Copy link
Contributor

frederichecht commented Jun 19, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants