STLreadfiletype

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Import/Export
Introduced first in SolidGeometry 1.0, Creation date: 2012-04-13, Last change: 2025-09-14

returns 'a' for ascii, 'b' for binary and -1 for file not found



See Also: VLFLreadSTL

Example Illustration

 missing image of STLreadfiletype(FName)

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

Output Results

Algorithm Steps

  1. Assign the input file name FName to the variable fname.
  2. Attempt to open the file using fopen with read permissions and little-endian byte ordering.
  3. If the file cannot be opened (i.e., fid < 0), print an error message, set c to -1, and exit the function.
  4. Read the first 80 bytes of the file into H to skip the header.
  5. Read the next 4 bytes as a single precision integer into n to skip the number of triangles.
  6. Rewind the file pointer to the beginning of the file.
  7. Read the first 1024 bytes of the file into T as unsigned 8-bit integers.
  8. Convert T to a character array and parse it into strings using sscanf.
  9. Close the file.
  10. Check for the presence of the strings 'solid', 'facet', and 'normal' in the parsed text t:
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