<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_header(self, out_strm, delim, f1_num_fields, f2_num_fields, f1_header=None, f2_header=None, missing_val=None):
 """ Write the header for a joined file. If headers are provided for one or more of the input files, then a header is generated for the output file. Otherwise, this does not output anything. :param out_strm: write to this stream :param delim: :param f1_num_fields: the number of columns in the first file :param f2_num_fields: the number of columns in the second file :param f1_header: :param f2_header: :param missing_val: """

    mm = f1_header != f2_header
    one_none = f1_header is None or f2_header is None
    if mm and one_none and missing_val is None:
      raise InvalidHeaderError("Cannot generate output header when one " +
                               "input file is missing a header and no " +
                               "missing value was provided to replace " +
                               "unknown entries.")

    if f1_header is not None and f2_header is not None:
      out_strm.write(delim.join(f1_header) + delim +
                     delim.join(f2_header) + "\n")
    elif f1_header is None and f2_header is not None:
      dummy_h = f1_num_fields * [missing_val]
      out_strm.write(delim.join(dummy_h) + delim +
                     delim.join(f2_header) + "\n")
    elif f1_header is not None and f2_header is None:
      dummy_h = f2_num_fields * [missing_val]
      out_strm.write(delim.join(f1_header) + delim +
                     delim.join(dummy_h) + "\n")