def determine_tool(filepath, tool_to_get):
file_regexp_reader_writer = {<EOL>"<STR_LIT>": {"<STR_LIT>": r"<STR_LIT>", "<STR_LIT>": _ScenReader, "<STR_LIT>": _ScenWriter},<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": _Scen7Reader,<EOL>"<STR_LIT>": _Scen7Writer,<EOL>},<EOL>"<STR_LIT>": {"<STR_LIT>": r"<STR_LIT>", "<STR_LIT>": _PrnReader, "<STR_LIT>": _PrnWriter},<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": _HistEmisInReader,<EOL>"<STR_LIT>": _HistEmisInWriter,<EOL>},<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": _ConcInReader,<EOL>"<STR_LIT>": _ConcInWriter,<EOL>},<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": _OpticalThicknessInReader,<EOL>"<STR_LIT>": _OpticalThicknessInWriter,<EOL>},<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": _RadiativeForcingInReader,<EOL>"<STR_LIT>": _RadiativeForcingInWriter,<EOL>},<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": _SurfaceTemperatureInReader,<EOL>"<STR_LIT>": _SurfaceTemperatureInWriter,<EOL>},<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": _OutReader,<EOL>"<STR_LIT>": None,<EOL>},<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": _EmisOutReader,<EOL>"<STR_LIT>": None,<EOL>},<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": _InverseEmisReader,<EOL>"<STR_LIT>": None,<EOL>},<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": _TempOceanLayersOutReader,<EOL>"<STR_LIT>": None,<EOL>},<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": r"<STR_LIT>",<EOL>"<STR_LIT>": _BinaryOutReader,<EOL>"<STR_LIT>": None,<EOL>},<EOL>"<STR_LIT>": {"<STR_LIT>": r"<STR_LIT>", "<STR_LIT>": _RCPDatReader, "<STR_LIT>": None}<EOL>}<EOL>fbase = basename(filepath)<EOL>if _unsupported_file(fbase):<EOL><INDENT>raise NoReaderWriterError(<EOL>"<STR_LIT>".format(<EOL>filepath<EOL>)<EOL>)<EOL><DEDENT>for file_type, file_tools in file_regexp_reader_writer.items():<EOL><INDENT>if re.match(file_tools["<STR_LIT>"], fbase):<EOL><INDENT>try:<EOL><INDENT>return file_tools[tool_to_get]<EOL><DEDENT>except KeyError:<EOL><INDENT>valid_tools = [k for k in file_tools.keys() if k != "<STR_LIT>"]<EOL>error_msg = (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(tool_to_get, valid_tools)<EOL>)<EOL>raise KeyError(error_msg)<EOL><DEDENT><DEDENT><DEDENT>para_file = "<STR_LIT>"<EOL>if (filepath.endswith("<STR_LIT>")) and (tool_to_get == "<STR_LIT>"):<EOL><INDENT>error_msg = (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(filepath)<EOL>)<EOL><DEDENT>elif (filepath.endswith(para_file)) and (tool_to_get == "<STR_LIT>"):<EOL><INDENT>error_msg = (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>else:<EOL><INDENT>regexp_list_str = "<STR_LIT:\n>".join(<EOL>[<EOL>"<STR_LIT>".format(k, v["<STR_LIT>"])<EOL>for k, v in file_regexp_reader_writer.items()<EOL>]<EOL>)<EOL>error_msg = (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(tool_to_get, fbase, regexp_list_str)<EOL>)<EOL><DEDENT>raise NoReaderWriterError(error_msg)<EOL>
Determine the tool to use for reading/writing.

The function uses an internally defined set of mappings between filepaths,
regular expresions and readers/writers to work out which tool to use
for a given task, given the filepath.

It is intended for internal use only, but is public because of its
importance to the input/output of pymagicc.

If it fails, it will give clear error messages about why and what the
available regular expressions are.

.. code:: python

    >>> mdata = MAGICCData()
    >>> mdata.read(MAGICC7_DIR, HISTRCP_CO2I_EMIS.txt)
    ValueError: Couldn't find appropriate writer for HISTRCP_CO2I_EMIS.txt.
    The file must be one of the following types and the filepath must match its corresponding regular expression:
    SCEN: ^.*\\.SCEN$
    SCEN7: ^.*\\.SCEN7$
    prn: ^.*\\.prn$

Parameters
----------
filepath : str
    Name of the file to read/write, including extension
tool_to_get : str
    The tool to get, valid options are "reader", "writer".
    Invalid values will throw a NoReaderWriterError.