Home > FMAToolbox > Database > DBGetFigures.m

DBGetFigures

PURPOSE ^

DBGetFigures - Get all figures that match given criteria.

SYNOPSIS ^

function f = DBGetFigures(query,varargin)

DESCRIPTION ^

DBGetFigures - Get all figures that match given criteria.

 Open figures and get related information such as code used to generate them.

  USAGE

    f = DBGetFigures(query,<options>)

    query          optional figure list query (WHERE clause; see Example)
    <options>      optional list of property-value pairs (see table below)

    =========================================================================
     Properties    Values
    -------------------------------------------------------------------------
     'output'       'figures' to get the figures but not the information,
                    i.e. eid, name, comments, parameters, etc. (default),
                    'info' for the information but not the figures, 'full'
                    for both, or 'keys' for eid and name only
    =========================================================================

  OUTPUT

    f is a structure with the following fields:

    eid            experiment ID (identifier string)
    name           figure descriptive name (identifier string)
    fig            figure handle
    comments       comments
    parameters     figure parameters
    code           text of m-files used to generate the figure
    date           date when the figure was saved
    user           the user that saved the figure

    Each field is a cell array.

  EXAMPLE

    Get all figures from experiment "experiment1", the name of which starts
    with "raster" (for details, see an SQL manual):

    [f,comments,parameters,code,date,user] = ...
      DBGetFigures('eid="experiment1" and name like "raster%"');

  SEE

    See also DBAddFigure, DBGetVariables, DBDisplay.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function f = DBGetFigures(query,varargin)
0002 
0003 %DBGetFigures - Get all figures that match given criteria.
0004 %
0005 % Open figures and get related information such as code used to generate them.
0006 %
0007 %  USAGE
0008 %
0009 %    f = DBGetFigures(query,<options>)
0010 %
0011 %    query          optional figure list query (WHERE clause; see Example)
0012 %    <options>      optional list of property-value pairs (see table below)
0013 %
0014 %    =========================================================================
0015 %     Properties    Values
0016 %    -------------------------------------------------------------------------
0017 %     'output'       'figures' to get the figures but not the information,
0018 %                    i.e. eid, name, comments, parameters, etc. (default),
0019 %                    'info' for the information but not the figures, 'full'
0020 %                    for both, or 'keys' for eid and name only
0021 %    =========================================================================
0022 %
0023 %  OUTPUT
0024 %
0025 %    f is a structure with the following fields:
0026 %
0027 %    eid            experiment ID (identifier string)
0028 %    name           figure descriptive name (identifier string)
0029 %    fig            figure handle
0030 %    comments       comments
0031 %    parameters     figure parameters
0032 %    code           text of m-files used to generate the figure
0033 %    date           date when the figure was saved
0034 %    user           the user that saved the figure
0035 %
0036 %    Each field is a cell array.
0037 %
0038 %  EXAMPLE
0039 %
0040 %    Get all figures from experiment "experiment1", the name of which starts
0041 %    with "raster" (for details, see an SQL manual):
0042 %
0043 %    [f,comments,parameters,code,date,user] = ...
0044 %      DBGetFigures('eid="experiment1" and name like "raster%"');
0045 %
0046 %  SEE
0047 %
0048 %    See also DBAddFigure, DBGetVariables, DBDisplay.
0049 %
0050 
0051 % Copyright (C) 2007-2013 by Michaƫl Zugaro
0052 %
0053 % This program is free software; you can redistribute it and/or modify
0054 % it under the terms of the GNU General Public License as published by
0055 % the Free Software Foundation; either version 3 of the License, or
0056 % (at your option) any later version.
0057 
0058 % Make sure MyM is installed and functional
0059 CheckMyM;
0060 
0061 % Default values
0062 output = 'figures';
0063 
0064 % Optional query provided?
0065 if nargin == 0,
0066     query = '';
0067 elseif isastring(query,'output'),
0068     varargin = {query varargin{:}};
0069     query = '';
0070 end
0071 
0072 % Edit query
0073 query = strtrim(query);
0074 query = regexprep(query,'^where','');
0075 if ~isempty(query), query = [' where ' query]; end
0076 
0077 % Parse options
0078 for i = 1:2:length(varargin),
0079     if ~ischar(varargin{i}),
0080         error(['Parameter ' num2str(i+1) ' is not a property (type ''help <a href="matlab:help DBGetFigures">DBGetFigures</a>'' for details).']);
0081     end
0082     switch(lower(varargin{i})),
0083         case 'output',
0084             output = lower(varargin{i+1});
0085             if ~isastring(output,'figures','info','full','keys'),
0086                 error('Incorrect value for property ''output'' (type ''help <a href="matlab:help DBGetFigures">DBGetFigures</a>'' for details).');
0087             end
0088         otherwise,
0089             error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help DBGetFigures">DBGetFigures</a>'' for details).']);
0090     end
0091 end
0092 
0093 % Query database
0094 switch output,
0095     case 'full',
0096         f = mym(['select fig,eid,name,comments,parameters,mfiles,code,date,user from figures' query]);
0097     case 'figures',
0098         f = mym(['select fig from figures' query]);
0099     case 'info',
0100         f = mym(['select eid,name,comments,parameters,mfiles,code,date,user from figures' query]);
0101     case 'keys',
0102         f = mym(['select eid,name from figures' query]);
0103 end
0104 
0105 % Make sure query results are not empty
0106 if isempty(f),
0107     warning(['No figures match (' query ').']);
0108 end
0109 
0110 % Create temporary fig files, open them and delete them
0111 if strcmp(output,'full') || strcmp(output,'figures'),
0112     for i = 1:length(f.fig),
0113         if isempty(f.fig{i}),
0114             warning(['Figure (' f.eid{i} ',' f.name{i} ') was stored as PNG only.']);
0115             f.fig{i} = [];
0116         else
0117             basename = tempname;
0118             figName = [basename '.fig'];
0119             file = fopen(figName,'wb');
0120             if file == -1,
0121                 error(['Could not create temporary file for figure (' f.eid{i} ',' f.name{i} ').']);
0122             end
0123             fwrite(file,f.fig{i});
0124             fclose(file);
0125             f.fig{i} = openfig(figName);
0126             delete(figName);
0127             set(f.fig{i},'visible','on');
0128         end
0129     end
0130 end
0131 
0132 % Format code
0133 if strcmp(output,'full') || strcmp(output,'info'),
0134     code = {};
0135     for i = 1:length(f.code),
0136         for j = 1:length(f.code{i}),
0137             code{i}{j} = char(f.code{i}{j})';
0138         end
0139     end
0140     f.code = code;
0141 end

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005