Generate an ascii STL file.
Type | Intent | Optional | 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 |
|
||
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) |
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