read_tab_file Subroutine

private subroutine read_tab_file(me, filename, istat)

Read a text vertex-facet file.

File Format

The file is a text file consisting of:

  • Number of Vertices [int, %12d], Number of Triangular Plates [int, %12d]
  • Vertex table:
    • Vertex Number [int, %10d], x coordinate [real, %15.5f], y coordinate [real, %15.5f], z coordinate [real, %15.5f]
  • Plate table:
    • Plate Number [int, %10d], 1st Plate Vertex Number [int, %10d], 2nd Plate Vertex Number [int, %10d], 3rd Plate Vertex Number [int, %10d]

Example

  • https://sbnarchive.psi.edu/pds4/non_mission/gaskell.phobos.shape-model/data/phobos_ver64q.tab
 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 Bound

stl_file

Arguments

Type IntentOptional Attributes Name
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)


Calls

proc~~read_tab_file~~CallsGraph proc~read_tab_file stl_file%read_tab_file proc~destroy_stl_file stl_file%destroy_stl_file proc~read_tab_file->proc~destroy_stl_file

Source Code

    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