Skip to content

Commit

Permalink
Merge branch 'splitModuleRoutineFile'
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienRietteMTO committed Nov 4, 2024
2 parents a0b498b + cf0589e commit d6a1668
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ in compute statement for optimization issue.

**--buildModi** Builds the corresponding modi_ file

**--splitModuleRoutineFile** Splits a file into several ones (one file per scope)

### OpenACC

**--addACCData** add !$acc data present and !$acc end data directives
Expand Down
13 changes: 13 additions & 0 deletions src/pyft/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ class Applications():
Methods for high-to-moderate level transformation
"""

@debugDecor
def splitModuleRoutineFile(self):
"""
Split all module and subroutine contain in a fortran file
Return a fortran file for each module and subroutine
"""
for scope in self.getScopes(level=1, excludeContains=False, includeItself=True):
with pyft.pyft.generateEmptyPYFT(scope.path.split(":")[1].lower() + ".F90") as file:
file.extend(scope.findall('./{*}*'))
if file[-1].tail is None:
file[-1].tail = '\n'
file.write()

@debugDecor
def buildModi(self):
"""
Expand Down
12 changes: 12 additions & 0 deletions src/pyft/pyft.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ def unlockFile(cls, filename, silence=False):
if not silence:
raise

def __enter__(self):
"""
Context manager
"""
return self

def __exit__(self, excType, excVal, excTb):
"""
Context manager
"""
self.close()

def close(self):
"""
Closes the FORTRAN file
Expand Down
4 changes: 2 additions & 2 deletions src/pyft/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ def append(self, *args, **kwargs):
https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element.append
"""
# Append after the 'END SUBROUTINE' statement
raise self._xml.append(*args, **kwargs)
return self._xml.append(*args, **kwargs)

def extend(self, *args, **kwargs):
"""
https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element.extend
"""
# Extend after the 'END SUBROUTINE' statement
raise self._xml.extend(*args, **kwargs)
return self._xml.extend(*args, **kwargs)

def _getIndex(self, index):
"""
Expand Down
4 changes: 4 additions & 0 deletions src/pyft/scripting.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ def updateParserApplications(parser):
gApplications.add_argument('--deleteRoutineCallsMesoNHGPU', default=False, action='store_true',
help='Delete parts of the code not compatible with MesoNH-OpenACC' +
'such as OCND2 blocks')
gApplications.add_argument('--splitModuleRoutineFile', default=False, action='store_true',
help='Split a file')
gApplications.add_argument('--deleteNonColumnCallsPHYEX', default=False, action='store_true',
help='Delete call to PHYEX routines that needs information on ' +
'horizontal points (multiple column dependency')
Expand Down Expand Up @@ -825,6 +827,8 @@ def applyTransfoApplications(pft, arg, args, simplify, parserOptions, stopScopes
pft.convertTypesInCompute()
elif arg == '--buildModi':
pft.buildModi()
elif arg == '--splitModuleRoutineFile':
pft.splitModuleRoutineFile()


def applyTransfoOpenACC(pft, arg, args, stopScopes): # pylint: disable=unused-argument
Expand Down

0 comments on commit d6a1668

Please sign in to comment.