{ "cells": [ { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{\"BitType\":0,\n", "\"BitSize\":0,\n", "\"BitCodeHundreds\":0,\n", "\"BitCodeTens\":0,\n", "\"BitCodeOnes\":0,\n", "\"BitNozzleSize\":0,\n", "\"BitLength\":0,\n", "\"BitWeightPerLength\":0,\n", "\"BitNozzleNo\":0,\n", "\"FloatValve\":0,\n", "\n" ] } ], "source": [ "input = open(\"Text1.txt\")\n", "output = \"{\"\n", "lines = input.readlines()\n", "for line in lines:\n", " name = line.split(\"::\")[-1].strip()\n", " type = line.split(\"::\")[0].strip()\n", " output += f\"\\\"{name}\\\":0,\\n\" \n", " # name = line.split(\"%\")[-1][:-1]\n", " # print(name)\n", "print(output+\"}\")\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "call json%add(p,\"ActiveMudType\",data%Configuration%Mud%ActiveMudType)\n", "call json%add(p,\"ActiveRheologyModel\",data%Configuration%Mud%ActiveRheologyModel)\n", "call json%add(p,\"ActiveMudVolume\",data%Configuration%Mud%ActiveMudVolume)\n", "call json%add(p,\"ActiveMudVolumeGal\",data%Configuration%Mud%ActiveMudVolumeGal)\n", "call json%add(p,\"ActiveDensity\",data%Configuration%Mud%ActiveDensity)\n", "call json%add(p,\"ActivePlasticViscosity\",data%Configuration%Mud%ActivePlasticViscosity)\n", "call json%add(p,\"ActiveYieldPoint\",data%Configuration%Mud%ActiveYieldPoint)\n", "call json%add(p,\"ActiveThetaThreeHundred\",data%Configuration%Mud%ActiveThetaThreeHundred)\n", "call json%add(p,\"ActiveThetaSixHundred\",data%Configuration%Mud%ActiveThetaSixHundred)\n", "call json%add(p,\"ReserveMudType\",data%Configuration%Mud%ReserveMudType)\n", "call json%add(p,\"ReserveMudVolume\",data%Configuration%Mud%ReserveMudVolume)\n", "call json%add(p,\"ReserveMudVolumeGal\",data%Configuration%Mud%ReserveMudVolumeGal)\n", "call json%add(p,\"ReserveDensity\",data%Configuration%Mud%ReserveDensity)\n", "call json%add(p,\"ReservePlasticViscosity\",data%Configuration%Mud%ReservePlasticViscosity)\n", "call json%add(p,\"ReserveYieldPoint\",data%Configuration%Mud%ReserveYieldPoint)\n", "call json%add(p,\"ReserveThetaThreeHundred\",data%Configuration%Mud%ReserveThetaThreeHundred)\n", "call json%add(p,\"ReserveThetaSixHundred\",data%Configuration%Mud%ReserveThetaSixHundred)\n", "call json%add(p,\"ActiveTotalTankCapacity\",data%Configuration%Mud%ActiveTotalTankCapacity)\n", "call json%add(p,\"ActiveTotalTankCapacityGal\",data%Configuration%Mud%ActiveTotalTankCapacityGal)\n", "call json%add(p,\"ActiveSettledContents\",data%Configuration%Mud%ActiveSettledContents)\n", "call json%add(p,\"ActiveSettledContentsGal\",data%Configuration%Mud%ActiveSettledContentsGal)\n", "call json%add(p,\"ActiveTotalContents\",data%Configuration%Mud%ActiveTotalContents)\n", "call json%add(p,\"ActiveTotalContentsGal\",data%Configuration%Mud%ActiveTotalContentsGal)\n", "call json%add(p,\"ActiveAutoDensity\",data%Configuration%Mud%ActiveAutoDensity)\n", "call json%add(p,\"InitialTripTankMudVolume\",data%Configuration%Mud%InitialTripTankMudVolume)\n", "call json%add(p,\"InitialTripTankMudVolumeGal\",data%Configuration%Mud%InitialTripTankMudVolumeGal)\n", "call json%add(p,\"PedalFlowMeter\",data%Configuration%Mud%PedalFlowMeter)\n" ] } ], "source": [ "precode = \"\"\"call json%add(p,\"\",data%Configuration%Mud%\"\"\"\n", "input = open(\"Text1.txt\")\n", "lines = input.readlines()\n", "for line in lines:\n", " name = line.split(\"::\")[-1].strip()\n", " icoute = precode.index(\"\\\"\")+1\n", " # name = line.split(\"%\")[-1][:-1]\n", " # print(name)\n", " newline = precode[:icoute]+name+precode[icoute:]+name+\")\"\n", " print(newline)\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\tGeo/GeoMain.f90 \\\n", "\n" ] } ], "source": [ "##Replace space with _ in filenames and list them for put them in makefile\n", "import os\n", "dir = 'Geo'\n", "files = os.listdir(dir)\n", "fstring = ''\n", "for f in files:\n", " if f.endswith('90'):\n", " newf = f.replace(' ','_')\n", " os.rename(os.path.join(dir,f),os.path.join(dir,newf))\n", " if newf.lower().endswith('variables.f90'):\n", " fstring = '\\t'+os.path.join(dir,newf).replace('\\\\','/') +' \\\\\\n' + fstring\n", " else:\n", " fstring = fstring + '\\t'+os.path.join(dir,newf).replace('\\\\','/') +' \\\\\\n'\n", "\n", "print(fstring)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Extract variable names from definition lines" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# %pwd\n", "lines = input(\"Enter lines:\").split(\" \")\n", "lines = [l.strip() for l in lines if len(l.strip())>0]\n", "vars = []\n", "for l in lines:\n", " if '::' in l:\n", " vars.append(l.split('::')[1].strip())" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import string\n", "string.ascii_letters" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "var: AnnularRegulatorSetControl\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: AirMasterValve\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: ByePassValve\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: AnnularValve\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: UpperRamsValve\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: MiddleRamsValve\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: KillLineValve\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: ChokeLineValve\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: LowerRamsValve\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: ManifoldPressureGauge\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: AirSupplyPressureGauge\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: AccumulatorPressureGauge\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: AnnularPressureGauge\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: AnnularOpenLED\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: AnnularCloseLED\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: UpperRamsOpenLED\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: UpperRamsCloseLED\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: MiddleRamsOpenLED\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: MiddleRamsCloseLED\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: KillLineOpenLED\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: KillLineCloseLED\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: ChokeLineOpenLED\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: ChokeLineCloseLED\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: LowerRamsOpenLED\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: LowerRamsCloseLED\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: AnnularStatus\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: UpperRamsStatus\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: MiddleRamsStatus\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n", "var: LowerRamsStatus\n", "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n", "Char before: \n", "Char after: \n", "\n" ] } ], "source": [ "import os\n", "import sys\n", "import re\n", "dir = '.'\n", "varNameChars = string.ascii_letters + '_'\n", "log = open(os.path.join(dir,'ReplaceVars.log',),'a')\n", "end=False\n", "for dir,subdirs,files in os.walk(dir):\n", " for filename in files:\n", " if filename.lower().endswith('.f90'):\n", " # print(filename)\n", " file = open(os.path.join(dir,filename))\n", " code = file.read()\n", " for var in vars:\n", " if var not in code:\n", " continue\n", " occurs = [m.start() for m in re.finditer(var, code)]\n", " for occurance in occurs:\n", " if code[occurs[0]-1] in varNameChars or code[occurs[0]+len(var)] in varNameChars:\n", " continue\n", " print(f\"var: {var}\")\n", " print(f\"file = {os.path.join(dir,filename)}\")\n", " print(f\"Char before: {code[occurs[0]-1]}\")\n", " print(f\"Char after: {code[occurs[0]+len(var)]}\")\n", " end = True\n", " if end:\n", " break" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "State\n", "Hoisting\n", "OperationScenario\n", "notifications\n", "permissions\n", "unitySignals\n", "StudentStation\n", "BopStackInput\n", "BopStackAcc\n", "RamLine\n", "AnnularComputational\n", "Annular\n", "PipeRam1\n", "ShearRam\n", "PipeRam2\n", "ChokeLine\n", "KillLine\n", "Pumps\n", "RAM\n", "RAMS\n", "Choke\n", "AirDrivenPump\n", "AirPumpLine\n", "CHOOKE\n", "Drawworks\n", "MudSystem\n", "MUD\n", "PUMP\n", "RTable\n", "TDS\n", "GasType(3)\n", "PressureDisplay\n", "ObservationPoint(:)\n", "FricPressDrop\n", "ROP_Spec\n", "ROP_Bit\n", "TDGeo\n", "F_String(:)\n", "F_Counts\n", "F_Interval(:)\n", "OD_Annulus(4)\n", "TD_DrillStem\n", "TD_DrillStems\n", "TD_String\n", "TD_Count\n", "G_StringElement\n", "TD_Vol\n", "TD_General\n", "TD_BOP\n", "TD_BOPElement(4)\n", "TD_StConn\n", "TD_Load\n", "TD_WellEl\n", "TD_Casing\n", "data%State%TD_Liner\n", "TD_OpenHole\n", "TD_ROPHole\n", "TD_WellGeneral\n", "TD_WellGeo(:)\n", "EquipmentControl\n", "BopControlPanel\n", "ChokeControlPanel\n", "ChokeManifold\n", "DataDisplayConsole\n", "DrillingConsole\n", "Hook\n", "StandPipeManifold\n", "TopDrivePanel\n", "DrillingWatch\n", "Tank\n", "Configuration\n", "StringConfiguration\n", "Formation\n", "Reservoir\n", "Shoe\n", "Accumulator\n", "BopStackSpecification\n", "Hoisting\n", "Power\n", "PumpsSpecification\n", "RigSize\n", "CasingLinerChoke\n", "PathGeneration\n", "WellSurveyData\n", "MudProperties\n", "problems\n", "BitProblems\n", "BopProblems\n", "ChokeProblems\n", "DrillStemProblems\n", "GaugesProblems\n", "HoistingProblems\n", "KickProblems\n", "LostProblems\n", "MudTreatmentProblems\n", "OtherProblems\n", "PumpProblems\n", "RotaryProblems\n" ] }, { "ename": "IndexError", "evalue": "list index out of range", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", "\u001b[1;32mc:\\Projects\\VSIM\\SimulationCore2\\helper.ipynb Cell 6\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 6\u001b[0m nsp\u001b[39m+\u001b[39m\u001b[39m=\u001b[39m\u001b[39m1\u001b[39m\n\u001b[0;32m 7\u001b[0m splits \u001b[39m=\u001b[39m line\u001b[39m.\u001b[39msplit(\u001b[39m\"\u001b[39m\u001b[39m::\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m----> 8\u001b[0m \u001b[39mprint\u001b[39m(splits[\u001b[39m1\u001b[39;49m]\u001b[39m.\u001b[39mstrip())\n", "\u001b[1;31mIndexError\u001b[0m: list index out of range" ] } ], "source": [ "f = open(\"hier.txt\")\n", "lines = f.readlines()\n", "for line in lines[1:]:\n", " nsp=0\n", " while line[nsp]==' ':\n", " nsp+=1\n", " splits = line.split(\"::\")\n", " print(splits[1].strip())" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'type SimulationDataType type(SimulationStateType)::State Type(HoistingType)::Hoisting type(OperationScenarioType)::OperationScenario type(NotificationType)::notifications type(PermissionsType):: permissions type(UnitySignalsType):: unitySignals type(StudentStationType)::StudentStation type(BopStackInputType)::BopStackInput type(BopStackAccType)::BopStackAcc type(RamLineType)::RamLine type(AnnularComputationalType)::AnnularComputational type(AnnularType)::Annular type(PipeRams1Type)::PipeRam1 type(ShearRamType)::ShearRam type(PipeRam2Type)::PipeRam2 type(ChokeLineType)::ChokeLine type(KillLineType)::KillLine type(PumpsType)::Pumps TYPE(BOP_TypeVars), DIMENSION(1:6) :: RAM TYPE(BOP_TypeVars2D) :: RAMS type(ChokeType)::Choke type(AirDrivenPumpType)::AirDrivenPump type(AirPumpLineType)::AirPumpLine TYPE(CHOKE_TypeVars), DIMENSION(1:2) :: CHOOKE TYPE(Drawworks_Var) :: Drawworks type(MudSystemType)::MudSystem TYPE(MUD_TypeVars), DIMENSION(1:10) :: MUD TYPE(Pump_Var), DIMENSION(1:3) :: PUMP TYPE(RTable_Var) :: RTable TYPE(TDS_Var) :: TDS TYPE(GasData) :: GasType(3) ! 1 = methane , 2 = Hydrogen sulfide , 3 = Carbon dioxid TYPE(PressureDisplayVARIABLESTYPE) :: PressureDisplay TYPE(ObservationAndGaugePointsInformations) , ALLOCATABLE :: ObservationPoint(:) TYPE(FricPressDropVarsTYPE) :: FricPressDrop TYPE(ROPSpecificationInfo) :: ROP_Spec TYPE(ROPInfo) :: ROP_Bit TYPE(Geo_Data) :: TDGeo TYPE(F_StringData) , Allocatable :: F_String(:) TYPE(F_IntervalsCountsData):: F_Counts TYPE(F_IntervalData) , Allocatable :: F_Interval(:) TYPE(OD_AnnulusData) :: OD_Annulus(4) TYPE(TD_DrillStemInfo), ALLOCATABLE, DIMENSION(:) :: TD_DrillStem TYPE(TD_SeparatedDrillStemInfo), ALLOCATABLE, DIMENSION(:) :: TD_DrillStems TYPE(TD_StringInfo) :: TD_String TYPE(TD_AddRemoveInfo) :: TD_Count TYPE(CStringComponents), ALLOCATABLE, DIMENSION(:) :: G_StringElement TYPE(TD_RemovedVolumeInfo) :: TD_Vol TYPE(TD_GeneralInfo) :: TD_General TYPE(TD_BOPInfo) :: TD_BOP TYPE(CBopElement) :: TD_BOPElement(4) TYPE(TD_StringconnectionInfo) :: TD_StConn TYPE(TD_LoadInfo) :: TD_Load TYPE(TD_WellElementsInfo) :: TD_WellEl TYPE(TD_CasingInfo), ALLOCATABLE, DIMENSION(:) :: TD_Casing TYPE(TD_LinerInfo), ALLOCATABLE, DIMENSION(:) :: data%State%TD_Liner TYPE(TD_OpenHoleInfo), ALLOCATABLE, DIMENSION(:) :: TD_OpenHole TYPE(TD_ROPHoleInfo), ALLOCATABLE, DIMENSION(:) :: TD_ROPHole TYPE(TD_WellGeneralInfo) :: TD_WellGeneral TYPE(TD_WellGeometryData), Allocatable :: TD_WellGeo(:) type(EquipmentControlType)::EquipmentControl type(BopControlPanelType) :: BopControlPanel Type(ChokeControlPanelType)::ChokeControlPanel Type(ChokeManifoldType)::ChokeManifold Type(DataDisplayConsoleType) :: DataDisplayConsole TYPE(DrillingConsoleType) :: DrillingConsole Type(HookType)::Hook type(StandPipeManifoldType)::StandPipeManifold Type(TopDrivePanelType)::TopDrivePanel Type(DrillingWatchType)::DrillingWatch Type(TankType)::Tank type(ConfigurationType)::Configuration Type(StringConfigurationType)::StringConfiguration Type(FormationType) :: Formation Type(ReservoirType)::Reservoir Type(ShoeType)::Shoe Type(AccumulatorType)::Accumulator Type(BopStackSpecificationType)::BopStackSpecification Type(HoistingType)::Hoisting Type(PowerType)::Power Type(PumpSpecificationType)::PumpsSpecification Type(RigSizeType)::RigSize Type(CasingLinerChokeType)::CasingLinerChoke Type(PathGenerationType)::PathGeneration Type(WellSurveyDataType)::WellSurveyData Type(MudPropertiesType)::MudProperties type(ProblemsType)::problems type(BitProblemsType)::BitProblems type(BopProblemsType)::BopProblems type(ChokeProblemsType)::ChokeProblems type(DrillStemProblemsType)::DrillStemProblems type(GaugesProblemsType)::GaugesProblems type(HoistingProblemsType):: HoistingProblems type(KickProblemsType)::KickProblems type(LostProblemsType)::LostProblems type(MudTreatmentProblemsType)::MudTreatmentProblems type(OtherProblemsType)::OtherProblems type(PumpProblemsType)::PumpProblems type(RotaryProblemsType)::RotaryProblems end type SimulationDataType'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "line" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for fn in modules:\n", " f = open(fn)\n", " lines = f.readlines()\n", " module_filenames = {}\n", " used_modules = []\n", " mod_count = 0\n", " for l in lines:\n", " l = l.strip().lower()\n", " if l.startswith('module ') and not l.startswith('module procedure '):\n", " mod_name = l.split(' ')[1]\n", " module_filenames[mod_name] = fn\n", " mod_count +=1\n", " if l.startswith('use'):\n", " used_modules.append(l.split(' ')[1])\n", " if mod_count !=1:\n", " print(f\"{fn} has {mod_count} modules\")\n", " module_filenames,used_modules" ] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.12" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "1ef4a26de7183d96d6da1045a38581e0a15b2215d0c1b98c7b273c6e514c6c7e" } } }, "nbformat": 4, "nbformat_minor": 2 }