summaryrefslogtreecommitdiff
path: root/script/make_depend_py3.py
diff options
context:
space:
mode:
authorstainer_t <thomas.stainer@oecd-nea.org>2025-09-08 13:48:49 +0200
committerstainer_t <thomas.stainer@oecd-nea.org>2025-09-08 13:48:49 +0200
commit7dfcc480ba1e19bd3232349fc733caef94034292 (patch)
tree03ee104eb8846d5cc1a981d267687a729185d3f3 /script/make_depend_py3.py
Initial commit from Polytechnique Montreal
Diffstat (limited to 'script/make_depend_py3.py')
-rwxr-xr-xscript/make_depend_py3.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/script/make_depend_py3.py b/script/make_depend_py3.py
new file mode 100755
index 0000000..a47d7fb
--- /dev/null
+++ b/script/make_depend_py3.py
@@ -0,0 +1,58 @@
+#!/bin/env python3
+""" generation of module dependances for a xxx.f90 or xxx.F90 file """
+
+import string,sys
+from subprocess import Popen, PIPE
+
+def noComment(mot):
+ """ remove comment characters in a word """
+ ind= mot.find('!')
+ if ind != -1:
+ mot= mot[:ind]
+ return mot
+
+class md9:
+ """ a file, its module and its dependances """
+ def __init__(self,fic):
+ self.name= fic
+ self.used= []
+ #find all module dependances
+ listeLignes= open(self.name,'r',encoding='utf8',errors='ignore').readlines()
+ self.module= "dummy"
+ for ligne in listeLignes:
+ ligne= ligne.lower()
+ if ligne.count('use'):
+ ligne= ligne.replace(',',' ')
+ listeMots= ligne.split()
+ if listeMots[0] == 'use':
+ mod= noComment(listeMots[1])
+ if mod not in self.used and mod != 'intrinsic':
+ self.used.append(mod)
+ elif ligne.count('module'):
+ listeMots= ligne.split()
+ if listeMots[0] == 'module' and \
+ noComment(listeMots[1]) != 'procedure':
+ self.module= listeMots[1]
+ def utilise(self,other):
+ return (other.module in self.used)
+
+#list the file names
+listeClasse= list()
+for x in sys.argv[1:]:
+ if x.endswith('.f90') or x.endswith('.F90'): listeClasse.append(md9(x))
+#sort the file list
+listeRes= []
+while listeClasse:
+ lgav= len(listeClasse)
+ for fic in listeClasse:
+ if len(list(filter(lambda x,y=fic:y.utilise(x),listeClasse))) == 0:
+ listeRes.append(fic)
+ listeClasse.remove(fic)
+ lgap= len(listeClasse)
+ if lgav == lgap and lgap != 0:
+ raise RuntimeError("make_depend: cross-references found")
+#result output
+resstr=''
+for fic in listeRes:
+ resstr=resstr+fic.name+' '
+print(resstr)