3 use iso_c_binding,
only : c_int, c_float, c_double, c_bool
30 integer (c_int) :: count = 0
78 character (len=*),
intent(in) :: sFilename
79 character (len=*),
intent(in),
optional :: sDelimiters
80 character (len=*),
intent(in),
optional :: sCommentChars
83 character (len=:),
allocatable :: sDelimiters_
84 character (len=:),
allocatable :: sCommentChars_
86 if (
present(scommentchars) )
then
87 scommentchars_ = scommentchars
92 if (
present(sdelimiters) )
then
93 sdelimiters_ = sdelimiters
98 this%count = this%count + 1
100 call this%filenames%append( sfilename )
101 call this%delimiters%append( sdelimiters_ )
102 call this%comment_chars%append( scommentchars_ )
111 character (len=*),
intent(in),
optional :: comment_chars
112 character (len=*),
intent(in),
optional :: delimiters
115 integer (c_int) :: iFileIndex, iColIndex, iTempIndex
116 integer (c_int) :: iStat
117 type (ASCII_FILE_T) :: DF
118 type (DICT_ENTRY_T),
pointer :: pDict
119 type (DICT_ENTRY_T),
pointer :: pCurrentDict
120 integer (c_int) :: iNumberOfHeaderLines
121 character (len=:),
allocatable :: sNumberOfHeaderLines
122 character (len=256) :: column_name
123 character (len=256) :: tempstr2
124 character (len=256) :: qualified_column_name
125 character (len=256) :: filename1
126 character (len=:),
allocatable :: comment_chars_
127 character (len=:),
allocatable :: delimiters_
128 logical (c_bool),
allocatable :: skip_this_column(:)
129 type (FSTRING_LIST_T) :: unique_file_list
130 integer (kind=c_int) :: row_indx
131 integer (c_int) :: number_of_columns
132 character (len=MAX_TABLE_RECORD_LEN) :: sRecord, sItem
134 if (
present(comment_chars) )
then
135 comment_chars_ = trim(comment_chars)
140 if (
present(delimiters) )
then
141 delimiters_ = trim(delimiters)
152 if ( this%filenames%get(1) .ne.
'<NA>' )
then
154 do ifileindex = 1, this%filenames%count
156 filename1 = this%filenames%get(ifileindex)
159 if ( unique_file_list%count_matching(filename1) > 0 ) cycle
161 call unique_file_list%append(filename1)
164 call df%open(sfilename = filename1, &
165 scommentchars = comment_chars_, &
166 sdelimiters = delimiters_ )
169 df%slColNames = df%readHeader()
171 number_of_columns = df%slColNames%count
173 call logs%write(
"Number of columns in file: "//
ascharacter( number_of_columns ), itab=35)
177 if (
allocated(skip_this_column))
deallocate(skip_this_column)
178 allocate(skip_this_column(number_of_columns))
179 skip_this_column =
false
182 do icolindex = 1, df%slColNames%count
184 column_name = df%slColNames%get(icolindex)
186 if (
params_dict%key_already_in_use( column_name ) )
then
188 skip_this_column( icolindex ) =
true
190 call warn(
"Column name "//
squote(column_name)//
" already in use. Data in this column will be ignored." &
191 //
" [filename = "//
squote(filename1)//
"]")
207 allocate( pdict, stat=istat )
208 call assert(istat == 0,
"Failed to allocate memory for dictionary object", &
213 call pdict%add_key( column_name )
223 do while ( .not. df%isEOF() )
226 srecord = df%readLine()
229 if ( len_trim(srecord) == 0 ) cycle
231 row_indx = row_indx + 1
234 do icolindex = 1, df%slColNames%count
237 call chomp(srecord, sitem, this%delimiters%get(ifileindex) )
239 if ( skip_this_column(icolindex) ) cycle
241 column_name = df%slColNames%get(icolindex)
245 pcurrentdict =>
params_dict%get_entry( column_name )
247 if (
associated( pcurrentdict ))
then
251 call pcurrentdict%add_value( sitem )
255 call warn(
"Internal programming error: null pointer detected" &
256 //
" -- was trying to find pointer associated with column "//
dquote(df%slColNames%get(icolindex)), &
265 deallocate(skip_this_column)
280 character (len=*),
intent(in) :: sKey
281 character (len=*),
intent(in),
optional :: sValues(:)
282 integer (c_int),
intent(in),
optional :: iValues(:)
283 real (c_float),
intent(in),
optional :: fValues(:)
284 real (c_double),
intent(in),
optional :: dValues(:)
285 logical (c_bool),
intent(in),
optional :: lValues(:)
288 integer (c_int) :: iStat
289 type (DICT_ENTRY_T),
pointer :: pDict
290 integer (c_int) :: iIndex
291 type (DICT_ENTRY_T),
pointer :: pCurrentDict
292 character (len=MAX_TABLE_RECORD_LEN) :: sRecord, sItem
295 pcurrentdict => null()
298 if ( .not.
associated( pcurrentdict ))
then
301 allocate( pcurrentdict, stat=istat )
303 call assert(istat == 0,
"Failed to allocate memory for dictionary object", &
307 call pcurrentdict%add_key( skey )
312 if (
present( svalues ) )
then
314 do iindex = lbound(svalues,1), ubound(svalues,1)
316 call pcurrentdict%add_value( svalues( iindex ) )
320 else if (
present ( ivalues ) )
then
322 do iindex = lbound(ivalues,1), ubound(ivalues,1)
324 call pcurrentdict%add_value( ivalues( iindex ) )
328 else if (
present ( fvalues ) )
then
330 do iindex = lbound(fvalues,1), ubound(fvalues,1)
332 call pcurrentdict%add_value( fvalues( iindex ) )
336 else if (
present ( dvalues ) )
then
338 do iindex = lbound(dvalues,1), ubound(dvalues,1)
340 call pcurrentdict%add_value( dvalues( iindex ) )
344 else if (
present ( lvalues ) )
then
346 do iindex = lbound(lvalues,1), ubound(lvalues,1)
348 call pcurrentdict%add_value( lvalues( iindex ) )
361 character (len=*),
intent(in) :: skey
362 logical (c_bool),
intent(in),
optional :: lfatal
366 logical (c_bool) :: lfatal_l
368 if (
present (lfatal) )
then
378 if ( sllist%get(1) .strequal.
"<NA>" ) &
379 call warn(
"Failed to find a lookup table column whose name contains " &
380 //
dquote( skey )//
".", lfatal = lfatal_l )
391 logical (c_bool),
intent(in out),
allocatable :: lValues(:)
392 type (FSTRING_LIST_T),
intent(in out),
optional :: slKeys
393 character (len=*),
intent(in ),
optional :: sKey
394 logical (c_bool),
intent(in),
optional :: lFatal
397 logical (c_bool) :: lFatal_l
399 if (
present (lfatal) )
then
405 if (
present( slkeys) )
then
407 call params_dict%get_values( slkeys=slkeys, lvalues=lvalues, &
414 else if (
present( skey) )
then
416 call params_dict%get_values( skey=skey, lvalues=lvalues )
431 type (DATETIME_T),
intent(in out),
allocatable :: dtValues(:)
432 type (FSTRING_LIST_T),
intent(in out),
optional :: slKeys
433 character (len=*),
intent(in ),
optional :: sKey
434 logical (c_bool),
intent(in),
optional :: lFatal
437 logical (c_bool) :: lFatal_l
438 type (FSTRING_LIST_T) :: slValues
440 integer (c_int) :: istat
442 if (
present (lfatal) )
then
448 if (
present( slkeys) )
then
450 call params_dict%get_values( slkeys=slkeys, slstring=slvalues, is_fatal=lfatal_l )
452 else if (
present( skey) )
then
454 call params_dict%get_values( skey=skey, slstring=slvalues )
458 allocate(dtvalues(slvalues%count), stat=istat)
460 do n=1, slvalues%count
461 call dtvalues(n)%parseDate(slvalues%get(n))
471 type (FSTRING_LIST_T),
intent(out) :: slValues
472 type (FSTRING_LIST_T),
intent(inout),
optional :: slKeys
473 character (len=*),
intent(in ),
optional :: sKey
474 logical (c_bool),
intent(in),
optional :: lFatal
477 logical (c_bool) :: lFatal_l
479 if (
present (lfatal) )
then
485 if (
present( slkeys) )
then
487 call params_dict%get_values( slkeys=slkeys, slstring=slvalues, &
490 if ( slvalues%get(1) .strequal.
"<NA>" )
then
491 call warn(
"Failed to find a lookup table column named " &
492 //
dquote( slkeys%list_all() )//
".", lfatal = lfatal_l )
495 else if (
present( skey) )
then
497 call params_dict%get_values( skey=skey, slstring=slvalues )
499 if ( slvalues%get(1) .strequal.
"<NA>" )
then
500 call warn(
"Failed to find a lookup table column named " &
501 //
dquote( skey )//
".", lfatal = lfatal_l )
513 integer (c_int),
intent(out),
allocatable :: iValues(:)
514 type (FSTRING_LIST_T),
intent(in out),
optional :: slKeys
515 character (len=*),
intent(in ),
optional :: sKey
516 logical (c_bool),
intent(in),
optional :: lFatal
519 logical (c_bool) :: lFatal_l
521 if (
present (lfatal) )
then
527 if (
present( slkeys) )
then
529 call params_dict%get_values( slkeys=slkeys, ivalues=ivalues, &
533 call warn(
"Failed to find a lookup table column named " &
534 //
dquote( slkeys%list_all() )//
".", lfatal = lfatal_l )
536 else if (
present( skey) )
then
538 call params_dict%get_values( skey=skey, ivalues=ivalues, &
542 call warn(
"Failed to find a lookup table column named " &
543 //
dquote( skey )//
".", lfatal = lfatal_l )
554 real (c_float),
intent(in out),
allocatable :: fValues(:)
555 type (FSTRING_LIST_T),
intent(in out),
optional :: slKeys
556 character (len=*),
intent(in ),
optional :: sKey
557 logical (c_bool),
intent(in),
optional :: lFatal
560 logical (c_bool) :: lFatal_l
562 if (
present (lfatal) )
then
568 if (
present( slkeys) )
then
570 call params_dict%get_values( slkeys=slkeys, fvalues=fvalues )
573 call warn(
"Failed to find a lookup table column named " &
574 //
dquote( slkeys%list_all() )//
".", lfatal = lfatal_l )
576 else if (
present( skey) )
then
578 call params_dict%get_values( skey=skey, fvalues=fvalues, &
582 call warn(
"Failed to find a lookup table column named " &
583 //
dquote( skey )//
".", lfatal = lfatal_l )
596 real (c_float),
intent(in out),
allocatable :: fValues(:,:)
597 character (len=*),
intent(in) :: sPrefix
598 integer (c_int),
intent(in) :: iNumRows
599 logical (c_bool),
intent(in),
optional :: lFatal
602 integer (c_int) :: iIndex
603 integer (c_int) :: iStat
604 character (len=256) :: sText
605 integer (c_int) :: iNumCols
606 type (FSTRING_LIST_T) :: slList
607 real (c_float),
allocatable :: fTempVal(:)
608 logical (c_bool) :: lFatal_l
610 if (
present (lfatal) )
then
616 sllist =
params%grep_name( sprefix )
618 inumcols = sllist%count
620 if ( inumcols == 0 )
then
622 call warn(
"Failed to find a lookup table column named " &
623 //
dquote( sprefix )//
".", lfatal = lfatal_l )
627 allocate( ftempval( inumrows ), stat=istat )
628 call assert( istat == 0,
"Problem allocating memory.", __file__, __line__ )
630 allocate( fvalues( inumrows, inumcols ), stat=istat )
631 call assert( istat == 0,
"Problem allocating memory." &
633 //
" sPrefix: "//
dquote(sprefix), __file__, __line__ )
635 do iindex = 1, inumcols
637 stext = trim( sllist%get( iindex ) )
638 call params_dict%get_values( skey=stext, fvalues=ftempval, &
641 call assert(
size( ftempval, 1) ==
size( fvalues, 1), &
642 "Mismatch in array size. Dictionary key: "//
squote( stext ) &
643 //
" expected size: "//
ascharacter(
size( fvalues, 1) ) &
644 //
" size of items in dictionary: " &
647 fvalues(:,iindex) = ftempval
This module contains physical constants and convenience functions aimed at performing unit conversion...
logical(c_bool), parameter, public true
logical(c_bool), parameter, public false
real(c_float), parameter ftinyval
integer(c_int), parameter, public itinyval
This module contains the DATETIME_T class and associated time and date-related routines,...
subroutine, public warn(smessage, smodule, iline, shints, lfatal, iloglevel, lecho)
character(len=1), parameter, public tab
character(len=3), parameter, public comment_characters
type(logfile_t), public logs
subroutine get_parameter_values_logical(this, lvalues, slkeys, skey, lfatal)
type(parameters_t), public params
subroutine get_parameter_table_float(this, fvalues, sprefix, inumrows, lfatal)
subroutine add_to_param_list_sub(this, skey, svalues, ivalues, fvalues, dvalues, lvalues)
subroutine munge_files_and_add_to_param_list_sub(this, comment_chars, delimiters)
type(dict_t), public params_dict
subroutine get_parameter_values_string_list(this, slvalues, slkeys, skey, lfatal)
integer(c_int), parameter max_table_record_len
type(fstring_list_t) function grep_parameter_name(this, skey, lfatal)
subroutine get_parameter_values_int(this, ivalues, slkeys, skey, lfatal)
subroutine get_parameter_values_datetime(this, dtvalues, slkeys, skey, lfatal)
subroutine add_filename_to_list_sub(this, sfilename, sdelimiters, scommentchars)
subroutine get_parameter_values_float(this, fvalues, slkeys, skey, lfatal)