OBJの1行を長さ制限なしで読み、行末の CR を除く。 固定長バッファで読むと長い面行が短い有効な面へ切り詰められるため、 非前進読込で行末まで連結する。
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | u |
読み込み中の装置番号。 |
||
| character(len=:), | intent(out), | allocatable | :: | line |
読み込んだ1行(行末の改行と CR を除く)。 |
|
| integer, | intent(out) | :: | ios |
0 なら1行を読んだ。ファイル終端または読込失敗では非0。 |
subroutine read_obj_line(u, line, ios) integer, intent(in) :: u character(len=:), allocatable, intent(out) :: line integer, intent(out) :: ios character(len=1024) :: chunk integer :: nread line = '' do read (u, '(a)', advance='no', size=nread, iostat=ios) chunk line = line//chunk(1:nread) if (ios == iostat_eor) then ios = 0 exit end if if (ios /= 0) then ! 改行のない最終行は、その行を返してから次の呼出しで終端を返す。 if (ios == iostat_end .and. len(line) > 0) ios = 0 exit end if end do call strip_cr(line) end subroutine read_obj_line