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.8 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. data%Configuration%StringConfiguration%StringConfigurationCount = n_children
  27. do i=1,n_children
  28. call json%get_child(pitems, i, pitem, found=is_found)
  29. call json%get(pitem,"ComponentType",pval)
  30. call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentType)
  31. call json%get(pitem,"NumberOfJoint",pval)
  32. call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NumberOfJoint)
  33. call json%get(pitem,"LengthPerJoint",pval)
  34. call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%LengthPerJoint)
  35. call json%get(pitem,"NominalOd",pval)
  36. call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NominalOd)
  37. call json%get(pitem,"NominalId",pval)
  38. call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NominalId)
  39. call json%get(pitem,"WeightPerLength",pval)
  40. call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%WeightPerLength)
  41. call json%get(pitem,"ComponentLength",pval)
  42. call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentLength)
  43. ! call json%get(pitem,"NominalToolJointOd",pval)
  44. ! call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NominalToolJointOd)
  45. ! call json%get(pitem,"Grade",pval)
  46. ! call json%get(pval,val)
  47. ! data%Configuration%StringConfiguration%StringConfigurations(i)%Grade = val
  48. end do
  49. call json%get(p,'BitDefenition',pbit)
  50. call json%get(pbit,'BitType',pval)
  51. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitType)
  52. call json%get(pbit,'BitSize',pval)
  53. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitSize)
  54. call json%get(pbit,'BitCodeHundreds',pval)
  55. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitCodeHundreds)
  56. call json%get(pbit,'BitCodeTens',pval)
  57. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitCodeTens)
  58. call json%get(pbit,'BitCodeOnes',pval)
  59. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitCodeOnes)
  60. call json%get(pbit,'BitNozzleSize',pval)
  61. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitNozzleSize)
  62. call json%get(pbit,'BitLength',pval)
  63. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitLength)
  64. call json%get(pbit,'BitWeightPerLength',pval)
  65. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitWeightPerLength)
  66. call json%get(pbit,'BitNozzleNo',pval)
  67. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitNozzleNo)
  68. call json%get(pbit,'FloatValve',pval)
  69. call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%FloatValve)
  70. end subroutine
  71. subroutine StringConfigurationToJson(parent)
  72. type(json_value),pointer :: parent
  73. type(json_core) :: json
  74. type(json_value),pointer :: pitems,pitem,pbit,p
  75. integer:: i,n
  76. ! 1. create new node
  77. call json%create_object(p,'StringConfiguration')
  78. call json%create_array(pitems,'StringConfigurationItems')
  79. ! 2. add member of data type to new node
  80. n = data%Configuration%StringConfiguration%StringConfigurationCount
  81. do i=1,n
  82. call json%create_object(pitem,'')
  83. call json%add(pitem,"ComponentLength",data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentLength)
  84. call json%add(pitem,"ComponentType",data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentType)
  85. ! call json%add(pitem,"Grade",data%Configuration%StringConfiguration%StringConfigurations(i)%Grade)
  86. call json%add(pitem,"LengthPerJoint",data%Configuration%StringConfiguration%StringConfigurations(i)%LengthPerJoint)
  87. call json%add(pitem,"NominalId",data%Configuration%StringConfiguration%StringConfigurations(i)%NominalId)
  88. call json%add(pitem,"NominalOd",data%Configuration%StringConfiguration%StringConfigurations(i)%NominalOd)
  89. ! call json%add(pitem,"NominalToolJointOd",data%Configuration%StringConfiguration%StringConfigurations(i)%NominalToolJointOd)
  90. call json%add(pitem,"NumberOfJoint",data%Configuration%StringConfiguration%StringConfigurations(i)%NumberOfJoint)
  91. call json%add(pitem,"WeightPerLength",data%Configuration%StringConfiguration%StringConfigurations(i)%WeightPerLength)
  92. call json%add(pitems,pitem)
  93. end do
  94. call json%create_object(pbit,"BitDefenition")
  95. call json%add(pbit,"BitCodeHundreds",data%Configuration%StringConfiguration%BitDefinition%BitCodeHundreds)
  96. call json%add(pbit,"BitCodeOnes",data%Configuration%StringConfiguration%BitDefinition%BitCodeOnes)
  97. call json%add(pbit,"BitCodeTens",data%Configuration%StringConfiguration%BitDefinition%BitCodeTens)
  98. call json%add(pbit,"BitLength",data%Configuration%StringConfiguration%BitDefinition%BitLength)
  99. call json%add(pbit,"BitNozzleNo",data%Configuration%StringConfiguration%BitDefinition%BitNozzleNo)
  100. call json%add(pbit,"BitNozzleSize",data%Configuration%StringConfiguration%BitDefinition%BitNozzleSize)
  101. call json%add(pbit,"BitSize",data%Configuration%StringConfiguration%BitDefinition%BitSize)
  102. call json%add(pbit,"BitType",data%Configuration%StringConfiguration%BitDefinition%BitType)
  103. call json%add(pbit,"BitWeightPerLength",data%Configuration%StringConfiguration%BitDefinition%BitWeightPerLength)
  104. call json%add(pbit,"FloatValve",data%Configuration%StringConfiguration%BitDefinition%FloatValve)
  105. ! call json%add(p,"StringConfigurationCount",dat%Configuration%StringConfiguration%StringConfigurationCount)
  106. ! 3. add new node to parent
  107. call json%add(p,pitems)
  108. call json%add(p,pbit)
  109. call json%add(parent,p)
  110. end subroutine
  111. end module CStringConfiguration