function data=mphstate(m,solname,varargin)
% MPHSTATE Get state-space matrices for dynamic system
% 
%   STR = MPHSTATE(MODEL,SOLNAME,'Out',{'SP'}) returns a MATLAB structure 
%   STR containing the state space matrix SP assembled using the solver 
%   node SOLNAME and accessible as STR.SP. SP being taken from the Out 
%   property list.
% 
%   STR = MPHSTATE(MODEL,SOLNAME,'Out',{'SP1','SP2',...}) returns a MATLAB
%   structure STR containing the state space matrices SP1, SP2, ... 
%   assembled using the solver node SOLNAME and accessible as STR.SP1 and 
%   STR.SP2. SP1 and SP2 being taken from the Out property list.
% 
%   Property      Expression        Description
%   -----------------------------------------------------------------------
%   Out           'MA'              McA matrix
%                 'MB'              McB matrix
%                 'A'               A matrix
%                 'B'               B matrix
%                 'C'               C matrix
%                 'D'               D matrix
%                 'Mc'              Mc matrix
%                 'Null'            Null matrix
%                 'ud'              ud vector
%                 'x0'              x0 vector
%   Keepfeature   {'off'} | 'on'    Keep the StateSpace feature in the 
%                                   model
%   Input         String            Input variables
%   Output        String            Output variables
%   Sparse        {'off'} | 'on'    Return sparse matrices
%   Initmethod    {''} | 'init' |   Use linearisation point
%                 'sol'   
%   Initsol       {solname} |       Solution to use for linearization
%                 'zero'      
%   Solnum        {'auto'}          Solution number
% 
%   The property Sparse controls whether the matrices A, B, C, D, M, MA, MB,
%   and Null are stored in the sparse format.
%   The input cannot be a variable constraint in the model.
% 
%   See the entry MPHSTATE in the LiveLink for MATLAB User's Guide for more 
%   information about the property/values.
% 
%   Example:
%     % Load heat_convection_2d.mph from the Model Library:
%     model = mphload('heat_convection_2d.mph');
%     % Set the temperature condition with a constant parameter:
%     model.param.set('T0','373');
%	  % Change the temperature constraint condition to a heat flux
%     % condition using a stiff spring:
% 	  ht = model.physics('ht');
%     hf2 = ht.feature.create('hf2', 'HeatFluxBoundary', 1);
%     hf2.selection.set(2);
%     hf2.set('HeatFluxType', 1,'InwardHeatFlux');
%     hf2.set('h', 1, '1e5');
%     hf2.set('Text', 1, 'T0');
%     ht.feature('temp1').active(false);
%     % Add a point probe at [0.3;0.8]:
%     pdom1 = model.probe.create('pdom1', 'DomainPoint');
%     pdom1.model('mod1');
%     pdom1.setIndex('coords2','0.8',0,0);
%     pdom1.setIndex('coords2','0.3',0,0);
%     % Extract matrix data:
%     M = mphstate(model,'sol1','out',{'MA' 'MB' 'C' 'D'},...
%        'input','T0', 'output', 'mod1.ppb1');

% Copyright 2010-2011 COMSOL
