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=:),
allocatable :: strimmedinput
151 character (len=1) :: sfirstchar
155 strimmedinput = adjustl(trim(this%sBuf))
156 ilen = len( strimmedinput )
160 sfirstchar = strimmedinput(1:1)
164 iindex = scan( sfirstchar , this%sCommentChars )
165 if ( iindex > 0 ) liscomment =
true
176 character (len=*),
intent(in) :: sfilename
177 character (len=*),
intent(in) :: scommentchars
178 character (len=*),
intent(in) :: sdelimiters
179 logical (c_bool),
intent(in),
optional :: lhasheader
182 character (len=len(sFilename) ) :: sfilename_l
188 this%sCommentChars = scommentchars
189 this%sDelimiters = sdelimiters
191 if (
present( lhasheader ) )
then
192 if (.not. lhasheader ) this%iNumberOfHeaderLines = 0
195 if ( this%isOpen() )
then
205 //
" Exit code: "//
ascharacter( this%iStat )//
".", __file__, __line__)
210 call this%countLines()
213 ilinesbefore=1, iloglevel=
log_all )
214 call logs%write(
"Comment characters: "//
dquote(scommentchars), itab=42 )
215 call logs%write(
"Number of lines in file: "//
ascharacter( this%numLines() ), itab=37 )
216 call logs%write(
"Number of lines excluding blanks, headers and comments: " &
228 character (len=*),
intent(in) :: sfilename
229 logical (c_bool),
intent(in),
optional :: lquiet
233 character (len=len(sFilename) ) :: sfilename_l
237 if (
present( lquiet ) )
then
243 if (.not. this%isOpen() )
then
244 this%sFilename = trim(sfilename_l)
245 open(newunit=this%iUnitNum, file=sfilename_l, iostat=this%iStat, action=
'WRITE')
246 call assert(this%iStat == 0,
"Failed to open file "//
dquote(sfilename_l)//
".", __file__, __line__)
250 this%lReadOnly =
false
251 this%sFilename = trim(sfilename_l)
253 if ( .not. lquiet_l ) &
254 call logs%write(
"Opened file with write access: "//
dquote(sfilename_l))
257 call logs%write(
"Failed to open file "//
dquote(sfilename_l)//
" with WRITE access" )
269 close(unit=this%iUnitNum, iostat=this%iStat)
280 character (len=*),
intent(in) :: sfilename
292 logical(c_bool) :: lisopen
294 lisopen = this%lIsOpen
305 integer (c_int) :: istat
306 integer (c_int) :: inumlines
307 integer (c_int) :: inumrecords
313 if ( this%isOpen() )
then
315 rewind( unit = this%iUnitNum )
319 read (unit = this%iUnitNum, fmt=
"(a)", iostat = istat) this%sBuf
321 if (istat == iostat_end)
exit
323 inumlines = inumlines + 1
325 if ( .not. this%isComment() ) inumrecords = inumrecords + 1
329 rewind( unit = this%iUnitNum )
331 this%iNumberOfLines= inumlines
332 this%iNumberOfRecords = inumrecords - this%iNumberOfHeaderLines
346 character (len=MAX_STR_LEN) :: ssubstring
347 character (len=MAX_STR_LEN) :: ssubstringclean
349 this%sBuf = this%readline()
352 do while ( len_trim( this%sBuf ) > 0)
354 call chomp( str=this%sBuf, substr=ssubstring, delimiter_chr=this%sDelimiters, &
355 remove_extra_delimiters=this%remove_extra_delimiters )
357 call replace(ssubstring,
" ",
"_")
358 call replace(ssubstring,
".",
"_")
360 call stlist%append( trim( adjustl( ssubstringclean ) ) )
371 character (len=*),
intent(in) :: sText
374 integer (c_int) :: iStat
376 call assert( .not. this%lReadOnly,
"INTERNAL ERROR -- File " &
378 //
" was opened as READONLY.", __file__, __line__ )
380 if (this%isOpen() )
then
382 write ( unit = this%iUnitNum, fmt =
"(a)", iostat = istat ) trim(stext)
393 character (len=:),
allocatable :: stext
396 integer (c_int) :: istat
397 logical (c_bool) :: liscomment
401 do while ( liscomment .and. this%isOpen() )
403 if (this%isOpen() )
then
405 read (unit = this%iUnitNum, fmt =
"(a)", iostat = istat) this%sBuf
407 if (istat == iostat_end)
then
412 stext = trim(this%sBuf)
413 this%iCurrentLinenum = this%iCurrentLinenum + 1
416 liscomment = this%isComment()
428 character(len=*),
intent(in) :: filename
429 character(len=*),
intent(in),
optional :: pathname
432 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)
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)
pure logical(c_bool) function is_file_open_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)
logical function does_file_exist_fn(this, sfilename)
integer(c_int) function return_fortran_unit_number_fn(this)
character(len=1), parameter, public double_quote
type(logfile_t), public logs