浏览代码

first FromJson sub written (CStringConfiguration)

najafi
mahmood19227 1年前
父节点
当前提交
ce98df4b6f
共有 11 个文件被更改,包括 968 次插入921 次删除
  1. +64
    -0
      CSharp/BasicInputs/Bha/CStringConfiguration.f90
  2. +4
    -0
      Makefile
  3. 二进制
     
  4. +191
    -4
      Simulator.f90
  5. +0
    -18
      Test/test.f90
  6. 二进制
     
  7. +10
    -19
      Text1.txt
  8. +249
    -0
      data-witharray.json
  9. +111
    -37
      helper.ipynb
  10. +311
    -843
      test.json
  11. +28
    -0
      testjson.f90

+ 64
- 0
CSharp/BasicInputs/Bha/CStringConfiguration.f90 查看文件

@@ -7,6 +7,70 @@ module CStringConfiguration
public
contains
subroutine StringConfigurationFromJson(parent)
use json_module,IK =>json_ik
type(json_value),pointer :: parent
type(json_core) :: json
type(json_value),pointer :: p,pitems,pitem,pval,pbit
logical::is_found
type(CStringItem) :: item
integer::i,n_children
CHARACTER(KIND=JSON_CK, LEN=:), ALLOCATABLE :: val
call json%get(parent,'StringConfiguration',p)
call json%get(p,'StringConfigurationItems',pitems)
call json%info(pitems, n_children=n_children)
if (.not. allocated(data%Configuration%StringConfiguration%StringConfigurations) .or. size(data%Configuration%StringConfiguration%StringConfigurations)/=n_children) then
ALLOCATE(data%Configuration%StringConfiguration%StringConfigurations(n_children))
endif
do i=1,n_children
call json%get_child(pitems, i, pitem, found=is_found)
call json%get(pitem,"ComponentType",pval)
call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentType)
call json%get(pitem,"NumberOfJoint",pval)
call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NumberOfJoint)
call json%get(pitem,"LengthPerJoint",pval)
call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%LengthPerJoint)
call json%get(pitem,"NominalOd",pval)
call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NominalOd)
call json%get(pitem,"NominalId",pval)
call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NominalId)
call json%get(pitem,"WeightPerLength",pval)
call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%WeightPerLength)
call json%get(pitem,"ComponentLength",pval)
call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentLength)
call json%get(pitem,"NominalToolJointOd",pval)
call json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NominalToolJointOd)
call json%get(pitem,"Grade",pval)
call json%get(pval,val)
data%Configuration%StringConfiguration%StringConfigurations(i)%Grade = val
end do
call json%get(p,'StringConfigurationItems',pbit)
call json%get(pbit,'BitType',pval)
call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitType)
call json%get(pbit,'BitSize',pval)
call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitSize)
call json%get(pbit,'BitCodeHundreds',pval)
call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitCodeHundreds)
call json%get(pbit,'BitCodeTens',pval)
call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitCodeTens)
call json%get(pbit,'BitCodeOnes',pval)
call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitCodeOnes)
call json%get(pbit,'BitNozzleSize',pval)
call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitNozzleSize)
call json%get(pbit,'BitLength',pval)
call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitLength)
call json%get(pbit,'BitWeightPerLength',pval)
call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitWeightPerLength)
call json%get(pbit,'BitNozzleNo',pval)
call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%BitNozzleNo)
call json%get(pbit,'FloatValve',pval)
call json%get(pval,data%Configuration%StringConfiguration%BitDefinition%FloatValve)
end subroutine
subroutine StringConfigurationToJson(parent)
type(json_value),pointer :: parent


+ 4
- 0
Makefile 查看文件

@@ -402,6 +402,10 @@ $(TARGET): $(OBJS_F)
$(OBJ_DIR)/%.o: %.f90
$(FC) $(FCFLAGS) -c -o $@ $<
testjson:
$(FC) -o Test_Json $(FCFLAGS) testjson.f90 lib/libjsonfortran.a
./Test_Json
testredis:
@echo "make test redis"
cc Redis/redis_io.c -c -o obj/redis_io.o


二进制
查看文件


+ 191
- 4
Simulator.f90 查看文件

@@ -71,7 +71,6 @@ module Simulator
type(json_value),pointer :: jsonvalue
type(json_core) :: jsoncore
logical :: is_found
real T1,T2
character(len=:),allocatable::redisContent
contains
@@ -221,9 +220,19 @@ module Simulator
print *,"write ends"
end subroutine

subroutine read_variables
call getData(redisContent)
call jsoncore%deserialize(jsonvalue,redisContent)
subroutine read_variables()

! call getData(redisContent)
! call jsoncore%deserialize(jsonvalue,redisContent)

call jsonfile%initialize()
call jsonfile%load_file('data-witharray.json'); if (jsonfile%failed()) stop
call jsonfile%json_file_get_root(jsonvalue)

call ConfigurationFromJson(jsonvalue)
! call WarningsFromJson(jsonvalue)
! call ProblemsFromJson(jsonvalue)
! call EquipmentsToJson(jsonvalue)
! print *,"Read from Redix:",redisContent
! ! Load the file.
! call jsonfile%load_file('config.json'); if (jsonfile%failed()) stop
@@ -482,6 +491,184 @@ module Simulator
call json%add(parent,p)
end subroutine

subroutine ConfigurationFromJson(parent)
type(json_value),pointer :: parent
type(json_core) :: json
type(json_value),pointer :: p

! 1. get related root
call jsonfile%get('Configuration',p,is_found)

call StringConfigurationFromJson(p)
! call FormationFromJson(p)
! call ReservoirFromJson(p)
! call ShoeFromJson(p)
! call AccumulatorFromJson(p)
! call BopStackFromJson(p)
! call HoistingFromJson(p)
! call PowerFromJson(p)
! call PumpsFromJson(p)
! call RigSizeFromJson(p)
! call CasingLinerChokeFromJson(p)
! call PathGenerationFromJson(p)
! call MudPropertiesFromJson(p)

! 3. add new node to parent
call json%add(parent,p)
end subroutine

subroutine WarningsFromJson(parent)
type(json_value),pointer :: parent
type(json_core) :: json
type(json_value),pointer :: p

! 1. create new node
! call json%create_object(p,'Warnings')
! ! 2. add member of data type to new node
! call json%add(p,"PumpWithKellyDisconnected",data%Warnings%PumpWithKellyDisconnected)
! call json%add(p,"PumpWithTopdriveDisconnected",data%Warnings%PumpWithTopdriveDisconnected)
! call json%add(p,"Pump1PopOffValveBlown",data%Warnings%Pump1PopOffValveBlown)
! call json%add(p,"Pump1Failure",data%Warnings%Pump1Failure)
! call json%add(p,"Pump2PopOffValveBlown",data%Warnings%Pump2PopOffValveBlown)
! call json%add(p,"Pump2Failure",data%Warnings%Pump2Failure)
! call json%add(p,"Pump3PopOffValveBlown",data%Warnings%Pump3PopOffValveBlown)
! call json%add(p,"Pump3Failure",data%Warnings%Pump3Failure)
! call json%add(p,"DrawworksGearsAbuse",data%Warnings%DrawworksGearsAbuse)
! call json%add(p,"RotaryGearsAbuse",data%Warnings%RotaryGearsAbuse)
! call json%add(p,"HoistLineBreak",data%Warnings%HoistLineBreak)
! call json%add(p,"PartedDrillString",data%Warnings%PartedDrillString)
! call json%add(p,"ActiveTankOverflow",data%Warnings%ActiveTankOverflow)
! call json%add(p,"ActiveTankUnderVolume",data%Warnings%ActiveTankUnderVolume)
! call json%add(p,"TripTankOverflow",data%Warnings%TripTankOverflow)
! call json%add(p,"DrillPipeTwistOff",data%Warnings%DrillPipeTwistOff)
! call json%add(p,"DrillPipeParted",data%Warnings%DrillPipeParted)
! call json%add(p,"TripWithSlipsSet",data%Warnings%TripWithSlipsSet)
! call json%add(p,"Blowout",data%Warnings%Blowout)
! call json%add(p,"UndergroundBlowout",data%Warnings%UndergroundBlowout)
! call json%add(p,"MaximumWellDepthExceeded",data%Warnings%MaximumWellDepthExceeded)
! call json%add(p,"CrownCollision",data%Warnings%CrownCollision)
! call json%add(p,"FloorCollision",data%Warnings%FloorCollision)
! call json%add(p,"TopdriveRotaryTableConfilict",data%Warnings%TopdriveRotaryTableConfilict)

! ! 3. add new node to parent
! call json%add(parent,p)
end subroutine

subroutine ProblemsFromJson(parent)
type(json_value),pointer :: parent
type(json_core) :: json
type(json_value),pointer :: p

! 1. create new node
! call json%create_object(p,'Problems')
! ! 2. add member of data type to new node
! call BitProblemsFromJson(p)
! call BopProblemsFromJson(p)
! call ChokeProblemsFromJson(p)
! call DrillStemProblemsFromJson(p)
! call GaugesProblemsFromJson(p)
! call HoistingProblemsFromJson(p)
! call KickProblemsFromJson(p)
! call LostProblemsFromJson(p)
! call MudTreatmentProblemsFromJson(p)
! call OtherProblemsFromJson(p)
! call PumpProblemsFromJson(p)
! call RotaryProblemsFromJson(p)
! ! 3. add new node to parent
! call json%add(parent,p)
end subroutine

subroutine StateFromJson(parent)

type(json_value),pointer :: parent
type(json_core) :: json
type(json_value),pointer :: p

! 1. create new node
! call json%create_object(p,'State')

! ! call OperationScenarioFromJson(p)
! call notificationsFromJson(p)
! call permissionsFromJson(p)
! call unitySignalsFromJson(p)
! call StudentStationFromJson(p)
! call BopStackInputFromJson(p)
! call BopStackAccFromJson(p)
! call RamLineFromJson(p)
! call AnnularComputationalFromJson(p)
! call AnnularFromJson(p)
! call PipeRam1FromJson(p)
! call ShearRamFromJson(p)
! call PipeRam2FromJson(p)
! call ChokeLineFromJson(p)
! call KillLineFromJson(p)
! call PumpsFromJson(p)
! call RAMFromJson(p)
! call RAMSFromJson(p)
! call ChokeFromJson(p)
! call AirDrivenPumpFromJson(p)
! call AirPumpLineFromJson(p)
! call CHOOKEFromJson(p)
! call DrawworksFromJson(p)
! call MudSystemFromJson(p)
! call MUDFromJson(p)
! call MPumpsFromJson(p)
! call PUMPFromJson(p)
! call RTableFromJson(p)
! call TDSFromJson(p)
! call GasType(3)FromJson(p)
! call PressureDisplayFromJson(p)
! call FricPressDropFromJson(p)
! call ROP_SpecFromJson(p)
! call ROP_BitFromJson(p)
! call TDGeoFromJson(p)
! call F_String(:)FromJson(p)
! call F_CountsFromJson(p)
! call F_Interval(:)FromJson(p)
! call OD_Annulus(4)FromJson(p)
! call TD_DrillStemFromJson(p)
! call TD_DrillStemsFromJson(p)
! call TD_StringFromJson(p)
! call TD_CountFromJson(p)
! call G_StringElementFromJson(p)
! call TD_VolFromJson(p)
! call TD_GeneralFromJson(p)
! call TD_BOPFromJson(p)
! call TD_BOPElement(4)FromJson(p)
! call TD_StConnFromJson(p)
! call TD_LoadFromJson(p)
! call TD_WellElFromJson(p)
! call TD_CasingFromJson(p)
! call TD_LinerFromJson(p)
! call TD_OpenHoleFromJson(p)
! call TD_ROPHoleFromJson(p)
! call TD_WellGeneralFromJson(p)
! call TD_WellGeo(:)FromJson(p)
! 2. add member of data type to new node

! 3. add new node to parent
call json%add(parent,p)
end subroutine

!use this as a template
subroutine notificationsFromJson(parent)

type(json_value),pointer :: parent
! type(json_core) :: json
! type(json_value),pointer :: p

! 1. create new node
! call json%create_object(p,'Notifications')
! ! 2. add member of data type to new node

! ! 3. add new node to parent
! call json%add(parent,p)
end subroutine


end module Simulator

+ 0
- 18
Test/test.f90 查看文件

@@ -1,18 +0,0 @@
Module RedisInterface
Interface
SUBROUTINE addnums(a, b) BIND(C,name='addnums')
USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT
IMPLICIT NONE
INTEGER(C_INT) :: a, b
END SUBROUTINE addnums
End Interface
END Module RedisInterface
program test
use RedisInterface
! external addnums
integer::x,y
x=5
y=12
call addnums(x,y)
end program

二进制
查看文件


+ 10
- 19
Text1.txt 查看文件

@@ -1,19 +1,10 @@
real(8) :: Depth
real(8) :: BitPosition
real(8) :: HookLoad
real(8) :: WeightOnBit
real(8) :: RPM
real(8) :: ROP
real(8) :: Torque
real(8) :: PumpPressure
real(8) :: SPM1
real(8) :: SPM2
real(8) :: CasingPressure
real(8) :: PercentFlow
real(8) :: PitGainLose
real(8) :: PitVolume
real(8) :: KillMudVolume
real(8) :: TripTankVolume
real(8) :: MudWeightIn
real(8) :: FillVolume
real(8) :: MudWeightOut
integer :: BitType
real(8) :: BitSize
integer :: BitCodeHundreds
integer :: BitCodeTens
integer :: BitCodeOnes
real(8) :: BitNozzleSize
real(8) :: BitLength
real(8) :: BitWeightPerLength
integer :: BitNozzleNo
logical :: FloatValve

+ 249
- 0
data-witharray.json 查看文件

@@ -0,0 +1,249 @@
{
"Configuration": {
"StringConfiguration": {
"StringConfigurationItems": [
{"ComponentType":1,
"NumberOfJoint":0,
"LengthPerJoint":0,
"NominalOd":0,
"NominalId":0,
"WeightPerLength":0,
"ComponentLength":1.5,
"NominalToolJointOd":0,
"Grade":"A"
},
{"ComponentType":2,
"NumberOfJoint":0,
"LengthPerJoint":0,
"NominalOd":0,
"NominalId":0,
"WeightPerLength":0,
"ComponentLength":2.6,
"NominalToolJointOd":0,
"Grade":"B"
}
],
"BitDefenition": {
"BitCodeHundreds": 0,
"BitCodeOnes": 0,
"BitCodeTens": 0,
"BitLength": 0.0E+0,
"BitNozzleNo": 0,
"BitNozzleSize": 0.0E+0,
"BitSize": 0.0E+0,
"BitType": 0,
"BitWeightPerLength": 0.0E+0,
"FloatValve": false
}
},
"Fromations": [
{"Top":0,
"Thickness":0,
"Drillablity":0,
"Abrasiveness":0,
"ThresholdWeight":0,
"PorePressureGradient":0
},
{"Top":0,
"Thickness":0,
"Drillablity":0,
"Abrasiveness":0,
"ThresholdWeight":0,
"PorePressureGradient":0
}
],
"Reservoir": {
"AutoMigrationRate": 0.0E+0,
"FluidGradient": 0.0E+0,
"FluidType": 0,
"FluidViscosity": 0.0E+0,
"FormationNo": 0,
"FormationPermeability": 0.0E+0,
"FormationTop": 0.0E+0,
"GeothermalGradient": 0.0E+0,
"InactiveInflux": false,
"IsAutoMigrationRateSelected": false,
"MakeKickSinglePacket": false,
"PressureGradient": 0.0E+0
},
"Shoe": {
"Breakdown": 0.0E+0,
"FormationNo": 0,
"FracturePropagation": 0.0E+0,
"InactiveFracture": false,
"LeakOff": 0.0E+0,
"ShoeDepth": 0.0E+0
},
"Accumulator": {
"AccumulatorMinimumOperatingPressure": 0.0E+0,
"AccumulatorSystemSize": 0.0E+0,
"AirPlungerPumpOutput": 0.0E+0,
"ElectricPumpOutput": 0.0E+0,
"NumberOfBottels": 0,
"OilTankVolume": 0.0E+0,
"PrechargePressure": 0.0E+0,
"StartPressure": 0.0E+0,
"StartPressure2": 0.0E+0,
"StopPressure": 0.0E+0,
"StopPressure2": 0.0E+0
},
"BopStack": {
"AboveAnnularHeight": 0.1E+2,
"AnnularPreventerClose": 0.0E+0,
"AnnularPreventerHeight": 0.10199999999999999E+2,
"AnnularPreventerOpen": 0.0E+0,
"AnnularStringDrag": 0.0E+0,
"BlindRamClose": 0.0E+0,
"BlindRamHeight": 0.16239999999999998E+2,
"BlindRamOpen": 0.0E+0,
"ChokeClose": 0.0E+0,
"ChokeLineId": 0.0E+0,
"ChokeLineLength": 0.0E+0,
"ChokeOpen": 0.0E+0,
"GroundLevel": 0.3E+2,
"KillClose": 0.15E+1,
"KillHeight": 0.18800000000000001E+2,
"KillOpen": 0.15E+1,
"LowerRamClose": 0.0E+0,
"LowerRamHeight": 0.21350000000000001E+2,
"LowerRamOpen": 0.0E+0,
"RamStringDrag": 0.0E+0,
"UpperRamClose": 0.0E+0,
"UpperRamHeight": 0.14632E+2,
"UpperRamOpen": 0.0E+0
},
"Hoisting": {
"DrillingLineBreakingLoadAbrasiveness": 0.0E+0,
"DriveTypeAbrasiveness": 0,
"KellyWeightAbrasiveness": 0.0E+0,
"NumberOfLineAbrasiveness": 0,
"TopDriveWeightAbrasiveness": 0.0E+0,
"TravelingBlockWeightAbrasiveness": 0.0E+0
},
"Power": {
"CementPump": 0.0E+0,
"Drawworks": 0.0E+0,
"GeneratorPowerRating": 0.0E+0,
"MudPump1": 0.0E+0,
"MudPump2": 0.0E+0,
"NumberOfgenerators": 0,
"RotaryTable": 0.0E+0,
"TopDrive": 0.0E+0
},
"Pumps": {
"MudPump1LinerDiameter": 0.0E+0,
"MudPump1Stroke": 0.0E+0,
"MudPump1MechanicalEfficiency": 0.0E+0,
"MudPump1VolumetricEfficiency": 0.0E+0,
"MudPump1Output": 0.0E+0,
"MudPump1OutputBblStroke": 0.0E+0,
"MudPump1Maximum": 0.0E+0,
"MudPump1ReliefValvePressure": 0.0E+0,
"MudPump2LinerDiameter": 0.0E+0,
"MudPump2Stroke": 0.0E+0,
"MudPump2MechanicalEfficiency": 0.0E+0,
"MudPump2VolumetricEfficiency": 0.0E+0,
"MudPump2Output": 0.0E+0,
"MudPump2OutputBblStroke": 0.0E+0,
"MudPump2Maximum": 0.0E+0,
"MudPump2ReliefValvePressure": 0.0E+0,
"CementPumpLinerDiameter": 0.0E+0,
"CementPumpStroke": 0.0E+0,
"CementPumpMechanicalEfficiency": 0.0E+0,
"CementPumpVolumetricEfficiency": 0.0E+0,
"CementPumpOutput": 0.0E+0,
"CementPumpOutputBblStroke": 0.0E+0,
"CementPumpMaximum": 0.0E+0,
"CementPumpReliefValvePressure": 0.0E+0,
"MudPump1ReliefValveIsSet": false,
"MudPump2ReliefValveIsSet": false,
"CementPumpReliefValveIsSet": false,
"ManualPumpPower": false,
"Valve1": false,
"Valve2": false,
"Valve3": false,
"Valve4": false,
"Valve5": false
},
"RigSize": {
"RigType": 0,
"CrownHeight": 0.0E+0,
"MonkeyBoandHeight": 0.0E+0,
"RigFloorHeight": 0.0E+0
},
"CasingLinerChoke": {
"CasingDepth": 0.0E+0,
"CasingId": 0.0E+0,
"CasingOd": 0.0E+0,
"CasingWeight": 0.0E+0,
"CasingCollapsePressure": 0.0E+0,
"CasingTensileStrength": 0.0E+0,
"LinerTopDepth": 0.0E+0,
"LinerLength": 0.0E+0,
"LinerId": 0.0E+0,
"LinerOd": 0.0E+0,
"LinerWeight": 0.0E+0,
"LinerCollapsePressure": 0.0E+0,
"LinerTensileStrength": 0.0E+0,
"OpenHoleId": 0.0E+0,
"OpenHoleLength": 0.0E+0
},
"Path": {
"Items": [
{"HoleType":0,
"Angle":0,
"Length":0,
"FinalAngle":0,
"TotalLength":0,
"MeasuredDepth":0,
"TotalVerticalDepth":0
},
{"HoleType":0,
"Angle":0,
"Length":0,
"FinalAngle":0,
"TotalLength":0,
"MeasuredDepth":0,
"TotalVerticalDepth":0
}
],
"DataPoints": [
{"X":0,
"Y":0
},
{"X":0,
"Y":0
}
]
},
"Mud": {
"ActiveMudType": 0,
"ActiveRheologyModel": 0,
"ActiveMudVolume": 0.0E+0,
"ActiveMudVolumeGal": 0.0E+0,
"ActiveDensity": 0.0E+0,
"ActivePlasticViscosity": 0.0E+0,
"ActiveYieldPoint": 0.0E+0,
"ActiveThetaThreeHundred": 0.0E+0,
"ActiveThetaSixHundred": 0.0E+0,
"ReserveMudType": 0,
"ReserveMudVolume": 0.0E+0,
"ReserveMudVolumeGal": 0.0E+0,
"ReserveDensity": 0.0E+0,
"ReservePlasticViscosity": 0.0E+0,
"ReserveYieldPoint": 0.0E+0,
"ReserveThetaThreeHundred": 0.0E+0,
"ReserveThetaSixHundred": 0.0E+0,
"ActiveTotalTankCapacity": 0.0E+0,
"ActiveTotalTankCapacityGal": 0.0E+0,
"ActiveSettledContents": 0.0E+0,
"ActiveSettledContentsGal": 0.0E+0,
"ActiveTotalContents": 0.0E+0,
"ActiveTotalContentsGal": 0.0E+0,
"ActiveAutoDensity": false,
"InitialTripTankMudVolume": 0.0E+0,
"InitialTripTankMudVolumeGal": 0.0E+0,
"PedalFlowMeter": 0.0E+0
}
}
}

+ 111
- 37
helper.ipynb 查看文件

@@ -384,25 +384,34 @@
},
{
"cell_type": "code",
"execution_count": 70,
"execution_count": 12,
"metadata": {},
"outputs": [
{
"ename": "ValueError",
"evalue": "cannot prepare() more than once",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32mc:\\Projects\\VSIM\\SimulationCore2\\helper.ipynb Cell 3\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/Projects/VSIM/SimulationCore2/helper.ipynb#X20sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m files \u001b[39m=\u001b[39m \u001b[39mtuple\u001b[39;49m(ts\u001b[39m.\u001b[39;49mstatic_order())\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Projects/VSIM/SimulationCore2/helper.ipynb#X20sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m \u001b[39mfor\u001b[39;00m file \u001b[39min\u001b[39;00m files:\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Projects/VSIM/SimulationCore2/helper.ipynb#X20sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m \u001b[39mprint\u001b[39m(file\u001b[39m.\u001b[39mreplace(\u001b[39m\"\u001b[39m\u001b[39m\\\\\u001b[39;00m\u001b[39m\"\u001b[39m,\u001b[39m\"\u001b[39m\u001b[39m/\u001b[39m\u001b[39m\"\u001b[39m)\u001b[39m+\u001b[39m\u001b[39m\"\u001b[39m\u001b[39m /\u001b[39m\u001b[39m\"\u001b[39m)\n",
"File \u001b[1;32mc:\\Users\\Mahmood\\Anaconda3\\lib\\graphlib.py:242\u001b[0m, in \u001b[0;36mTopologicalSorter.static_order\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 233\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mstatic_order\u001b[39m(\u001b[39mself\u001b[39m):\n\u001b[0;32m 234\u001b[0m \u001b[39m\"\"\"Returns an iterable of nodes in a topological order.\u001b[39;00m\n\u001b[0;32m 235\u001b[0m \n\u001b[0;32m 236\u001b[0m \u001b[39m The particular order that is returned may depend on the specific\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 240\u001b[0m \u001b[39m cycle is detected, :exc:`CycleError` will be raised.\u001b[39;00m\n\u001b[0;32m 241\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[1;32m--> 242\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mprepare()\n\u001b[0;32m 243\u001b[0m \u001b[39mwhile\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mis_active():\n\u001b[0;32m 244\u001b[0m node_group \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mget_ready()\n",
"File \u001b[1;32mc:\\Users\\Mahmood\\Anaconda3\\lib\\graphlib.py:93\u001b[0m, in \u001b[0;36mTopologicalSorter.prepare\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 85\u001b[0m \u001b[39m\"\"\"Mark the graph as finished and check for cycles in the graph.\u001b[39;00m\n\u001b[0;32m 86\u001b[0m \n\u001b[0;32m 87\u001b[0m \u001b[39mIf any cycle is detected, \"CycleError\" will be raised, but \"get_ready\" can\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 90\u001b[0m \u001b[39mtherefore no more nodes can be added using \"add\".\u001b[39;00m\n\u001b[0;32m 91\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[0;32m 92\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_ready_nodes \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m---> 93\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mcannot prepare() more than once\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m 95\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_ready_nodes \u001b[39m=\u001b[39m [\n\u001b[0;32m 96\u001b[0m i\u001b[39m.\u001b[39mnode \u001b[39mfor\u001b[39;00m i \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_node2info\u001b[39m.\u001b[39mvalues() \u001b[39mif\u001b[39;00m i\u001b[39m.\u001b[39mnpredecessors \u001b[39m==\u001b[39m \u001b[39m0\u001b[39m\n\u001b[0;32m 97\u001b[0m ]\n\u001b[0;32m 98\u001b[0m \u001b[39m# ready_nodes is set before we look for cycles on purpose:\u001b[39;00m\n\u001b[0;32m 99\u001b[0m \u001b[39m# if the user wants to catch the CycleError, that's fine,\u001b[39;00m\n\u001b[0;32m 100\u001b[0m \u001b[39m# they can continue using the instance to grab as many\u001b[39;00m\n\u001b[0;32m 101\u001b[0m \u001b[39m# nodes as possible before cycles block more progress\u001b[39;00m\n",
"\u001b[1;31mValueError\u001b[0m: cannot prepare() more than once"
"name": "stdout",
"output_type": "stream",
"text": [
"CSharp/Equipments/ControlPanels/CBopControlPanel.f90\n",
"CSharp/Equipments/ControlPanels/CChokeControlPanel.f90\n",
"CSharp/Equipments/ControlPanels/CChokeManifold.f90\n",
"CSharp/Equipments/ControlPanels/CDataDisplayConsole.f90\n",
"CSharp/Equipments/ControlPanels/CDrillingConsole.f90\n",
"CSharp/Equipments/ControlPanels/CEquipmentsConstants.f90\n",
"CSharp/Equipments/ControlPanels/CHook.f90\n",
"CSharp/Equipments/ControlPanels/CHookActions.f90\n",
"CSharp/Equipments/ControlPanels/CStandPipeManifold.f90\n",
"CSharp/Equipments/ControlPanels/CTopDrivePanel.f90\n"
]
}
],
"source": [
"files = tuple(ts.static_order())\n"
"dir = 'CSharp/Equipments/ControlPanels'\n",
"import os\n",
"os.listdir(dir)\n",
"for f in os.listdir(dir):\n",
" if f.endswith('Variables.f90'):\n",
" continue\n",
" print(dir+'/'+f)"
]
},
{
@@ -894,6 +903,65 @@
" print(f\"2-{a}\")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# FromJson"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\t\t\tcall json%get(pitem,\"ComponentType\",pval)\n",
"\t\t\tcall json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentType)\n",
"\n",
"\t\t\tcall json%get(pitem,\"NumberOfJoint\",pval)\n",
"\t\t\tcall json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NumberOfJoint)\n",
"\n",
"\t\t\tcall json%get(pitem,\"LengthPerJoint\",pval)\n",
"\t\t\tcall json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%LengthPerJoint)\n",
"\n",
"\t\t\tcall json%get(pitem,\"NominalOd\",pval)\n",
"\t\t\tcall json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NominalOd)\n",
"\n",
"\t\t\tcall json%get(pitem,\"NominalId\",pval)\n",
"\t\t\tcall json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NominalId)\n",
"\n",
"\t\t\tcall json%get(pitem,\"WeightPerLength\",pval)\n",
"\t\t\tcall json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%WeightPerLength)\n",
"\n",
"\t\t\tcall json%get(pitem,\"ComponentLength\",pval)\n",
"\t\t\tcall json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%ComponentLength)\n",
"\n",
"\t\t\tcall json%get(pitem,\"NominalToolJointOd\",pval)\n",
"\t\t\tcall json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%NominalToolJointOd)\n",
"\n",
"\t\t\tcall json%get(pitem,\"Grade\",pval)\n",
"\t\t\tcall json%get(pval,data%Configuration%StringConfiguration%StringConfigurations(i)%Grade)\n",
"\n"
]
}
],
"source": [
"pattern=\"\"\"\t\tcall json%get(pbit,'@@@',pval)\n",
"\t\tcall json%get(pval,data%Configuration%StringConfiguration%BitDefinition%@@@)\"\"\"\n",
"\n",
"input = open(\"Text1.txt\")\n",
"lines = input.readlines()\n",
"for line in lines:\n",
"\tname = line.split(\"::\")[-1].strip()\n",
"\tnewline = pattern.replace(\"@@@\",name)\n",
"\tprint(newline)\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
@@ -904,32 +972,22 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\"Depth\":0,\n",
"\"BitPosition\":0,\n",
"\"HookLoad\":0,\n",
"\"WeightOnBit\":0,\n",
"\"RPM\":0,\n",
"\"ROP\":0,\n",
"\"Torque\":0,\n",
"\"PumpPressure\":0,\n",
"\"SPM1\":0,\n",
"\"SPM2\":0,\n",
"\"CasingPressure\":0,\n",
"\"PercentFlow\":0,\n",
"\"PitGainLose\":0,\n",
"\"PitVolume\":0,\n",
"\"KillMudVolume\":0,\n",
"\"TripTankVolume\":0,\n",
"\"MudWeightIn\":0,\n",
"\"FillVolume\":0,\n",
"\"MudWeightOut\":0,\n",
"{\"ComponentType\":0,\n",
"\"NumberOfJoint\":0,\n",
"\"LengthPerJoint\":0,\n",
"\"NominalOd\":0,\n",
"\"NominalId\":0,\n",
"\"WeightPerLength\":0,\n",
"\"ComponentLength\":0,\n",
"\"NominalToolJointOd\":0,\n",
"\"Grade\":0,\n",
"}\n"
]
}
@@ -950,21 +1008,37 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"call ProblemToJson(p,\"ElevatorConnection\",data%State%OperationScenarios%ElevatorConnection)\n",
"call ProblemToJson(p,\"StringUpdate\",data%State%OperationScenarios%StringUpdate)\n",
"call ProblemToJson(p,\"KellyConnection\",data%State%OperationScenarios%KellyConnection)\n"
"call json%add(p,\"Depth\",data%EquipmentControl%DrillingWatch%Depth)\n",
"call json%add(p,\"BitPosition\",data%EquipmentControl%DrillingWatch%BitPosition)\n",
"call json%add(p,\"HookLoad\",data%EquipmentControl%DrillingWatch%HookLoad)\n",
"call json%add(p,\"WeightOnBit\",data%EquipmentControl%DrillingWatch%WeightOnBit)\n",
"call json%add(p,\"RPM\",data%EquipmentControl%DrillingWatch%RPM)\n",
"call json%add(p,\"ROP\",data%EquipmentControl%DrillingWatch%ROP)\n",
"call json%add(p,\"Torque\",data%EquipmentControl%DrillingWatch%Torque)\n",
"call json%add(p,\"PumpPressure\",data%EquipmentControl%DrillingWatch%PumpPressure)\n",
"call json%add(p,\"SPM1\",data%EquipmentControl%DrillingWatch%SPM1)\n",
"call json%add(p,\"SPM2\",data%EquipmentControl%DrillingWatch%SPM2)\n",
"call json%add(p,\"CasingPressure\",data%EquipmentControl%DrillingWatch%CasingPressure)\n",
"call json%add(p,\"PercentFlow\",data%EquipmentControl%DrillingWatch%PercentFlow)\n",
"call json%add(p,\"PitGainLose\",data%EquipmentControl%DrillingWatch%PitGainLose)\n",
"call json%add(p,\"PitVolume\",data%EquipmentControl%DrillingWatch%PitVolume)\n",
"call json%add(p,\"KillMudVolume\",data%EquipmentControl%DrillingWatch%KillMudVolume)\n",
"call json%add(p,\"TripTankVolume\",data%EquipmentControl%DrillingWatch%TripTankVolume)\n",
"call json%add(p,\"MudWeightIn\",data%EquipmentControl%DrillingWatch%MudWeightIn)\n",
"call json%add(p,\"FillVolume\",data%EquipmentControl%DrillingWatch%FillVolume)\n",
"call json%add(p,\"MudWeightOut\",data%EquipmentControl%DrillingWatch%MudWeightOut)\n"
]
}
],
"source": [
"precode = \"\"\"call json%add(pform,\"TopDriveTdsPowerState\",data%EquipmentControl%DrillingWatch%\"\"\"\n",
"precode = \"\"\"call json%add(p,\"\",data%EquipmentControl%DrillingWatch%\"\"\"\n",
"input = open(\"Text1.txt\")\n",
"lines = input.readlines()\n",
"for line in lines:\n",


+ 311
- 843
test.json
文件差异内容过多而无法显示
查看文件


+ 28
- 0
testjson.f90 查看文件

@@ -0,0 +1,28 @@
program RedisInterface
use json_module
use CStringConfigurationVariables
type(json_file) :: jsonfile
type(json_value),pointer :: jsonvalue,jsonvalue2,child,child2,jsonvalue3
type(json_core) :: jsoncore
logical :: is_found
integer ::n_children,i,j
type(CStringItem), allocatable :: StringConfigurations(:)

call jsonfile%initialize()
call jsonfile%load_file('data-witharray.json'); if (jsonfile%failed()) stop
call jsonfile%json_file_get_root(jsonvalue)
call jsoncore%get(jsonvalue,'Configuration',jsonvalue2)
call jsoncore%get(jsonvalue2,'StringConfiguration',jsonvalue)
call jsoncore%get(jsonvalue,'StringConfigurationItems',jsonvalue2)
call jsoncore%info(jsonvalue2, n_children=n_children)
do i=1,n_children
call jsoncore%get_child(jsonvalue2, i, child, found=is_found)
if (.not. is_found) print *,"not found"
call jsoncore%get(child,"BitCodeHundreds",child2)
call jsoncore%get(child2,j)
print *,"BitCodeHundreds=",j
end do
print *,"n_children=",n_children
call jsonfile%destroy()
end program

正在加载...
取消
保存