<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def wr_header_file(self, rec_write_fields, sig_write_fields, write_dir):
 """ Write a header file using the specified fields. Converts Record attributes into appropriate wfdb format strings. Parameters rec_write_fields : list List of record specification fields to write sig_write_fields : dict Dictionary of signal specification fields to write, values being equal to a list of channels to write for each field. write_dir : str The directory in which to write the header file """

        # Create record specification line
        record_line = ''
        # Traverse the ordered dictionary
        for field in RECORD_SPECS.index:
            # If the field is being used, add it with its delimiter
            if field in rec_write_fields:
                string_field = str(getattr(self, field))

                # Certain fields need extra processing

                if field == 'fs' and isinstance(self.fs, float):
                    if round(self.fs, 8) == float(int(self.fs)):
                        string_field = str(int(self.fs))
                elif field == 'base_time' and '.' in string_field:
                    string_field = string_field.rstrip('0')
                elif field == 'base_date':
                    string_field = '/'.join((string_field[8:],
                                             string_field[5:7],
                                             string_field[:4]))

                record_line += RECORD_SPECS.loc[field, 'delimiter'] + string_field
                # The 'base_counter' field needs to be closed with ')'
                if field == 'base_counter':
                    record_line += ')'

        header_lines = [record_line]

        # Create signal specification lines (if any) one channel at a time
        if self.n_sig > 0:
            signal_lines = self.n_sig * ['']
            for ch in range(self.n_sig):
                # Traverse the signal fields
                for field in SIGNAL_SPECS.index:
                    # If the field is being used, add each of its
                    # elements with the delimiter to the appropriate
                    # line
                    if field in sig_write_fields and ch in sig_write_fields[field]:
                        signal_lines[ch] += SIGNAL_SPECS.loc[field, 'delimiter'] + str(getattr(self, field)[ch])
                    # The 'baseline' field needs to be closed with ')'
                    if field == 'baseline':
                        signal_lines[ch] += ')'

            header_lines += signal_lines

        # Create comment lines (if any)
        if 'comments' in rec_write_fields:
            comment_lines = ['# ' + comment for comment in self.comments]
            header_lines += comment_lines

        lines_to_file(self.record_name + '.hea', write_dir, header_lines)