Read the JSON solution file and put the x vector in the mission.
Can be used to restart a solution from a previous run
(e.g., with different settings, as long as the fundamental problem isn't changed).
Note
No error checking here to make sure the file is consistent with the current mission!
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(mission_type), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(out), | dimension(:), allocatable | :: | x |
scaled |
subroutine get_x_from_json_file(me,x) class(mission_type),intent(inout) :: me real(wp),dimension(:),intent(out),allocatable :: x !! scaled `x` vector real(wp),dimension(:),allocatable :: xscale !! scale factors type(json_core) :: json type(json_file) :: f type(json_value),pointer :: xvec, p_element integer :: n_children, i logical :: found if (allocated(me%initial_guess_from_file)) then ! read this file: ! { ! "xvec": [ ! { ! "i": 1, ! "label": "SEG1 T0 (day)", ! "value": -0.96866230153337847E-3, ! "scale": 0.1E+1 ! }, ! ... call f%load(me%initial_guess_from_file) call f%get('xvec',xvec,found) if (.not. found) error stop 'invalid JSON solution file' call json%info(xvec,n_children=n_children) ! get size of x allocate(x(n_children)) allocate(xscale(n_children)) !TODO: should verify size of x compared to current problem. ! really should check that all the vars are the same ! get each element: do i = 1, n_children call json%get_child(xvec, i, p_element, found) call json%get(p_element,'value',x(i), found) if (.not. found) error stop 'could not find value in json file' call json%get(p_element,'scale',xscale(i), found) if (.not. found) error stop 'could not find scale in json file' end do x = x / xscale ! return scaled vector else error stop 'error: the initial_guess_from_file has not been initialized' end if end subroutine get_x_from_json_file