Skip to content

Commit f6393e9

Browse files
committed
Save matrices compiles
1 parent 1d0b667 commit f6393e9

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

src/Modules/Legacy/Matlab/Interface/InterfaceWithMatlab.cc

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
using namespace SCIRun;
7474
using namespace SCIRun::Modules::Matlab::Interface;
7575
using namespace SCIRun::Core::Datatypes;
76+
using namespace SCIRun::Core::Algorithms;
77+
using namespace SCIRun::Core::Algorithms::Matlab;
7678
using namespace SCIRun::Dataflow::Networks;
7779
using namespace SCIRun::MatlabIO;
7880
using namespace SCIRun::Core::Logging;
@@ -172,7 +174,7 @@ namespace MatlabImpl
172174
#endif
173175
static matlabarray::mitype convertdataformat(const std::string& dataformat);
174176
static std::string totclstring(const std::string& instring);
175-
std::vector<std::string> converttcllist(const std::string& str);
177+
std::vector<std::string> converttcllist(const Variable::List& str);
176178

177179
void update_status(const std::string& text);
178180

@@ -545,41 +547,20 @@ matlabarray::mitype InterfaceWithMatlabImpl::convertdataformat(const std::string
545547
// converts a TCL formatted list into a STL array
546548
// of strings
547549

548-
std::vector<std::string> InterfaceWithMatlabImpl::converttcllist(const std::string& str)
550+
std::vector<std::string> InterfaceWithMatlabImpl::converttcllist(const Variable::List& vars)
549551
{
550-
std::string result;
551552
std::vector<std::string> list;
552-
#if 0
553-
int lengthlist = 0;
554-
555-
// Yeah, it is TCL dependent:
556-
// TCL::llength determines the length of the list
557-
TCLInterface::eval("llength { "+str + " }",result);
558-
std::istringstream iss(result);
559-
iss >> lengthlist;
560-
if (lengthlist < 0) return(list);
561-
562-
list.resize(lengthlist);
563-
for (int p = 0;p<lengthlist;p++)
564-
{
565-
std::ostringstream oss;
566-
// TCL dependency:
567-
// TCL::lindex retrieves the p th element from the list
568-
oss << "lindex { " << str << " } " << p;
569-
TCLInterface::eval(oss.str(),result);
570-
list[p] = result;
571-
}
572-
#endif
573-
return(list);
553+
std::transform(vars.begin(), vars.end(), std::back_inserter(list), [](const Variable& v) { return v.toString(); });
554+
return list;
574555
}
575556

576557
bool InterfaceWithMatlabImpl::synchronise_input()
577558
{
578-
std::string str;
579-
str = input_matrix_name_.get(); input_matrix_name_list_ = converttcllist(str);
580-
str = input_matrix_type_.get(); input_matrix_type_list_ = converttcllist(str);
581-
str = input_matrix_array_.get(); input_matrix_array_list_ = converttcllist(str);
582-
str = output_matrix_name_.get(); output_matrix_name_list_ = converttcllist(str);
559+
auto state = module_->get_state();
560+
input_matrix_name_list_ = converttcllist(state->getValue(Parameters::InputMatrixNames).toVector());
561+
input_matrix_type_list_ = converttcllist(state->getValue(Parameters::InputMatrixTypes).toVector());
562+
input_matrix_array_list_ = converttcllist(state->getValue(Parameters::InputMatrixArrays).toVector());
563+
output_matrix_name_list_ = converttcllist(state->getValue(Parameters::OutputMatrixNames).toVector());
583564
#if 0
584565
str = input_field_name_.get(); input_field_name_list_ = converttcllist(str);
585566
str = input_field_array_.get(); input_field_array_list_ = converttcllist(str);
@@ -593,7 +574,7 @@ bool InterfaceWithMatlabImpl::synchronise_input()
593574
str = input_string_name_.get(); input_string_name_list_ = converttcllist(str);
594575
str = output_string_name_.get(); output_string_name_list_ = converttcllist(str);
595576
#endif
596-
matlab_code_list_ = matlab_code_.get();
577+
matlab_code_list_ = state->getValue(Parameters::MatlabCode).toString();
597578

598579
return(true);
599580
}
@@ -1379,7 +1360,7 @@ void InterfaceWithMatlab::execute()
13791360
// this one was not created again
13801361
// hence we do not need to translate it again
13811362
// with big datasets this should improve performance
1382-
loadcmd = "load " + file_transfer_->remote_file(input_matrix_matfile_[p]) + ";\n";
1363+
loadcmd = "load " + file_transfer_->remote_file(input_matrix_matfile_[port]) + ";\n";
13831364
m_file << loadcmd;
13841365
continue;
13851366
}
@@ -1402,17 +1383,17 @@ void InterfaceWithMatlab::execute()
14021383
translate.setdatatype(convertdataformat(input_matrix_type_list_[port]));
14031384
translate.sciMatrixTOmlArray(matrix, ma);
14041385

1405-
mf.putmatlabarray(ma,input_matrix_name_list_[p]);
1386+
mf.putmatlabarray(ma,input_matrix_name_list_[port]);
14061387
mf.close();
14071388

1408-
loadcmd = "load " + file_transfer_->remote_file(input_matrix_matfile_[p]) + ";\n";
1389+
loadcmd = "load " + file_transfer_->remote_file(input_matrix_matfile_[port]) + ";\n";
14091390
m_file << loadcmd;
14101391

14111392
if (need_file_transfer_)
14121393
{
14131394
if(!(file_transfer_->put_file(
1414-
file_transfer_->local_file(input_matrix_matfile_[p]),
1415-
file_transfer_->remote_file(input_matrix_matfile_[p]))))
1395+
file_transfer_->local_file(input_matrix_matfile_[port]),
1396+
file_transfer_->remote_file(input_matrix_matfile_[port]))))
14161397
{
14171398
module_->error("InterfaceWithMatlab: Could not transfer file");
14181399
std::string err = "Error :" + file_transfer_->geterror();
@@ -1827,3 +1808,9 @@ void InterfaceWithMatlab::execute()
18271808
Module::tcl_command(args, userdata);
18281809
}
18291810
#endif
1811+
1812+
ALGORITHM_PARAMETER_DEF(Matlab, MatlabCode);
1813+
ALGORITHM_PARAMETER_DEF(Matlab, InputMatrixNames);
1814+
ALGORITHM_PARAMETER_DEF(Matlab, InputMatrixTypes);
1815+
ALGORITHM_PARAMETER_DEF(Matlab, InputMatrixArrays);
1816+
ALGORITHM_PARAMETER_DEF(Matlab, OutputMatrixNames);

src/Modules/Legacy/Matlab/Interface/InterfaceWithMatlab.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,24 @@
3030
#define MODULES_LEGACY_MATLAB_MATLABINTERFACE_H
3131

3232
#include <Dataflow/Network/Module.h>
33+
#include <Core/Algorithms/Base/AlgorithmMacros.h>
3334
#include <Modules/Legacy/Matlab/Interface/share.h>
3435

3536
namespace SCIRun {
37+
namespace Core {
38+
namespace Algorithms
39+
{
40+
namespace Matlab
41+
{
42+
ALGORITHM_PARAMETER_DECL(MatlabCode);
43+
ALGORITHM_PARAMETER_DECL(InputMatrixNames);
44+
ALGORITHM_PARAMETER_DECL(InputMatrixTypes);
45+
ALGORITHM_PARAMETER_DECL(InputMatrixArrays);
46+
ALGORITHM_PARAMETER_DECL(OutputMatrixNames);
47+
}
48+
}
49+
}
50+
3651
namespace Modules {
3752
namespace Matlab {
3853
namespace Interface {
@@ -60,6 +75,7 @@ namespace Interface {
6075
boost::shared_ptr<class InterfaceWithMatlabImpl> impl_;
6176
};
6277

78+
6379
}}}}
6480

6581
#endif

0 commit comments

Comments
 (0)