Simulation Core
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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