【发布时间】:2020-01-04 10:10:04
【问题描述】:
文件说明:STL文件包括
solid <solid_name>
facet normal n1 n2 n3 (the triangles normal vector)
outerloop (one of the markers I want to read)
v1 x1 y1 z1
v2 x2 y2 z2 (three vertex of the triangle/facet)
v3 x3 y3 z3
endloop
end facet
endsolid
这个想法是读取每一行的信息。首先,我正在尝试!阅读第一行:solid
program Leitura
!use, intrinsic :: trim
implicit none
integer ilo, ierror, ihi, ios, iunit, num_text, len_blanck,
len_word,
len_text, i
character(len=80) :: filename
character(len=:), dimension(:), allocatable :: text, lenc
character(len=:), dimension(:), allocatable :: word
character(len=:), dimension(:), allocatable :: blanck
len_blanck=1
len_word=11
len_text=256
allocate(character(len=len_blanck) :: blanck(1))
allocate(character(len=len_word) :: word(1))
allocate(character(len=len_text) :: text(1))
allocate(character(len=len_text) :: lenc(1))
blanck= " "
ierror = 0
iunit=10
filename="Esfera.stl"
!Opening the STL file
open(unit=iunit, file=filename, status='old', access='stream', form='unformatted')
! If NUM_TEXT is zero, then initialize TEXT.
!
if ( num_text <= 0 ) then
num_text = 0
text = blanck
end if
!
! If TEXT is blank, try to read a new line from the file.
if ( ios /= 0 ) then
ierror = 1
word = blanck
text = blanck
return
end if
num_text = num_text + 1
!Reading the first line of information- should be solid name, aka, ! !the name of the solid
read ( iunit, '(a)', iostat = ios ) text
do i=1,len(text)
if ( text(i)==blanck ) then
word = blanck
return
end if
end do
!
! Extract the next word from TEXT into WORD and return.
!
lenc = len_trim ( text )
!
! Find ILO, the index of the first nonblank in TEXT.
!
ilo = 1
do while ( text(ilo:ilo) == blanck )
ilo = ilo + 1
end do
!
! Find IHI, the index of the last consecutive nonblank after the one
! at ILO.
!
ihi = ilo
do while ( ihi+1 <= lenc )
if ( text(ihi+1:ihi+1) == blanck ) then
exit
end if
ihi = ihi + 1
end do
!
! Set WORD.
!
word = text(ilo:ihi)
!
! Slide TEXT to the left.
!
if ( ihi+1 <= lenc ) then
text = text(ihi+1:)
else
text = ' '
end if
return
end program Leitura
【问题讨论】:
-
我正在尝试在这里发布整个代码,但我遇到了麻烦...
标签: arrays string fortran character fortran90