Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

# encoding: utf-8 

from __future__ import print_function 

 

import os 

 

from .interpreter_bridge import InterpreterBridge 

from .errors import InvalidScriptName 

 

 

class MatlabRunner(InterpreterBridge): 

 

NAME = "MATLAB" 

EXTRA_ARGS = ["-nodisplay", "-nodesktop", "-nojvm", "-nosplash"] 

MSG_MARKER = "!!!" 

TEMPLATE = """ 

 

clear; 

exit_code__ = 0 

try 

 

{command}; 

 

catch ME 

 

exit_code__ = 1 

disp('{MSG_MARKER}ERROR:START'); 

disp(ME); 

if length(ME.stack) > 0 

disp('STACK :'); 

for k=1:length(ME.stack) 

disp(sprintf('STACK ELEMENT %d', k)) 

disp(ME.stack(k)) 

end 

end 

disp('{MSG_MARKER}ERROR:END'); 

 

end 

disp(sprintf('{MSG_MARKER}EXITCODE:%d', exit_code__)); 

disp('{MSG_MARKER}FINISHED'); 

""" 

 

def run_script(self, path_to_script, in_file_path, out_file_path, verbose=False): 

file_name = os.path.basename(path_to_script) 

if file_name != "conversion.m": 

raise InvalidScriptName( 

"script at {} must have name 'conversion.m'".format(path_to_script)) 

 

script_folder = os.path.dirname(path_to_script) 

 

code = """ 

saved_path = path; 

path(saved_path, '{script_folder}'); 

try 

conversion('{in_file_path}', '{out_file_path}'); 

catch ME 

path(saved_path); 

rethrow(ME) 

end 

path(saved_path); 

""".format(**locals()) 

 

return self.run_command(code, verbose=verbose)