File indexing completed on 2024-04-06 12:05:30
0001 import fileinput
0002 import re
0003
0004 def index(line,substr):
0005 result = line.index(substr)
0006 return result
0007
0008 def errorPrint(line,indices):
0009 print(line.replace('\t',' '))
0010 ll = len(line)
0011 errstr=" "*ll
0012 for i in indices:
0013 errstr = errstr[:i] + '^-----' + errstr[i+5:]
0014 print(errstr)
0015
0016 def findValuesWithUnits(line,ln):
0017 numList = re.findall(r"\d*?[\s,.]?\d*\*\w*", line)
0018 errindices = []
0019 for match in re.finditer(r"\d*?[\s,.]?\d*\*\w*", line):
0020 errindices.append(match.start())
0021 l = len(numList)
0022 if l > 0:
0023 text = fileinput.filename()+': line# '+str(ln)+' units defined: '
0024 print(text)
0025 errorPrint(line,errindices)
0026 return l
0027
0028 def findIndices(line,strList):
0029 indices=[]
0030 for x in strList:
0031 idx = index(line,x)
0032 indices.append(idx)
0033 print(indices)
0034 return indices
0035
0036 def findValuesWithoutUnits(line,ln):
0037 numList = re.findall(r"\d+?[\s,.]?\d+[\s\"]", line)
0038 errindices = []
0039 for match in re.finditer(r"\d+?[\s,.]?\d+[\s\"]", line):
0040 errindices.append(match.start())
0041 l = len(numList)
0042 if l > 0:
0043 if 'MaterialFraction' in line:
0044 return l
0045 if '<?xml' in line:
0046 return l
0047 text = fileinput.filename()+': line# '+str(ln)+' warning: numerical value without units: '
0048 print(text)
0049 errorPrint(line,errindices)
0050 return l
0051
0052 def lineNumber(lookup):
0053 with open(fileinput.filename()) as myfile:
0054 for num, line in enumerate(myfile, 1):
0055 if lookup in line:
0056 return num
0057
0058 def process(line):
0059 ln = lineNumber(line)
0060 l = findValuesWithUnits(line,ln)
0061 k = findValuesWithoutUnits(line,ln)
0062
0063 def check(line):
0064 return 0;
0065
0066 for line in fileinput.input():
0067 check(line)
0068
0069 with open(fileinput.filename()) as myfile:
0070 for num, line in enumerate(myfile, 1):
0071 process(line)
0072
0073