This routine writes the current configuration to a file with descriptions
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(CFG_t), | intent(in) | :: | cfg_in | |||
| character(len=*), | intent(in) | :: | filename | |||
| logical, | intent(in), | optional | :: | hide_unused |
subroutine CFG_write(cfg_in, filename, hide_unused) use iso_fortran_env type(CFG_t), intent(in) :: cfg_in character(len=*), intent(in) :: filename logical, intent(in), optional :: hide_unused logical :: hide_not_used type(CFG_t) :: cfg integer :: i, j, io_state, myUnit character(len=CFG_name_len) :: name_format, var_name character(len=CFG_name_len) :: category, prev_category character(len=CFG_string_len) :: err_string hide_not_used = .false. if (present(hide_unused)) hide_not_used = hide_unused ! Always print a sorted configuration cfg = cfg_in if (.not. cfg%sorted) call CFG_sort(cfg) write(name_format, FMT="(A,I0,A)") "(A,A", CFG_name_len, ",A)" if (filename == "stdout") then myUnit = output_unit else myUnit = 333 open(myUnit, FILE=filename, ACTION="WRITE", ERR=999, IOSTAT=io_state) end if category = "" prev_category = "" do i = 1, cfg%num_vars if (.not. cfg%vars(i)%used .and. hide_not_used) cycle if (cfg%vars(i)%var_type == CFG_unknown_type) cycle ! Write category when it changes call split_category(cfg%vars(i), category, var_name) if (category /= prev_category .and. category /= '') then write(myUnit, ERR=998, FMT="(A)") '[' // trim(category) // ']' prev_category = category end if ! Indent if inside category if (category /= "") then write(myUnit, ERR=998, FMT="(A,A,A)") " # ",& trim(cfg%vars(i)%description), ":" write(myUnit, ADVANCE="NO", ERR=998,& FMT="(A)") " " // trim(var_name) // " =" else write(myUnit, ERR=998, FMT="(A,A,A)") "# ",& trim(cfg%vars(i)%description), ":" write(myUnit, ADVANCE="NO", ERR=998,& FMT="(A)") trim(var_name) // " =" end if select case(cfg%vars(i)%var_type) case (CFG_integer_type) do j = 1, cfg%vars(i)%var_size write(myUnit, ADVANCE="NO", ERR=998, FMT="(A,I0)") " ",& cfg%vars(i)%int_data(j) end do case (CFG_real_type) do j = 1, cfg%vars(i)%var_size write(myUnit, ADVANCE="NO", ERR=998, FMT="(A,E11.4)") " ",& cfg%vars(i)%real_data(j) end do case (CFG_string_type) do j = 1, cfg%vars(i)%var_size write(myUnit, ADVANCE="NO", ERR=998,& FMT="(A)") " '" // trim(cfg%vars(i)%char_data(j)) // "'" end do case (CFG_logic_type) do j = 1, cfg%vars(i)%var_size write(myUnit, ADVANCE="NO", ERR=998, FMT="(A,L1)") " ",& cfg%vars(i)%logic_data(j) end do end select write(myUnit, ERR=998, FMT="(A)") "" write(myUnit, ERR=998, FMT="(A)") "" end do if (myUnit /= output_unit) close(myUnit, ERR=999, IOSTAT=io_state) call CFG_check(cfg_in) return 998 continue write(err_string, *) "CFG_write error: io_state = ", io_state,& " while writing ", trim(var_name), " to ", filename call handle_error(err_string) 999 continue ! If there was an error, the routine will end here write(err_string, *) "CFG_write error: io_state = ", io_state,& " while writing to ", filename call handle_error(err_string) end subroutine CFG_write