, , - - , . -. : , , ...... "backspace" , , . , - , , .
... , "#" . : "" - . , - - .
P.S. "Fortran" Fortran 90 - "FORTRAN" FORTRAN 77 .
module read_file_module
implicit none
contains
subroutine read_file (UnitNum, FileName, NumRows, NumCols, Array )
integer, intent (in) :: UnitNum
character (len=*), intent (in) :: FileName
integer, intent (in) :: NumRows, NumCols
real, dimension (1:NumRows, 1:NumCols), intent (out) :: Array
character (len=300) :: line
integer :: i, j
open (unit=UnitNum, file=FileName, status='old', action='read' )
ReadComments: do
read (UnitNum, '(A)') line
if (line (1:1) /= "#") exit ReadComments
end do ReadComments
backspace (UnitNum)
do i=1, NumRows
read (UnitNum, *) (Array (i, j), j=1,NumCols)
end do
close (UnitNum)
return
end subroutine read_file
end module read_file_module
program test_prog
use read_file_module
implicit none
real, dimension (1:8, 1:4) :: Array
integer :: i, j
call read_file (66, 'TestFile.txt', 8, 4, Array)
do i=1, 8
write (*, '( 4(2X, F7.3) )' ) (Array (i, j), j=1,4)
end do
end program test_prog
, , :
# comment one
# comment two
1.1 2.0 3.0 4.1
1.2 2.0 3.0 4.2
1.3 2.0 3.0 4.3
1.4
2.0 3.0 4.4
1.5 2.0 3.0 4.5
1.6 2.0 3.0 4.6
1.7 2.0 3.0 4.7
1.8 2.0 3.0 4.8