Read a text vertex-facet file.
The file is a text file consisting of:
25350 49152
1 -6.77444 6.26815 6.01149
2 -6.63342 6.34195 6.08444
3 -6.49302 6.41635 6.15759
4 -6.34883 6.48872 6.22619
...
1 1 67 2
2 1 66 67
3 66 132 67
4 66 131 132
5 131 197 132
...
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(stl_file), | intent(out) | :: | me | |||
character(len=*), | intent(in) | :: | filename |
Vertex-facet file name |
||
integer, | intent(out) | :: | istat |
|
subroutine read_tab_file(me,filename,istat) implicit none class(stl_file),intent(out) :: me character(len=*),intent(in) :: filename !! Vertex-facet file name integer,intent(out) :: istat !! `iostat` code (=0 if no errors) integer :: iunit !! file unit integer :: number_of_vertices !! number of vertices in the file integer :: number_of_plates !! number of plates defined in the file (three vertices) integer :: i !! counter integer :: ii !! vertex or plate index integer :: i1 !! 1st vertex index of plate integer :: i2 !! 2nd vertex index of plate integer :: i3 !! 3rd vertex index of plate real(wp),dimension(:,:),allocatable :: v !! vertices from the file real(wp) :: x !! x coordinate of vertex real(wp) :: y !! y coordinate of vertex real(wp) :: z !! z coordinate of vertex !initialize: call me%destroy() !open the file: open(newunit = iunit,& file = filename,& action = 'READ',& status = 'OLD',& iostat = istat) if (istat==0) then read(iunit,*,iostat=istat) number_of_vertices, number_of_plates if (istat==0) then me%n_plates = number_of_plates allocate(me%plates(me%n_plates)) allocate(v(3,number_of_vertices)) ! first accumulate the vertex coordinates: do i = 1, number_of_vertices read(iunit,*,iostat=istat) ii, x, y, z !get the data: if (istat==0) then v(1,i) = x v(2,i) = y v(3,i) = z else write(error_unit,'(A)') 'Error reading vertex from file: '//trim(filename) call me%destroy() close(iunit) return end if end do ! now, read the plate vertex indices, and add them to the class do i = 1, number_of_plates read(iunit,*,iostat=istat) ii,i1,i2,i3 if (istat==0) then me%plates(i)%v1 = v(:,i1) me%plates(i)%v2 = v(:,i2) me%plates(i)%v3 = v(:,i3) else write(error_unit,'(A)') 'Error reading plate from file: '//trim(filename) call me%destroy() close(iunit) return end if end do ! close the file: close(iunit) deallocate(v) else write(error_unit,'(A)') 'Error reading first line from file: '//trim(filename) close(iunit) end if end if end subroutine read_tab_file