def save(self, fname, mode=None, validate=True, encoding='utf-8',
             wd=False, inline=False, relative=False, pack=False):
        """Save the workflow to file.

        Save the workflow to a CWL file that can be run with a CWL runner.

        Args:
            fname (str): file to save the workflow to.
            mode (str): one of  (rel, abs, wd, inline, pack)
            encoding (str): file encoding to use (default: ``utf-8``).
        """
        self._closed()

        if mode is None:
            mode = 'abs'
            if pack:
                mode = 'pack'
            elif wd:
                mode = 'wd'
            elif relative:
                mode = 'rel'

            msg = 'Using deprecated save method. Please save the workflow ' \
                  'with: wf.save(\'{}\', mode=\'{}\'). Redirecting to new ' \
                  'save method.'.format(fname, mode)
            warnings.warn(msg, DeprecationWarning)

        modes = ('rel', 'abs', 'wd', 'inline', 'pack')
        if mode not in modes:
            msg = 'Illegal mode "{}". Choose one of ({}).'\
                  .format(mode, ','.join(modes))
            raise ValueError(msg)

        if validate:
            self.validate()

        dirname = os.path.dirname(os.path.abspath(fname))
        if not os.path.exists(dirname):
            os.makedirs(dirname)

        if mode == 'inline':
            msg = ('Inline saving is deprecated. Please save the workflow '
                   'using mode=\'pack\'. Setting mode to pack.')
            warnings.warn(msg, DeprecationWarning)
            mode = 'pack'

        if mode == 'rel':
            relpath = dirname
            save_yaml(fname=fname, wf=self, pack=False, relpath=relpath,
                      wd=False)

        if mode == 'abs':
            save_yaml(fname=fname, wf=self, pack=False, relpath=None,
                      wd=False)

        if mode == 'pack':
            self._pack(fname, encoding)

        if mode == 'wd':
            if self.get_working_dir() is None:
                raise ValueError('Working directory not set.')
            else:
                # save in working_dir
                bn = os.path.basename(fname)
                wd_file = os.path.join(self.working_dir, bn)
                save_yaml(fname=wd_file, wf=self, pack=False, relpath=None,
                          wd=True)
                # and copy workflow file to other location (as though all steps
                # are in the same directory as the workflow)
                try:
                    shutil.copy2(wd_file, fname)
                except shutil.Error:
                    pass
Save the workflow to file.

        Save the workflow to a CWL file that can be run with a CWL runner.

        Args:
            fname (str): file to save the workflow to.
            mode (str): one of  (rel, abs, wd, inline, pack)
            encoding (str): file encoding to use (default: ``utf-8``).