-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfoamToCSVVector.py
More file actions
63 lines (45 loc) · 1.32 KB
/
foamToCSVVector.py
File metadata and controls
63 lines (45 loc) · 1.32 KB
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
#!/usr/bin/python
"""
This function offers a simple way to convert the results file from FOAM format to CSV one.
It will erase the strings which start with a word.
How to use it: Run as python foamToCSV.py time/field fileoutput
i.e. python foamToCSVVector.py 0/U U
Warning: It works only on reconstructed file
Warning: it will erase also the first numerical line
Tested with Python 2.7.16
"""
import os
import sys
version=1
subversion=0
if sys.argv[1]=='-help':
print("Version "+str(version)+"."+str(subversion))
print("-version for version number")
print("-help to run the help")
print("Run as python foamToCSV.py time/field fileoutput")
print("WARNING: It doesn't work with vector fields")
if sys.argv[1]=='-version':
print("Version "+str(version)+"."+str(subversion))
def read_file(file_name):
with open(file_name) as f:
content = f.readlines()
f.close()
return content
def foamToCSVVector(file_name,filename_out):
file_contents = read_file(file_name)
temp = open(filename_out, 'w')
with open(file_name, 'r') as f:
flag=False
for line in file_contents:
if line.startswith("(") and flag:
temp.write(line)
if line.startswith("("):
flag=True
else:
flag=False
temp.close()
f.close()
return
file_name = sys.argv[1]
filename_out = sys.argv[2]
foamToCSVVector(file_name, filename_out)