read_table(3f) - [M_io:READ] read file containing a table of numeric values (LICENSE:PD)
Synopsis
Description
Options
Examples
Author
License
subroutine read_table(filename,array,ierr,comment)
character(len=*),intent(in) :: filename TYPE,allocatable,intent(out) :: array(:,:) integer,intent(out) :: ierr character(len=1,intent(in),optional :: commentwhere TYPE may be REAL, INTEGER, or DOUBLEPRECISION
Read a table from a file that is assumed to be columns of numbers, ignoring characters not in the set [0-9edED+-.] and requiring each row contain the same number of values.The input file is assumed to be of a small enough size that it can be copied into memory.
filename filename to read array array to create. May be INTEGER, REAL, or DOUBLEPRECISION ierr zero if no error occurred. comment ignore lines which contain this as the first non-blank character. Ignore it and subsequent characters on any line.
Sample program, assuming the input file "inputfile" exists:
program demo_read_table use M_io, only : read_table implicit none doubleprecision,allocatable :: array(:,:) integer :: i, ierrResults:! create test file open(file=inputfile,unit=10,action=write) write(10,(a)) [character(len=80):: & ___.___.___ , & | 1 | 5 | 3 | , & |---+---+---| , & | 4 | 2 | 6 | , & ----------- , & #-----#-----#------# , & | | 1 | 3e2 | 4 | , & | #-----#-----#------# , & | | 2.0 | -5 | +2.2 | , & #-----#-----#------# , & , & #___#___#___# , & | 1 | 5 | 3 | , & #---#---#---# , & | 4 | 2 | 6 | , & #---#---#---# , & , & 1;10;45 , & 10, ,, ,,20 45 , & 2 20 15 , & big=20.345 medium=20 small=15 , & , & 30 30e3 0 , & 4 300.444e-1 -10 , & 40 30.5555d0 -10 , & 4 300.444E-1 -10 , & 40 30.5555D0 -10 , & ] close(unit=10)
! read file as a table call read_table(inputfile,array,ierr)
! print values write(*,*)size= ,size(array) write(*,*)size(dim=1)=,size(array,dim=1) write(*,*)size=(dim=2),size(array,dim=2) do i=1,size(array,dim=1) write(*,*)array(i,:) enddo
! remove sample file open(file=inputfile,unit=10) close(unit=10,status=delete)
end program demo_read_table
size= 45 size(dim=1)= 15 size=(dim=2) 3 1.000000000000000 5.000000000000000 3.000000000000000 4.000000000000000 2.000000000000000 6.000000000000000 1.000000000000000 300.0000000000000 4.000000000000000 2.000000000000000 -5.000000000000000 2.200000000000000 1.000000000000000 5.000000000000000 3.000000000000000 4.000000000000000 2.000000000000000 6.000000000000000 1.000000000000000 10.00000000000000 45.00000000000000 10.00000000000000 20.00000000000000 45.00000000000000 2.000000000000000 20.00000000000000 15.00000000000000 20.34499999999999 20.00000000000000 15.00000000000000 30.00000000000000 30000.00000000000 0.000000000000000 4.000000000000000 30.04440000000000 -10.00000000000000 40.00000000000000 30.55549999999999 -10.00000000000000 4.000000000000000 30.04440000000000 -10.00000000000000 40.00000000000000 30.55549999999999 -10.00000000000000
John S. Urban
Public Domain
Nemo Release 3.1 | read_table (3m_io) | October 25, 2024 |