@staticmethod
    def load(f, model, ext_unit_dict=None, check=True):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.modflow.mf.Modflow`) to
            which this package will be added.
        ext_unit_dict : dictionary, optional
            If the arrays in the file are specified using EXTERNAL,
            or older style array control records, then `f` should be a file
            handle.  In this case ext_unit_dict is required, which can be
            constructed using the function
            :class:`flopy.utils.mfreadnam.parsenamefile`.
        check : boolean
            Check package data for common errors. (default True)

        Returns
        -------
        dis : ModflowUPW object
            ModflowLpf object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> upw = flopy.modflow.ModflowUpw.load('test.upw', m)

        """

        if model.verbose:
            sys.stdout.write('loading upw package file...\n')

        if model.version != 'mfnwt':
            msg = "Warning: model version was reset from " + \
                  "'{}' to 'mfnwt' in order to load a UPW file".format(
                      model.version)
            print(msg)
            model.version = 'mfnwt'

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        # dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # determine problem dimensions
        nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        # Item 1: IBCFCB, HDRY, NPLPF - line already read above
        if model.verbose:
            print('   loading ipakcb, HDRY, NPUPW, IPHDRY...')
        t = line.strip().split()
        ipakcb, hdry, npupw, iphdry = int(t[0]), float(t[1]), int(t[2]), int(
                t[3])
        if ipakcb != 0:
            model.add_pop_key_list(ipakcb)
            ipakcb = 53
        # options
        noparcheck = False
        if len(t) > 3:
            for k in range(3, len(t)):
                if t[k].upper() in 'NOPARCHECK':
                    noparcheck = True
        # LAYTYP array
        if model.verbose:
            print('   loading LAYTYP...')
        line = f.readline()
        t = line.strip().split()
        laytyp = np.array((t[0:nlay]), dtype=np.int)
        # LAYAVG array
        if model.verbose:
            print('   loading LAYAVG...')
        line = f.readline()
        t = line.strip().split()
        layavg = np.array((t[0:nlay]), dtype=np.int)
        # CHANI array
        if model.verbose:
            print('   loading CHANI...')
        line = f.readline()
        t = line.strip().split()
        chani = np.array((t[0:nlay]), dtype=np.float32)
        # LAYVKA array
        if model.verbose:
            print('   loading LAYVKA...')
        line = f.readline()
        t = line.strip().split()
        layvka = np.array((t[0:nlay]), dtype=np.int)
        # LAYWET array
        if model.verbose:
            print('   loading LAYWET...')
        line = f.readline()
        t = line.strip().split()
        laywet = np.array((t[0:nlay]), dtype=np.int)
        # Item 7: WETFCT, IWETIT, IHDWET
        wetfct, iwetit, ihdwet = None, None, None
        iwetdry = laywet.sum()
        if iwetdry > 0:
            raise Exception('LAYWET should be 0 for UPW')

        # get parameters
        par_types = []
        if npupw > 0:
            par_types, parm_dict = mfpar.load(f, npupw, model.verbose)

        # get arrays
        transient = not model.get_package('DIS').steady.all()
        hk = [0] * nlay
        hani = [0] * nlay
        vka = [0] * nlay
        ss = [0] * nlay
        sy = [0] * nlay
        vkcb = [0] * nlay
        for k in range(nlay):
            if model.verbose:
                print('   loading hk layer {0:3d}...'.format(k + 1))
            if 'hk' not in par_types:
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'hk',
                                ext_unit_dict)
            else:
                line = f.readline()
                t = mfpar.parameter_fill(model, (nrow, ncol), 'hk', parm_dict,
                                         findlayer=k)
            hk[k] = t
            if chani[k] < 1:
                if model.verbose:
                    print('   loading hani layer {0:3d}...'.format(k + 1))
                if 'hani' not in par_types:
                    t = Util2d.load(f, model, (nrow, ncol), np.float32, 'hani',
                                    ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'hani',
                                             parm_dict, findlayer=k)
                hani[k] = t
            if model.verbose:
                print('   loading vka layer {0:3d}...'.format(k + 1))
            if 'vka' not in par_types and 'vani' not in par_types:
                key = 'vka'
                if layvka[k] != 0:
                    key = 'vani'
                t = Util2d.load(f, model, (nrow, ncol), np.float32, key,
                                ext_unit_dict)
            else:
                line = f.readline()
                key = 'vka'
                if 'vani' in par_types:
                    key = 'vani'
                t = mfpar.parameter_fill(model, (nrow, ncol), key, parm_dict,
                                         findlayer=k)
            vka[k] = t
            if transient:
                if model.verbose:
                    print('   loading ss layer {0:3d}...'.format(k + 1))
                if 'ss' not in par_types:
                    t = Util2d.load(f, model, (nrow, ncol), np.float32, 'ss',
                                    ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'ss',
                                             parm_dict, findlayer=k)
                ss[k] = t
                if laytyp[k] != 0:
                    if model.verbose:
                        print('   loading sy layer {0:3d}...'.format(k + 1))
                    if 'sy' not in par_types:
                        t = Util2d.load(f, model, (nrow, ncol), np.float32,
                                        'sy',
                                        ext_unit_dict)
                    else:
                        line = f.readline()
                        t = mfpar.parameter_fill(model, (nrow, ncol), 'sy',
                                                 parm_dict, findlayer=k)
                    sy[k] = t
            if model.get_package('DIS').laycbd[k] > 0:
                if model.verbose:
                    print('   loading vkcb layer {0:3d}...'.format(k + 1))
                if 'vkcb' not in par_types:
                    t = Util2d.load(f, model, (nrow, ncol), np.float32, 'vkcb',
                                    ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'vkcb',
                                             parm_dict, findlayer=k)
                vkcb[k] = t

        # create upw object
        upw = ModflowUpw(model, ipakcb=ipakcb, iphdry=iphdry, hdry=hdry,
                         noparcheck=noparcheck,
                         laytyp=laytyp, layavg=layavg, chani=chani,
                         layvka=layvka, laywet=laywet,
                         hk=hk, hani=hani, vka=vka, ss=ss, sy=sy, vkcb=vkcb)
        if check:
            upw.check(f='{}.chk'.format(upw.name[0]),
                      verbose=upw.parent.verbose, level=0)
        # return upw object
        return upw
dataset/ETHPy150Open modflowpy/flopy/flopy/modflow/mfupw.py/ModflowUpw.load/swapped operands of `in`