-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify_settings.py
121 lines (97 loc) · 3.67 KB
/
verify_settings.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import configparser
import os
def file_len(fname):
with open(fname) as f:
for i, l in enumerate(f):
pass
return i + 1
change = False
aux = True
config = configparser.ConfigParser()
config.optionxform=str
while (aux):
try:
config.read('settings.ini')
aux = False
except configparser.DuplicateSectionError as a:
print(a)
a = input("\nChange the settings file then enter to continue.\n")
pass
N = int(config['global']['N'].split()[0])
ntype = int(config['global']['Ntype'].split()[0])
quant = []
i = ntype
aux = True
while aux:
try:
quant.append(int(config['par_'+str(i)]['quantidade'].split()[0]))
print("Number of particle types greater then expected (ntype = {} but there is par_0 to par_{}).\n".format(ntype,i))
os.system('xdg-open settings.ini')
input("Fix the config file, then enter to continue...")
config.read('settings.ini')
# nty = input("Enter the right number of particle types.\n")
# i = int(nty)
# config.set('global','Ntype',nty)
except KeyError:
aux = False
pass
j = 0
aux = True
while aux:
try:
for i in range(ntype):
quant.append(int(config['par_'+str(i)]['quantidade'].split()[0]))
aux = False
except:
print("Number of particle types (ntype) smaller then expected. It maybe correct to proceed with ntype = {}".format(j))
os.system('xdg-open settings.ini')
input("Fix the config file, then enter to continue...")
config.read('settings.ini')
aux = True
while aux:
for i in range(ntype):
x_file = config['par_'+str(i)]['x'].split()[0]
x_file = x_file.replace("'","")
x_file = x_file.replace('"','')
if os.path.isfile(x_file):
q = int(config['par_'+str(i)]['quantidade'].split()[0])
if file_len(x_file) < q:
print('Number of particles in file smaller then expected.')
os.system('xdg-open settings.ini')
break
else:
aux = False
else:
print("Position file {} not found.".format(x_file))
os.system('xdg-open settings.ini')
input("Fix the config file, then enter to continue...")
config.read('settings.ini')
break
v_file = config['par_'+str(i)]['v_file'].split()[0]
v_file = v_file.replace("'","")
v_file = v_file.replace('"','')
if v_file[0] != '%':
if os.path.isfile(v_file):
q = config['par_'+str(i)]['quantidade'].split()[0]
if file_len(v_file) < int(q):
print('Number of particles in file smaller then expected.')
os.system('xdg-open settings.ini')
break
else:
aux = False
else:
print("Velocity file {} not found.".format(v_file))
os.system('xdg-open settings.ini')
input("Fix the config file, then enter to continue...")
config.read('settings.ini')
break
if sum(quant) != N:
print("The particle groups have a different number of particles then specified {}. \nIt should maybe be corrected to {}".format(N,sum(quant)))
os.system('xdg-open settings.ini')
input("Fix the config file, then enter to continue...")
config.read('settings.ini')
try:
from evtk.hl import pointsToVTK
except ModuleNotFoundError:
print("Evtk module not found! You will not be able to convert the .CSV files to .VTU. Try:\n")
print("conda install -c e3sm evtk OR\npip install pyevtk")