MATLAB Web Server For Use with MATLAB ® Computation Visualization Programming MATLAB Web Server Version 1
How to Contact The MathWorks: www.mathworks.com comp.soft-sys.matlab Web Newsgroup info@mathworks.com Technical support Product enhancement suggestions Bug reports Documentation error reports Order status, license renewals, passcodes Sales, pricing, and general information 508-647-7000 Phone 508-647-7001 Fax The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098 Mail support@mathworks.com suggest@mathworks.com bugs@mathworks.com doc@mathworks.com service@mathworks.
Contents Preface About This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vi Organization of the Document . . . . . . . . . . . . . . . . . . . . . . . . . . . vi Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii Related Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . viii MATLAB on the Web 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Getting Started 2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Creating Input Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Input Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Creating MATLAB Web Server M-Files . . . . . . . . . . . . . . . . . . 2-7 M-File Template . . . . . . . . . .
Reference 4 Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . htmlrep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . matweb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . wscleanup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . wsprintjpeg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . wssetfield . . . . . .
iv Contents
Preface About This Book . . . . . . . . . . . . . . . . . . . vi Organization of the Document . . . . . . . . . . . . . . vi Typographical Conventions . . . . . . . . . . . . . .vii Related Products . . . . . . . . . . . . . . . . . .
Preface About This Book This book describes the MATLAB® Web Server. The MATLAB Web Server lets you deploy MATLAB based applications over a network using standard Web technology. Organization of the Document vi Chapter Description Chapter 1 Chapter 1, “MATLAB on the Web” provides basic information about how to develop MATLAB applications in a Web environment. Discusses how to install the MATLAB Web Server.
Typographical Conventions Typographical Conventions This manual uses some or all of these conventions. Item Convention Used Example Example code Monospace font To assign the value 5 to A, enter A = 5 Function names/syntax Monospace font The cos function finds the cosine of each array element. Syntax line example is MLGetVar ML_var_name Keys Boldface with an initial capital letter Press the Return key.
Preface Related Products The MATLAB Web Server requires MATLAB Release 11 or later. No other MathWorks-supplied software is required. See “Product Requirements” on page 1-5 for additional requirements specific to Web-based software applications. The MathWorks provides numerous products that can be used in conjunction with the MATLAB Web Server.
Related Products Product Description MATLAB C/C++ Graphics Library Library for automatically compiling MATLAB programs that contain graphics and graphical user interfaces (GUIs) into complete stand-alone applications MATLAB Runtime Server MATLAB environment in which you can take an existing MATLAB application and turn it into a stand-alone product that is easy and cost-effective to package and distribute.
Preface x
1 MATLAB on the Web Introduction . . . . . . . . . . . . . . . . . . . . 1-2 MATLAB Web Server Environment . . . . . . . . . . . 1-2 Building MATLAB Web Server Applications . . . . . . . 1-3 Product Requirements . . . . . . . . . . . . . . . 1-5 Web Requirements . . . . . . . . . . . . . . . . . . 1-5 Installation . . . . . . . . . . . . Availability . . . . . . . . . . . . . Installation Procedure . . . . . . . . General Post-Installation Procedures . .
1 MATLAB on the Web Introduction MATLAB Web Server Environment The MATLAB® Web Server enables you to create MATLAB applications that use the capabilities of the World Wide Web to send data to MATLAB for computation and to display the results in a Web browser. The MATLAB Web Server depends upon TCP/IP networking for transmission of data between the client system and MATLAB. The required networking software and hardware must be installed on your system prior to using the MATLAB Web Server.
Introduction In a more complex network, the Web server daemon can run on a machine apart from the others. Building MATLAB Web Server Applications MATLAB Web Server applications are a combination of M-files, Hypertext Markup Language (HTML), and graphics. Knowledge of MATLAB programming and basic HTML are the only requirements. The application development process requires a small number of simple steps: 1 Create the HTML documents for collection of the input data from users and display of output.
1 MATLAB on the Web 3 Write a MATLAB M-file that: a Receives the data entered in the HTML input form. b Analyzes the data and generates any requested graphics. c Places the output data into a MATLAB structure. d Calls htmlrep to place the output data into an HTML output document template. (See htmlrep for a description of this process.) The maximum amount of HTML data you can receive from MATLAB is 256 KB.
Product Requirements Product Requirements The MATLAB Web Server has the same supporting hardware and software requirements as MATLAB itself, except for memory required. MATLAB hardware and software requirements are documented in the MATLAB Installation Guide for your computer. Memory requirements while running the MATLAB Web Server vary with the number of MATLABs configured. Each MATLAB running under the MATLAB Web Server consumes 256 KB of memory.
1 MATLAB on the Web Installation Availability The MATLAB Web Server is available on UNIX (Solaris) workstations and IBM PC compatible computers running Microsoft Windows NT or Linux. Installation Procedure To install the MATLAB Web Server, follow the normal MATLAB installation procedure for your platform, as documented in the MATLAB Installation Guide for PC and the MATLAB Installation Guide for UNIX.
Installation -m 1 This number represents the number of MATLABs that can run concurrently. After testing that everything is working properly, you can change this number to something more convenient. On Windows NT edit matlabserver.conf directly with a text editor. Note To see any changes made to matlabserver.conf, you need to stop and restart the MATLAB Web Server. See the section “Understanding matlabserver” on page 3-5 for more information on matlabserver.conf.
1 MATLAB on the Web • Copy matweb.conf in /toolbox/webserver/wsdemos to the directory aliased by /cgi-bin or equivalent. • Copy all demo HTML files in /toolbox/webserver/wsdemos to the directory where the httpd keeps all HTML files (often referred to as the home or default alias). Note that when aliases are different from those provided in the demo HTML files, you will have to make the corresponding changes in those HTML files. For example, if you use the Apache Web Server (http://www.
Installation at the command prompt to see detailed information about a specific script. After completing the MATLAB and MATLAB Web Server installation process, run the webconf script to generate the matlabserver.conf file. Then run webstart to start matlabserver. Run webdown at any time to stop matlabserver execution. Automatic Startup at System Boot 1 To start matlabserver automatically at system boot, create the following links and file while logged in as root (superuser).
1 MATLAB on the Web 3 Open the copied file in a text editor and follow the directions for modifying the file. Save and close the file when you are done.
Installation 4 Solaris users should create a link in the rc directory associated with run level 3. cd /etc/rc3.d; ln -s ../init.d/webserver S20webserver Linux users should look in /etc/inittab for the default run level. Create a link in the rc directory associated with that run level. For example, if it is 5 cd /etc/rc5.d; ln -s ../init.d/webserver S95weberver (Debian) cd /etc/rc.d/rc5.d; ln -s init.d/webserver S95webserver (Red Hat) 5 You can test the changes you have made without rebooting your system.
1 MATLAB on the Web Deinstallation To remove MATLAB Server from the Windows NT Registry, open a command prompt (MS-DOS) window.
Graphics Display Graphics Display We recommend that Solaris/Linux users use Virtual Network Computing (VNC) for their X display. VNC can be used even on systems where there is no hardware frame buffer. It is easy to use, can be easily started with the boot scripts, provides complete user control, and has good performance. For information about use of the VNC software with the MATLAB Web Server, see: • “Downloading and Installing VNC” on page 1-13. • “Starting and Stopping VNC” on page 1-14.
1 MATLAB on the Web The file directory created contains a README file that discusses how to install the software. The directory contains four files vncviewer vncserver vncpasswd Xvnc that should be copied to a standard directory on your UNIX path. Downloading and Installing Perl The Perl software is available at the Web site http://www.activestate.com. Under Products select ActivePerl; then select Download Now next to the ActivePerl description on the Products page.
Graphics Display The first time you run the vncserver, you will be prompted for a password. This password controls access to the VNC viewer, which is not used with the Web Server. You do not have to specify a display number when starting the VNC server, but it is best to specify one to prevent any potential conflict with the main X display, which is normally 0. Starting VNC To start the VNC server, enter vncserver :number where number is something other than 0. 1 is a good value.
1 MATLAB on the Web webstart -display :1 [webstart]:Calling webdown to take down MATLAB Web Server . . . No server to take down . . . [webstart]:Calling webboot to start MATLAB Web Server . . . Waiting for MATLAB Web Server to come up . . . Type your interrupt character (usually CTRL-C) to quit. Time = 10 secs : still waiting for 1 of 2 MATLAB sessions . . . Time = 20 secs : still waiting for 1 of 2 MATLAB sessions . . . Time = 30 secs : still waiting for 1 of 2 MATLAB sessions . . .
2 Getting Started Introduction . . . . . . . . . . . . . . . . . . . . 2-2 Templates . . . . . . . . . . . . . . . . . . . . . 2-2 Creating Input Documents . . . . . . . . . . . . . 2-4 Input Template . . . . . . . . . . . . . . . . . . . 2-4 Creating MATLAB Web Server M-Files . . . . . . . . 2-7 M-File Template . . . . . . . . . . . . . . . . . . . 2-7 Creating Output Documents . . . . . . . . . . . . . 2-10 Output Template . . . . . . . . . . . . . . . . . . . 2-10 Debugging Your Application . . . . . . .
2 Getting Started Introduction The process of creating a MATLAB Web Server application involves the creation of: • An HTML input document for data submission to MATLAB. See “Creating Input Documents” on page 2-4. • An HTML output document for display of MATLAB’s computations. See “Creating Output Documents” on page 2-10. • A MATLAB M-file to process input data and compute results. See “Creating MATLAB Web Server M-Files” on page 2-7.
Introduction • webmagic1.html: the webmagic input document • webmagic2.html: the webmagic output document • webmagic.m: the webmagic MATLAB M-file • twebmagic.m: the webmagic stand-alone test file To learn how the four templates were modified to create the webmagic application, we will examine templates and note the specific changes applied. If you want to look at some other applications created with these templates, see the section “Additional Application Examples” on page 2-15.
2 Getting Started Creating Input Documents Input Template The file input_template.html provides the code needed to create a MATLAB Web Server input document. An abbreviated version looks like
Creating MATLAB Web Server M-Files Creating MATLAB Web Server M-Files M-File Template You use the M-file template to code your MATLAB application as you normally do. The template provides the additional code you need to accept input from your HTML input document and to return results to your HTML output document. An abbreviated version looks like function retstr = mfile_template(instruct, outfile) % STEP 1 % Initialize the return string. retstr = char(''); % STEP 2 % Set working directory.
2 Getting Started % created and the filename you created from OUTPUT_TEMPLATE.HTML. % Replace with the name of the HTML output % file you created using OUTPUT_TEMPLATE.HTML. % This call fills the string RETSTR to return and optionally % writes the output as a file if a valid filename is given as the % second argument to the present function. templatefile = which('
Creating MATLAB Web Server M-Files % Create magic square in output structure OUTSTRUCT. outstruct.msquare = magic(msize); % Get column, row, and diagonal sum. d = sum(outstruct.msquare,1); outstruct.msum = d(1,1); Put in OUTSTRUCT. % Output the results and optionally write as a file if the % filename was given as the second argument to WEBMAGIC. (Step 6) templatefile = which('webmagic2.
2 Getting Started Creating Output Documents Output Template The file output_template.html provides the code needed to create a MATLAB Web Server output document. An abbreviated version looks like .html, where is replaced by a name that has meaning within the context of your application. -->