view scripts/plot/util/hgload.m @ 18614:13c80c3e9660

Add new functions hgsave and hgload (bug #39532). * NEWS: Announce new functions. * scripts/plot/util/hgload.m: New function. * scripts/plot/util/hgsave.m: New function. * scripts/plot/util/module.mk: Add functions to build system. * hdl2struct.m, print.m, saveas.m, struct2hdl.m: Add seealso references to new functions in docstrings. * plot.txi: Add functions to Octave manual. * __unimplemented__.m: Remove functions from unimplemented list.
author Massimiliano Fasi <mogrob.sanit@gmail.com> and Rik <rik@octave.org>
date Thu, 06 Mar 2014 22:52:59 +0100
parents
children 70cff922a42d
line wrap: on
line source

## Copyright (C) 2014 Massimiliano Fasi
##
## This file is part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or (at
## your option) any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn  {Function File} {@var{h} =} hgload (@var{filename})
## Load the graphics object in @var{filename} into the graphics handle @var{h}.
##
## If @var{filename} has no extension, Octave will try to find the file with
## and without the standard extension of @file{.ofig}.
## @seealso{hgsave, struct2hdl}
## @end deftypefn

## Author: Massimiliano Fasi

function h = hgload (filename)

  ## Check input arguments
  if (nargin != 1)
    print_usage ();
  endif
  
  ## Check file existence
  if (! exist (filename))
    [~, ~, ext] = fileparts (filename);
    if (isempty (ext))
      filename = [filename ".ofig"];
    endif
    if (! exist (filename))
      error ("hgload: unable to locate file %s", filename);
    endif
  endif

  ## Load the handle
  try
    stmp = load (filename, "s_oct40");
  catch
    error ("hgload: could not load hgsave-formatted object in %s", filename);
  end_try_catch

  h = struct2hdl (stmp.s_oct40);
  
endfunction


## Functional test for hgload/hgsave pair is in hgsave.m

%% Test input validation
%!error hgload ()
%!error hgload (1, 2)
%!error <unable to locate file> hgload ("%%_A_REALLY_UNLIKELY_FILENAME_%%")