write_ascii_stl_file Subroutine

private subroutine write_ascii_stl_file(me, filename, modelname, istat, bounding_box)

Generate an ascii STL file.

Type Bound

stl_file

Arguments

Type IntentOptional Attributes Name
class(stl_file), intent(in) :: me
character(len=*), intent(in) :: filename

STL file name

character(len=*), intent(in) :: modelname

the solid name (should not contain spaces)

integer, intent(out) :: istat

iostat code (=0 if no errors)

real(kind=wp), intent(in), optional :: bounding_box

scale vertices so that model fits in a box of this size (if <=0, no scaling is done)


Calls

proc~~write_ascii_stl_file~~CallsGraph proc~write_ascii_stl_file stl_file%write_ascii_stl_file proc~compute_vertex_scale stl_file%compute_vertex_scale proc~write_ascii_stl_file->proc~compute_vertex_scale proc~normal normal proc~write_ascii_stl_file->proc~normal proc~cross cross proc~normal->proc~cross proc~unit unit proc~normal->proc~unit

Source Code

    subroutine write_ascii_stl_file(me,filename,modelname,istat,bounding_box)

    implicit none

    class(stl_file),intent(in)    :: me
    character(len=*),intent(in)   :: filename      !! STL file name
    character(len=*),intent(in)   :: modelname     !! the solid name (should not contain spaces)
    integer,intent(out)           :: istat         !! `iostat` code (=0 if no errors)
    real(wp),intent(in),optional  :: bounding_box  !! scale vertices so that model fits in a
                                                   !! box of this size (if <=0, no scaling is done)

    integer  :: iunit  !! file unit number
    integer  :: i      !! counter
    real(wp) :: scale  !! scale factor

    character(len=*),parameter :: fmt = '(A,1X,E30.16,1X,E30.16,1X,E30.16)' !! format statement for vectors

    scale = me%compute_vertex_scale(bounding_box)

    ! open the text file:
    open(newunit=iunit, file=trim(filename), status='REPLACE', iostat=istat)

    if (istat==0) then

        ! write the file:
        write(iunit,'(A)') 'solid '//trim(modelname)
        do i = 1, me%n_plates
            write(iunit,fmt)    'facet normal', normal(me%plates(i)%v1,me%plates(i)%v2,me%plates(i)%v3)
            write(iunit,'(A)')  '    outer loop'
            write(iunit,fmt)    '        vertex', me%plates(i)%v1 * scale
            write(iunit,fmt)    '        vertex', me%plates(i)%v2 * scale
            write(iunit,fmt)    '        vertex', me%plates(i)%v3 * scale
            write(iunit,'(A)')  '    end loop'
            write(iunit,'(A)')  'end facet'
        end do
        write(iunit,'(A)') 'endsolid '//trim(modelname)

        ! close the file:
        close(iunit)

    end if

    end subroutine write_ascii_stl_file