|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- {
- "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
- }
|