org.scilab.modules.javasci
Class Scilab

java.lang.Object
  extended by org.scilab.modules.javasci.Scilab

public class Scilab
extends java.lang.Object

This class provides the capability to access to the Scilab engine from a Java application.

Example:
Scilab sci = new Scilab();
if (sci.open()) {
double [][]a={{21.2, 22.0, 42.0, 39.0},{23.2, 24.0, 44.0, 40.0}};
ScilabDouble aOriginal = new ScilabDouble(a);
sci.put("a",aOriginal);
ScilabDouble aFromScilab = (ScilabDouble)sci.get("a");
}

See Also:
org.scilab.modules.types

Constructor Summary
Scilab()
          Creator of the Scilab Javasci object.
Scilab(boolean advancedMode)
          Creator of the Scilab Javasci object in advanced mode
Scilab data path is autodetected
Example:
Scilab sci = new Scilab(true); // Starts in advanced mode

Scilab(java.lang.String SCI)
          Creator of the Scilab Javasci object with a specific Scilab path.
Advanced features are disabled (faster)
Example:
Scilab sci = new Scilab("/path/to/Scilab/data/dir/");

Scilab(java.lang.String SCIPath, boolean advancedMode)
          Creator of the Scilab Javasci object.
 
Method Summary
 boolean close()
          Shutdown Scilab
This function is based on TerminateScilab from call_scilab
Example:
sci.close();

 boolean exec(java.io.File scriptFilename)
          Execute a Scilab script .sce/.sci and throws an exception in case
the file is not found
This function is based on SendScilabJob from call_scilab
Note that this function is a direct call on the Scilab function exec: this.exec("exec('" + scriptFilename + "');");
Example:
sci.exec(new File("/tmp/myscript.sci"));

 boolean exec(java.lang.String job)
          Execute a single command in Scilab
This function is based on SendScilabJob from call_scilab
Example:
sci.exec("a=2*%pi");

 boolean exec(java.lang.String[] jobs)
          Execute several commands in Scilab
This function is based on SendScilabJob from call_scilab
Example:
sci.exec(new String[]{"a=42*2;","b=44*2", "c=(a==b)"});

 void execException(java.io.File scriptFilename)
          Execute a Scilab script .sce/.sci and throws an exception in case
of a Scilab error
Returns a ScilabErrorException in case of Scilab problem
This function is based on SendScilabJob from call_scilab
Note that this function is a direct call on the Scilab function exec: this.exec("exec('" + scriptFilename + "');");
Example:
sci.exec(new File("/tmp/myscript.sci"));

 void execException(java.lang.String job)
          Execute a single command in Scilab
Returns a ScilabErrorException in case of Scilab problem
This function is based on SendScilabJob from call_scilab
Example:
sci.exec("a=2*%pi");

 void execException(java.lang.String[] jobs)
          Execute several commands in Scilab
Returns a ScilabErrorException in case of Scilab problem
This function is based on SendScilabJob from call_scilab
Example:
sci.exec(new String[]{"a=42*2;","b=44*2", "c=(a==b)"});

 ScilabType get(java.lang.String varname)
          Returns a variable named varname
Throws an exception if the datatype is not managed or if the variable is not available
Example:
double [][]a={{21.2, 22.0, 42.0, 39.0},{23.2, 24.0, 44.0, 40.0}};
double [][]aImg={{212.2, 221.0, 423.0, 393.0},{234.2, 244.0, 441.0, 407.0}};
ScilabDouble aOriginal = new ScilabDouble(a, aImg);
sci.put("a",aOriginal);
ScilabDouble aFromScilab = (ScilabDouble)sci.get("a");

 ScilabType getByReference(java.lang.String varname)
          Returns a reference variable named varname
Throws an exception if the datatype is not managed or if the variable is not available
Example:
double [][]a={{21.2, 22.0, 42.0, 39.0},{23.2, 24.0, 44.0, 40.0}};
double [][]aImg={{212.2, 221.0, 423.0, 393.0},{234.2, 244.0, 441.0, 407.0}};
ScilabDouble aOriginal = new ScilabDouble(a, aImg);
sci.put("a",aOriginal);
ScilabDouble aFromScilab = (ScilabDouble)sci.get("a");

static ScilabType getInCurrentScilabSession(java.lang.String varname)
          Returns a variable named varname in the current Scilab session
Throws an exception if the datatype is not managed or if the variable is not available
Example:
double [][]a={{21.2, 22.0, 42.0, 39.0},{23.2, 24.0, 44.0, 40.0}};
double [][]aImg={{212.2, 221.0, 423.0, 393.0},{234.2, 244.0, 441.0, 407.0}};
ScilabDouble aOriginal = new ScilabDouble(a, aImg);
sci.put("a",aOriginal);
ScilabDouble aFromScilab = (ScilabDouble)sci.get("a");

static ScilabType getInCurrentScilabSession(java.lang.String varname, boolean byref)
          Returns a variable named varname in the current Scilab session
Throws an exception if the datatype is not managed or if the variable is not available
Example:
double [][]a={{21.2, 22.0, 42.0, 39.0},{23.2, 24.0, 44.0, 40.0}};
double [][]aImg={{212.2, 221.0, 423.0, 393.0},{234.2, 244.0, 441.0, 407.0}};
ScilabDouble aOriginal = new ScilabDouble(a, aImg);
sci.put("a",aOriginal);
ScilabDouble aFromScilab = (ScilabDouble)sci.get("a");

 int getLastErrorCode()
          Return the last error code
Example:
sci.open("a=1+"); // Wrong operation
sci.getLastErrorCode() // Returns 2

 java.lang.String getLastErrorMessage()
          Return the last error message
Example:
sci.open("a=1+");
System.err.println(sci.getLastErrorMessage());

 ScilabTypeEnum getVariableType(java.lang.String varName)
          Return the code type of a variable varname
Example:
sci.exec("a = 2*%pi");
if (sci.getVariableType("a") == ScilabTypeEnum.sci_matrix) {
System.out.println("a is a double matrix");
}

static ScilabTypeEnum getVariableTypeInCurrentScilabSession(java.lang.String varName)
          Return the code type of a variable varname in the current Scilab session
Example:
sci.exec("a = 2*%pi");
if (sci.getVariableType("a") == ScilabTypeEnum.sci_matrix) {
System.out.println("a is a double matrix");
}

 boolean isExistingVariable(java.lang.String varname)
          Detect if a variable (varname) exists in Scilab
Example:
double [][]a={{21.2, 22.0, 42.0, 39.0},{23.2, 24.0, 44.0, 40.0}};
ScilabDouble aOriginal = new ScilabDouble(a);
sci.put("a",aOriginal);
assert sci.isExistingVariable("a") == true;

 boolean isGraphicOpened()
          Detect if a Scilab graphic window is still opened
This function is based on ScilabHaveAGraph from call_scilab
Example:
sci.exec("plot3d();");
sci.isGraphicOpened();

 boolean open()
          Open a connection to the Scilab engine
This function is based on Call_ScilabOpen from call_scilab
Note: For now, only one instance of Scilab can be launched
A second launch will return FALSE

Example:
Scilab sci = new Scilab();
sci.open();

 boolean open(java.io.File scriptFilename)
          Open a connection to the Scilab engine and run thefile scriptFilename
This function is based on Call_ScilabOpen from call_scilab
Note: For now, only one instance of Scilab can be launched
A second launch will return FALSE

Example:
Scilab sci = new Scilab();
sci.open(new File("/tmp/myscript.sce"));

 boolean open(java.lang.String job)
          Open a connection to the Scilab engine and run the command job
This function is based on Call_ScilabOpen from call_scilab
Note: For now, only one instance of Scilab can be launched
A second launch will return FALSE

Example:
Scilab sci = new Scilab();
sci.open("a=%pi;");

 boolean open(java.lang.String[] jobs)
          Open a connection to the Scilab engine and run commands job
This function is based on Call_ScilabOpen from call_scilab
Note: For now, only one instance of Scilab can be launched
A second launch will return FALSE

Example:
Scilab sci = new Scilab();
sci.open(new String[]{"a=42*2;","b=44*2", "c=(a==b)"});

 boolean put(java.lang.String varname, ScilabType theVariable)
          Send to Scilab a variable theVariable named varname
Throws an exception if the datatype is not managed or if the variable is not available
Example:
boolean [][]a={{true, true, false, false},{true, false, true, false}};
ScilabBoolean aOriginal = new ScilabBoolean(a);
sci.put("a",aOriginal);
ScilabBoolean aFromScilab = (ScilabBoolean)sci.get("a");

static boolean putInCurrentScilabSession(java.lang.String varname, ScilabType theVariable)
          Send to the current Scilab session a variable theVariable named varname
Throws an exception if the datatype is not managed or if the variable is not available
Example:
boolean [][]a={{true, true, false, false},{true, false, true, false}};
ScilabBoolean aOriginal = new ScilabBoolean(a);
sci.put("a",aOriginal);
ScilabBoolean aFromScilab = (ScilabBoolean)sci.get("a");

 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Scilab

public Scilab()
       throws JavasciException.InitializationException
Creator of the Scilab Javasci object.
Scilab data path is autodetected and advanced features disabled

Throws:
JavasciException.InitializationException

Scilab

public Scilab(java.lang.String SCI)
       throws JavasciException.InitializationException
Creator of the Scilab Javasci object with a specific Scilab path.
Advanced features are disabled (faster)
Example:
Scilab sci = new Scilab("/path/to/Scilab/data/dir/");

Parameters:
SCI - provide the path to Scilab data
Throws:
JavasciException.InitializationException

Scilab

public Scilab(boolean advancedMode)
       throws JavasciException.InitializationException
Creator of the Scilab Javasci object in advanced mode
Scilab data path is autodetected
Example:
Scilab sci = new Scilab(true); // Starts in advanced mode

Parameters:
advancedMode - true enables the advanced mode (GUI, graphics, Tcl/Tk, sciNotes...). Smaller.
Throws:
JavasciException.InitializationException

Scilab

public Scilab(java.lang.String SCIPath,
              boolean advancedMode)
       throws JavasciException.InitializationException
Creator of the Scilab Javasci object.
Under GNU/Linux / Mac OS X, try to detect Scilab base path
if the property SCI is set, use it
if not, try with the global variable SCI
if not, throws a new exception
Under Windows, use also the registery

Example:
Scilab sci = new Scilab("/path/to/Scilab/data/dir/",true); // Starts in advanced mode

Parameters:
SCIPath - the path to Scilab data
advancedMode - true enables the advanced mode (GUI, graphics, Tcl/Tk, sciNotes...). Smaller.
Throws:
JavasciException.InitializationException
Method Detail

open

public boolean open()
             throws JavasciException
Open a connection to the Scilab engine
This function is based on Call_ScilabOpen from call_scilab
Note: For now, only one instance of Scilab can be launched
A second launch will return FALSE

Example:
Scilab sci = new Scilab();
sci.open();

Returns:
if the operation is successful
Throws:
JavasciException.AlreadyRunningException - Scilab is already running
JavasciException.InitializationException - Cannot start Scilab
JavasciException

open

public boolean open(java.lang.String job)
             throws JavasciException
Open a connection to the Scilab engine and run the command job
This function is based on Call_ScilabOpen from call_scilab
Note: For now, only one instance of Scilab can be launched
A second launch will return FALSE

Example:
Scilab sci = new Scilab();
sci.open("a=%pi;");

Parameters:
job - The job to run on startup
Returns:
if the operation is successful
Throws:
JavasciException

open

public boolean open(java.lang.String[] jobs)
             throws JavasciException
Open a connection to the Scilab engine and run commands job
This function is based on Call_ScilabOpen from call_scilab
Note: For now, only one instance of Scilab can be launched
A second launch will return FALSE

Example:
Scilab sci = new Scilab();
sci.open(new String[]{"a=42*2;","b=44*2", "c=(a==b)"});

Parameters:
jobs - The serie of jobs to run on startup
Returns:
if the operation is successful
Throws:
JavasciException

open

public boolean open(java.io.File scriptFilename)
             throws JavasciException,
                    java.io.FileNotFoundException
Open a connection to the Scilab engine and run thefile scriptFilename
This function is based on Call_ScilabOpen from call_scilab
Note: For now, only one instance of Scilab can be launched
A second launch will return FALSE

Example:
Scilab sci = new Scilab();
sci.open(new File("/tmp/myscript.sce"));

Parameters:
scriptFilename - The script to execute on startup
Returns:
if the operation is successful
Throws:
JavasciException
java.io.FileNotFoundException

exec

public boolean exec(java.lang.String job)
Execute a single command in Scilab
This function is based on SendScilabJob from call_scilab
Example:
sci.exec("a=2*%pi");

Parameters:
job - the job to execute
Returns:
if the operation is successful

execException

public void execException(java.lang.String job)
                   throws JavasciException.ScilabErrorException
Execute a single command in Scilab
Returns a ScilabErrorException in case of Scilab problem
This function is based on SendScilabJob from call_scilab
Example:
sci.exec("a=2*%pi");

Parameters:
job - the job to execute
Throws:
JavasciException.ScilabErrorException
Since:
5.4.0

exec

public boolean exec(java.lang.String[] jobs)
Execute several commands in Scilab
This function is based on SendScilabJob from call_scilab
Example:
sci.exec(new String[]{"a=42*2;","b=44*2", "c=(a==b)"});

Parameters:
jobs - the serie of job to execute
Returns:
if the operation is successful

execException

public void execException(java.lang.String[] jobs)
                   throws JavasciException.ScilabErrorException
Execute several commands in Scilab
Returns a ScilabErrorException in case of Scilab problem
This function is based on SendScilabJob from call_scilab
Example:
sci.exec(new String[]{"a=42*2;","b=44*2", "c=(a==b)"});

Parameters:
jobs - the serie of job to execute
Throws:
JavasciException.ScilabErrorException
Since:
5.4.0

execException

public void execException(java.io.File scriptFilename)
                   throws java.io.FileNotFoundException,
                          JavasciException.ScilabErrorException
Execute a Scilab script .sce/.sci and throws an exception in case
of a Scilab error
Returns a ScilabErrorException in case of Scilab problem
This function is based on SendScilabJob from call_scilab
Note that this function is a direct call on the Scilab function exec: this.exec("exec('" + scriptFilename + "');");
Example:
sci.exec(new File("/tmp/myscript.sci"));

Parameters:
scriptFilename - the script to execute
Throws:
java.io.FileNotFoundException
JavasciException.ScilabErrorException
Since:
5.4.0

exec

public boolean exec(java.io.File scriptFilename)
             throws java.io.FileNotFoundException
Execute a Scilab script .sce/.sci and throws an exception in case
the file is not found
This function is based on SendScilabJob from call_scilab
Note that this function is a direct call on the Scilab function exec: this.exec("exec('" + scriptFilename + "');");
Example:
sci.exec(new File("/tmp/myscript.sci"));

Parameters:
scriptFilename - the script to execute
Returns:
if the operation is successful
Throws:
java.io.FileNotFoundException

isExistingVariable

public boolean isExistingVariable(java.lang.String varname)
Detect if a variable (varname) exists in Scilab
Example:
double [][]a={{21.2, 22.0, 42.0, 39.0},{23.2, 24.0, 44.0, 40.0}};
ScilabDouble aOriginal = new ScilabDouble(a);
sci.put("a",aOriginal);
assert sci.isExistingVariable("a") == true;

Parameters:
varname - the variable to check
Returns:
if the variable exists or not

close

public boolean close()
Shutdown Scilab
This function is based on TerminateScilab from call_scilab
Example:
sci.close();

Returns:
if the operation is successful

getLastErrorCode

public int getLastErrorCode()
Return the last error code
Example:
sci.open("a=1+"); // Wrong operation
sci.getLastErrorCode() // Returns 2

Returns:
the error code

getLastErrorMessage

public java.lang.String getLastErrorMessage()
Return the last error message
Example:
sci.open("a=1+");
System.err.println(sci.getLastErrorMessage());

Returns:
the error message itself

isGraphicOpened

public boolean isGraphicOpened()
Detect if a Scilab graphic window is still opened
This function is based on ScilabHaveAGraph from call_scilab
Example:
sci.exec("plot3d();");
sci.isGraphicOpened();

Returns:
if the graphic is open or not

getVariableType

public ScilabTypeEnum getVariableType(java.lang.String varName)
                               throws JavasciException
Return the code type of a variable varname
Example:
sci.exec("a = 2*%pi");
if (sci.getVariableType("a") == ScilabTypeEnum.sci_matrix) {
System.out.println("a is a double matrix");
}

Parameters:
varName - the name of the variable
Returns:
the type of the variable
Throws:
JavasciException.UndefinedVariableException - The variable does not exist
JavasciException.UnknownTypeException - Cannot find the type
JavasciException

getVariableTypeInCurrentScilabSession

public static ScilabTypeEnum getVariableTypeInCurrentScilabSession(java.lang.String varName)
                                                            throws JavasciException
Return the code type of a variable varname in the current Scilab session
Example:
sci.exec("a = 2*%pi");
if (sci.getVariableType("a") == ScilabTypeEnum.sci_matrix) {
System.out.println("a is a double matrix");
}

Parameters:
varName - the name of the variable
Returns:
the type of the variable
Throws:
JavasciException.UndefinedVariableException - The variable does not exist
JavasciException.UnknownTypeException - Cannot find the type
JavasciException

get

public ScilabType get(java.lang.String varname)
               throws JavasciException
Returns a variable named varname
Throws an exception if the datatype is not managed or if the variable is not available
Example:
double [][]a={{21.2, 22.0, 42.0, 39.0},{23.2, 24.0, 44.0, 40.0}};
double [][]aImg={{212.2, 221.0, 423.0, 393.0},{234.2, 244.0, 441.0, 407.0}};
ScilabDouble aOriginal = new ScilabDouble(a, aImg);
sci.put("a",aOriginal);
ScilabDouble aFromScilab = (ScilabDouble)sci.get("a");

Parameters:
varname - the name of the variable
Returns:
return the variable
Throws:
JavasciException.UnsupportedTypeException - Type not managed yet.
JavasciException

getByReference

public ScilabType getByReference(java.lang.String varname)
                          throws JavasciException
Returns a reference variable named varname
Throws an exception if the datatype is not managed or if the variable is not available
Example:
double [][]a={{21.2, 22.0, 42.0, 39.0},{23.2, 24.0, 44.0, 40.0}};
double [][]aImg={{212.2, 221.0, 423.0, 393.0},{234.2, 244.0, 441.0, 407.0}};
ScilabDouble aOriginal = new ScilabDouble(a, aImg);
sci.put("a",aOriginal);
ScilabDouble aFromScilab = (ScilabDouble)sci.get("a");

Parameters:
varname - the name of the variable
Returns:
return the variable
Throws:
JavasciException.UnsupportedTypeException - Type not managed yet.
JavasciException

getInCurrentScilabSession

public static ScilabType getInCurrentScilabSession(java.lang.String varname)
                                            throws JavasciException
Returns a variable named varname in the current Scilab session
Throws an exception if the datatype is not managed or if the variable is not available
Example:
double [][]a={{21.2, 22.0, 42.0, 39.0},{23.2, 24.0, 44.0, 40.0}};
double [][]aImg={{212.2, 221.0, 423.0, 393.0},{234.2, 244.0, 441.0, 407.0}};
ScilabDouble aOriginal = new ScilabDouble(a, aImg);
sci.put("a",aOriginal);
ScilabDouble aFromScilab = (ScilabDouble)sci.get("a");

Parameters:
varname - the name of the variable
Returns:
return the variable
Throws:
JavasciException.UnsupportedTypeException - Type not managed yet.
JavasciException

getInCurrentScilabSession

public static ScilabType getInCurrentScilabSession(java.lang.String varname,
                                                   boolean byref)
                                            throws JavasciException
Returns a variable named varname in the current Scilab session
Throws an exception if the datatype is not managed or if the variable is not available
Example:
double [][]a={{21.2, 22.0, 42.0, 39.0},{23.2, 24.0, 44.0, 40.0}};
double [][]aImg={{212.2, 221.0, 423.0, 393.0},{234.2, 244.0, 441.0, 407.0}};
ScilabDouble aOriginal = new ScilabDouble(a, aImg);
sci.put("a",aOriginal);
ScilabDouble aFromScilab = (ScilabDouble)sci.get("a");

Parameters:
varname - the name of the variable
Returns:
return the variable
Throws:
JavasciException.UnsupportedTypeException - Type not managed yet.
JavasciException

put

public boolean put(java.lang.String varname,
                   ScilabType theVariable)
            throws JavasciException
Send to Scilab a variable theVariable named varname
Throws an exception if the datatype is not managed or if the variable is not available
Example:
boolean [][]a={{true, true, false, false},{true, false, true, false}};
ScilabBoolean aOriginal = new ScilabBoolean(a);
sci.put("a",aOriginal);
ScilabBoolean aFromScilab = (ScilabBoolean)sci.get("a");

Parameters:
varname - the name of the variable
theVariable - the variable itself
Returns:
true if the operation is successful
Throws:
JavasciException.UnsupportedTypeException - Type not managed yet.
JavasciException

putInCurrentScilabSession

public static boolean putInCurrentScilabSession(java.lang.String varname,
                                                ScilabType theVariable)
                                         throws JavasciException
Send to the current Scilab session a variable theVariable named varname
Throws an exception if the datatype is not managed or if the variable is not available
Example:
boolean [][]a={{true, true, false, false},{true, false, true, false}};
ScilabBoolean aOriginal = new ScilabBoolean(a);
sci.put("a",aOriginal);
ScilabBoolean aFromScilab = (ScilabBoolean)sci.get("a");

Parameters:
varname - the name of the variable
theVariable - the variable itself
Returns:
true if the operation is successful
Throws:
JavasciException.UnsupportedTypeException - Type not managed yet.
JavasciException