Simulation Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

123 lines
6.7 KiB

  1. module CStringConfiguration
  2. use CStringConfigurationVariables
  3. use SimulationVariables
  4. use json_module
  5. implicit none
  6. public
  7. contains
  8. subroutine StringConfigurationFromJson(parent)
  9. use json_module,IK =>json_ik
  10. type(json_value),pointer :: parent
  11. type(json_core) :: json
  12. type(json_value),pointer :: p,pitems,pitem,pval,pbit
  13. logical::is_found
  14. integer::i,n_children
  15. CHARACTER(KIND=JSON_CK, LEN=:), ALLOCATABLE :: val
  16. call json%get(parent,'StringConfiguration',p)
  17. call json%get(p,'StringConfigurationItems',pitems)
  18. call json%info(pitems, n_children=n_children)
  19. if (.not. allocated(data%Configuration%StringConfiguration%StringConfigurations)) then
  20. ALLOCATE(data%Configuration%StringConfiguration%StringConfigurations(n_children))
  21. endif
  22. if(size(data%Configuration%StringConfiguration%StringConfigurations)/=n_children) then
  23. DEALLOCATE(data%Configuration%StringConfiguration%StringConfigurations)
  24. ALLOCATE(data%Configuration%StringConfiguration%StringConfigurations(n_children))
  25. endif
  26. do i=1,n_children
  27. call json%get_child(pitems, i, pitem, found=is_found)
  28. call json%get(pitem,"ComponentType",pval)
  29. call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentType)
  30. call json%get(pitem,"NumberOfJoint",pval)
  31. call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NumberOfJoint)
  32. call json%get(pitem,"LengthPerJoint",pval)
  33. call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%LengthPerJoint)
  34. call json%get(pitem,"NominalOd",pval)
  35. call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NominalOd)
  36. call json%get(pitem,"NominalId",pval)
  37. call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NominalId)
  38. call json%get(pitem,"WeightPerLength",pval)
  39. call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%WeightPerLength)
  40. call json%get(pitem,"ComponentLength",pval)
  41. call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentLength)
  42. call json%get(pitem,"NominalToolJointOd",pval)
  43. call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NominalToolJointOd)
  44. call json%get(pitem,"Grade",pval)
  45. call json%get(pval,val)
  46. data%Configuration%StringConfiguration%StringConfigurations(i)%Grade = val
  47. end do
  48. call json%get(p,'BitDefenition',pbit)
  49. call json%get(pbit,'BitType',pval)
  50. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitType)
  51. call json%get(pbit,'BitSize',pval)
  52. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitSize)
  53. call json%get(pbit,'BitCodeHundreds',pval)
  54. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitCodeHundreds)
  55. call json%get(pbit,'BitCodeTens',pval)
  56. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitCodeTens)
  57. call json%get(pbit,'BitCodeOnes',pval)
  58. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitCodeOnes)
  59. call json%get(pbit,'BitNozzleSize',pval)
  60. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitNozzleSize)
  61. call json%get(pbit,'BitLength',pval)
  62. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitLength)
  63. call json%get(pbit,'BitWeightPerLength',pval)
  64. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitWeightPerLength)
  65. call json%get(pbit,'BitNozzleNo',pval)
  66. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitNozzleNo)
  67. call json%get(pbit,'FloatValve',pval)
  68. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%FloatValve)
  69. end subroutine
  70. subroutine StringConfigurationToJson(parent)
  71. type(json_value),pointer :: parent
  72. type(json_core) :: json
  73. type(json_value),pointer :: pitems,pitem,pbit,p
  74. integer:: i,n
  75. ! 1. create new node
  76. call json%create_object(p,'StringConfiguration')
  77. call json%create_array(pitems,'StringConfigurationItems')
  78. ! 2. add member of data type to new node
  79. n = data%Configuration%StringConfiguration%StringConfigurationCount
  80. do i=1,n
  81. call json%create_object(pitem,'')
  82. call json%add(pitem,"ComponentLength",data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentLength)
  83. call json%add(pitem,"ComponentType",data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentType)
  84. call json%add(pitem,"Grade",data%Configuration%StringConfiguration%StringConfigurations(i)%Grade)
  85. call json%add(pitem,"LengthPerJoint",data%Configuration%StringConfiguration%StringConfigurations(i)%LengthPerJoint)
  86. call json%add(pitem,"NominalId",data%Configuration%StringConfiguration%StringConfigurations(i)%NominalId)
  87. call json%add(pitem,"NominalOd",data%Configuration%StringConfiguration%StringConfigurations(i)%NominalOd)
  88. call json%add(pitem,"NominalToolJointOd",data%Configuration%StringConfiguration%StringConfigurations(i)%NominalToolJointOd)
  89. call json%add(pitem,"NumberOfJoint",data%Configuration%StringConfiguration%StringConfigurations(i)%NumberOfJoint)
  90. call json%add(pitem,"WeightPerLength",data%Configuration%StringConfiguration%StringConfigurations(i)%WeightPerLength)
  91. call json%add(pitems,pitem)
  92. end do
  93. call json%create_object(pbit,"BitDefenition")
  94. call json%add(pbit,"BitCodeHundreds",data%Configuration%StringConfiguration%BitDefinition%BitCodeHundreds)
  95. call json%add(pbit,"BitCodeOnes",data%Configuration%StringConfiguration%BitDefinition%BitCodeOnes)
  96. call json%add(pbit,"BitCodeTens",data%Configuration%StringConfiguration%BitDefinition%BitCodeTens)
  97. call json%add(pbit,"BitLength",data%Configuration%StringConfiguration%BitDefinition%BitLength)
  98. call json%add(pbit,"BitNozzleNo",data%Configuration%StringConfiguration%BitDefinition%BitNozzleNo)
  99. call json%add(pbit,"BitNozzleSize",data%Configuration%StringConfiguration%BitDefinition%BitNozzleSize)
  100. call json%add(pbit,"BitSize",data%Configuration%StringConfiguration%BitDefinition%BitSize)
  101. call json%add(pbit,"BitType",data%Configuration%StringConfiguration%BitDefinition%BitType)
  102. call json%add(pbit,"BitWeightPerLength",data%Configuration%StringConfiguration%BitDefinition%BitWeightPerLength)
  103. call json%add(pbit,"FloatValve",data%Configuration%StringConfiguration%BitDefinition%FloatValve)
  104. ! call json%add(p,"StringConfigurationCount",dat%Configuration%StringConfiguration%StringConfigurationCount)
  105. ! 3. add new node to parent
  106. call json%add(p,pitems)
  107. call json%add(p,pbit)
  108. call json%add(parent,p)
  109. end subroutine
  110. end module CStringConfiguration