-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathslashcomment.py
More file actions
executable file
·280 lines (239 loc) · 6.15 KB
/
slashcomment.py
File metadata and controls
executable file
·280 lines (239 loc) · 6.15 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/usr/bin/env python
## EPlusInterface (EPI) - An interface for EnergyPlus
## Copyright (C) 2004 Santosh Philip
##
# This file is part of EPlusInterface.
# =======================================================================
# Distributed under the MIT License.
# (See accompanying file LICENSE or copy at
# http://opensource.org/licenses/MIT)
# =======================================================================
# VERSION: 0.2
import sys
import getopt
import os
import string
import user
sys.path.append(user.home+'/Library/PythonFiles')
import mylib1,mylib2,mylib3
import eplus2,time
import parse_idd
# block,commlst,commdct=parse_idd.extractidddata('./Energy+.idd')
#
# cm=commdct[3]
# cmm=cm[0]
def printcdt(i):
for el in comm[i]:
print el
# commtype=['field', 'note', 'required-field', 'units', 'ip-units', 'minimum',
# 'minimum>', 'maximum', 'maximum<', 'default', 'autosizable', 'type',
# 'key', 'object-list', 'reference',
# 'memo', 'unique-object', 'required-object', 'min-fields',
# 'obsolete', 'extensible',
# 'group']
class slashcomment:
def __init__(self):
self.allkeys=['field', 'note', 'required-field', 'units', 'ip-units', 'minimum',
'minimum>', 'maximum', 'maximum<', 'default', 'autosizable', 'type',
'key', 'object-list', 'reference',
'memo', 'unique-object', 'required-object', 'min-fields',
'obsolete', 'extensible',
'group']
self.commentnow={
'default': ['4'],
'maximum': ['6'],
'required-field': [''],
'note': [
'Number in hour: validity 1 to 6: 4 suggested',
'Should be evenly divisible into 60',
'Specifying 6 as maximum as higher values may cause instability.'],
'field': ['Time Step in Hour'],
'minimum': ['1'],
'type': ['integer']}
def keyshere(self,cmm):
ls=[]
for el in self.allkeys:
if cmm.has_key(el):
ls.append(el)
return ls
def checkNumber(num):
"""
check if num is a number
and raise an error
"""
try:
return float(num)
except:
raise "anError", "%s is not a real"%(num)
def checkInteger(num):
"""
check if num is an integer
and raise an error
"""
try:
return int(num)
except:
raise "anError", "%s is not an integer"%(num)
def getobjectindex(blocklst,object):
"""
getobjectindex(blocklst,'SOLUTION ALGORITHM')
returns the index of the object
corresponding slashcomments can be retrived using this index
"""
ls=[]
for el in blocklst:
ls.append(el[0].upper())
return ls.index(object.upper())
def getrepeats():
"""
no docs -
I used it for debugging
to find how many items had 'field' in more than one line
"""
key='reference'
for i in range(len(commdct)):
for j in range(len(commdct[i])):
try:
val=commdct[i][j][key]
if len(val)>1:
print commdct[i][j]
print i,j,'====',len(val)
except:
pass
def checkVal(val,commentdct=None):
"""
raise an error if the value does not fall into
the description of commentdct
"""
# check autosizable
# check type - real, integer
# check min max min> max<
# check key
# check object-list
error="anError"
#check on autosize - return if value is autosize
if commentdct.has_key('autosizable'):
print 'autosizeable'
if val=='autosize':
return
#check type - initially check number
keyval=getkeyval('type',commentdct)
if keyval!=None:
if keyval.upper()=='real'.upper():
val=checkNumber(val)
if keyval!=None:
if keyval.upper()=='integer'.upper():
val=checkInteger(val)
# check min max min> max<
keyval=getkeyval('minimum',commentdct)
if keyval!=None:
if not val>=keyval:
raise error, "value should be greater than or equal to %s"%(keyval)
keyval=getkeyval('minimum>',commentdct)
if keyval!=None:
if not val>keyval:
raise error, "value should be greater than %s"%(keyval)
keyval=getkeyval('maximum',commentdct)
if keyval!=None:
if not val<=keyval:
raise error, "value should be less than or equal to %s"%(keyval)
keyval=getkeyval('maximum<',commentdct)
if keyval!=None:
if not val<keyval:
raise error, "value should be less than%s"%(keyval)
# check key
keyval=getkeyval('key',commentdct)
if keyval!=None:
try:
keyval.index(val)
except:
raise "anError", "%s is not in list" %(val,)
def getkeyval(key,commentdct):
"""
returns the value of the key
commentdct can be {'default': ['4'], 'maximum': ['6'], 'required-field': [''],
'note':['this is', ' a note']}
now key='default' will return the number 4
key='note' will return 'this is\\n a note'
"""
#--------minimum, minimum>, maximum, maximum<, min-fields----------
#returns the number or None
if key.upper() in [
'minimum'.upper(),
'minimum>'.upper(),
'maximum'.upper(),
'maximum<'.upper(),
'min-fields'.upper()]:
try:
val=commentdct[key][0]
return float(val)
except KeyError:
return None
#--------field, note, units, ip-units,
# default, type, object-list, memo----------
#returns the value or None
if key.upper() in [
'field'.upper(),
'note'.upper(),
'units'.upper(),
'ip-units'.upper(),
'default'.upper(),
'type'.upper(),
'object-list'.upper(),
'memo'.upper()]:
try:
val=commentdct[key]
st=''
for el in val:
st=st+el+'\n'
st=st[:-1]
except KeyError:
return None
return st
#--------required-field, autosizable, unique-object, required-object----------
#returns True or False
if key.upper()in [
'required-field'.upper(),
'autosizable'.upper(),
'unique-object'.upper(),
'required-object'.upper()]:
return commentdct.has_key(key)
#--------key, reference----------
#returns a list
if key.upper()in [
'key'.upper(),
'reference'.upper()]:
try:
return commentdct[key]
except KeyError:
return None
#key var -> to run getkeyval
# i=7
# j=0
# print block[i], block[i][j]
# cm=commdct[i]
# key='memo'
# print getkeyval(key,cm[j])
# block,commlst,commdct=parse_idd.extractidddata('./Energy+.idd')
# commentdct={
# 'units': ['deltaC'],
# 'field': ['Temperature Convergence Tolerance Value'],
# 'minimum>': ['0.0'],
# 'type': ['real'], 'default': ['.4']}
#
#
#
# checkVal(-5,commentdct)
#
#
# try:
# checkVal(-2,commentdct)
# except "anError",d:
# print d
#
#
# try:
# checkNumber('a')
# except "anError",d:
# print d
#