Line Code
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
import fileinput
import re

def index(line,substr):
    result = line.index(substr)
    return result

def errorPrint(line,indices):
    print(line.replace('\t',' '))
    ll = len(line)
    errstr=" "*ll
    for i in indices:
        errstr = errstr[:i] + '^-----' + errstr[i+5:]
    print(errstr)
    
def findValuesWithUnits(line,ln):
    numList = re.findall(r"\d*?[\s,.]?\d*\*\w*", line)
    errindices = []
    for match in re.finditer(r"\d*?[\s,.]?\d*\*\w*", line):
        errindices.append(match.start())
    l = len(numList)
    if l > 0:
        text = fileinput.filename()+': line# '+str(ln)+' units defined: '
        print(text)
        errorPrint(line,errindices)
    return l

def findIndices(line,strList):
    indices=[]
    for x in strList:
        idx = index(line,x)
        indices.append(idx)
    print(indices)
    return indices

def findValuesWithoutUnits(line,ln):
    numList = re.findall(r"\d+?[\s,.]?\d+[\s\"]", line)
    errindices = []
    for match in re.finditer(r"\d+?[\s,.]?\d+[\s\"]", line):
        errindices.append(match.start())
    l = len(numList)
    if l > 0:
        if 'MaterialFraction' in line:
            return l
        if '<?xml' in line:
            return l
        text = fileinput.filename()+': line# '+str(ln)+' warning: numerical value without units: '
        print(text)
        errorPrint(line,errindices)
    return l

def lineNumber(lookup):
    with open(fileinput.filename()) as myfile:
        for num, line in enumerate(myfile, 1):
            if lookup in line:
                return num
    
def process(line):
    ln = lineNumber(line)
    l = findValuesWithUnits(line,ln)
    k = findValuesWithoutUnits(line,ln)

def check(line):
    return 0;

for line in fileinput.input():
    check(line)

with open(fileinput.filename()) as myfile:
    for num, line in enumerate(myfile, 1):
        process(line)