Implement CCLite 0.1.1 input parser
This commit is contained in:
+16
-2
@@ -1,5 +1,7 @@
|
||||
program cclite_main
|
||||
use ccl_case_types, only: CCL_Case_Type, ccl_case_print_summary
|
||||
use ccl_errors, only: CCL_SUCCESS, CCL_ERROR_INPUT_MISSING_ARGUMENT
|
||||
use ccl_inp_parser, only: ccl_case_read
|
||||
use ccl_log, only: ccl_log_info, ccl_log_error
|
||||
use ccl_version, only: ccl_print_version
|
||||
implicit none
|
||||
@@ -44,6 +46,8 @@ contains
|
||||
character(len=*), intent(in) :: mode
|
||||
integer, intent(in) :: argc_value
|
||||
character(len=512) :: input_file
|
||||
character(len=512) :: errmsg
|
||||
type(CCL_Case_Type) :: ccl_case
|
||||
|
||||
if (argc_value < 2) then
|
||||
call ccl_log_error("app", trim(mode) // " requires a CCLite .inp file")
|
||||
@@ -52,8 +56,18 @@ contains
|
||||
end if
|
||||
|
||||
call get_command_argument(2, input_file)
|
||||
call ccl_log_info("app", trim(mode) // " mode accepted input: " // trim(input_file))
|
||||
call ccl_log_info("app", "0.1.0 only provides the command skeleton")
|
||||
call ccl_log_info("app", trim(mode) // " mode reading input: " // trim(input_file))
|
||||
|
||||
call ccl_case_read(trim(input_file), ccl_case, ierr, errmsg)
|
||||
if (ierr /= CCL_SUCCESS) then
|
||||
call ccl_log_error("case", trim(errmsg))
|
||||
return
|
||||
end if
|
||||
|
||||
call ccl_case_print_summary(ccl_case)
|
||||
if (trim(mode) /= "check") then
|
||||
call ccl_log_info("app", "0.1.1 validates input only; IPC execution starts in later patches")
|
||||
end if
|
||||
ierr = CCL_SUCCESS
|
||||
end function handle_mode
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
module ccl_case_types
|
||||
use ccl_log, only: ccl_log_info
|
||||
implicit none
|
||||
|
||||
integer, parameter :: CCL_TEXT_LEN = 256
|
||||
integer, parameter :: CCL_SOLVER_SPH = 1
|
||||
integer, parameter :: CCL_SOLVER_FEM = 2
|
||||
|
||||
type :: CCL_Solver_Config
|
||||
logical :: is_set = .false.
|
||||
character(len=16) :: id = ""
|
||||
character(len=32) :: kind = ""
|
||||
character(len=CCL_TEXT_LEN) :: executable = ""
|
||||
character(len=CCL_TEXT_LEN) :: input = ""
|
||||
end type CCL_Solver_Config
|
||||
|
||||
type :: CCL_IPC_Config
|
||||
logical :: is_set = .false.
|
||||
character(len=32) :: ipc_type = ""
|
||||
character(len=CCL_TEXT_LEN) :: name_prefix = ""
|
||||
character(len=32) :: buffer = "DOUBLE"
|
||||
integer :: timeout_ms = 5000
|
||||
end type CCL_IPC_Config
|
||||
|
||||
type :: CCL_Time_Config
|
||||
logical :: is_set = .false.
|
||||
real(8) :: start_time = 0.0d0
|
||||
real(8) :: end_time = 0.0d0
|
||||
real(8) :: dt = 0.0d0
|
||||
end type CCL_Time_Config
|
||||
|
||||
type :: CCL_Interface_Config
|
||||
logical :: is_set = .false.
|
||||
character(len=CCL_TEXT_LEN) :: name = ""
|
||||
character(len=CCL_TEXT_LEN) :: sph_region = ""
|
||||
character(len=CCL_TEXT_LEN) :: fem_surface = ""
|
||||
end type CCL_Interface_Config
|
||||
|
||||
type :: CCL_Output_Config
|
||||
logical :: is_set = .false.
|
||||
character(len=CCL_TEXT_LEN) :: directory = ""
|
||||
logical :: csv = .true.
|
||||
logical :: log = .true.
|
||||
end type CCL_Output_Config
|
||||
|
||||
type :: CCL_Case_Type
|
||||
logical :: has_control = .false.
|
||||
character(len=CCL_TEXT_LEN) :: name = ""
|
||||
character(len=32) :: mode = ""
|
||||
character(len=32) :: version = "0.1"
|
||||
type(CCL_Solver_Config) :: solver(2)
|
||||
type(CCL_IPC_Config) :: ipc
|
||||
type(CCL_Time_Config) :: time
|
||||
type(CCL_Interface_Config) :: interface
|
||||
type(CCL_Output_Config) :: output
|
||||
end type CCL_Case_Type
|
||||
|
||||
contains
|
||||
|
||||
subroutine ccl_case_init(ccl_case)
|
||||
type(CCL_Case_Type), intent(out) :: ccl_case
|
||||
ccl_case = CCL_Case_Type()
|
||||
ccl_case%solver(CCL_SOLVER_SPH)%id = "SPH"
|
||||
ccl_case%solver(CCL_SOLVER_FEM)%id = "FEM"
|
||||
end subroutine ccl_case_init
|
||||
|
||||
integer function ccl_solver_slot(solver_id) result(slot)
|
||||
character(len=*), intent(in) :: solver_id
|
||||
|
||||
select case (trim(solver_id))
|
||||
case ("SPH")
|
||||
slot = CCL_SOLVER_SPH
|
||||
case ("FEM")
|
||||
slot = CCL_SOLVER_FEM
|
||||
case default
|
||||
slot = 0
|
||||
end select
|
||||
end function ccl_solver_slot
|
||||
|
||||
subroutine ccl_case_print_summary(ccl_case)
|
||||
type(CCL_Case_Type), intent(in) :: ccl_case
|
||||
character(len=64) :: msg
|
||||
|
||||
call ccl_log_info("case", "case name=" // trim(ccl_case%name))
|
||||
call ccl_log_info("case", "mode=" // trim(ccl_case%mode))
|
||||
call ccl_log_info("case", "sph executable=" // trim(ccl_case%solver(CCL_SOLVER_SPH)%executable))
|
||||
call ccl_log_info("case", "fem executable=" // trim(ccl_case%solver(CCL_SOLVER_FEM)%executable))
|
||||
call ccl_log_info("case", "ipc type=" // trim(ccl_case%ipc%ipc_type))
|
||||
write(msg, '(a,es12.4,a,es12.4,a,es12.4)') "time start=", ccl_case%time%start_time, &
|
||||
" end=", ccl_case%time%end_time, " dt=", ccl_case%time%dt
|
||||
call ccl_log_info("case", trim(msg))
|
||||
call ccl_log_info("case", "interface=" // trim(ccl_case%interface%name))
|
||||
call ccl_log_info("case", "output=" // trim(ccl_case%output%directory))
|
||||
end subroutine ccl_case_print_summary
|
||||
|
||||
end module ccl_case_types
|
||||
@@ -0,0 +1,489 @@
|
||||
module ccl_inp_parser
|
||||
use ccl_case_types, only: CCL_Case_Type, CCL_SOLVER_FEM, CCL_SOLVER_SPH, ccl_case_init, ccl_solver_slot
|
||||
use ccl_errors, only: CCL_SUCCESS, CCL_ERROR_INPUT_INVALID_VALUE, &
|
||||
CCL_ERROR_INPUT_MISSING_ARGUMENT, CCL_ERROR_INPUT_PARSE_FAILED
|
||||
use ccl_string_utils, only: ccl_parse_bool, ccl_strip_quotes, ccl_to_upper
|
||||
implicit none
|
||||
|
||||
contains
|
||||
|
||||
subroutine ccl_case_read(filename, ccl_case, ierr, errmsg)
|
||||
character(len=*), intent(in) :: filename
|
||||
type(CCL_Case_Type), intent(out) :: ccl_case
|
||||
integer, intent(out) :: ierr
|
||||
character(len=*), intent(out) :: errmsg
|
||||
|
||||
integer :: unit_id
|
||||
integer :: ios
|
||||
integer :: line_no
|
||||
integer :: current_solver
|
||||
character(len=1024) :: line
|
||||
character(len=64) :: section
|
||||
|
||||
call ccl_case_init(ccl_case)
|
||||
ierr = CCL_SUCCESS
|
||||
errmsg = ""
|
||||
section = ""
|
||||
current_solver = 0
|
||||
line_no = 0
|
||||
|
||||
open(newunit=unit_id, file=trim(filename), status="old", action="read", iostat=ios)
|
||||
if (ios /= 0) then
|
||||
ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT
|
||||
errmsg = "cannot open input file: " // trim(filename)
|
||||
return
|
||||
end if
|
||||
|
||||
do
|
||||
read(unit_id, '(a)', iostat=ios) line
|
||||
if (ios /= 0) exit
|
||||
line_no = line_no + 1
|
||||
call ccl_parse_line(line, line_no, ccl_case, section, current_solver, ierr, errmsg)
|
||||
if (ierr /= CCL_SUCCESS) exit
|
||||
end do
|
||||
|
||||
close(unit_id)
|
||||
if (ierr /= CCL_SUCCESS) return
|
||||
|
||||
call ccl_validate_case(ccl_case, ierr, errmsg)
|
||||
end subroutine ccl_case_read
|
||||
|
||||
subroutine ccl_parse_line(line, line_no, ccl_case, section, current_solver, ierr, errmsg)
|
||||
character(len=*), intent(in) :: line
|
||||
integer, intent(in) :: line_no
|
||||
type(CCL_Case_Type), intent(inout) :: ccl_case
|
||||
character(len=*), intent(inout) :: section
|
||||
integer, intent(inout) :: current_solver
|
||||
integer, intent(out) :: ierr
|
||||
character(len=*), intent(out) :: errmsg
|
||||
|
||||
character(len=1024) :: clean_line
|
||||
integer :: first_nonblank
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
errmsg = ""
|
||||
clean_line = adjustl(line)
|
||||
if (len_trim(clean_line) == 0) return
|
||||
if (clean_line(1:1) == "#") return
|
||||
if (len_trim(clean_line) >= 2) then
|
||||
if (clean_line(1:2) == "**") return
|
||||
end if
|
||||
|
||||
first_nonblank = 1
|
||||
if (clean_line(first_nonblank:first_nonblank) == "*") then
|
||||
call parse_keyword_line(clean_line, line_no, ccl_case, section, current_solver, ierr, errmsg)
|
||||
else
|
||||
call parse_param_list(clean_line, line_no, section, ccl_case, current_solver, ierr, errmsg)
|
||||
end if
|
||||
end subroutine ccl_parse_line
|
||||
|
||||
subroutine parse_keyword_line(line, line_no, ccl_case, section, current_solver, ierr, errmsg)
|
||||
character(len=*), intent(in) :: line
|
||||
integer, intent(in) :: line_no
|
||||
type(CCL_Case_Type), intent(inout) :: ccl_case
|
||||
character(len=*), intent(inout) :: section
|
||||
integer, intent(inout) :: current_solver
|
||||
integer, intent(out) :: ierr
|
||||
character(len=*), intent(out) :: errmsg
|
||||
|
||||
integer :: comma_pos
|
||||
character(len=256) :: keyword
|
||||
character(len=1024) :: params
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
errmsg = ""
|
||||
comma_pos = index(line, ",")
|
||||
if (comma_pos > 0) then
|
||||
keyword = ccl_to_upper(adjustl(line(2:comma_pos-1)))
|
||||
params = line(comma_pos+1:)
|
||||
else
|
||||
keyword = ccl_to_upper(adjustl(line(2:)))
|
||||
params = ""
|
||||
end if
|
||||
|
||||
section = trim(keyword)
|
||||
current_solver = 0
|
||||
|
||||
select case (trim(section))
|
||||
case ("CCLITE CONTROL")
|
||||
ccl_case%has_control = .true.
|
||||
case ("CCLITE SOLVER")
|
||||
continue
|
||||
case ("CCLITE IPC")
|
||||
ccl_case%ipc%is_set = .true.
|
||||
case ("CCLITE TIME")
|
||||
ccl_case%time%is_set = .true.
|
||||
case ("CCLITE INTERFACE")
|
||||
ccl_case%interface%is_set = .true.
|
||||
case ("CCLITE OUTPUT")
|
||||
ccl_case%output%is_set = .true.
|
||||
case ("CCLITE SURFACE INTERACTION", "CCLITE CONTACT PAIR")
|
||||
continue
|
||||
case default
|
||||
ierr = CCL_ERROR_INPUT_PARSE_FAILED
|
||||
write(errmsg, '(a,i0,a,a)') "line ", line_no, ": unsupported keyword *", trim(section)
|
||||
return
|
||||
end select
|
||||
|
||||
if (len_trim(params) > 0) then
|
||||
call parse_param_list(params, line_no, section, ccl_case, current_solver, ierr, errmsg)
|
||||
end if
|
||||
end subroutine parse_keyword_line
|
||||
|
||||
subroutine parse_param_list(text, line_no, section, ccl_case, current_solver, ierr, errmsg)
|
||||
character(len=*), intent(in) :: text
|
||||
integer, intent(in) :: line_no
|
||||
character(len=*), intent(in) :: section
|
||||
type(CCL_Case_Type), intent(inout) :: ccl_case
|
||||
integer, intent(inout) :: current_solver
|
||||
integer, intent(out) :: ierr
|
||||
character(len=*), intent(out) :: errmsg
|
||||
|
||||
integer :: start_pos
|
||||
integer :: comma_pos
|
||||
integer :: eq_pos
|
||||
character(len=1024) :: remaining
|
||||
character(len=512) :: token
|
||||
character(len=128) :: key
|
||||
character(len=512) :: value
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
errmsg = ""
|
||||
remaining = trim(text)
|
||||
start_pos = 1
|
||||
|
||||
do while (start_pos <= len_trim(remaining))
|
||||
comma_pos = index(remaining(start_pos:), ",")
|
||||
if (comma_pos == 0) then
|
||||
token = adjustl(remaining(start_pos:))
|
||||
start_pos = len_trim(remaining) + 1
|
||||
else
|
||||
token = adjustl(remaining(start_pos:start_pos+comma_pos-2))
|
||||
start_pos = start_pos + comma_pos
|
||||
end if
|
||||
|
||||
if (len_trim(token) == 0) cycle
|
||||
eq_pos = index(token, "=")
|
||||
if (eq_pos <= 1) then
|
||||
ierr = CCL_ERROR_INPUT_PARSE_FAILED
|
||||
write(errmsg, '(a,i0,a,a)') "line ", line_no, ": parameter must use KEY=VALUE: ", trim(token)
|
||||
return
|
||||
end if
|
||||
|
||||
key = ccl_to_upper(token(:eq_pos-1))
|
||||
value = ccl_strip_quotes(adjustl(token(eq_pos+1:)))
|
||||
call apply_param(section, trim(key), trim(value), line_no, ccl_case, current_solver, ierr, errmsg)
|
||||
if (ierr /= CCL_SUCCESS) return
|
||||
end do
|
||||
end subroutine parse_param_list
|
||||
|
||||
subroutine apply_param(section, key, value, line_no, ccl_case, current_solver, ierr, errmsg)
|
||||
character(len=*), intent(in) :: section
|
||||
character(len=*), intent(in) :: key
|
||||
character(len=*), intent(in) :: value
|
||||
integer, intent(in) :: line_no
|
||||
type(CCL_Case_Type), intent(inout) :: ccl_case
|
||||
integer, intent(inout) :: current_solver
|
||||
integer, intent(out) :: ierr
|
||||
character(len=*), intent(out) :: errmsg
|
||||
|
||||
integer :: slot
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
errmsg = ""
|
||||
|
||||
select case (trim(section))
|
||||
case ("CCLITE CONTROL")
|
||||
call apply_control_param(key, value, ccl_case, ierr, errmsg)
|
||||
case ("CCLITE SOLVER")
|
||||
if (key == "ID") then
|
||||
slot = ccl_solver_slot(ccl_to_upper(value))
|
||||
if (slot == 0) then
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
errmsg = "unsupported solver id: " // trim(value)
|
||||
return
|
||||
end if
|
||||
current_solver = slot
|
||||
ccl_case%solver(slot)%is_set = .true.
|
||||
ccl_case%solver(slot)%id = ccl_to_upper(value)
|
||||
else
|
||||
if (current_solver == 0) then
|
||||
ierr = CCL_ERROR_INPUT_PARSE_FAILED
|
||||
write(errmsg, '(a,i0,a)') "line ", line_no, ": solver ID must be specified before other solver parameters"
|
||||
return
|
||||
end if
|
||||
call apply_solver_param(key, value, ccl_case%solver(current_solver), ierr, errmsg)
|
||||
end if
|
||||
case ("CCLITE IPC")
|
||||
call apply_ipc_param(key, value, ccl_case, ierr, errmsg)
|
||||
case ("CCLITE TIME")
|
||||
call apply_time_param(key, value, ccl_case, ierr, errmsg)
|
||||
case ("CCLITE INTERFACE")
|
||||
call apply_interface_param(key, value, ccl_case, ierr, errmsg)
|
||||
case ("CCLITE OUTPUT")
|
||||
call apply_output_param(key, value, ccl_case, ierr, errmsg)
|
||||
case ("CCLITE SURFACE INTERACTION", "CCLITE CONTACT PAIR")
|
||||
continue
|
||||
case default
|
||||
ierr = CCL_ERROR_INPUT_PARSE_FAILED
|
||||
errmsg = "parameters found before a supported CCLite keyword"
|
||||
end select
|
||||
|
||||
if (ierr /= CCL_SUCCESS) then
|
||||
errmsg = "line " // trim(int_to_text(line_no)) // ": " // trim(errmsg)
|
||||
end if
|
||||
end subroutine apply_param
|
||||
|
||||
subroutine apply_control_param(key, value, ccl_case, ierr, errmsg)
|
||||
character(len=*), intent(in) :: key
|
||||
character(len=*), intent(in) :: value
|
||||
type(CCL_Case_Type), intent(inout) :: ccl_case
|
||||
integer, intent(out) :: ierr
|
||||
character(len=*), intent(out) :: errmsg
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
errmsg = ""
|
||||
select case (key)
|
||||
case ("NAME")
|
||||
ccl_case%name = value
|
||||
case ("MODE")
|
||||
ccl_case%mode = ccl_to_upper(value)
|
||||
case ("VERSION")
|
||||
ccl_case%version = value
|
||||
case default
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
errmsg = "unsupported CONTROL parameter: " // trim(key)
|
||||
end select
|
||||
end subroutine apply_control_param
|
||||
|
||||
subroutine apply_solver_param(key, value, solver, ierr, errmsg)
|
||||
use ccl_case_types, only: CCL_Solver_Config
|
||||
character(len=*), intent(in) :: key
|
||||
character(len=*), intent(in) :: value
|
||||
type(CCL_Solver_Config), intent(inout) :: solver
|
||||
integer, intent(out) :: ierr
|
||||
character(len=*), intent(out) :: errmsg
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
errmsg = ""
|
||||
select case (key)
|
||||
case ("KIND")
|
||||
solver%kind = ccl_to_upper(value)
|
||||
case ("EXECUTABLE")
|
||||
solver%executable = value
|
||||
case ("INPUT")
|
||||
solver%input = value
|
||||
case default
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
errmsg = "unsupported SOLVER parameter: " // trim(key)
|
||||
end select
|
||||
end subroutine apply_solver_param
|
||||
|
||||
subroutine apply_ipc_param(key, value, ccl_case, ierr, errmsg)
|
||||
character(len=*), intent(in) :: key
|
||||
character(len=*), intent(in) :: value
|
||||
type(CCL_Case_Type), intent(inout) :: ccl_case
|
||||
integer, intent(out) :: ierr
|
||||
character(len=*), intent(out) :: errmsg
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
errmsg = ""
|
||||
select case (key)
|
||||
case ("TYPE")
|
||||
ccl_case%ipc%ipc_type = ccl_to_upper(value)
|
||||
case ("NAME_PREFIX")
|
||||
ccl_case%ipc%name_prefix = value
|
||||
case ("BUFFER")
|
||||
ccl_case%ipc%buffer = ccl_to_upper(value)
|
||||
case ("TIMEOUT_MS")
|
||||
read(value, *, iostat=ierr) ccl_case%ipc%timeout_ms
|
||||
if (ierr /= 0) errmsg = "TIMEOUT_MS must be an integer"
|
||||
case default
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
errmsg = "unsupported IPC parameter: " // trim(key)
|
||||
end select
|
||||
end subroutine apply_ipc_param
|
||||
|
||||
subroutine apply_time_param(key, value, ccl_case, ierr, errmsg)
|
||||
character(len=*), intent(in) :: key
|
||||
character(len=*), intent(in) :: value
|
||||
type(CCL_Case_Type), intent(inout) :: ccl_case
|
||||
integer, intent(out) :: ierr
|
||||
character(len=*), intent(out) :: errmsg
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
errmsg = ""
|
||||
select case (key)
|
||||
case ("START")
|
||||
read(value, *, iostat=ierr) ccl_case%time%start_time
|
||||
case ("END")
|
||||
read(value, *, iostat=ierr) ccl_case%time%end_time
|
||||
case ("DT")
|
||||
read(value, *, iostat=ierr) ccl_case%time%dt
|
||||
case default
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
errmsg = "unsupported TIME parameter: " // trim(key)
|
||||
return
|
||||
end select
|
||||
if (ierr /= 0) errmsg = "TIME value must be numeric"
|
||||
end subroutine apply_time_param
|
||||
|
||||
subroutine apply_interface_param(key, value, ccl_case, ierr, errmsg)
|
||||
character(len=*), intent(in) :: key
|
||||
character(len=*), intent(in) :: value
|
||||
type(CCL_Case_Type), intent(inout) :: ccl_case
|
||||
integer, intent(out) :: ierr
|
||||
character(len=*), intent(out) :: errmsg
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
errmsg = ""
|
||||
select case (key)
|
||||
case ("NAME")
|
||||
ccl_case%interface%name = value
|
||||
case ("SPH_REGION")
|
||||
ccl_case%interface%sph_region = value
|
||||
case ("FEM_SURFACE")
|
||||
ccl_case%interface%fem_surface = value
|
||||
case default
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
errmsg = "unsupported INTERFACE parameter: " // trim(key)
|
||||
end select
|
||||
end subroutine apply_interface_param
|
||||
|
||||
subroutine apply_output_param(key, value, ccl_case, ierr, errmsg)
|
||||
character(len=*), intent(in) :: key
|
||||
character(len=*), intent(in) :: value
|
||||
type(CCL_Case_Type), intent(inout) :: ccl_case
|
||||
integer, intent(out) :: ierr
|
||||
character(len=*), intent(out) :: errmsg
|
||||
|
||||
logical :: bool_value
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
errmsg = ""
|
||||
select case (key)
|
||||
case ("DIRECTORY")
|
||||
ccl_case%output%directory = value
|
||||
case ("CSV")
|
||||
call ccl_parse_bool(value, bool_value, ierr)
|
||||
if (ierr == CCL_SUCCESS) ccl_case%output%csv = bool_value
|
||||
case ("LOG")
|
||||
call ccl_parse_bool(value, bool_value, ierr)
|
||||
if (ierr == CCL_SUCCESS) ccl_case%output%log = bool_value
|
||||
case default
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
errmsg = "unsupported OUTPUT parameter: " // trim(key)
|
||||
return
|
||||
end select
|
||||
if (ierr /= CCL_SUCCESS) errmsg = "OUTPUT boolean must be YES or NO"
|
||||
end subroutine apply_output_param
|
||||
|
||||
subroutine ccl_validate_case(ccl_case, ierr, errmsg)
|
||||
type(CCL_Case_Type), intent(in) :: ccl_case
|
||||
integer, intent(out) :: ierr
|
||||
character(len=*), intent(out) :: errmsg
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
errmsg = ""
|
||||
|
||||
if (.not. ccl_case%has_control) then
|
||||
ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT
|
||||
errmsg = "missing *CCLITE CONTROL"
|
||||
return
|
||||
end if
|
||||
if (len_trim(ccl_case%name) == 0) then
|
||||
ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT
|
||||
errmsg = "CONTROL NAME is required"
|
||||
return
|
||||
end if
|
||||
if (len_trim(ccl_case%mode) == 0) then
|
||||
ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT
|
||||
errmsg = "CONTROL MODE is required"
|
||||
return
|
||||
end if
|
||||
call validate_solver(ccl_case, CCL_SOLVER_SPH, "SPH", ierr, errmsg)
|
||||
if (ierr /= CCL_SUCCESS) return
|
||||
call validate_solver(ccl_case, CCL_SOLVER_FEM, "FEM", ierr, errmsg)
|
||||
if (ierr /= CCL_SUCCESS) return
|
||||
if (.not. ccl_case%ipc%is_set) then
|
||||
ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT
|
||||
errmsg = "missing *CCLITE IPC"
|
||||
return
|
||||
end if
|
||||
if (trim(ccl_case%ipc%ipc_type) /= "WINDOWS_SHMEM") then
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
errmsg = "0.1.x only supports IPC TYPE=WINDOWS_SHMEM"
|
||||
return
|
||||
end if
|
||||
if (ccl_case%ipc%timeout_ms <= 0) then
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
errmsg = "IPC TIMEOUT_MS must be positive"
|
||||
return
|
||||
end if
|
||||
if (.not. ccl_case%time%is_set) then
|
||||
ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT
|
||||
errmsg = "missing *CCLITE TIME"
|
||||
return
|
||||
end if
|
||||
if (ccl_case%time%dt <= 0.0d0) then
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
errmsg = "TIME DT must be positive"
|
||||
return
|
||||
end if
|
||||
if (ccl_case%time%end_time < ccl_case%time%start_time) then
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
errmsg = "TIME END must be greater than or equal to START"
|
||||
return
|
||||
end if
|
||||
if (.not. ccl_case%interface%is_set) then
|
||||
ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT
|
||||
errmsg = "missing *CCLITE INTERFACE"
|
||||
return
|
||||
end if
|
||||
if (len_trim(ccl_case%interface%sph_region) == 0 .or. len_trim(ccl_case%interface%fem_surface) == 0) then
|
||||
ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT
|
||||
errmsg = "INTERFACE requires SPH_REGION and FEM_SURFACE"
|
||||
return
|
||||
end if
|
||||
if (.not. ccl_case%output%is_set) then
|
||||
ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT
|
||||
errmsg = "missing *CCLITE OUTPUT"
|
||||
return
|
||||
end if
|
||||
if (len_trim(ccl_case%output%directory) == 0) then
|
||||
ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT
|
||||
errmsg = "OUTPUT DIRECTORY is required"
|
||||
end if
|
||||
end subroutine ccl_validate_case
|
||||
|
||||
subroutine validate_solver(ccl_case, slot, label, ierr, errmsg)
|
||||
type(CCL_Case_Type), intent(in) :: ccl_case
|
||||
integer, intent(in) :: slot
|
||||
character(len=*), intent(in) :: label
|
||||
integer, intent(out) :: ierr
|
||||
character(len=*), intent(out) :: errmsg
|
||||
|
||||
ierr = CCL_SUCCESS
|
||||
errmsg = ""
|
||||
if (.not. ccl_case%solver(slot)%is_set) then
|
||||
ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT
|
||||
errmsg = "missing " // trim(label) // " *CCLITE SOLVER"
|
||||
return
|
||||
end if
|
||||
if (len_trim(ccl_case%solver(slot)%executable) == 0) then
|
||||
ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT
|
||||
errmsg = trim(label) // " solver EXECUTABLE is required"
|
||||
return
|
||||
end if
|
||||
if (len_trim(ccl_case%solver(slot)%input) == 0) then
|
||||
ierr = CCL_ERROR_INPUT_MISSING_ARGUMENT
|
||||
errmsg = trim(label) // " solver INPUT is required"
|
||||
end if
|
||||
end subroutine validate_solver
|
||||
|
||||
character(len=32) function int_to_text(value) result(text)
|
||||
integer, intent(in) :: value
|
||||
write(text, '(i0)') value
|
||||
end function int_to_text
|
||||
|
||||
end module ccl_inp_parser
|
||||
@@ -0,0 +1,59 @@
|
||||
module ccl_string_utils
|
||||
use ccl_errors, only: CCL_SUCCESS, CCL_ERROR_INPUT_INVALID_VALUE
|
||||
implicit none
|
||||
|
||||
contains
|
||||
|
||||
function ccl_to_upper(text) result(out)
|
||||
character(len=*), intent(in) :: text
|
||||
character(len=len(text)) :: out
|
||||
integer :: i
|
||||
integer :: code
|
||||
|
||||
out = text
|
||||
do i = 1, len(text)
|
||||
code = iachar(out(i:i))
|
||||
if (code >= iachar("a") .and. code <= iachar("z")) then
|
||||
out(i:i) = achar(code - 32)
|
||||
end if
|
||||
end do
|
||||
out = adjustl(out)
|
||||
end function ccl_to_upper
|
||||
|
||||
function ccl_strip_quotes(text) result(out)
|
||||
character(len=*), intent(in) :: text
|
||||
character(len=len(text)) :: out
|
||||
integer :: n
|
||||
|
||||
out = adjustl(text)
|
||||
out = trim(out)
|
||||
n = len_trim(out)
|
||||
if (n >= 2) then
|
||||
if ((out(1:1) == '"' .and. out(n:n) == '"') .or. &
|
||||
(out(1:1) == "'" .and. out(n:n) == "'")) then
|
||||
out = out(2:n-1)
|
||||
end if
|
||||
end if
|
||||
end function ccl_strip_quotes
|
||||
|
||||
subroutine ccl_parse_bool(text, value, ierr)
|
||||
character(len=*), intent(in) :: text
|
||||
logical, intent(out) :: value
|
||||
integer, intent(out) :: ierr
|
||||
character(len=len(text)) :: upper_text
|
||||
|
||||
upper_text = ccl_to_upper(text)
|
||||
select case (trim(upper_text))
|
||||
case ("YES", "TRUE", "1", "ON")
|
||||
value = .true.
|
||||
ierr = CCL_SUCCESS
|
||||
case ("NO", "FALSE", "0", "OFF")
|
||||
value = .false.
|
||||
ierr = CCL_SUCCESS
|
||||
case default
|
||||
value = .false.
|
||||
ierr = CCL_ERROR_INPUT_INVALID_VALUE
|
||||
end select
|
||||
end subroutine ccl_parse_bool
|
||||
|
||||
end module ccl_string_utils
|
||||
@@ -3,8 +3,8 @@ module ccl_version
|
||||
|
||||
integer, parameter :: CCL_VERSION_MAJOR = 0
|
||||
integer, parameter :: CCL_VERSION_MINOR = 1
|
||||
integer, parameter :: CCL_VERSION_PATCH = 0
|
||||
character(len=*), parameter :: CCL_VERSION_LABEL = "0.1.0"
|
||||
integer, parameter :: CCL_VERSION_PATCH = 1
|
||||
character(len=*), parameter :: CCL_VERSION_LABEL = "0.1.1"
|
||||
|
||||
contains
|
||||
|
||||
|
||||
Reference in New Issue
Block a user