Syntax
c=STLreadfiletype(FName)
Input Parameter
FName : | | Full file name including path and extension '.STL' |
Output Parameter
c : | | -1=not found, 'a'=asci format, 'b'=binary format |
Examples
Check the type of specified file name:
c=STLreadfiletype ('~/Desktop/TEST-1.STL')
Copyright 2012-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, STLreadfiletype
, determines the format of an STL file, which can be either ASCII or binary. It returns 'a' for ASCII, 'b' for binary, and -1 if the file is not found.
Input Parameters
- FName: The full file name, including the path and the '.STL' extension.
Output Results
- c: The result indicating the file type: -1 if the file is not found, 'a' for ASCII format, and 'b' for binary format.
Algorithm Steps
- Assign the input file name
FName
to the variable fname
.
- Attempt to open the file using
fopen
with read permissions and little-endian byte ordering.
- If the file cannot be opened (i.e.,
fid < 0
), print an error message, set c
to -1, and exit the function.
- Read the first 80 bytes of the file into
H
to skip the header.
- Read the next 4 bytes as a single precision integer into
n
to skip the number of triangles.
- Rewind the file pointer to the beginning of the file.
- Read the first 1024 bytes of the file into
T
as unsigned 8-bit integers.
- Convert
T
to a character array and parse it into strings using sscanf
.
- Close the file.
- Check for the presence of the strings 'solid', 'facet', and 'normal' in the parsed text
t
:
- If all three strings are found, set
c
to 'a' (indicating ASCII format).
- If any of the strings are not found, set
c
to 'b' (indicating binary format).
Algorithm explaination created using ChatGPT on 2025-08-19 01:15. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21