write_optvars_to_file Subroutine

public subroutine write_optvars_to_file(me, filename, x)

Write the current x variables to a file (compatible with the Copernicus optvar file).

Type Bound

mission_type

Arguments

Type IntentOptional 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


Calls

proc~~write_optvars_to_file~~CallsGraph proc~write_optvars_to_file mission_type%write_optvars_to_file add add proc~write_optvars_to_file->add create_array create_array proc~write_optvars_to_file->create_array create_object create_object proc~write_optvars_to_file->create_object destroy destroy proc~write_optvars_to_file->destroy initialize initialize proc~write_optvars_to_file->initialize insert_after insert_after proc~write_optvars_to_file->insert_after proc~get_case_name mission_type%get_case_name proc~write_optvars_to_file->proc~get_case_name

Called by

proc~~write_optvars_to_file~~CalledByGraph proc~write_optvars_to_file mission_type%write_optvars_to_file proc~halo_solver_main halo_solver_main proc~halo_solver_main->proc~write_optvars_to_file

Source Code

    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