Skip to content

Commit 6e0aa67

Browse files
committed
Reformat
1 parent 6cf46c8 commit 6e0aa67

File tree

1 file changed

+65
-70
lines changed

1 file changed

+65
-70
lines changed

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

Lines changed: 65 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -654,13 +654,13 @@ void InterfaceWithMatlab::execute()
654654
error("InterfaceWithMatlab: Could not create m-file code for matlabengine");
655655
return;
656656
}
657-
#if 0
658-
if (!send_matlab_job())
657+
658+
if (!impl_->send_matlab_job())
659659
{
660660
error("InterfaceWithMatlab: Matlab returned an error or Matlab could not be launched");
661661
return;
662662
}
663-
663+
#if 0
664664
if (!load_output_matrices())
665665
{
666666
error("InterfaceWithMatlab: Could not load matrices that matlab generated");
@@ -669,86 +669,81 @@ void InterfaceWithMatlab::execute()
669669
#endif
670670
}
671671

672-
#if 0
673-
void InterfaceWithMatlab::presave()
672+
bool InterfaceWithMatlabImpl::send_matlab_job()
673+
{
674+
std::string mfilename = mfile_.substr(0,mfile_.size()-2); // strip the .m
675+
std::string remotefile = file_transfer_->remote_file(mfilename);
676+
#ifndef USE_MATLAB_ENGINE_LIBRARY
677+
IComPacketHandle packet = new IComPacket;
678+
679+
if (packet.get_rep() == 0)
674680
{
675-
TCLInterface::execute(get_id() + " update_text"); // update matlab-code before saving.
681+
error("InterfaceWithMatlab: Could not create packet");
682+
return(false);
676683
}
677684

678-
bool InterfaceWithMatlab::send_matlab_job()
679-
{
680-
std::string mfilename = mfile_.substr(0,mfile_.size()-2); // strip the .m
681-
std::string remotefile = file_transfer_->remote_file(mfilename);
682-
#ifndef USE_MATLAB_ENGINE_LIBRARY
683-
IComPacketHandle packet = new IComPacket;
685+
thread_info_->dolock();
686+
thread_info_->code_done_ = false;
687+
thread_info_->unlock();
684688

685-
if (packet.get_rep() == 0)
686-
{
687-
error("InterfaceWithMatlab: Could not create packet");
688-
return(false);
689-
}
689+
packet->settag(TAG_MCODE);
690+
packet->setstring(remotefile);
691+
matlab_engine_->send(packet);
690692

691-
thread_info_->dolock();
692-
thread_info_->code_done_ = false;
693-
thread_info_->unlock();
694-
695-
packet->settag(TAG_MCODE);
696-
packet->setstring(remotefile);
697-
matlab_engine_->send(packet);
698-
699-
thread_info_->dolock();
700-
if (!thread_info_->code_done_)
693+
thread_info_->dolock();
694+
if (!thread_info_->code_done_)
695+
{
696+
thread_info_->wait_code_done_.wait(thread_info_->lock);
697+
}
698+
bool success = thread_info_->code_success_;
699+
bool exitcond = thread_info_->exit_;
700+
if (!success)
701+
{
702+
if (exitcond)
701703
{
702-
thread_info_->wait_code_done_.wait(thread_info_->lock);
704+
error("InterfaceWithMatlab: the matlab engine crashed or did not start: "+ thread_info_->code_error_);
705+
error("InterfaceWithMatlab: possible causes are:");
706+
error("(1) matlab code failed in such a way that the engine was no able to catch the error (e.g. failure mex of code)");
707+
error("(2) matlab crashed and the matlab engine detected an end of communication of the matlab process");
708+
error("(3) temparory files could not be created or are corrupted");
709+
error("(4) improper matlab version, use matlab V5 or higher, currently matlab V5-V7 are supported");
703710
}
704-
bool success = thread_info_->code_success_;
705-
bool exitcond = thread_info_->exit_;
706-
if (!success)
711+
else
707712
{
708-
if (exitcond)
709-
{
710-
error("InterfaceWithMatlab: the matlab engine crashed or did not start: "+ thread_info_->code_error_);
711-
error("InterfaceWithMatlab: possible causes are:");
712-
error("(1) matlab code failed in such a way that the engine was no able to catch the error (e.g. failure mex of code)");
713-
error("(2) matlab crashed and the matlab engine detected an end of communication of the matlab process");
714-
error("(3) temparory files could not be created or are corrupted");
715-
error("(4) improper matlab version, use matlab V5 or higher, currently matlab V5-V7 are supported");
716-
}
717-
else
718-
{
719-
error("InterfaceWithMatlab: matlab code failed: "+thread_info_->code_error_);
720-
error("InterfaceWithMatlab: Detected an error in the Matlab code, the matlab engine is still running and caught the exception");
721-
error("InterfaceWithMatlab: Please check the matlab code in the GUI and try again. The output window in the GUI should contain the reported error message generated by matlab");
722-
}
723-
thread_info_->code_done_ = false;
724-
thread_info_->unlock();
725-
return(false);
713+
error("InterfaceWithMatlab: matlab code failed: "+thread_info_->code_error_);
714+
error("InterfaceWithMatlab: Detected an error in the Matlab code, the matlab engine is still running and caught the exception");
715+
error("InterfaceWithMatlab: Please check the matlab code in the GUI and try again. The output window in the GUI should contain the reported error message generated by matlab");
726716
}
727717
thread_info_->code_done_ = false;
728718
thread_info_->unlock();
719+
return(false);
720+
}
721+
thread_info_->code_done_ = false;
722+
thread_info_->unlock();
729723

730724
#else
731-
std::string command = std::string("addpath('") + remotefile.substr(0,remotefile.size()-12) +"');";
732-
bool success = (engEvalString(engine_, command.c_str()) == 0);
725+
std::string command = std::string("addpath('") + remotefile.substr(0,remotefile.size()-12) +"');";
726+
bool success = (engEvalString(engine_, command.c_str()) == 0);
733727

734-
command = "scirun_code;";
735-
success = (engEvalString(engine_, command.c_str()) == 0);
728+
command = "scirun_code;";
729+
success = (engEvalString(engine_, command.c_str()) == 0);
736730

737-
std::string output(output_buffer_);
738-
std::string cmd = get_id()+" AddOutput \"" + InterfaceWithMatlab::totclstring(output) + "\"";
739-
TCLInterface::lock();
740-
TCLInterface::execute(cmd);
741-
TCLInterface::unlock();
731+
std::string output(output_buffer_);
732+
std::string cmd = get_id()+" AddOutput \"" + InterfaceWithMatlab::totclstring(output) + "\"";
733+
TCLInterface::lock();
734+
TCLInterface::execute(cmd);
735+
TCLInterface::unlock();
742736

743-
std::cout << output_buffer_ << std::endl;
737+
std::cout << output_buffer_ << std::endl;
744738

745-
// without this, matlab will cache the first file as a function and ignore the rest of them.
746-
engEvalString(engine_, "clear functions");
747-
// output_buffer_ has output in it - do something with it
739+
// without this, matlab will cache the first file as a function and ignore the rest of them.
740+
engEvalString(engine_, "clear functions");
741+
// output_buffer_ has output in it - do something with it
748742
#endif
749-
return(success);
750-
}
743+
return(success);
744+
}
751745

746+
#if 0
752747
bool InterfaceWithMatlab::send_input(std::string str)
753748
{
754749
#ifndef USE_MATLAB_ENGINE_LIBRARY
@@ -977,13 +972,13 @@ void InterfaceWithMatlab::execute()
977972
if(!(matlab_engine_->recv(packet)))
978973
{
979974
matlab_engine_->close();
980-
//file_transfer_->close();
975+
file_transfer_->close();
981976
module_->error(std::string("InterfaceWithMatlab: Could not get answer from matlab engine (error=") + matlab_engine_->geterror() + std::string(")"));
982977
module_->error(std::string("InterfaceWithMatlab: This is an internal communication error, make sure that the portnumber is correct"));
983978
module_->error(std::string("InterfaceWithMatlab: If address information is correct, this most probably points to a bug in the SCIRun software"));
984979

985980
matlab_engine_.reset();
986-
//file_transfer_ = 0;
981+
file_transfer_.reset();
987982

988983
return(false);
989984
}
@@ -992,7 +987,7 @@ void InterfaceWithMatlab::execute()
992987
if (packet->gettag() == TAG_MERROR)
993988
{
994989
matlab_engine_->close();
995-
//file_transfer_->close();
990+
file_transfer_->close();
996991

997992
module_->error(std::string("InterfaceWithMatlab: InterfaceWithMatlab engine returned an error (error=") + packet->getstring() + std::string(")"));
998993
module_->error(std::string("InterfaceWithMatlab: Please check whether '[MATLAB_DIRECTORY]/services/matlabengine.rc' has been setup properly"));
@@ -1001,7 +996,7 @@ void InterfaceWithMatlab::execute()
1001996
module_->error(std::string("InterfaceWithMatlab: If you running matlab remotely, this file must be edited on the machine running matlab"));
1002997

1003998
matlab_engine_.reset();
1004-
//file_transfer_ = 0;
999+
file_transfer_.reset();
10051000

10061001
return(false);
10071002
}
@@ -1010,11 +1005,11 @@ void InterfaceWithMatlab::execute()
10101005
if (!thread_info_)
10111006
{
10121007
matlab_engine_->close();
1013-
//file_transfer_->close();
1008+
file_transfer_->close();
10141009

10151010
module_->error("InterfaceWithMatlab: Could not create thread information object");
10161011
matlab_engine_.reset();
1017-
//file_transfer_ = 0;
1012+
file_transfer_.reset();
10181013

10191014
return(false);
10201015
}

0 commit comments

Comments
 (0)