Simulation Core
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

120 righe
4.3 KiB

  1. # 1 "/mnt/c/Projects/VSIM/SimulationCore2/CSharp/Problems/CProblemDifinition.f90"
  2. module CProblemDifinition
  3. use json_module
  4. use CIActionReference
  5. implicit none
  6. public
  7. integer, parameter :: Time_ProblemType = 0
  8. integer, parameter :: PumpStrokes_ProblemType = 1
  9. integer, parameter :: VolumePumped_ProblemType = 2
  10. integer, parameter :: DistanceDrilled_ProblemType = 3
  11. integer, parameter :: Clear_StatusType = 0
  12. integer, parameter :: Now_StatusType = 1
  13. integer, parameter :: Later_StatusType = 2
  14. integer, parameter :: Executed_StatusType = 3
  15. type, bind(c), public :: CProblem
  16. integer :: ProblemType
  17. integer :: StatusType
  18. real(8) :: Value
  19. real(8) :: DueValue
  20. end type CProblem
  21. contains
  22. subroutine ProblemFromJson(parent,name,problem)
  23. type(json_value),pointer :: parent
  24. character(len=*)::name
  25. type(CProblem)::problem
  26. type(json_core) :: json
  27. type(json_value),pointer :: p,pval
  28. call json%get(parent,name,p)
  29. ! ! 2. add member of data type to new node
  30. call json%get(p,'ProblemType',pval)
  31. call json%get(pval,problem%ProblemType)
  32. call json%get(p,'StatusType',pval)
  33. call json%get(pval,problem%StatusType)
  34. call json%get(p,'Value',pval)
  35. call json%get(pval,problem%Value)
  36. call json%get(p,'DueValue',pval)
  37. call json%get(pval,problem%DueValue)
  38. end subroutine
  39. subroutine ProblemToJson(parent,name,problem)
  40. type(json_value),pointer :: parent
  41. character(len=*)::name
  42. type(CProblem)::problem
  43. type(json_core) :: json
  44. type(json_value),pointer :: p
  45. ! 1. create new node
  46. call json%create_object(p,name)
  47. ! 2. add member of data type to new node
  48. call json%add(p,"ProblemType",problem%ProblemType)
  49. call json%add(p,"StatusType",problem%StatusType)
  50. call json%add(p,"Value",problem%Value)
  51. call json%add(p,"DueValue",problem%DueValue)
  52. ! 3. add new node to parent
  53. call json%add(parent,p)
  54. end subroutine
  55. subroutine Execute(problem, action)
  56. type(CProblem), intent(inout) :: problem
  57. procedure (ActionInteger), pointer, intent(in) :: action
  58. problem%StatusType = Executed_StatusType
  59. if(problem%StatusType == Executed_StatusType .and. associated(action)) call action(Executed_StatusType)
  60. end subroutine
  61. subroutine ProcessDueTime(problem, action, time)
  62. use CLog3
  63. implicit none
  64. type(CProblem) :: problem
  65. procedure (ActionInteger), pointer, intent(in) :: action
  66. integer :: time
  67. if(problem%ProblemType == Time_ProblemType .and. problem%StatusType /= Executed_StatusType .and. problem%StatusType /= Clear_StatusType) then
  68. if(time >= int(problem%DueValue)) call Execute(problem, action)
  69. end if
  70. end subroutine
  71. subroutine ProcessDuePumpStrokes(problem, action, strokes)
  72. implicit none
  73. type(CProblem) :: problem
  74. procedure (ActionInteger), pointer, intent(in) :: action
  75. integer :: strokes
  76. if(problem%ProblemType == PumpStrokes_ProblemType .and. problem%StatusType /= Executed_StatusType .and. problem%StatusType /= Clear_StatusType) then
  77. if(strokes >= int(problem%DueValue)) call Execute(problem, action)
  78. end if
  79. end subroutine
  80. subroutine ProcessDueVolumePumped(problem, action, volume)
  81. implicit none
  82. type(CProblem) :: problem
  83. procedure (ActionInteger), pointer, intent(in) :: action
  84. real(8) :: volume
  85. if(problem%ProblemType == VolumePumped_ProblemType .and. problem%StatusType /= Executed_StatusType .and. problem%StatusType /= Clear_StatusType) then
  86. if(volume >= problem%DueValue) call Execute(problem, action)
  87. end if
  88. end subroutine
  89. subroutine ProcessDueDistanceDrilled(problem, action, distance)
  90. implicit none
  91. type(CProblem) :: problem
  92. procedure (ActionInteger), pointer, intent(in) :: action
  93. real(8) :: distance
  94. if(problem%ProblemType == DistanceDrilled_ProblemType .and. problem%StatusType /= Executed_StatusType .and. problem%StatusType /= Clear_StatusType) then
  95. if(distance >= problem%DueValue) call Execute(problem, action)
  96. end if
  97. end subroutine
  98. end module CProblemDifinition