module CFormation
    use CFormationVariables
    use SimulationVariables
    use json_module
    implicit none

    contains

    subroutine FormationToJson(parent)

        type(json_value),pointer :: parent
        type(json_core) :: json
        type(json_value),pointer :: p,pform
        integer :: i

        ! 1. create new node
        call json%create_array(p,'Formations')

        do i=1,data%Configuration%Formation%Count
            call json%create_object(pform,'')
            call json%add(pform,"Abrasiveness",data%Configuration%Formation%Formations(i)%Abrasiveness)
            call json%add(pform,"Drillablity",data%Configuration%Formation%Formations(i)%Drillablity)
            call json%add(pform,"PorePressureGradient",data%Configuration%Formation%Formations(i)%PorePressureGradient)
            call json%add(pform,"Thickness",data%Configuration%Formation%Formations(i)%Thickness)
            call json%add(pform,"ThresholdWeight",data%Configuration%Formation%Formations(i)%ThresholdWeight)
            call json%add(pform,"Top",data%Configuration%Formation%Formations(i)%Top)
            call json%add(p,pform)
        end do

        call json%add(parent,p)
    end subroutine
    
end module CFormation