def dump_chk(filename, data):
with open(filename, '<STR_LIT:w>') as f:<EOL><INDENT>for key, value in sorted(data.items()):<EOL><INDENT>if not isinstance(key, str):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>if len(key) > <NUM_LIT>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if '<STR_LIT:\n>' in key:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if isinstance(value, str):<EOL><INDENT>if len(value) > <NUM_LIT>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if '<STR_LIT:\n>' in value:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>print('<STR_LIT>' % (key.ljust(<NUM_LIT>), value), file=f)<EOL><DEDENT>elif isinstance(value, bool):<EOL><INDENT>print('<STR_LIT>' % (key.ljust(<NUM_LIT>), value), file=f)<EOL><DEDENT>elif isinstance(value, (int, np.integer)):<EOL><INDENT>print('<STR_LIT>' % (key.ljust(<NUM_LIT>), value), file=f)<EOL><DEDENT>elif isinstance(value, float):<EOL><INDENT>print('<STR_LIT>' % (key.ljust(<NUM_LIT>), value), file=f)<EOL><DEDENT>elif isinstance(value, np.ndarray) or isinstance(value, list) orisinstance(value, tuple):<EOL><INDENT>if isinstance(value, list) or isinstance(value, tuple):<EOL><INDENT>value = np.array(value)<EOL><DEDENT>if value.dtype.fields is not None:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>shape_str = '<STR_LIT:U+002C>'.join(str(i) for i in value.shape)<EOL>if issubclass(value.dtype.type, (str, np.unicode, np.bytes_)):<EOL><INDENT>value = value.astype(np.unicode)<EOL>for cell in value.flat:<EOL><INDENT>if len(cell) >= <NUM_LIT>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if '<STR_LIT:U+0020>' in cell or '<STR_LIT:\n>' in cell:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>print('<STR_LIT>' % (key.ljust(<NUM_LIT>), shape_str), file=f)<EOL>format_str = '<STR_LIT>'<EOL><DEDENT>elif issubclass(value.dtype.type, np.integer):<EOL><INDENT>print('<STR_LIT>' % (key.ljust(<NUM_LIT>), shape_str), file=f)<EOL>format_str = '<STR_LIT>'<EOL><DEDENT>elif issubclass(value.dtype.type, np.bool_):<EOL><INDENT>print('<STR_LIT>' % (key.ljust(<NUM_LIT>), shape_str), file=f)<EOL>format_str = '<STR_LIT>'<EOL><DEDENT>elif issubclass(value.dtype.type, float):<EOL><INDENT>print('<STR_LIT>' % (key.ljust(<NUM_LIT>), shape_str), file=f)<EOL>format_str = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>raise TypeError('<STR_LIT>' % value.dtype.type)<EOL><DEDENT>short_len = <NUM_LIT:4><EOL>short = []<EOL>for x in value.ravel():<EOL><INDENT>short.append(x)<EOL>if len(short) == <NUM_LIT:4>:<EOL><INDENT>print('<STR_LIT:U+0020>'.join(format_str  % s for s in short), file=f)<EOL>short = []<EOL><DEDENT><DEDENT>if len(short) > <NUM_LIT:0>:<EOL><INDENT>print('<STR_LIT:U+0020>'.join(format_str  % s for s in short), file=f)<EOL><DEDENT><DEDENT>elif value is None:<EOL><INDENT>print('<STR_LIT>' % key.ljust(<NUM_LIT>), file=f)<EOL><DEDENT>else:<EOL><INDENT>raise TypeError('<STR_LIT>' % type(value))<EOL><DEDENT><DEDENT><DEDENT>
Dump a checkpoint file

       Argument:
        | filename  --  the file to write to
        | data  -- a dictionary whose keys are field labels and the values can
                   be None, string, integer, float, boolean, an array/list of
                   strings, integers, floats or booleans.

       The file format is similar to the Gaussian fchk format, but has the extra
       feature that the shapes of the arrays are also stored.