def record_add_fields(rec, tag, fields, field_position_local=None,<EOL>field_position_global=None):
if field_position_local is None and field_position_global is None:<EOL><INDENT>for field in fields:<EOL><INDENT>record_add_field(<EOL>rec, tag, ind1=field[<NUM_LIT:1>],<EOL>ind2=field[<NUM_LIT:2>], subfields=field[<NUM_LIT:0>],<EOL>controlfield_value=field[<NUM_LIT:3>])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>fields.reverse()<EOL>for field in fields:<EOL><INDENT>record_add_field(<EOL>rec, tag, ind1=field[<NUM_LIT:1>], ind2=field[<NUM_LIT:2>],<EOL>subfields=field[<NUM_LIT:0>], controlfield_value=field[<NUM_LIT:3>],<EOL>field_position_local=field_position_local,<EOL>field_position_global=field_position_global)<EOL><DEDENT><DEDENT>return field_position_local<EOL>
Add the fields into the record at the required position.

The position is specified by the tag and the field_position_local in the
list of fields.

:param rec: a record structure
:param tag: the tag of the fields to be moved
:param field_position_local: the field_position_local to which the field
                             will be inserted. If not specified, appends
                             the fields to the tag.
:param a: list of fields to be added
:return: -1 if the operation failed, or the field_position_local if it was
         successful