This repository was archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathcactus_element_file.py
107 lines (86 loc) · 2.98 KB
/
cactus_element_file.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
import numpy as np
import pandas as pd
import os
try:
from .file import File, WrongFormatError, BrokenFormatError
except:
EmptyFileError = type('EmptyFileError', (Exception,),{})
WrongFormatError = type('WrongFormatError', (Exception,),{})
BrokenFormatError = type('BrokenFormatError', (Exception,),{})
File=dict
class CactusElementFile(File):
@staticmethod
def defaultExtensions():
return ['.in']
@staticmethod
def formatName():
return 'CACTUS file'
def __init__(self,filename=None,**kwargs):
self.filename = filename
if filename:
self.read(**kwargs)
def read(self, filename=None, **kwargs):
""" read self, or read filename if provided """
if filename:
self.filename = filename
if not self.filename:
raise Exception('No filename provided')
if not os.path.isfile(self.filename):
raise OSError(2,'File not found:',self.filename)
if os.stat(self.filename).st_size == 0:
raise EmptyFileError('File is empty:',self.filename)
# Calling children function
self._read(**kwargs)
def write(self, filename=None):
""" write self, or to filename if provided """
if filename:
self.filename = filename
if not self.filename:
raise Exception('No filename provided')
# Calling children function
self._write()
def _read(self):
""" """
import f90nml
from .csv_file import CSVFile
filepath = self.filename
basepath = '_'.join(filepath.split('_')[:-1])
basename = os.path.basename(basepath)
parentdir = os.path.dirname(basepath)
mainfile = parentdir[:-6]+basename+'.in'
print(basename)
print(basepath)
print(parentdir)
print(mainfile)
print(os.path.dirname(basepath))
# elemfile=
# if len(df.columns)!=len(cols):
# print('column for rename:',cols)
# print('columns in file :',df.columns)
# print(len(df.columns))
# print(len(cols))
# raise Exception('Problem with number of columns')
# df.columns=cols
#
# # --- Read elem
# elemfile = f.replace('TimeData','ElementData')
# dsfile = f.replace('TimeData','DSData')
# dfElem = weio.read(elemfile).toDataFrame()
#with open(self.filename, 'r', errors="surrogateescape") as f:
# for i, line in enumerate(f):
# data.append(line)
def _write(self):
""" """
with open(self.filename,'w') as f:
f.write(self.toString)
def toDataFrame(self):
#cols=['Alpha_[deg]','Cl_[-]','Cd_[-]','Cm_[-]']
#dfs[name] = pd.DataFrame(data=..., columns=cols)
#df=pd.DataFrame(data=,columns=)
return
def toString(self):
s=''
return s
def __repr__(self):
s ='Class XXXX (attributes: data)\n'
return s