% convert dynare into mine
%model=(textread('equations_leduc2_B.m','%s','bufsize',1000000,'commentstyle','matlab','delimiter',';'));
function [tmp]=dyn2mine(model,maxll);
%maxll=5;
if isempty(model)
    disp('model is empty in dyn2mine.m')
    tmp=[];
    return
end

if ~iscell(model)
for jj=1:size(model);
    newmod{jj,1}=model(jj,:);
end
model=newmod;
end
% keyboard
% for jj=1:size(model,1)
%     model{1}=maple('factor',char(model{1}));
% end

nmod=size(model,1);
signs=str2mat('[\+]','','\-');
signstr=strvcat('_plus','_plus','_minus');

dd=[];
tmp=model;
%for uu=1:nmod
for jj=1:maxll
    for kk=1:3 
        %new on 20 December 2006
        tmp=regexprep(tmp,['((?<![\^\+\-\*\/])\(\-)([1-9]*)(?![1-9])(\))'],['_minus$2']);
        tmp=regexprep(tmp,['((?<![\^\+\-\*\/])\(\+)([1-9]*)(?![1-9])(\))'],['_plus$2']);
        
        % below (?<!\^) added 11 Nov 2006
    %tmp=regexprep(tmp,['(?<!\^)(\(',deblank(signs(kk,:)),num2str(jj),'\)*)'],[deblank(signstr(kk,:)),num2str(jj)]);
%       tmp=regexprep(model,['([A-Za-Z_0-9\_]\(',signs(kk,:),num2str(jj),'\)[A-Za-Z_0-9\_\+\-\*\/\^])'],[signstr(kk,:),num2str(jj)]);

    %dd=[dd;[eval(maple('lhs',tmp)),eval(maple('rhs',tmp))]];
    end
end
%end