Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified messenger/mexa64/messenger.mex
Binary file not shown.
Binary file modified messenger/mexa64/messenger.mexa64
Binary file not shown.
12 changes: 10 additions & 2 deletions messenger/src/messenger.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "mex.h"
#include "zmq.h"

Expand All @@ -12,6 +13,7 @@ static int initialized = 0;
/* Initialize a ZMQ server */
int initialize(char *socket_addr) {
int rc;
mexLock();
ctx = zmq_ctx_new();
socket_ptr = zmq_socket(ctx, ZMQ_REP);
rc = zmq_bind(socket_ptr, socket_addr);
Expand All @@ -33,7 +35,7 @@ int listen_zmq(char *buffer, int buflen) {
mexErrMsgTxt("Error: ZMQ session not initialized");
}

return zmq_recv(socket_ptr, buffer, buflen, 0);
return zmq_recv(socket_ptr, buffer, buflen, ZMQ_NOBLOCK);
}

/* Sending out a message */
Expand Down Expand Up @@ -108,13 +110,19 @@ void mexFunction(int nlhs, mxArray *plhs[],

int byte_recvd = listen_zmq(recv_buffer, BUFLEN);

while (byte_recvd == -1 && errno == EAGAIN) {
mexCallMATLAB(0, NULL, 0, NULL, "drawnow");
byte_recvd = listen_zmq(recv_buffer, BUFLEN);
}

/* Check if the received data is complete and correct */
if ((byte_recvd > -1) && (byte_recvd <= BUFLEN)) {
plhs[0] = mxCreateString(recv_buffer);
} else if (byte_recvd > BUFLEN){
mexErrMsgTxt("Receiver buffer overflow. Message truncated");
} else {
mexErrMsgTxt("Failed to receive a message due to ZMQ error");
sprintf(recv_buffer, "Failed to receive a message due to ZMQ error %s", strerror(errno));
mexErrMsgTxt(recv_buffer);
}

return;
Expand Down
4 changes: 3 additions & 1 deletion pymatbridge/matlab/util/make_figs.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
saveas(h, [filename, '.png']);
% Once you've saved it, close it, so it doesn't get dragged into the
% scope of other cells
close(h);
if (strcmp(get(h, 'visible'), 'off'))
close(h);
end
fig_files{fig} = [filename '.png'];
end

Expand Down
2 changes: 2 additions & 0 deletions pymatbridge/matlab/util/pymat_eval.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
response.content = '';
response.result = '';

close all hidden;

try
% tempname is less likely to get bonked by another process.
diary_file = [tempname() '_diary.txt'];
Expand Down
7 changes: 6 additions & 1 deletion pymatbridge/matlab_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ def set_matlab_var(self, name, value):
help='Pixel size of plots, "width,height.'
)

@argument(
'-g', '--gui', action='store_true',
help='Show plots in a graphical user interface'
)

@argument(
'code',
nargs='*',
Expand All @@ -148,7 +153,7 @@ def matlab(self, line, cell=None, local_ns=None):
local_ns = {}

width, height = args.size.split(',')
self.Matlab.set_default_plot_size(width, height)
self.Matlab.set_plot_settings(width, height, not args.gui)

if args.input:
for input in ','.join(args.input).split(','):
Expand Down
23 changes: 13 additions & 10 deletions pymatbridge/pymatbridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def start(self):
# Test if connection is established
if self.is_connected():
print("%s started and connected!" % self._program_name())
self.set_default_plot_size()
self.set_plot_settings()
return True
else:
print("%s failed to start" % self._program_name())
Expand Down Expand Up @@ -318,12 +318,16 @@ def set_variable(self, varname, value):
return self._set_sparse_variable(varname, value)
return self.run_func('assignin', 'base', varname, value, nargout=0)

def set_default_plot_size(self, width=512, height=384):
code = "set(0, 'defaultfigurepaperunits', 'inches');\n"
code += "set(0, 'defaultfigureunits', 'inches');\n"
size = "set(0, 'defaultfigurepaperposition', [0 0 %s %s])\n;"
code += size % (int(width) / 150., int(height) / 150.)
self.run_code(code)
def set_plot_settings(self, width=512, height=384, inline=True):
if inline:
code = ["set(0, 'defaultfigurevisible', 'off')"]
else:
code = ["set(0, 'defaultfigurevisible', 'on')"]
size = "set(0, 'defaultfigurepaperposition', [0 0 %s %s])"
code += ["set(0, 'defaultfigurepaperunits', 'inches')",
"set(0, 'defaultfigureunits', 'inches')",
size % (int(width) / 150., int(height) / 150.)]
self.run_code(';'.join(code))

def _set_sparse_variable(self, varname, value):
value = value.todok()
Expand Down Expand Up @@ -436,9 +440,9 @@ def __init__(self, executable='matlab', socket_addr=None,
platform = sys.platform
if startup_options is None:
if platform == 'win32':
startup_options = ' -automation -noFigureWindows'
startup_options = ' -automation'
else:
startup_options = ' -nodesktop -nodisplay'
startup_options = ' -nodesktop'
if log:
startup_options += ' -logfile ./pymatbridge/logs/matlablog_%s.txt' % id
super(Matlab, self).__init__(executable, socket_addr, id, log, maxtime,
Expand Down Expand Up @@ -499,7 +503,6 @@ def _preamble_code(self):
code = super(Octave, self)._preamble_code()
if self.log:
code.append("diary('./pymatbridge/logs/octavelog_%s.txt')" % self.id)
code.append("set(0, 'defaultfigurevisible', 'off');")
code.append("graphics_toolkit('gnuplot')")
return code

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pyzmq
numpy>=1.7