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.

CStringConfiguration.f90 6.6 KiB

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