Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- 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()