module CPathGeneration
	use SimulationVariables !@
    use json_module
	implicit none    
	public    
	contains

    subroutine PathGenerationToJson(parent)

        type(json_value),pointer :: parent
        type(json_core) :: json
        type(json_value),pointer :: ppath,pitems,pdp,p
        integer::i

        ! 1. create new node
        call json%create_object(ppath,'Path')

        call json%create_array(pitems,'Items')
        do i=1,data%Configuration%Path%ItemCount
            call json%create_object(p,'')
            call json%add(p,"HoleType",data%Configuration%Path%items(i)%HoleType)
            call json%add(p,"Angle",data%Configuration%Path%items(i)%Angle)
            call json%add(p,"Length",data%Configuration%Path%items(i)%Length)
            call json%add(p,"FinalAngle",data%Configuration%Path%items(i)%FinalAngle)
            call json%add(p,"TotalLength",data%Configuration%Path%items(i)%TotalLength)
            call json%add(p,"MeasuredDepth",data%Configuration%Path%items(i)%MeasuredDepth)
            call json%add(p,"TotalVerticalDepth",data%Configuration%Path%items(i)%TotalVerticalDepth)
            call json%add(pitems,p)
        end do
        
        call json%create_array(pdp,'DataPoints')
        do i=1,data%Configuration%Path%DataPointsCount
            call json%create_object(p,'')
            call json%add(p,"X",data%Configuration%Path%DataPoints(i)%X)
            call json%add(p,"Y",data%Configuration%Path%DataPoints(i)%Y)
            call json%add(pdp,p)
        end do

        ! 3. add new node to parent
        call json%add(ppath,pitems)
        call json%add(ppath,pdp)
        call json%add(parent,ppath)
    end subroutine

end module CPathGeneration