# 1 "/home/admin/SimulationCore2/CSharp/DownHole/DownHole.f90" module DownHoleModule use SimulationVariables contains subroutine DownHoleToJson(parent) type(json_value),pointer :: parent type(json_core) :: json type(json_value),pointer :: p,jsonarray,pitem integer::i ! 1. create new node call json%create_object(p,'DownHole') ! 2. add member of data type to new node call json%add(p,"DrillPipePressure",data%Equipments%DownHole%DrillPipePressure) call json%add(p,"CasingPressure",data%Equipments%DownHole%CasingPressure) call json%add(p,"ShoePressure",data%Equipments%DownHole%ShoePressure) call json%add(p,"BottomHolePressure",data%Equipments%DownHole%BottomHolePressure) call json%add(p,"FormationPressure",data%Equipments%DownHole%FormationPressure) call json%add(p,"InfluxRate",data%Equipments%DownHole%InfluxRate) call json%add(p,"KickVolume",data%Equipments%DownHole%KickVolume) call json%add(p,"SecondKickVolume",data%Equipments%DownHole%SecondKickVolume) call json%add(p,"PermeabilityExposedHeight",data%Equipments%DownHole%PermeabilityExposedHeight) call json%create_array(jsonarray, 'String') do i = 1, data%Equipments%DownHole%StringCount call json%create_object(pitem,'') call json%add(pitem,'StartMd', data%Equipments%DownHole%String(i)%StartMd) call json%add(pitem,'EndMd', data%Equipments%DownHole%String(i)%EndMd) call json%add(pitem,'ComponentType', data%Equipments%DownHole%String(i)%ComponentType) call json%add(jsonarray,pitem) nullify(pitem) enddo call json%add(p,jsonarray) nullify(jsonarray) call json%create_array(jsonarray, 'StringFluids') do i = 1, data%Equipments%DownHole%StringCount call json%create_object(pitem,'') call json%add(pitem,'StartMd', data%Equipments%DownHole%StringFluids(i)%StartMd) call json%add(pitem,'EndMd', data%Equipments%DownHole%StringFluids(i)%EndMd) call json%add(pitem,'Density', data%Equipments%DownHole%StringFluids(i)%Density) call json%add(pitem,'MudType', data%Equipments%DownHole%StringFluids(i)%MudType) call json%add(jsonarray,pitem) nullify(pitem) enddo call json%add(p,jsonarray) nullify(jsonarray) ! call json%create_array(jsonarray, 'AnnalusFluids') ! do i = 1, data%Equipments%DownHole%AnnalusFluidsCount ! call json%create_object(pitem,'') ! call json%add(pitem,'StartMd', data%Equipments%DownHole%AnnalusFluids(i)%StartMd) ! call json%add(pitem,'EndMd', data%Equipments%DownHole%AnnalusFluids(i)%EndMd) ! call json%add(pitem,'Density', data%Equipments%DownHole%AnnalusFluids(i)%Density) ! call json%add(pitem,'MudType', data%Equipments%DownHole%AnnalusFluids(i)%MudType) ! call json%add(jsonarray,pitem) ! nullify(pitem) ! enddo ! call json%add(p,jsonarray) nullify(jsonarray) call json%create_array(jsonarray, 'BOPElements') do i = 1, 4 call json%create_object(pitem,'') call json%add(pitem,'ElementType', data%Equipments%DownHole%BOPElements(i)%ElementType) call json%add(pitem,'ElementStart', data%Equipments%DownHole%BOPElements(i)%ElementStart) call json%add(pitem,'ElementEnd', data%Equipments%DownHole%BOPElements(i)%ElementEnd) call json%add(jsonarray,pitem) nullify(pitem) enddo call json%add(p,jsonarray) nullify(jsonarray) ! 3. add new node to parent call json%add(parent,p) end subroutine subroutine SetAnnalusFluids(count, array) implicit none integer, intent(in) :: count integer :: i, offset type(CFluid), intent(inout), target :: array(count) type(CFluid), pointer :: item ! data%Equipments%DownHole%AnnalusFluidsCount = count ! if(print_log) print*, 'AnnalusFluidsCount = ', count if(size(data%Equipments%DownHole%AnnalusFluids) > 0) then deallocate(data%Equipments%DownHole%AnnalusFluids) end if if(count > 0) then offset = 0; item => array(1) if(item%StartMd > 0) then data%Equipments%DownHole%AnnalusFluidsCount = data%Equipments%DownHole%AnnalusFluidsCount + 1 offset = 1; allocate(data%Equipments%DownHole%AnnalusFluids(data%Equipments%DownHole%AnnalusFluidsCount)) data%Equipments%DownHole%AnnalusFluids(1)%StartMd = 0 data%Equipments%DownHole%AnnalusFluids(1)%EndMd = item%StartMd data%Equipments%DownHole%AnnalusFluids(1)%Density = 0 data%Equipments%DownHole%AnnalusFluids(1)%MudType = FLUID_NO_MUD endif !if(associated(AnnalusMudCountPtr)) then ! call AnnalusMudCountPtr(AnnalusFluidsCount) !end if if(.not.allocated(data%Equipments%DownHole%AnnalusFluids))allocate(data%Equipments%DownHole%AnnalusFluids(data%Equipments%DownHole%AnnalusFluidsCount)) !if(print_log) print*, '============START-AN============' if(item%StartMd < 0) data%Equipments%DownHole%AnnalusFluids(1)%StartMd = 0 do i = 1, count item => array(i) data%Equipments%DownHole%AnnalusFluids(i + offset)%StartMd = item%StartMd if(i==1) data%Equipments%DownHole%AnnalusFluids(i)%StartMd = 0 !if(print_log) print*, 'AnnalusFluids(',i,')%StartMd=', AnnalusFluids(i)%StartMd data%Equipments%DownHole%AnnalusFluids(i + offset)%EndMd = item%EndMd !if(print_log) print*, 'AnnalusFluids(',i,')%EndMd=', AnnalusFluids(i)%EndMd data%Equipments%DownHole%AnnalusFluids(i + offset)%Density = item%Density !if(print_log) print*, 'AnnalusFluids(',i,')%Density=', AnnalusFluids(i)%Density data%Equipments%DownHole%AnnalusFluids(i + offset)%MudType = item%MudType !if(print_log) print*, 'AnnalusFluids(',i,')%MudType=', AnnalusFluids(i)%MudType !if(print_log) print*, '----------------------------' end do !if(print_log) print*, '============END-AN============' !if(associated(AnnalusMudArrayPtr)) then ! !AnnalusFluidsPtr => AnnalusFluids ! call AnnalusMudArrayPtr(AnnalusFluids) !end if end if end subroutine SetAnnalusFluids subroutine SetStringFluids(count, array) implicit none integer, intent(in) :: count integer :: i, offset !, startArr type(CFluid), intent(inout), target :: array(count) type(CFluid), pointer :: item data%Equipments%DownHole%StringFluidsCount = count ! if(print_log) print*, 'StringFluidsCount = ', count if(size(data%Equipments%DownHole%StringFluids) > 0) then deallocate(data%Equipments%DownHole%StringFluids) end if !startArr = 1 if(count > 0) then offset = 0; item => array(1) ! !if(item%StartMd <= 0 .and. item%EndMd <= 0) then ! StringFluidsCount = StringFluidsCount - 1 ! count = count - 1 ! offset = offset + 1 ! startArr = startArr + 1 !endif ! !if(count <= 0) return if(item%StartMd > 0) then data%Equipments%DownHole%StringFluidsCount = data%Equipments%DownHole%StringFluidsCount + 1 offset = offset + 1 allocate(data%Equipments%DownHole%StringFluids(data%Equipments%DownHole%StringFluidsCount)) data%Equipments%DownHole%StringFluids(1)%StartMd = 0 data%Equipments%DownHole%StringFluids(1)%EndMd = item%StartMd data%Equipments%DownHole%StringFluids(1)%Density = 0 data%Equipments%DownHole%StringFluids(1)%MudType = FLUID_NO_MUD endif !if(associated(StringMudCountPtr)) then ! call StringMudCountPtr(count) !end if if(.not.allocated(data%Equipments%DownHole%StringFluids))allocate(data%Equipments%DownHole%StringFluids(data%Equipments%DownHole%StringFluidsCount)) !if(print_log) print*, '============START-ST============' !if(print_log) print*, 'count=', count do i = 1, count item => array(i) data%Equipments%DownHole%StringFluids(i + offset)%StartMd = item%StartMd if(i==1) data%Equipments%DownHole%StringFluids(i)%StartMd = 0 !if(print_log) print*, 'StringFluids(i)%StartMd=', StringFluids(i)%StartMd data%Equipments%DownHole%StringFluids(i + offset)%EndMd = item%EndMd !if(print_log) print*, 'StringFluids(i)%EndMd=', StringFluids(i)%EndMd data%Equipments%DownHole%StringFluids(i + offset)%Density = item%Density data%Equipments%DownHole%StringFluids(i + offset)%MudType = item%MudType !if(print_log) print*, '----------------------------' end do !!if(item%StartMd < 0) StringFluids(1)%StartMd = 0 !!if(print_log) print*, '============END-ST============' !if(associated(StringMudArrayPtr)) then ! call StringMudArrayPtr(StringFluids) !end if end if end subroutine SetStringFluids subroutine SetString(count, array) use CLog3 implicit none integer, intent(in) :: count integer :: i !, j type(CStringComponents), intent(inout), target :: array(count) type(CStringComponents), pointer :: item data%Equipments%DownHole%StringCount = count if(size(data%Equipments%DownHole%String) > 0) then deallocate(data%Equipments%DownHole%String) end if if(count > 0) then !if(associated(StringComponentCountPtr)) then ! call StringComponentCountPtr(count) !end if allocate(data%Equipments%DownHole%String(count)) !j = 0 !if(print_log) print*, '============CMP-ST============' !call Log_3( '============CMP-ST============') !do i = count, 1, -1 do i = 1, count item => array(i) !String(i)%Length = item%Length !String(i)%TopDepth = item%TopDepth !String(i)%DownDepth = item%DownDepth !String(i)%Od = item%Od !String(i)%Id = item%Id data%Equipments%DownHole%String(i)%ComponentType= item%ComponentType !j = j + 1 data%Equipments%DownHole%String(i)%StartMd = item%TopDepth data%Equipments%DownHole%String(i)%EndMd = item%DownDepth data%Equipments%DownHole%String(i)%ComponentType=0 !if(item%ComponentType > 4 ) then ! String(i)%ComponentType=0 ! String(i)%StartMd = 0 !endif if(item%ComponentType == 3) data%Equipments%DownHole%String(i)%ComponentType=0 if(item%ComponentType == 4) data%Equipments%DownHole%String(i)%ComponentType=1 if(item%ComponentType == 2) data%Equipments%DownHole%String(i)%ComponentType=2 if(item%ComponentType == 1) data%Equipments%DownHole%String(i)%ComponentType=3 !if(print_log) print*, 'item%ComponentType=', item%ComponentType !if(print_log) print*, 'String(i)%ComponentType=', String(i)%ComponentType !if(print_log) print*, 'String(i)%StartMd=', String(i)%StartMd !if(print_log) print*, 'String(i)%EndMd=', String(i)%EndMd !if(print_log) print*, '----------------------------' !call Log_3( 'item%ComponentType=', item%ComponentType) !call Log_3( 'String(i)%ComponentType=', String(i)%ComponentType) !call Log_3( 'String(i)%StartMd=', String(i)%StartMd) !call Log_3( 'String(i)%EndMd=', String(i)%EndMd) !call Log_3( '----------------------------') end do !!if(print_log) print*, '============CMP-ST============' !!call Log_3( '============CMP-ST============') !if(associated(StringComponentArrayPtr)) then ! call StringComponentArrayPtr(String) !end if end if end subroutine SetString subroutine SetBopElements(array) use CLog4 implicit none integer, parameter :: count = 4 integer :: i = 1 !, j type(CBopElement), intent(inout), target :: array(count) type(CBopElement), pointer :: item if(size(data%Equipments%DownHole%BopElements) > 0) deallocate(data%Equipments%DownHole%BopElements) allocate(data%Equipments%DownHole%BopElements(count)) do i = 1, count item => array(i) !call Log_4('item%ElementStart', item%ElementStart) !call Log_4('item%ElementEnd', item%ElementEnd) !call Log_4('item%ElementType', item%ElementType) !call Log_4('=====================================================') data%Equipments%DownHole%BopElements(i)%ElementStart = item%ElementStart data%Equipments%DownHole%BopElements(i)%ElementEnd = item%ElementEnd data%Equipments%DownHole%BopElements(i)%ElementType = item%ElementType end do !if(associated(BopElementsPtr)) call BopElementsPtr(BopElements) end subroutine SetBopElements end module DownHoleModule