http://web.mit.edu/29.123/www/matweb-application.html
For a detailed diagram of how the Matlab Web Server components operate, see page 2-3 of the online manual. Note that the ACS server has been customized to work in our environment, and thus some descriptions in the manual do not match our configuration; the differences are documented below.
For each of these, MathWorks provides a template file which we have modified to indicate values specific to our environment:
(To view the HTML files, follow the links and choose View->Source, or use File->Save As and select Source as the format.)
In addition, we have a local files which indicate specific values to use if you will be generating graphics:
and for making your top-level M-file act as a launcher for multiple applications:
Other samples referred to in the manual can be found at http://matweb.mit.edu/demos/wsdemos/ but keep in mind that you will need to make local modifications as indicated in the above templates.
The mlmfile variable stores the name of your matweb application (i.e., the name of the main function in your top-level M-file). It is passed to the server from this line in your input HTML file:
<input type="hidden" name="mlmfile" value="app-name">For administrative purposes, we will register a single name for any course, including its subject number. (Since Matlab doesn't like periods in function names, we will use an underscore instead, e.g. matweb29_123.) This will correspond to a single top-level M-file in your course locker (e.g., /mit/29.123/matlab/matweb29_123.m); you may design your code to call other functions and M-files in any manner convenient to you, without requiring any changes to the server configuration.
The mldir variable stores the path to your mlmfile (e.g. /mit/29.123/matweb); it is added to the matlab search path when your application is called, so that any other files you have stored there will be accessible to your application.
Our installation is configured so that instructors maintain their HTML files and M-files in course lockers. You may choose any names and locations you like, as long as the top-level M-file name includes the MIT Subject number and can be found in the directory registered on the server (respectively, in the variables mlmfile and mldir).
In the M-file, you will need to specify the full AFS path to your HTML output file, e.g.
templatefile = '/afs/athena/29/29.123/www/matweb-output.html';
The ACS Matlab Server is running a standalone copy of Matlab (i.e., separate from the Athena installation). The same vendor toolboxes are available as on Athena, and the directory for your matweb application is automatically added to the search path. If you need access to other files on Athena, you will need to add their directories to the search path via the full AFS path. For example, if your application is /mit/29.123/matlab/matweb29_123.m but you also want to use utilities stored in /mit/29.789/matlab/share/ add this line to your M-file:
addpath /afs/athena/course/29/29.789/matlab/share
The procedure for standalone testing is described on page 2-13 of the online manual. In our environment, you may debug using Matlab on Athena (Suns only); in order to use the relevant functions from the matweb toolbox, copy the following files to the directory where your application resides:
athena% cp /afs/athena.mit.edu/user/j/a/jamous/www/matweb/debug/* .
These files include the MATLAB Web Server specific functions plus a debugging example for the webmagic
demo. The example includes the following files:
twebmagic.m
: driver program that calls webmagic
webmagic.m
: M-file to be debugged
webmagic2.html
: HTML output template used by webmagic.m
Your HTML input file is stored in your course locker and served by the main MIT web server, from a URL such as:
http://web.mit.edu/29.123/www/matweb-input.htmlcorresponding to the file
/mit/29.123/www/matweb-input.htmlIf your application generates graphics, these will be stored in a temp dir on the ACS server, and served through the URL:
http://matweb.mit.edu/tmp/corresponding to files stored in the server directory:
/var/local/httpd/htdocs/matweb/tmpNote that in order to generate such files, you must change the working directory in your M-file to the above.
When writing your HTML files, keep in mind that relative URLs in the input file will resolve to paths on web.mit.edu, while relative URLs in the output template will resolve to paths on matweb.mit.edu. For example:
file | relative URL | full URL | |
---|---|---|---|
HTML input | /mit/29.123/www/matweb-app.html | <a href="admin/syllabus.html"> | http://web.mit.edu/29.123/www/admin/syllabus.html |
HTML output template | /mit/29.123/www/matweb-output.html | <img src="/tmp/$GraphFileName$"> | http://matweb.mit.edu/tmp/ml00465matweb29_123.jpeg |
Depending upon how you code your HTML files, the output can
appear
to users as a separate page, as in the MATLAB Matrix display demo, in
which case the location will appear as
http://matweb.mit.edu/cgi-bin/matweb
or on the same page as the input, as in the Peaks Plot demo. Note that the
latter example uses frames, which are generally discouraged for
MIT web sites. While this approach has its advantages, before you
adopt it please read Why Frames are Not Supported
at MIT to make an informed design decision.
code text
indicates a variable to be replaced
with your own value.
File | Syntax | Purpose |
---|---|---|
input HTML | <form action="http://matweb.mit.edu/cgi-bin/matweb" method=post> | CGI program on server which extracts input data |
<input type="hidden" name="mlmfile" value="app-name "> |
mlmfile: name of main Matlab function (e.g., matweb29_123
from matweb29_123.m) |
|
<input type="type " name="var "
value="val " ... > |
form fields for user input | |
M-file | function retstr = app-name(instruct) |
function def, e.g. function rs = matweb29_123(instruct)
( instruct is the Matlab structure which will contain
the input data from your HTML form and other fields such as
instruct.mlid used below)
|
mlid = getfield(instruct , 'mlid'); |
mlid: unique identifier (to form file names, e.g. for graphics) | |
cd /var/local/httpd/htdocs/matweb/tmp; | working dir: temp dir on server for storage of graphics files, etc. | |
input_var = instruct.var |
assign user's input values to your variables | |
outstruct.var = ... |
structure for variables to be returned in output HTML, e.g.outstruct.GraphFileName =
sprintf('%sapp-name .jpeg', mlid) to store a unique file
name for graphic (via mlid) in
GraphFileName field of outstruct
|
|
wscleanup('ml*app-name .jpeg', 1); |
wscleanup: removes jpegs from app-name older than 1
hour. (We run a script on the server which periodically purges stale
files, but recommend including this in your M-file to keep your application from eating up disk space unnecessarily.) |
|
wsprintjpeg(fig , outstruct.GraphFileName ); |
create jpeg file from figure, with above filename | |
templatefile = '/afs/path/to/output.html '; |
full path to output HTML file, e.g. /afs/athena/course/29/29.123/www/matweb-output.html |
retstr = htmlrep(outstruct ,templatefile ) |
htmlrep: fills in values of Matlab variables in the output
HTML file. For example, outstruct.GraphFileName from
matweb29_123.m -> $GraphFileName$ in output.html. |
output HTML | $outputvar $ |
Matlab variable, to be replaced via htmlrep. For example,
$GraphFileName$ in <img src="/tmp/ $GraphFileName$ "> would be replaced with the
filename of the generated graphic in the server's temp dir, such as <img
src="/tmp/ml00465matweb29_123.jpeg ">
|