def close(self):
if not self.fp.closed:<EOL><INDENT>try:<EOL><INDENT>self.flush()<EOL><DEDENT>finally:<EOL><INDENT>self.variables = {}<EOL>if self._mm_buf is not None:<EOL><INDENT>ref = weakref.ref(self._mm_buf)<EOL>self._mm_buf = None<EOL>if ref() is None:<EOL><INDENT>self._mm.close()<EOL><DEDENT>else:<EOL><INDENT>warnings.warn((<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>), category=RuntimeWarning)<EOL><DEDENT><DEDENT>self._mm = None<EOL>self.fp.close()<EOL><DEDENT><DEDENT>
Closes the NetCDF file.