7373using namespace SCIRun ;
7474using namespace SCIRun ::Modules::Matlab::Interface;
7575using namespace SCIRun ::Core::Datatypes;
76+ using namespace SCIRun ::Core::Algorithms;
77+ using namespace SCIRun ::Core::Algorithms::Matlab;
7678using namespace SCIRun ::Dataflow::Networks;
7779using namespace SCIRun ::MatlabIO;
7880using 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
576557bool 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);
0 commit comments