<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add_magic_table(self, dtype, fname=None, df=None):
 """ Read in a new file to add a table to self.tables. Requires dtype argument and EITHER filename or df. Parameters dtype : str MagIC table name (plural, i.e. 'specimens') fname : str filename of MagIC format file (short path, directory is self.directory) default: None df : pandas DataFrame data to create the new table with default: None """

        if df is None:
            # if providing a filename but no data type
            if dtype == "unknown":
                filename = os.path.join(self.directory, fname)
                if not os.path.exists(filename):
                    return False, False
                data_container = MagicDataFrame(filename, dmodel=self.data_model)
                dtype = data_container.dtype
                if dtype == 'empty':
                    return False, False
                else:
                    self.tables[dtype] = data_container
                    return dtype, data_container
            # if providing a data type, use the canonical filename
            elif dtype not in self.filenames:
                print('-W- "{}" is not a valid MagIC table type'.format(dtype))
                print("-I- Available table types are: {}".format(", ".join(self.table_names)))
                return False, False
            #filename = os.path.join(self.directory, self.filenames[dtype])
            filename = pmag.resolve_file_name(self.filenames[dtype], self.directory)
            if os.path.exists(filename):
                data_container = MagicDataFrame(filename, dtype=dtype,
                                                dmodel=self.data_model)
                if data_container.dtype != "empty":
                    self.tables[dtype] = data_container
                    return dtype, data_container
                else:
                    return False, False
            else:
                #print("-W- No such file: {}".format(filename))
                return False, False
        # df is not None
        else:
            if not dtype:
                print("-W- Must provide dtype")
                return False, False
            data_container = MagicDataFrame(dtype=dtype, df=df)
            self.tables[dtype] = data_container
        self.tables[dtype].sort_dataframe_cols()
        return dtype, self.tables[dtype]