MATLAB Runtime Server    

Organizing Files and Managing Startup Tasks

This section discusses the locations of the files you write for the runtime application, and special startup issues. The startup issues include the startup and path definition functions that the Runtime Server invokes when it first runs. These utility functions, matlabrt and pathdefrt, are variations of the functions matlabrc and pathdef that commercial MATLAB invokes upon startup. This section also discusses startup considerations for PC applications.

Where to Place Your Files

You can arrange the MATLAB portion of your application just as you would in the case of a runtime GUI application. This is described in the earlier section Where to Place Your Files. MATLAB places no restriction on the directory structure of the non-MATLAB portion of your application and no restriction on the relative locations of the MATLAB and non-MATLAB portions of your application.

Creating the Startup Function

The startup function matlabrt is the runtime analogue of matlabrc. When the front end of the application launches MATLAB, MATLAB executes matlabrt.p. Furthermore, matlabrt acts as the gateway to the MATLAB portion of the application.

The matlabrt.p file should reside in the toolbox\local directory, and should perform these tasks (in addition to ordinary tasks that matlabrc performs):

Either matlabrt or another M-file should be a top-level M-file in the sense that it acts as an intermediary between the front end and the application's M-file functions. The front end then communicates only with this top-level M-file. When an event occurs in the front end that requires a MATLAB function to execute, the front end calls the top-level M-file with a switch that indicates which action should occur. The top-level M-file then executes the appropriate function to accomplish the action.

Creating the Path Definition Function

The startup function matlabrt invokes the path definition function pathdefrt. Create pathdefrt as described in Creating the Path Definition Function.

PC Startup Considerations

During a MATLAB runtime engine application, MATLAB registers itself as an as an Automation server.

Default Executable.   If MATLAB is not currently running as an Automation server on the system, then the MATLAB executable file (matlab.exe) that is launched by the controller is the one most recently run. If MATLAB is already running on the system, then the ActiveX controller uses the currently running instance of MATLAB.

Users Who Have MATLAB Installed on the System.   If a copy of commercial MATLAB is installed on the same system as the Runtime Server application (for example, if the user works with MATLAB), then there is a possibility that your application will invoke commercial MATLAB instead of the Runtime Server. This will happen if the user launches the application while commercial MATLAB is running as an Automation server, or when commercial MATLAB was run as an Automation server more recently than the MATLAB Runtime Server.

The application should run normally with commercial MATLAB, although certain Runtime Server adaptations will be absent (splash screen, global error behavior, etc.). If it is important that the application not use commercial MATLAB, then you can include a variant test in the startup procedure using the isruntime command.

Handling Multiple Application Instances and Multiple Versions of MATLAB.   Your application can launch the MATLAB Automation server either as a multiple-client server or as a dedicated server. Also, if a user of your application has two different versions of MATLAB installed, then your application can launch either the default version, as described above, or a specific version. You make these choices when you decide what ProgID to use when coding your application. The possible values for ProgID, and the corresponding results when MATLAB is launched, are summarized in the table below.

ProgID
Version of MATLAB Launched
Type of Server
Matlab.Application
Default
Multiple-client
Matlab.Application.6
Version 6
Multiple-client
Matlab.Application.Single
Default
Dedicated
Matlab.Application.Single.6
Version 6
Dedicated

Suppose that the user starts up multiple instances of the application. If you have chosen to use a multiple-client server, then each new client instance shares the same instance of the Runtime Server. You should therefore either design the MATLAB side of the application to service multiple clients, or prevent multiple clients from simultaneously using the Runtime Server. If, on the other hand, you have chosen to use a dedicated server, then each instance will be served by a different instance of the Runtime Server.


  Parts of a MATLAB Runtime Engine Application Compiling the Application