forked from tenko/feapy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck
More file actions
executable file
·107 lines (87 loc) · 3.71 KB
/
Copy pathcheck
File metadata and controls
executable file
·107 lines (87 loc) · 3.71 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
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# This file is part of feapy - See LICENSE.txt
#
import sys
import os
import re
import glob
import itertools
def strip(s):
return re.sub("\s+" , "", s)
def main(args):
log = open('check.log', 'w')
if len(args):
files = args
else:
files = glob.glob('*.inp')
for path in files:
isOK = True
filename = os.path.split(path)[-1]
casename = os.path.splitext(filename)[0]
# remove old files
for ext in ('.dat', '.frd', '.sec'):
if os.path.exists(casename + ext):
os.remove(casename + ext)
# solve case
print >>log, "Solving %s ..." % casename
os.system("../feapy %s" % casename)
# check if files are created
exts = []
hasFiles = False
for ext in ('.dat', '.frd', '.sec'):
if os.path.exists(casename + ext):
exts.append(ext)
if not exts:
isOK = False
print >>log, "%s : NO FILES CREATED" % casename
# check if content of files are similar
for ext in exts:
content = open(casename + ext).read()
ref = open(casename + ext + '.ref').read()
if strip(content) != strip(ref):
content = [line.rstrip() for line in open(casename + ext) if line.strip()]
ref = [line.rstrip() for line in open(casename + ext + '.ref') if line.strip()]
for test, correct in zip(content, ref):
if test.startswith(' 1UTIME') or test.startswith(' 1UDATE'):
continue
if test.startswith('** Date:') or test.startswith('** Time:'):
continue
if test != correct:
a = test.split()
b = correct.split()
if len(a) != len(b):
print >>log, "LINE :'%s'" % test
print >>log, "EXPECT:'%s'" % correct
isOK = False
break
for va, vb in zip(a, b):
try:
va = float(va)
except ValueError:
print >>log, "LINE :'%s'" % test
print >>log, "EXPECT:'%s'" % correct
isOK = False
break
try:
vb = float(vb)
except ValueError:
print >>log, "LINE :'%s'" % test
print >>log, "EXPECT:'%s'" % correct
isOK = False
break
diff = abs(va - vb)
if diff > 1e-10:
print >>log, "DEVIATION"
print >>log, "LINE :'%s'" % test
print >>log, "EXPECT:'%s'" % correct
args = va, vb, diff
print >>log, "abs(% 12.5E) - abs(% 12.5E) = % 12.5E" % args
isOK = False
if isOK:
print >>log, "%s OK\n" % casename
else:
print >>log, "%s FAILED\n" % casename
if __name__ == '__main__':
main(sys.argv[1:])