Exemplo n.º 1
0
        public void TestCreateCommand_InvalidSession()
        {
            string       cmdText = "b=a*a";
            MatlabEngine engine  = new MatlabEngine();

            engine.Shutdown();
            engine.CreateCommand(cmdText);
        }
Exemplo n.º 2
0
        public void TestCreateComplexCommand_InvalidSession()
        {
            MatlabEngine engine = new MatlabEngine();

            engine.Shutdown();

            engine.CreateCommand(new string[] { });
        }
Exemplo n.º 3
0
        public void TestCreateCommand_ValidArgs()
        {
            string        cmdText = "b=a*a";
            MatlabEngine  engine  = new MatlabEngine();
            MatlabCommand cmd     = engine.CreateCommand(cmdText);
            SingleStatementMatlabCommand theCmd = cmd as SingleStatementMatlabCommand;

            Assert.AreEqual(cmdText, theCmd.Input);
        }
Exemplo n.º 4
0
 private void _populateEngine(MatlabEngine e, MatlabProperties p)
 {
     foreach (MatlabParameter parameter in p.Parameters)
     {
         Workspace       w     = parameter.Workspace == "Base" ? e.Base : e.Global;
         IParameterValue value = parameter.Value;
         value.Put(parameter.Name, w);
     }
 }
Exemplo n.º 5
0
 private void _execute(MatlabProperties p)
 {
     using (MatlabEngine engine = new MatlabEngine())
     {
         _populateEngine(engine, p);
         _putInput(engine);
         var script = _extractScript(p);
         _runScript(engine, script);
         _setOutput(engine);
     }
 }
Exemplo n.º 6
0
        private void _setOutput(MatlabEngine engine)
        {
            object output = _getDipsOutput(engine.Base);

            if (output is string == false)
            {
                throw new AlgorithmException("Script did not output file path");
            }


            _matlabOutputPath = (string)output;
            _tryLoadOutputFromPath();
        }
Exemplo n.º 7
0
        private void _putInput(MatlabEngine e)
        {
            string name = "Tmp.bmp";
            string path = string.Format(@"{0}/{1}", Directory.GetCurrentDirectory(), name);

            // Ensure we are giving Matlab the newest file by deleting the previous
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            Input.Save(path, ImageFormat.Bmp);
            e.Base.PutObject("dipsinput", name);
        }
Exemplo n.º 8
0
 private void _runScript(MatlabEngine engine, IEnumerable <string> script)
 {
     try
     {
         string        currentDir = Directory.GetCurrentDirectory();
         string        cdToDir    = string.Format("cd {0}", currentDir);
         MatlabCommand cmd        = engine.CreateCommand(cdToDir);
         cmd.Execute();
         MatlabCommand c = engine.CreateCommand(script);
         c.Execute();
         MatlabCommand close = engine.CreateCommand("fclose('all')");
         close.Execute();
     }
     catch (Exception e)
     {
         string err = "Error executing Matlab script. Ensure all variables have been provided " +
                      "and that the script functions within Matlab.";
         throw new AlgorithmException(err, e);
     }
 }
Exemplo n.º 9
0
 public void TestCreateComplexCommand_ValidArgs()
 {
     IEnumerable <string> cmds   = new [] { "a=1+1" };
     MatlabEngine         engine = new MatlabEngine();
     MatlabCommand        cmd    = engine.CreateCommand(cmds);
 }
Exemplo n.º 10
0
        public void TestCreateComplexCommand_NullCmds()
        {
            MatlabEngine engine = new MatlabEngine();

            engine.CreateCommand(null as IEnumerable <string>);
        }
Exemplo n.º 11
0
        public void TestCreateCommand_NullCommand()
        {
            MatlabEngine engine = new MatlabEngine();

            engine.CreateCommand(null as string);
        }