|
- {
- "cells": [
- {
- "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": 3,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "('.',\n",
- " ['.git',\n",
- " '.vs',\n",
- " 'Common',\n",
- " 'CSharp',\n",
- " 'Equipments',\n",
- " 'FluidFlow',\n",
- " 'Geo',\n",
- " 'lib',\n",
- " 'Rop',\n",
- " 'TorqueDrag',\n",
- " 'x64'])"
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "dir,subdirs"
- ]
- },
- {
- "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
- }
|