2019-05-14 22:12:27 +02:00
|
|
|
function [ast, jsonmodel] = get_ast(eqtags)
|
|
|
|
|
|
|
|
% Returns the Abstract Syntax Tree the JSON output of preprocessor for the
|
2019-01-22 00:57:24 +01:00
|
|
|
% given equation tags. Equations are ordered in eqtag order
|
2019-01-11 11:26:13 +01:00
|
|
|
%
|
|
|
|
% INPUTS
|
2019-05-14 22:12:27 +02:00
|
|
|
% - eqtags [cellstr] names of equation tags for which to get info.
|
2019-01-22 00:57:24 +01:00
|
|
|
% If empty, get all equations
|
2019-01-11 11:26:13 +01:00
|
|
|
%
|
|
|
|
% OUTPUTS
|
2019-05-14 22:12:27 +02:00
|
|
|
% - ast [cell array] JSON representation of the abstract syntax tree
|
|
|
|
% - jsonmodel [cell array] JSON representation of the equations.
|
2019-01-11 11:26:13 +01:00
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
|
2022-04-13 13:15:19 +02:00
|
|
|
% Copyright © 2019 Dynare Team
|
2019-01-11 11:26:13 +01:00
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare 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.
|
|
|
|
%
|
|
|
|
% Dynare 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
|
2021-06-09 17:33:48 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2019-01-11 11:26:13 +01:00
|
|
|
|
|
|
|
global M_
|
|
|
|
|
|
|
|
if ~isempty(eqtags) && ~(ischar(eqtags) || iscell(eqtags))
|
2019-05-14 22:12:27 +02:00
|
|
|
error('eqtags not passed correctly')
|
2019-01-11 11:26:13 +01:00
|
|
|
end
|
|
|
|
|
2019-05-14 22:12:27 +02:00
|
|
|
jsonfile = sprintf('%s%smodel%sjson%smodfile-original.json', M_.fname, filesep(), filesep(), filesep());
|
|
|
|
|
|
|
|
if ~exist(jsonfile, 'file')
|
|
|
|
error('Could not find %s! Please use the json=compute option (see the Dynare invocation section in the reference manual).', jsonfile)
|
|
|
|
end
|
|
|
|
|
2020-01-28 16:36:40 +01:00
|
|
|
tmp = loadjson_(jsonfile);
|
2019-05-14 22:12:27 +02:00
|
|
|
ast = tmp.abstract_syntax_tree;
|
|
|
|
|
|
|
|
if nargout>1
|
|
|
|
jsonmodel = tmp.model;
|
2019-01-11 11:26:13 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if ~isempty(eqtags)
|
|
|
|
ast = getEquationsByTags(ast, 'name', eqtags);
|
2019-05-14 22:12:27 +02:00
|
|
|
if nargout>1
|
|
|
|
jsonmodel = getEquationsByTags(jsonmodel, 'name', eqtags);
|
|
|
|
end
|
|
|
|
end
|