Simulation Core
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 3,
  6. "metadata": {},
  7. "outputs": [
  8. {
  9. "name": "stdout",
  10. "output_type": "stream",
  11. "text": [
  12. "\tGeo/GeoMain.f90 \\\n",
  13. "\n"
  14. ]
  15. }
  16. ],
  17. "source": [
  18. "##Replace space with _ in filenames and list them for put them in makefile\n",
  19. "import os\n",
  20. "dir = 'Geo'\n",
  21. "files = os.listdir(dir)\n",
  22. "fstring = ''\n",
  23. "for f in files:\n",
  24. " if f.endswith('90'):\n",
  25. " newf = f.replace(' ','_')\n",
  26. " os.rename(os.path.join(dir,f),os.path.join(dir,newf))\n",
  27. " if newf.lower().endswith('variables.f90'):\n",
  28. " fstring = '\\t'+os.path.join(dir,newf).replace('\\\\','/') +' \\\\\\n' + fstring\n",
  29. " else:\n",
  30. " fstring = fstring + '\\t'+os.path.join(dir,newf).replace('\\\\','/') +' \\\\\\n'\n",
  31. "\n",
  32. "print(fstring)"
  33. ]
  34. },
  35. {
  36. "attachments": {},
  37. "cell_type": "markdown",
  38. "metadata": {},
  39. "source": [
  40. "## Extract variable names from definition lines"
  41. ]
  42. },
  43. {
  44. "cell_type": "code",
  45. "execution_count": 1,
  46. "metadata": {},
  47. "outputs": [],
  48. "source": [
  49. "# %pwd\n",
  50. "lines = input(\"Enter lines:\").split(\" \")\n",
  51. "lines = [l.strip() for l in lines if len(l.strip())>0]\n",
  52. "vars = []\n",
  53. "for l in lines:\n",
  54. " if '::' in l:\n",
  55. " vars.append(l.split('::')[1].strip())"
  56. ]
  57. },
  58. {
  59. "cell_type": "code",
  60. "execution_count": 8,
  61. "metadata": {},
  62. "outputs": [
  63. {
  64. "data": {
  65. "text/plain": [
  66. "'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'"
  67. ]
  68. },
  69. "execution_count": 8,
  70. "metadata": {},
  71. "output_type": "execute_result"
  72. }
  73. ],
  74. "source": [
  75. "import string\n",
  76. "string.ascii_letters"
  77. ]
  78. },
  79. {
  80. "cell_type": "code",
  81. "execution_count": 9,
  82. "metadata": {},
  83. "outputs": [
  84. {
  85. "name": "stdout",
  86. "output_type": "stream",
  87. "text": [
  88. "var: AnnularRegulatorSetControl\n",
  89. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  90. "Char before: \n",
  91. "Char after: \n",
  92. "\n",
  93. "var: AirMasterValve\n",
  94. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  95. "Char before: \n",
  96. "Char after: \n",
  97. "\n",
  98. "var: ByePassValve\n",
  99. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  100. "Char before: \n",
  101. "Char after: \n",
  102. "\n",
  103. "var: AnnularValve\n",
  104. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  105. "Char before: \n",
  106. "Char after: \n",
  107. "\n",
  108. "var: UpperRamsValve\n",
  109. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  110. "Char before: \n",
  111. "Char after: \n",
  112. "\n",
  113. "var: MiddleRamsValve\n",
  114. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  115. "Char before: \n",
  116. "Char after: \n",
  117. "\n",
  118. "var: KillLineValve\n",
  119. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  120. "Char before: \n",
  121. "Char after: \n",
  122. "\n",
  123. "var: ChokeLineValve\n",
  124. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  125. "Char before: \n",
  126. "Char after: \n",
  127. "\n",
  128. "var: LowerRamsValve\n",
  129. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  130. "Char before: \n",
  131. "Char after: \n",
  132. "\n",
  133. "var: ManifoldPressureGauge\n",
  134. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  135. "Char before: \n",
  136. "Char after: \n",
  137. "\n",
  138. "var: AirSupplyPressureGauge\n",
  139. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  140. "Char before: \n",
  141. "Char after: \n",
  142. "\n",
  143. "var: AccumulatorPressureGauge\n",
  144. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  145. "Char before: \n",
  146. "Char after: \n",
  147. "\n",
  148. "var: AnnularPressureGauge\n",
  149. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  150. "Char before: \n",
  151. "Char after: \n",
  152. "\n",
  153. "var: AnnularOpenLED\n",
  154. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  155. "Char before: \n",
  156. "Char after: \n",
  157. "\n",
  158. "var: AnnularCloseLED\n",
  159. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  160. "Char before: \n",
  161. "Char after: \n",
  162. "\n",
  163. "var: UpperRamsOpenLED\n",
  164. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  165. "Char before: \n",
  166. "Char after: \n",
  167. "\n",
  168. "var: UpperRamsCloseLED\n",
  169. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  170. "Char before: \n",
  171. "Char after: \n",
  172. "\n",
  173. "var: MiddleRamsOpenLED\n",
  174. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  175. "Char before: \n",
  176. "Char after: \n",
  177. "\n",
  178. "var: MiddleRamsCloseLED\n",
  179. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  180. "Char before: \n",
  181. "Char after: \n",
  182. "\n",
  183. "var: KillLineOpenLED\n",
  184. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  185. "Char before: \n",
  186. "Char after: \n",
  187. "\n",
  188. "var: KillLineCloseLED\n",
  189. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  190. "Char before: \n",
  191. "Char after: \n",
  192. "\n",
  193. "var: ChokeLineOpenLED\n",
  194. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  195. "Char before: \n",
  196. "Char after: \n",
  197. "\n",
  198. "var: ChokeLineCloseLED\n",
  199. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  200. "Char before: \n",
  201. "Char after: \n",
  202. "\n",
  203. "var: LowerRamsOpenLED\n",
  204. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  205. "Char before: \n",
  206. "Char after: \n",
  207. "\n",
  208. "var: LowerRamsCloseLED\n",
  209. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  210. "Char before: \n",
  211. "Char after: \n",
  212. "\n",
  213. "var: AnnularStatus\n",
  214. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  215. "Char before: \n",
  216. "Char after: \n",
  217. "\n",
  218. "var: UpperRamsStatus\n",
  219. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  220. "Char before: \n",
  221. "Char after: \n",
  222. "\n",
  223. "var: MiddleRamsStatus\n",
  224. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  225. "Char before: \n",
  226. "Char after: \n",
  227. "\n",
  228. "var: LowerRamsStatus\n",
  229. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  230. "Char before: \n",
  231. "Char after: \n",
  232. "\n"
  233. ]
  234. }
  235. ],
  236. "source": [
  237. "import os\n",
  238. "import sys\n",
  239. "import re\n",
  240. "dir = '.'\n",
  241. "varNameChars = string.ascii_letters + '_'\n",
  242. "log = open(os.path.join(dir,'ReplaceVars.log',),'a')\n",
  243. "end=False\n",
  244. "for dir,subdirs,files in os.walk(dir):\n",
  245. " for filename in files:\n",
  246. " if filename.lower().endswith('.f90'):\n",
  247. " # print(filename)\n",
  248. " file = open(os.path.join(dir,filename))\n",
  249. " code = file.read()\n",
  250. " for var in vars:\n",
  251. " if var not in code:\n",
  252. " continue\n",
  253. " occurs = [m.start() for m in re.finditer(var, code)]\n",
  254. " for occurance in occurs:\n",
  255. " if code[occurs[0]-1] in varNameChars or code[occurs[0]+len(var)] in varNameChars:\n",
  256. " continue\n",
  257. " print(f\"var: {var}\")\n",
  258. " print(f\"file = {os.path.join(dir,filename)}\")\n",
  259. " print(f\"Char before: {code[occurs[0]-1]}\")\n",
  260. " print(f\"Char after: {code[occurs[0]+len(var)]}\")\n",
  261. " end = True\n",
  262. " if end:\n",
  263. " break"
  264. ]
  265. },
  266. {
  267. "cell_type": "code",
  268. "execution_count": 3,
  269. "metadata": {},
  270. "outputs": [
  271. {
  272. "data": {
  273. "text/plain": [
  274. "('.',\n",
  275. " ['.git',\n",
  276. " '.vs',\n",
  277. " 'Common',\n",
  278. " 'CSharp',\n",
  279. " 'Equipments',\n",
  280. " 'FluidFlow',\n",
  281. " 'Geo',\n",
  282. " 'lib',\n",
  283. " 'Rop',\n",
  284. " 'TorqueDrag',\n",
  285. " 'x64'])"
  286. ]
  287. },
  288. "execution_count": 3,
  289. "metadata": {},
  290. "output_type": "execute_result"
  291. }
  292. ],
  293. "source": [
  294. "dir,subdirs"
  295. ]
  296. },
  297. {
  298. "cell_type": "code",
  299. "execution_count": null,
  300. "metadata": {},
  301. "outputs": [],
  302. "source": [
  303. "for fn in modules:\n",
  304. " f = open(fn)\n",
  305. " lines = f.readlines()\n",
  306. " module_filenames = {}\n",
  307. " used_modules = []\n",
  308. " mod_count = 0\n",
  309. " for l in lines:\n",
  310. " l = l.strip().lower()\n",
  311. " if l.startswith('module ') and not l.startswith('module procedure '):\n",
  312. " mod_name = l.split(' ')[1]\n",
  313. " module_filenames[mod_name] = fn\n",
  314. " mod_count +=1\n",
  315. " if l.startswith('use'):\n",
  316. " used_modules.append(l.split(' ')[1])\n",
  317. " if mod_count !=1:\n",
  318. " print(f\"{fn} has {mod_count} modules\")\n",
  319. " module_filenames,used_modules"
  320. ]
  321. }
  322. ],
  323. "metadata": {
  324. "kernelspec": {
  325. "display_name": "base",
  326. "language": "python",
  327. "name": "python3"
  328. },
  329. "language_info": {
  330. "codemirror_mode": {
  331. "name": "ipython",
  332. "version": 3
  333. },
  334. "file_extension": ".py",
  335. "mimetype": "text/x-python",
  336. "name": "python",
  337. "nbconvert_exporter": "python",
  338. "pygments_lexer": "ipython3",
  339. "version": "3.9.12"
  340. },
  341. "orig_nbformat": 4,
  342. "vscode": {
  343. "interpreter": {
  344. "hash": "1ef4a26de7183d96d6da1045a38581e0a15b2215d0c1b98c7b273c6e514c6c7e"
  345. }
  346. }
  347. },
  348. "nbformat": 4,
  349. "nbformat_minor": 2
  350. }