From 3e98a7bf434af8706efef32c6fc853e844458ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Tue, 10 Oct 2017 10:05:59 +0200 Subject: [PATCH] Use cells of strings instead of char arrays. --- ComputingTasks.cc | 8 +++--- SymbolList.cc | 8 +++--- SymbolTable.cc | 65 ++++++++++++++++++++++------------------------- 3 files changed, 38 insertions(+), 43 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 5e8c9b63..9e0b157b 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2017 Dynare Team + * Copyright (C) 2003-2018 Dynare Team * * This file is part of Dynare. * @@ -589,15 +589,15 @@ RamseyPolicyStatement::writeOutput(ostream &output, const string &basename, bool output << "options_.k_order_solver = 1;" << endl; options_list.writeOutput(output); - output << "var_list_ = char("; + output << "var_list_ = {"; for (vector::const_iterator it = ramsey_policy_list.begin(); it != ramsey_policy_list.end(); ++it) { if (it != ramsey_policy_list.begin()) - output << ","; + output << ";"; output << "'" << *it << "'"; } - output << ");" << endl + output << "};" << endl << "ramsey_policy(var_list_);" << endl; } diff --git a/SymbolList.cc b/SymbolList.cc index d729f447..5d7efd4f 100644 --- a/SymbolList.cc +++ b/SymbolList.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2017 Dynare Team + * Copyright (C) 2003-2018 Dynare Team * * This file is part of Dynare. * @@ -28,15 +28,15 @@ SymbolList::addSymbol(const string &symbol) void SymbolList::writeOutput(const string &varname, ostream &output) const { - output << varname << " = char("; + output << varname << " = {"; for (vector::const_iterator it = symbols.begin(); it != symbols.end(); ++it) { if (it != symbols.begin()) - output << ","; + output << ";"; output << "'" << *it << "'"; } - output << ");" << endl; + output << "};" << endl; } void diff --git a/SymbolTable.cc b/SymbolTable.cc index 3d035b09..5b71e5e1 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2017 Dynare Team + * Copyright (C) 2003-2018 Dynare Team * * This file is part of Dynare. * @@ -219,14 +219,13 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException) if (exo_nbr() > 0) { - output << "M_.exo_names = '" << getName(exo_ids[0]) << "';" << endl; - output << "M_.exo_names_tex = '" << getTeXName(exo_ids[0]) << "';" << endl; - output << "M_.exo_names_long = '" << getLongName(exo_ids[0]) << "';" << endl; - for (int id = 1; id < exo_nbr(); id++) - output << "M_.exo_names = char(M_.exo_names, '" << getName(exo_ids[id]) << "');" << endl - << "M_.exo_names_tex = char(M_.exo_names_tex, '" << getTeXName(exo_ids[id]) << "');" << endl - << "M_.exo_names_long = char(M_.exo_names_long, '" << getLongName(exo_ids[id]) << "');" << endl; - + output << "M_.exo_names = cell(" << exo_nbr() << ",1);" << endl; + output << "M_.exo_names_tex = cell(" << exo_nbr() << ",1);" << endl; + output << "M_.exo_names_long = cell(" << exo_nbr() << ",1);" << endl; + for (int id = 0; id < exo_nbr(); id++) + output << "M_.exo_names(" << id+1 << ") = {'" << getName(exo_ids[id]) << "'};" << endl + << "M_.exo_names_tex(" << id+1 << ") = {'" << getTeXName(exo_ids[id]) << "'};" << endl + << "M_.exo_names_long(" << id+1 << ") = {'" << getLongName(exo_ids[id]) << "'};" << endl; map > partitions = getPartitionsForType(eExogenous); for (map >::const_iterator it = partitions.begin(); it != partitions.end(); it++) @@ -248,14 +247,13 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException) if (exo_det_nbr() > 0) { - output << "M_.exo_det_names = '" << getName(exo_det_ids[0]) << "';" << endl; - output << "M_.exo_det_names_tex = '" << getTeXName(exo_det_ids[0]) << "';" << endl; - output << "M_.exo_det_names_long = '" << getLongName(exo_det_ids[0]) << "';" << endl; - for (int id = 1; id < exo_det_nbr(); id++) - output << "M_.exo_det_names = char(M_.exo_det_names, '" << getName(exo_det_ids[id]) << "');" << endl - << "M_.exo_det_names_tex = char(M_.exo_det_names_tex, '" << getTeXName(exo_det_ids[id]) << "');" << endl - << "M_.exo_det_names_long = char(M_.exo_det_names_long, '" << getLongName(exo_det_ids[id]) << "');" << endl; - + output << "M_.exo_det_names = cell(" << exo_det_nbr() << ",1);" << endl; + output << "M_.exo_det_names_tex = cell(" << exo_det_nbr() << ",1);" << endl; + output << "M_.exo_det_names_long = cell(" << exo_det_nbr() << ",1);" << endl; + for (int id = 0; id < exo_det_nbr(); id++) + output << "M_.exo_det_names(" << id+1 << ") = {'" << getName(exo_det_ids[id]) << "'};" << endl + << "M_.exo_det_names_tex(" << id+1 << ") = {'" << getTeXName(exo_det_ids[id]) << "'};" << endl + << "M_.exo_det_names_long(" << id+1 << ") = {'" << getLongName(exo_det_ids[id]) << "'};" << endl; output << "M_.exo_det_partitions = struct();" << endl; map > partitions = getPartitionsForType(eExogenousDet); for (map >::const_iterator it = partitions.begin(); @@ -278,14 +276,13 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException) if (endo_nbr() > 0) { - output << "M_.endo_names = '" << getName(endo_ids[0]) << "';" << endl; - output << "M_.endo_names_tex = '" << getTeXName(endo_ids[0]) << "';" << endl; - output << "M_.endo_names_long = '" << getLongName(endo_ids[0]) << "';" << endl; - for (int id = 1; id < endo_nbr(); id++) - output << "M_.endo_names = char(M_.endo_names, '" << getName(endo_ids[id]) << "');" << endl - << "M_.endo_names_tex = char(M_.endo_names_tex, '" << getTeXName(endo_ids[id]) << "');" << endl - << "M_.endo_names_long = char(M_.endo_names_long, '" << getLongName(endo_ids[id]) << "');" << endl; - + output << "M_.endo_names = cell(" << endo_nbr() << ",1);" << endl; + output << "M_.endo_names_tex = cell(" << endo_nbr() << ",1);" << endl; + output << "M_.endo_names_long = cell(" << endo_nbr() << ",1);" << endl; + for (int id = 0; id < endo_nbr(); id++) + output << "M_.endo_names(" << id+1 << ") = {'" << getName(endo_ids[id]) << "'};" << endl + << "M_.endo_names_tex(" << id+1 << ") = {'" << getTeXName(endo_ids[id]) << "'};" << endl + << "M_.endo_names_long(" << id+1 << ") = {'" << getLongName(endo_ids[id]) << "'};" << endl; output << "M_.endo_partitions = struct();" << endl; map > partitions = getPartitionsForType(eEndogenous); for (map >::const_iterator it = partitions.begin(); @@ -308,19 +305,17 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException) if (param_nbr() > 0) { - output << "M_.param_names = '" << getName(param_ids[0]) << "';" << endl; - output << "M_.param_names_tex = '" << getTeXName(param_ids[0]) << "';" << endl; - output << "M_.param_names_long = '" << getLongName(param_ids[0]) << "';" << endl; - for (int id = 1; id < param_nbr(); id++) + output << "M_.param_names = cell(" << param_nbr() << ",1);" << endl; + output << "M_.param_names_tex = cell(" << param_nbr() << ",1);" << endl; + output << "M_.param_names_long = cell(" << param_nbr() << ",1);" << endl; + for (int id = 0; id < param_nbr(); id++) { - output << "M_.param_names = char(M_.param_names, '" << getName(param_ids[id]) << "');" << endl - << "M_.param_names_tex = char(M_.param_names_tex, '" << getTeXName(param_ids[id]) << "');" << endl - << "M_.param_names_long = char(M_.param_names_long, '" << getLongName(param_ids[id]) << "');" << endl; - + output << "M_.param_names(" << id+1 << ") = {'" << getName(param_ids[id]) << "'};" << endl + << "M_.param_names_tex(" << id+1 << ") = {'" << getTeXName(param_ids[id]) << "'};" << endl + << "M_.param_names_long(" << id+1 << ") = {'" << getLongName(param_ids[id]) << "'};" << endl; if (getName(param_ids[id]) == "dsge_prior_weight") output << "options_.dsge_var = 1;" << endl; } - output << "M_.param_partitions = struct();" << endl; map > partitions = getPartitionsForType(eParameter); for (map >::const_iterator it = partitions.begin(); @@ -393,7 +388,7 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException) if (observedVariablesNbr() > 0) { int ic = 1; - output << "options_.varobs = cell(1);" << endl; + output << "options_.varobs = cell(" << observedVariablesNbr() << ", 1);" << endl; for (vector::const_iterator it = varobs.begin(); it != varobs.end(); it++, ic++) output << "options_.varobs(" << ic << ") = {'" << getName(*it) << "'};" << endl;