generate a Pst instance from the model io files.  If 'inschek'
    is available (either in the current directory or registered
    with the system variables) and the model output files are available
    , then the observation values in the control file will be set to the
    values of the model-simulated equivalents to observations.  This can be
    useful for testing

    Parameters
    ----------
    tpl_files : list
        list of pest template files
    in_files : list
        list of corresponding model input files
    ins_files : list
        list of pest instruction files
    out_files: list
        list of corresponding model output files
    pst_filename : str
        name of file to write the control file to.  If None,
        control file is not written.  Default is None

    Returns
    -------
    pst : pyemu.Pst


    Example
    -------
    ``>>>import pyemu``

    this will construct a new Pst instance from template and instruction files
    found in the current directory, assuming that the naming convention follows
    that listed in parse_dir_for_io_files()

    ``>>>pst = pyemu.helpers.pst_from_io_files(*pyemu.helpers.parse_dir_for_io_files('.'))``

def pst_from_io_files(tpl_files,in_files,ins_files,out_files,pst_filename=None):
    """generate a Pst instance from the model io files.  If 'inschek'
    is available (either in the current directory or registered
    with the system variables) and the model output files are available
    , then the observation values in the control file will be set to the
    values of the model-simulated equivalents to observations.  This can be
    useful for testing

    Parameters
    ----------
    tpl_files : list
        list of pest template files
    in_files : list
        list of corresponding model input files
    ins_files : list
        list of pest instruction files
    out_files: list
        list of corresponding model output files
    pst_filename : str
        name of file to write the control file to.  If None,
        control file is not written.  Default is None

    Returns
    -------
    pst : pyemu.Pst


    Example
    -------
    ``>>>import pyemu``

    this will construct a new Pst instance from template and instruction files
    found in the current directory, assuming that the naming convention follows
    that listed in parse_dir_for_io_files()

    ``>>>pst = pyemu.helpers.pst_from_io_files(*pyemu.helpers.parse_dir_for_io_files('.'))``

    """
    par_names = set()
    if not isinstance(tpl_files,list):
        tpl_files = [tpl_files]
    if not isinstance(in_files,list):
        in_files = [in_files]
    assert len(in_files) == len(tpl_files),"len(in_files) != len(tpl_files)"

    for tpl_file in tpl_files:
        assert os.path.exists(tpl_file),"template file not found: "+str(tpl_file)
        #new_names = [name for name in pyemu.pst_utils.parse_tpl_file(tpl_file) if name not in par_names]
        #par_names.extend(new_names)
        new_names = pyemu.pst_utils.parse_tpl_file(tpl_file)
        par_names.update(new_names)

    if not isinstance(ins_files,list):
        ins_files = [ins_files]
    if not isinstance(out_files,list):
        out_files = [out_files]
    assert len(ins_files) == len(out_files),"len(out_files) != len(out_files)"


    obs_names = []
    for ins_file in ins_files:
        assert os.path.exists(ins_file),"instruction file not found: "+str(ins_file)
        obs_names.extend(pyemu.pst_utils.parse_ins_file(ins_file))

    new_pst = pyemu.pst_utils.generic_pst(list(par_names),list(obs_names))

    new_pst.template_files = tpl_files
    new_pst.input_files = in_files
    new_pst.instruction_files = ins_files
    new_pst.output_files = out_files

    #try to run inschek to find the observtion values
    pyemu.pst_utils.try_run_inschek(new_pst)

    if pst_filename:
        new_pst.write(pst_filename,update_regul=True)
    return new_pst