Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Méso-NH code
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Méso-NH
Méso-NH code
Commits
e8babd1d
Unverified
Commit
e8babd1d
authored
2 years ago
by
QuentinRodier
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Quentin 30/03/2022: add first try of fortran indentation parser
parent
858cf0e0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mnh_expand/parser_fortran_python.py
+49
-0
49 additions, 0 deletions
mnh_expand/parser_fortran_python.py
with
49 additions
and
0 deletions
mnh_expand/parser_fortran_python.py
0 → 100644
+
49
−
0
View file @
e8babd1d
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 30 22:32:56 2022
@author: Quentin
"""
def
count_blank
(
text
):
count
=
0
for
t
in
text
:
if
t
==
"
"
:
count
=
count
+
1
else
:
break
return
count
def
check_indent
(
n
,
indent_score
,
worktext
):
nblank
=
count_blank
(
worktext
)
rawtext
=
worktext
[
nblank
:]
correcttext
=
'
'
*
((
indent_score
)
*
1
)
+
rawtext
return
correcttext
filein
=
open
(
'
mode_tke_eps_sources.f90
'
,
'
r
'
)
fileout
=
open
(
'
new.F90
'
,
'
w
'
)
contentbyline
=
filein
.
readlines
()
ncurrline
=
0
indent_score
=
0
for
i
in
contentbyline
:
#Si la ligne est un commentaire (commence par !) : next (ne pas indenter)
#
# ligne de calcul sans ajout d'indentation (DO, ENDDDO, IF, ENDIF)
if
indent_score
>
0
and
(
"
DO J
"
not
in
i
and
"
ENDDO
"
not
in
i
):
textwrite
=
check_indent
(
ncurrline
,
indent_score
,
i
)
elif
"
DO J
"
in
i
:
textwrite
=
check_indent
(
ncurrline
,
indent_score
,
i
)
indent_score
=
indent_score
+
1
elif
"
ENDDO
"
in
i
:
indent_score
=
indent_score
-
1
textwrite
=
check_indent
(
ncurrline
,
indent_score
,
i
)
#Ajouter le case IF et ENDIF qui ajoute de lindentation
else
:
textwrite
=
i
ncurrline
=
ncurrline
+
1
fileout
.
writelines
(
textwrite
)
fileout
.
close
()
filein
.
close
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment