def transfer_keyvar(self, key, field, occurrence=1, rowoffset=0):
        """Searches for a key relative to the current anchor and then grabs
        a field from that line.

        field: integer
            Which field to transfer. Field 0 is the key.

        occurrence: integer
            Find nth instance of text; default is 1 (first value
            field). Use -1 to find last occurance. Position 0 is the key
            field, so it should not be used as a value for occurrence.

        rowoffset: integer (optional)
            Optional row offset from the occurrence of key. This can
            also be negative.

        You can do the same thing with a call to ``mark_anchor`` and ``transfer_var``.
        This function just combines them for convenience."""

        if not isinstance(occurrence, int) or occurrence==0:
            msg = "The value for occurrence must be a nonzero integer"
            raise ValueError(msg)

        instance = 0
        if occurrence > 0:
            row = 0
            for line in self.data[self.current_row:]:
                if line.find(key) > -1:
                    instance += 1
                    if instance == occurrence:
                        break

                row += 1

        elif occurrence < 0:
            row = -1
            for line in reversed(self.data[self.current_row:]):
                if line.find(key) > -1:
                    instance += -1
                    if instance == occurrence:
                        break

                row -= 1

        j = self.current_row + row + rowoffset
        line = self.data[j]

        fields = self._parse_line().parseString(line.replace(key,"KeyField"))

        return fields[field]
dataset/ETHPy150Open OpenMDAO/OpenMDAO-Framework/openmdao.util/src/openmdao/util/filewrap.py/FileParser.transfer_keyvar/original