function outstr = fluids1_061(instruct, outfile)
% FLUIDS1_061   from  LAUNCHER    
%  Application m-file which serves as the launcher for 
%  other application m-files. Having a single
%  application launcher circumvents the need to update
%  matweb.conf every time a new application is created.
%  MATWEB(INSTRUCT) calls LAUNCHER, which is specified
%  in the mlmfile field of the structure INSTRUCT, and
%  also passes this structure to LAUNCHER.
%  LAUNCHER(INSTRUCT) in turns calls the actual
%  application m-file specified in the runmfile field
%  of INSTRUCT.
%
%  LAUNCHER(INSTRUCT) is based on matweb.m, which comes
%  with the Web Server distribution. INSTRUCT is a
%  MATLAB structure containing the following fields: 
%   
%  All the data from the HTML input document
%
%    MLMFILE, which stores the name of the M-file to call
%
%    RUNMFILE, which stores the name of actual application
%
%    MLDIR, the working directory specified in matweb.conf
%
%    MLID, the unique identifier for creating filenames and
%    for maintaining contexts. 
%
%  If a MATLAB error is encountered, the text is
%  captured, using the EVAL and LASTERR functions, and
%  returned to the user's browser.  Warnings are turned
%  off and then restored.
%
%    See also EVAL, LASTERR, and LASTWARN, and WARNING.
%
%   Author(s): M. Greenstein, 08-04-97
%   Copyright (c) 1998 by The MathWorks, Inc.
%   $Revision: 1.5 $   $Date: 1998/05/21 15:54:49 $
%
%%%
%%%  Modified by D. Tran, 09-21-99
%%%

%% ACS comments begin with %%
%% last modified ajfox 20010117

%% To use this method, code your input HTML file with the following:
%%
%%   <input type="hidden" name="mlmfile" value="fluids1_061">
%%   <input type="hidden" name="runmfile" value="demo_file_name">
%%
%% where <app> is your application name (the top-level M-file registered
%% on the server), and <my_m_file> is the actual M-file you want to run.

% Initialize the return string.
outstr = char('');

% Warnings are turned off here and restored below. 
[savestate, savefrequency] = warning;
warning off;

% Use try/catch mechanism to trap errors.
try
   % Get specific mfile to run out of the input argument.
   runmfile = getfield(instruct, 'runmfile');
   % Execute the application m-file with 1 or 2 arguments 
   % depending whether an output test file is specified
   if (nargin == 1)
      outstr = feval(runmfile, instruct);
   elseif (nargin == 2) 
      outstr = feval(runmfile, instruct, outfile);
   end
catch
   outstr = [ sprintf('Content-type: text/html\n\n<html><body>') ...
      'MATLAB Application Error:<p><p>' lasterr '</body></html>' ];
end   

% Uncomment to debug
% sprintf('Nargin = %d', nargin)
% instruct

% Send the output string back to stdio.
% Uncomment when debugging in stand-alone
% mode.  Otherwise this will duplicate the 
% HTML output returned by HTMLREP.
%disp(outstr);

% Restore the warning state.
warning(savestate);

% end of function
