load a version 2 control file

def _load_version2(self,filename):
        """load a version 2 control file



        """
        self.lcount  = 0
        self.comments = {}
        self.prior_information = self.null_prior
        assert os.path.exists(filename), "couldn't find control file {0}".format(filename)
        f = open(filename, 'r')
        last_section = ""
        req_sections = {"* parameter data":False, "* observation data":False,
                        "* model command line":False,"* model input":False, "* model output":False}
        while True:

            next_section, section_lines, comments = self._read_section_comments(f, True)


            if "* control data" in last_section.lower():
                req_sections[last_section] = True
                iskeyword = False
                if "keyword" in last_section.lower():
                    iskeyword = True
                self.pestpp_options = self.control_data.parse_values_from_lines(section_lines, iskeyword=iskeyword)
                if len(self.pestpp_options) > 0:
                    ppo = self.pestpp_options
                    svd_opts = ["svdmode","eigthresh","maxsing","eigwrite"]
                    for svd_opt in svd_opts:
                        if svd_opt in ppo:
                            self.svd_data.__setattr__(svd_opt, ppo.pop(svd_opt))
                    for reg_opt in self.reg_data.should_write:
                        if reg_opt in ppo:
                            self.reg_data.__setattr__(reg_opt, ppo.pop(reg_opt))

            elif "* parameter groups" in last_section.lower():
                req_sections[last_section] = True
                self.parameter_groups = self._cast_df_from_lines(next_section, section_lines, self.pargp_fieldnames,
                                                                self.pargp_converters, self.pargp_defaults)
                self.parameter_groups.index = self.parameter_groups.pargpnme

            elif "* parameter data" in last_section.lower():
                req_sections[last_section] = True
                self.parameter_data = self._cast_df_from_lines(next_section, section_lines, self.par_fieldnames,
                                                               self.par_converters, self.par_defaults)
                self.parameter_data.index = self.parameter_data.parnme

            elif "* observation data" in last_section.lower():
                req_sections[last_section] = True
                self.observation_data = self._cast_df_from_lines(next_section, section_lines, self.obs_fieldnames,
                                                                self.obs_converters, self.obs_defaults)
                self.observation_data.index = self.observation_data.obsnme

            elif "* model command line" in last_section.lower():
                req_sections[last_section] = True
                for line in section_lines:
                    self.model_command.append(line.strip())

            elif "* model input" in last_section.lower():
                req_sections[last_section] = True
                if section_lines[0].strip().split()[0].lower() == "external":
                    filename = section_lines[0].strip().split()[1]
                    assert os.path.exists(filename),"Pst.flex_load() external template data file '{0}' not found".format(filename)
                    df = pd.read_csv(filename)
                    df.columns = df.columns.str.lower()
                    assert "pest_file" in df.columns,"Pst.flex_load() external template data file must have 'pest_file' in columns"
                    assert "model_file" in df.columns, "Pst.flex_load() external template data file must have 'model_file' in columns"
                    for pfile,mfile in zip(df.pest_file,df.model_file):
                        self.template_files.append(pfile)
                        self.input_files.append(mfile)

                else:
                    for iline,line in enumerate(section_lines):
                        raw = line.split()
                        self.template_files.append(raw[0])
                        self.input_files.append(raw[1])

            elif "* model output" in last_section.lower():
                req_sections[last_section] = True
                if section_lines[0].strip().split()[0].lower() == "external":
                    filename = section_lines[0].strip().split()[1]
                    assert os.path.exists(filename), "Pst.flex_load() external instruction data file '{0}' not found".format(
                        filename)
                    df = pd.read_csv(filename)
                    df.columns = df.columns.str.lower()
                    assert "pest_file" in df.columns, "Pst.flex_load() external instruction data file must have 'pest_file' in columns"
                    assert "model_file" in df.columns, "Pst.flex_load() external instruction data file must have 'model_file' in columns"
                    for pfile, mfile in zip(df.pest_file, df.model_file):
                        self.instruction_files.append(pfile)
                        self.output_files.append(mfile)
                else:
                    for iline, line in enumerate(section_lines):
                        raw = line.split()
                        self.instruction_files.append(raw[0])
                        self.output_files.append(raw[1])

            elif "* prior information" in last_section.lower():
                req_sections[last_section] = True
                self._cast_prior_df_from_lines(section_lines)

            elif len(last_section) > 0:
                print("Pst._load_version2() warning: unrecognized section: ", last_section)
                self.comments[last_section] = section_lines

            last_section = next_section
            if next_section == None or len(section_lines) == 0:
                break

        not_found = []
        for section,found in req_sections.items():
            if not found:
                not_found.append(section)
        if len(not_found) > 0:
            raise Exception("Pst._load_version2() error: the following required sections were"+\
                    "not found:{0}".format(",".join(not_found)))