Bruce Jackson, NASA Langley Research Center <[email protected]>

Shown below is a Matlab® script, dave_demo.m, that exercises a DAVE-ML model, using the DAVEtools Java objects.

In order to work properly, it may be necessary to edit the classpath.txt file found in $MATLAB_ROOT/toolbox/local directory to include explicit paths to three .jar files that are included in the DAVEtools.zip distribution:

    a. Execute the following on the MATLAB Command line:

           cd([matlabroot,'/toolbox/local'])
           edit classpath.txt

    b. The "classpath.txt" file will open in the editor window. Scroll
       to the last line of the file and include the full path of the
       library files.

    For example:

       /Users/ebjackso/Documents/Projects/DAVE/DAVEtools/lib/jdom-1.1.1.jar
       /Users/ebjackso/Documents/Projects/DAVE/DAVEtools/lib/xerces-2.9.0.jar
       /Users/ebjackso/Documents/Projects/DAVE/DAVEtools/lib/resolver-1.2.jar

    c. Save the “classpath.txt” in the folder that is returned by the
       following command:

           userpath
dave_demo.m listing
function dave_demo
%
% example of calling a DAVE-ML model from within Matlab
%
% requires a copy of DAVEtools (NASA Open Source), available
% from
%
%  http://dscb.larc.nasa.gov/Products/SW/DAVEtools.html
%
% 2011-03-07 Bruce Jackson, NASA Langley
%            [email protected]
%
%
pathNeeded = 1;
f = strfind(javaclasspath('-dynamic'),'DAVEtools.jar');
if ~isempty(f)
    if ~isempty(f{1})
        pathNeeded = 0;
    end
end
if pathNeeded
    javaaddpath('/Users/bjax/DAVE/Tools/DAVEtools/DAVEtools.jar')
end
dave = gov.nasa.daveml.dave.DAVE();
dave.setInputFileName('HL20_aero.dml')
ok = dave.parseFile;
if ~ok
    error('unable to parse file')
end

% open model
mass_props = dave.getModel;

% set inputs to zero
inputs = mass_props.getInputVector;
for i=1:inputs.size
    input = inputs.get(i-1);
    input.setValue(0);
end

outputs = mass_props.getOutputVector;

% initialize and cycle the model
mass_props.initialize
mass_props.cycle

% report results

fprintf('Inputs:\n');
theVector = inputs;
printVectorInfo( theVector );

fprintf('Outputs:\n');
theVector = outputs;
printVectorInfo( theVector );

return


function printVectorInfo( theVector )
for i=1:theVector.size
    signal = theVector.get(i-1);
    name  = signal.getName;
    units = signal.getUnits;
    value = signal.getValue;
    fprintf('%34s (%10s): %15.4e\n', char(name), char(units), value)
end
return