Skip to content

Commit 9ed7ef0

Browse files
committed
Send output builds
1 parent d7b3245 commit 9ed7ef0

File tree

1 file changed

+113
-95
lines changed

1 file changed

+113
-95
lines changed

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

Lines changed: 113 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
#include <boost/thread.hpp>
5454
#include <Core/Services/FileTransferClient.h>
5555
#include <Core/Datatypes/Matrix.h>
56+
#include <Core/Datatypes/String.h>
57+
#include <Core/Datatypes/Legacy/Field/Field.h>
5658

5759
#if 0
5860

@@ -168,23 +170,7 @@ namespace MatlabImpl
168170
output_nrrd_matfile_(NUM_OUTPUT_NRRDS),
169171
output_string_matfile_(NUM_OUTPUT_STRINGS)
170172
{}
171-
#if 0
172-
173-
// Constructor
174-
InterfaceWithMatlab(GuiContext* ctx);
175-
176-
// Destructor
177-
virtual ~InterfaceWithMatlab();
178173

179-
// Std functions for each module
180-
// execute():
181-
// Execute the module and put data on the output port
182-
183-
virtual void execute();
184-
virtual void presave();
185-
virtual void tcl_command(GuiArgs& args, void* userdata);
186-
187-
#endif
188174
static matlabarray::mitype convertdataformat(const std::string& dataformat);
189175
static std::string totclstring(const std::string& instring);
190176
std::vector<std::string> converttcllist(const Variable::List& str);
@@ -217,6 +203,9 @@ namespace MatlabImpl
217203
bool isMatrixOutputPortConnected(int index) const;
218204
bool isFieldOutputPortConnected(int index) const;
219205
bool isStringOutputPortConnected(int index) const;
206+
void sendMatrixOutput(int index, MatrixHandle matrix) const;
207+
void sendFieldOutput(int index, FieldHandle field) const;
208+
void sendStringOutput(int index, StringHandle str) const;
220209

221210
// GUI variables
222211
#if 0
@@ -295,7 +284,6 @@ namespace MatlabImpl
295284
TempFileManager tfmanager_;
296285
std::string mfile_;
297286
#if 0
298-
GuiString matlab_code_;
299287
GuiString matlab_code_file_;
300288
GuiString matlab_var_;
301289

@@ -1088,49 +1076,48 @@ bool InterfaceWithMatlabImpl::close_matlab_engine()
10881076
return(true);
10891077
}
10901078

1091-
bool InterfaceWithMatlab::load_output_matrices()
1079+
bool InterfaceWithMatlabImpl::load_output_matrices()
10921080
{
1093-
int port = 0;
1094-
try
1081+
for (int p = 0; p < NUM_OUTPUT_MATRICES; p++)
10951082
{
1096-
for (int p = 0; p < NUM_MATRIX_PORTS; p++)
1097-
{
1098-
if (!oport_connected(port)) { port++; continue; }
1099-
1100-
// Test whether the matrix port exists
1101-
if (output_matrix_name_list_[p] == "") continue;
1102-
if (output_matrix_matfile_[p] == "") continue;
1103-
1104-
matlabfile mf;
1105-
matlabarray ma;
1083+
if (!isMatrixOutputPortConnected(p))
1084+
continue;
1085+
if (output_matrix_name_list_[p].empty())
1086+
continue;
1087+
if (output_matrix_matfile_[p].empty())
1088+
continue;
11061089

1107-
try
1108-
{
1109-
if (need_file_transfer_) file_transfer_->get_file(file_transfer_->remote_file(output_matrix_matfile_[p]),file_transfer_->local_file(output_matrix_matfile_[p]));
1110-
mf.open(file_transfer_->local_file(output_matrix_matfile_[p]),"r");
1111-
ma = mf.getmatlabarray(output_matrix_name_list_[p]);
1112-
mf.close();
1113-
}
1114-
catch(...)
1115-
{
1116-
error("InterfaceWithMatlab: Could not read output matrix");
1117-
continue;
1118-
}
1090+
matlabfile mf;
1091+
matlabarray ma;
11191092

1120-
if (ma.isempty())
1121-
{
1122-
error("InterfaceWithMatlab: Could not read output matrix");
1123-
continue;
1124-
}
1093+
try
1094+
{
1095+
if (need_file_transfer_) file_transfer_->get_file(file_transfer_->remote_file(output_matrix_matfile_[p]),file_transfer_->local_file(output_matrix_matfile_[p]));
1096+
mf.open(file_transfer_->local_file(output_matrix_matfile_[p]),"r");
1097+
ma = mf.getmatlabarray(output_matrix_name_list_[p]);
1098+
mf.close();
1099+
}
1100+
catch(...)
1101+
{
1102+
module_->error("InterfaceWithMatlab: Could not read output matrix");
1103+
continue;
1104+
}
11251105

1126-
MatrixHandle handle;
1127-
std::string info;
1128-
matlabconverter translate(dynamic_cast<SCIRun::ProgressReporter *>(this));
1129-
if (translate.sciMatrixCompatible(ma,info)) translate.mlArrayTOsciMatrix(ma,handle);
1130-
send_output_handle(port,handle,true); port++;
1106+
if (ma.isempty())
1107+
{
1108+
module_->error("InterfaceWithMatlab: Could not read output matrix");
1109+
continue;
11311110
}
11321111

1112+
MatrixHandle handle;
1113+
std::string info;
1114+
matlabconverter translate(module_->getLogger());
1115+
if (translate.sciMatrixCompatible(ma,info))
1116+
translate.mlArrayTOsciMatrix(ma,handle);
1117+
sendMatrixOutput(p, handle);
1118+
}
11331119

1120+
#ifdef SCIRUN4_CODE_TO_BE_ENABLED_LATER
11341121
for (int p = 0; p < NUM_FIELD_PORTS; p++)
11351122
{
11361123
if (!oport_connected(port)) { port++; continue; }
@@ -1241,11 +1228,8 @@ bool InterfaceWithMatlab::load_output_matrices()
12411228
if (translate.sciStringCompatible(ma,info)) translate.mlArrayTOsciString(ma,handle);
12421229
send_output_handle(port,handle,true); port++;
12431230
}
1244-
}
1245-
catch(...)
1246-
{
1247-
return(false);
1248-
}
1231+
#endif
1232+
12491233
return(true);
12501234
}
12511235

@@ -1368,6 +1352,39 @@ bool InterfaceWithMatlabImpl::isStringOutputPortConnected(int index) const
13681352
}
13691353
}
13701354

1355+
void InterfaceWithMatlabImpl::sendMatrixOutput(int index, MatrixHandle matrix) const
1356+
{
1357+
switch (index)
1358+
{
1359+
case 0:
1360+
module_->sendOutput(module_->OutputMatrix0, matrix);
1361+
case 1:
1362+
module_->sendOutput(module_->OutputMatrix1, matrix);
1363+
}
1364+
}
1365+
1366+
void InterfaceWithMatlabImpl::sendFieldOutput(int index, FieldHandle field) const
1367+
{
1368+
switch (index)
1369+
{
1370+
case 0:
1371+
module_->sendOutput(module_->OutputField0, field);
1372+
case 1:
1373+
module_->sendOutput(module_->OutputField1, field);
1374+
}
1375+
}
1376+
1377+
void InterfaceWithMatlabImpl::sendStringOutput(int index, StringHandle str) const
1378+
{
1379+
switch (index)
1380+
{
1381+
case 0:
1382+
module_->sendOutput(module_->OutputString0, str);
1383+
case 1:
1384+
module_->sendOutput(module_->OutputString1, str);
1385+
}
1386+
}
1387+
13711388
bool InterfaceWithMatlabImpl::save_input_matrices()
13721389
{
13731390
try
@@ -1681,52 +1698,53 @@ bool InterfaceWithMatlabImpl::isStringOutputPortConnected(int index) const
16811698
return(true);
16821699
}
16831700

1684-
bool InterfaceWithMatlabImpl::create_temp_directory()
1701+
bool InterfaceWithMatlabImpl::create_temp_directory()
1702+
{
1703+
if (temp_directory_.empty())
16851704
{
1686-
if (temp_directory_.empty())
1687-
{
1688-
return (tfmanager_.create_tempdir("matlab-engine.XXXXXX",temp_directory_));
1689-
}
1690-
return(true);
1705+
return (tfmanager_.create_tempdir("matlab-engine.XXXXXX",temp_directory_));
16911706
}
1707+
return(true);
1708+
}
16921709

16931710

1694-
bool InterfaceWithMatlabImpl::delete_temp_directory()
1711+
bool InterfaceWithMatlabImpl::delete_temp_directory()
1712+
{
1713+
if(temp_directory_ != "") tfmanager_.delete_tempdir(temp_directory_);
1714+
temp_directory_ = "";
1715+
return(true);
1716+
}
1717+
1718+
std::string InterfaceWithMatlabImpl::totclstring(const std::string &instring)
1719+
{
1720+
size_t strsize = instring.size();
1721+
int specchar = 0;
1722+
for (int p = 0; p < strsize; p++)
1723+
if ((instring[p]=='\n')||(instring[p]=='\t')||(instring[p]=='\b')||(instring[p]=='\r')||(instring[p]=='{')||(instring[p]=='}')
1724+
||(instring[p]=='[')||(instring[p]==']')||(instring[p]=='\\')||(instring[p]=='$')||(instring[p]=='"')) specchar++;
1725+
1726+
std::string newstring;
1727+
newstring.resize(strsize+specchar);
1728+
int q = 0;
1729+
for (int p = 0; p < strsize; p++)
16951730
{
1696-
if(temp_directory_ != "") tfmanager_.delete_tempdir(temp_directory_);
1697-
temp_directory_ = "";
1698-
return(true);
1731+
if (instring[p]=='\n') { newstring[q++] = '\\'; newstring[q++] = 'n'; continue; }
1732+
if (instring[p]=='\t') { newstring[q++] = '\\'; newstring[q++] = 't'; continue; }
1733+
if (instring[p]=='\b') { newstring[q++] = '\\'; newstring[q++] = 'b'; continue; }
1734+
if (instring[p]=='\r') { newstring[q++] = '\\'; newstring[q++] = 'r'; continue; }
1735+
if (instring[p]=='{') { newstring[q++] = '\\'; newstring[q++] = '{'; continue; }
1736+
if (instring[p]=='}') { newstring[q++] = '\\'; newstring[q++] = '}'; continue; }
1737+
if (instring[p]=='[') { newstring[q++] = '\\'; newstring[q++] = '['; continue; }
1738+
if (instring[p]==']') { newstring[q++] = '\\'; newstring[q++] = ']'; continue; }
1739+
if (instring[p]=='\\') { newstring[q++] = '\\'; newstring[q++] = '\\'; continue; }
1740+
if (instring[p]=='$') { newstring[q++] = '\\'; newstring[q++] = '$'; continue; }
1741+
if (instring[p]=='"') { newstring[q++] = '\\'; newstring[q++] = '"'; continue; }
1742+
newstring[q++] = instring[p];
16991743
}
17001744

1701-
std::string InterfaceWithMatlabImpl::totclstring(const std::string &instring)
1702-
{
1703-
size_t strsize = instring.size();
1704-
int specchar = 0;
1705-
for (int p = 0; p < strsize; p++)
1706-
if ((instring[p]=='\n')||(instring[p]=='\t')||(instring[p]=='\b')||(instring[p]=='\r')||(instring[p]=='{')||(instring[p]=='}')
1707-
||(instring[p]=='[')||(instring[p]==']')||(instring[p]=='\\')||(instring[p]=='$')||(instring[p]=='"')) specchar++;
1708-
1709-
std::string newstring;
1710-
newstring.resize(strsize+specchar);
1711-
int q = 0;
1712-
for (int p = 0; p < strsize; p++)
1713-
{
1714-
if (instring[p]=='\n') { newstring[q++] = '\\'; newstring[q++] = 'n'; continue; }
1715-
if (instring[p]=='\t') { newstring[q++] = '\\'; newstring[q++] = 't'; continue; }
1716-
if (instring[p]=='\b') { newstring[q++] = '\\'; newstring[q++] = 'b'; continue; }
1717-
if (instring[p]=='\r') { newstring[q++] = '\\'; newstring[q++] = 'r'; continue; }
1718-
if (instring[p]=='{') { newstring[q++] = '\\'; newstring[q++] = '{'; continue; }
1719-
if (instring[p]=='}') { newstring[q++] = '\\'; newstring[q++] = '}'; continue; }
1720-
if (instring[p]=='[') { newstring[q++] = '\\'; newstring[q++] = '['; continue; }
1721-
if (instring[p]==']') { newstring[q++] = '\\'; newstring[q++] = ']'; continue; }
1722-
if (instring[p]=='\\') { newstring[q++] = '\\'; newstring[q++] = '\\'; continue; }
1723-
if (instring[p]=='$') { newstring[q++] = '\\'; newstring[q++] = '$'; continue; }
1724-
if (instring[p]=='"') { newstring[q++] = '\\'; newstring[q++] = '"'; continue; }
1725-
newstring[q++] = instring[p];
1726-
}
1745+
return(newstring);
1746+
}
17271747

1728-
return(newstring);
1729-
}
17301748
#if 0
17311749
void InterfaceWithMatlab::tcl_command(GuiArgs& args, void* userdata)
17321750
{

0 commit comments

Comments
 (0)