This routine actually reads the data (points, triangles, normals) from the binary file and stores them.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=PathLen), | intent(in) | :: | filename | name of the binary stl file |
||
integer, | intent(in) | :: | nNodesRead | Number of nodes read from the file header, to compare against the actual number of nodes read |
||
integer, | intent(in) | :: | nTrisRead | Number of triangles read from the file header, to compare against the actual number of triangles read |
||
real(kind=rk), | intent(out) | :: | nodes(:,:) | point coordinates read from the stl-file size: 3, nPoints_total |
||
integer, | intent(out) | :: | tri_node(:,:) | connectivity array for the triangles size: 3, nTriangles_total |
||
integer, | intent(out) | :: | iError | error while openeing the file, or if the number of nodes/trias do not match to the ones read from the header (if error -> iError > 0) |
subroutine tem_read_stlb( filename, nNodesRead, nTrisRead, nodes, tri_node, &
& ierror )
! ---------------------------------------------------------------------------
!> name of the binary stl file
character(len=PathLen),intent(in) :: filename
!> point coordinates read from the stl-file
!! size: 3, nPoints_total
real(kind=rk),intent(out) :: nodes(:,:)
!> connectivity array for the triangles
!! size: 3, nTriangles_total
integer,intent(out) :: tri_node(:,:)
!> Number of nodes read from the file header, to compare against the actual
!! number of nodes read
integer,intent(in) :: nNodesRead
!> Number of triangles read from the file header, to compare against the
!! actual number of triangles read
integer,intent(in) :: nTrisRead
!> error while openeing the file, or if the number of nodes/trias do not
!! match to the ones read from the header (if error -> iError > 0)
integer,intent(out) :: iError
! ---------------------------------------------------------------------------
! buffer for reading the data from file
real(kind=single_k) :: temp(3) ! has to be single_k
character(len=80) :: header ! has to be of length 80
character(len=2) :: attribute
integer :: nTriangles ! has to be 4 byte integer
integer :: stlUnit
integer :: i
integer :: nNodes
integer :: nTris
! ---------------------------------------------------------------------------
stlUnit = newUnit()
open( unit = stlUnit, file = trim(filename), access = 'stream', &
& action = 'read', status = 'old', iostat = iError )
if( iError .ne. 0 ) then
write(logUnit(0),*) "An error appeared when opening the file " // &
& trim(filename)//". Stopping!!!"
call tem_abort()
end if
read(stlUnit) header
read(stlUnit) nTriangles
nNodes = 0
nTris = 0
do i=1,nTriangles
! assign node coordinates
! and nodes to tris
nTris = nTris+1
read(stlUnit) temp(:) ! normal vector
read(stlUnit) temp(:) ! node 1 coords
nNodes = nNodes+1
nodes(1:3,nNodes) = real(temp(1:3),kind=rk)
tri_node(1,nTris) = nNodes
read(stlUnit) temp(:) ! node 2 coords
nNodes = nNodes+1
nodes(1:3,nNodes) = real(temp(1:3),kind=rk)
tri_node(2,nTris) = nNodes
read(stlUnit) temp(:) ! node 3 coords
nNodes = nNodes+1
nodes(1:3,nNodes) = real(temp(1:3),kind=rk)
tri_node(3,nTris) = nNodes
read(stlUnit) attribute
end do
close(stlUnit)
if ( nTris .ne. nTrisRead) then
write(logUnit(0),*) "Inconsistency found in number of triangles!"
iError = 1
endif
if ( nNodes .ne. nNodesRead) then
write(logUnit(0),*) "Inconsistency found in number of nodes!"
iError = 1
endif
end subroutine tem_read_stlb