3 use iso_c_binding,
only : c_int, c_float, c_double, c_bool
4 use iso_fortran_env,
only : iostat_end
20 character (len=:),
allocatable :: sfilename
21 character (len=:),
allocatable :: sdelimiters
22 character (len=:),
allocatable :: scommentchars
24 logical (c_bool) :: remove_extra_delimiters =
false
25 integer (c_int) :: icurrentlinenum = 0
26 integer (c_int) :: inumberoflines = 0
27 integer (c_int) :: inumberofrecords = 0
28 integer (c_int) :: inumberofheaderlines = 1
29 logical (c_bool) :: lisopen =
false
30 logical (c_bool) :: lreadonly =
true
31 logical (c_bool) :: leof =
false
32 integer (c_int) :: iunitnum
33 integer (c_int) :: istat
34 character (len=MAX_STR_LEN) :: sbuf
35 character (len=:),
allocatable :: stmissingvalue
90 integer (c_int) :: iunitnum
92 iunitnum = this%iUnitNum
101 integer (c_int) :: inumlines
103 inumlines = this%iNumberOfLines
112 integer (c_int) :: inumrecords
114 inumrecords = this%iNumberOfRecords
123 integer (c_int) :: icurrentlinenum
125 icurrentlinenum = this%iCurrentLinenum
134 logical (c_bool) :: liseof
145 logical (c_bool) :: liscomment
148 integer (c_int) :: iindex
149 integer (c_int) :: ilen
150 character (len=1) :: sbuftemp
152 ilen = len_trim( this%sBuf )
154 sbuftemp = adjustl(this%sBuf)
156 iindex = verify( sbuftemp , this%sCommentChars )
160 if ( iindex == 0 .or. len_trim(this%sBuf) == 0 ) liscomment =
true
169 character (len=*),
intent(in) :: sfilename
170 character (len=*),
intent(in) :: scommentchars
171 character (len=*),
intent(in) :: sdelimiters
172 logical (c_bool),
intent(in),
optional :: lhasheader
175 character (len=len(sFilename) ) :: sfilename_l
181 this%sCommentChars = scommentchars
182 this%sDelimiters = sdelimiters
184 if (
present( lhasheader ) )
then
185 if (.not. lhasheader ) this%iNumberOfHeaderLines = 0
188 if ( this%isOpen() )
then
196 //
" Exit code: "//
ascharacter( this%iStat )//
".", __file__, __line__)
201 call this%countLines()
204 ilinesbefore=1, iloglevel=
log_all )
205 call logs%write(
"Comment characters: "//
dquote(scommentchars), itab=42 )
206 call logs%write(
"Number of lines in file: "//
ascharacter( this%numLines() ), itab=37 )
207 call logs%write(
"Number of lines excluding blanks, headers and comments: " &
219 character (len=*),
intent(in) :: sfilename
220 logical (c_bool),
intent(in),
optional :: lquiet
224 character (len=len(sFilename) ) :: sfilename_l
228 if (
present( lquiet ) )
then
234 if (.not. this%isOpen() )
then
236 open(newunit=this%iUnitNum, file=sfilename_l, iostat=this%iStat, action=
'WRITE')
237 call assert(this%iStat == 0,
"Failed to open file "//
dquote(sfilename_l)//
".", __file__, __line__)
241 this%lReadOnly =
false
242 this%sFilename = trim(sfilename_l)
244 if ( .not. lquiet_l ) &
245 call logs%write(
"Opened file with write access: "//
dquote(sfilename_l))
248 call logs%write(
"Failed to open file "//
dquote(sfilename_l)//
" with WRITE access" )
259 integer (c_int) :: istat
261 close(unit=this%iUnitNum, iostat=this%iStat)
272 character (len=*),
intent(in) :: sfilename
273 logical(c_bool) :: lexists
284 logical(c_bool) :: lisopen
286 lisopen = this%lIsOpen
297 integer (c_int) :: istat
298 integer (c_int) :: inumlines
299 integer (c_int) :: inumrecords
300 integer (c_int) :: iindex
306 if ( this%isOpen() )
then
308 rewind( unit = this%iUnitNum )
312 read (unit = this%iUnitNum, fmt=
"(a)", iostat = istat) this%sBuf
314 if (istat == iostat_end)
exit
316 inumlines = inumlines + 1
318 if ( .not. this%isComment() ) inumrecords = inumrecords + 1
322 rewind( unit = this%iUnitNum )
324 this%iNumberOfLines= inumlines
325 this%iNumberOfRecords = inumrecords - this%iNumberOfHeaderLines
339 character (len=MAX_STR_LEN) :: sstring
340 character (len=MAX_STR_LEN) :: ssubstring
341 character (len=MAX_STR_LEN) :: ssubstringclean
342 integer (c_int) :: istat
344 this%sBuf = this%readline()
347 do while ( len_trim( this%sBuf ) > 0)
349 call chomp( str=this%sBuf, substr=ssubstring, delimiter_chr=this%sDelimiters, &
350 remove_extra_delimiters=this%remove_extra_delimiters )
352 call replace(ssubstring,
" ",
"_")
353 call replace(ssubstring,
".",
"_")
355 call stlist%append( trim( adjustl( ssubstringclean ) ) )
366 character (len=*),
intent(in) :: sText
369 integer (c_int) :: iStat
371 call assert( .not. this%lReadOnly,
"INTERNAL ERROR -- File " &
373 //
" was opened as READONLY.", __file__, __line__ )
375 if (this%isOpen() )
then
377 write ( unit = this%iUnitNum, fmt =
"(a)", iostat = istat ) trim(stext)
388 character (len=:),
allocatable :: stext
391 integer (c_int) :: istat
392 logical (c_bool) :: liscomment
396 do while ( liscomment .and. this%isOpen() )
398 if (this%isOpen() )
then
400 read (unit = this%iUnitNum, fmt =
"(a)", iostat = istat) this%sBuf
402 if (istat == iostat_end)
then
407 stext = trim(this%sBuf)
408 this%iCurrentLinenum = this%iCurrentLinenum + 1
411 liscomment = this%isComment()
423 character(len=*),
intent(in) :: filename
424 character(len=*),
intent(in),
optional :: pathname
427 if (.not.
present(pathname) )
then
This module contains physical constants and convenience functions aimed at performing unit conversion...
character(len=len_trim(input_pathname)) function fix_pathname(input_pathname)
logical(c_bool), parameter, public true
logical(c_bool), parameter, public false
subroutine, public die(smessage, smodule, iline, shints, scalledby, icalledbyline)
subroutine count_number_of_lines_sub(this)
type(fstring_list_t) function read_header_fn(this)
subroutine open_file_write_access_sub(this, sfilename, lquiet)
character(len=:) function, allocatable, public fully_qualified_filename(filename, pathname)
character(len=:) function, allocatable read_line_of_data_fn(this)
logical(c_bool) function is_file_open_fn(this)
subroutine close_file_sub(this)
integer(c_int), parameter max_str_len
subroutine write_line_of_data_sub(this, stext)
integer(c_int) function return_num_records_fn(this)
logical(c_bool) function have_we_reached_the_eof_fn(this)
integer(c_int) function return_num_lines_fn(this)
logical(c_bool) function is_current_line_a_comment_fn(this)
subroutine open_file_read_access_sub(this, sfilename, scommentchars, sdelimiters, lhasheader)
integer(c_int) function return_current_linenum_fn(this)
integer(c_int) function return_fortran_unit_number_fn(this)
logical(c_bool) function does_file_exist_fn(this, sfilename)
character(len=1), parameter, public double_quote
type(logfile_t), public logs