from typing import OrderedDict


def readStateFile(filename):
    """Reads VIC initial state file."""
    state = OrderedDict()
    with open(filename) as fin:
        dateline = fin.readline()
        nlayer, nnodes = map(int, fin.readline().split())
        lines = fin.readlines()
        c = 0
        while c < len(lines):
            cell = lines[c].split()
            cellid, nveg, nbands = map(int, cell[:3])
            # state[cellid] = lines[c:c+(nveg+1)*nbands+nveg+2]
            # c = c + (nveg + 1)*nbands + nveg + 2
            state[cellid] = lines[c:c + (nveg + 1) * nbands + 1]
            c = c + (nveg + 1) * nbands + 1
    return state, nlayer, nnodes, dateline