In the post STL files and fortran, I posted a fortran binary stl file reader program.
Thomas was having problem using the code. He suspected that maybe it’s the problem of 32 and 64 incompatibility issue. I promised that I will check.
Last week I dug out the executable I created then and sure enough it worked. I fed it different 64 and 32 bit written stl files and it read them all.
After this, I downloaded the code posted on the blog, suspecting something is wrong in the uploaded code.
I compiled it. Tried reading the previously tested stl files and it failed. Confused I began debugging.
As I went through the code line by line, suddenly it clicked.
I recompiled the code and it worked.
The magic was in using the compiler option /assume:byterecl with the intel fortran compiler.
So the compilation was done as
Ifort /assume:byterecl stlreader.f90
Since the code is opening the binary file with RECL specifier, the assume:byterecl specifies that the units for the OPEN statement RECL specifier ie record length value are in bytes for unformatted data files, not longwords.
Thanks Thomas for the comment which led to this. 😉
The binary stl file reader fortran code is available here, make sure you use the assume byterecl option while compiling.