Write the current x
variables to a file (compatible with the Copernicus optvar file).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(mission_type), | intent(inout) | :: | me | |||
character(len=*), | intent(in) | :: | filename |
file name [without extension] |
||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
solver opt vars vector |
subroutine write_optvars_to_file(me,filename,x) implicit none class(mission_type),intent(inout) :: me character(len=*),intent(in) :: filename !! file name [without extension] real(wp),dimension(:),intent(in) :: x !! solver opt vars vector integer :: i !! counter type(json_core) :: json type(json_value),pointer :: p_root, p_xvec, p_element, p_last call json%initialize() call json%create_object(p_root, '') call json%create_array(p_xvec, 'xvec') call json%add(p_root, p_xvec) p_last => null() ! for the first element do i = 1, size(x) nullify(p_element) call json%create_object(p_element, '') ! allocate call json%add(p_element, 'i', i) call json%add(p_element, 'label', trim(me%xname(i))) call json%add(p_element, 'value', x(i)*me%xscale(i)) call json%add(p_element, 'scale', me%xscale(i)) ! to speed this up, we keep track of the ! last element and insert after it. if (associated(p_last)) then ! insert after the last one call json%insert_after(p_last, p_element) else ! first element call json%add(p_xvec, p_element) end if p_last => p_element end do call json%print(p_root, trim(filename)//'_'//me%get_case_name()//'.json') call json%destroy(p_root) end subroutine write_optvars_to_file