function varargout = slvnvruntest(model, dataFile, runOpts)
%SLVNVRUNTEST - Simulate model using input data 
%
%   OUTDATA = SLVNVRUNTEST(MODEL, DATAFILE) simulates MODEL using all 
%   test cases in DATAFILE. OUTDATA is an array of Simulink.SimulationOutput 
%   objects where each array element is associated to the simulation output 
%   of corresponding test case.
%
%   OUTDATA = SLVNVRUNTEST(MODEL, DATAFILE, RUNOPTS) simulates MODEL 
%   using all the test cases in DATAFILE. RUNOPTS defines the options for 
%   simulating the test cases.
%
%   [OUTDATA, COVDATA] = SLVNVRUNTEST(MODEL, DATAFILE, RUNOPTS) simulates 
%   MODEL using the test cases in DATAFILE. When the RUNOPTS field 
%   coverageEnabled field is true, the Simulink Coverage software collects
%   model coverage information during the simulation and returns the 
%   coverage data in the cvdata object COVDATA.
%
%   Input Arguments:
%     MODEL : Name or handle of the Simulink model to simulate.    
%
%     DATAFILE : Name of the data file or structure that contains the input 
%     data. You can generate DATAFILE using the Simulink Design Verifier 
%     software, or by running the slvnvlogsignals function.
%
%     RUNOPTS : A structure whose fields specify the configuration of 
%     slvnvruntest.
%
%       testIdx            Test case index array to simulate from DATAFILE.
%                          If testIdx is [], slvnvruntest simulates 
%                          all test cases.
%                          Default: []
%
%       signalLoggingSaveFormat   Specify format for signal logging data
%                                 for signals connecting to the outports of 
%                                 the model and for intermediate signals
%                                 that are already configured for logging.
%                          'Dataset' (default) Data will be stored in
%                                              Simulink.SimulationData.Dataset
%                                              objects.
%                          'ModelDataLogs'     Data will be stored in
%                                              Simulink.ModelDataLogs objects.
%
%       coverageEnabled    If true, specifies that Simulink Coverage
%                          collect model coverage data during simulation.
%                          Default: false 
%
%       coverageSetting    cvtest object for collecting model coverage. 
%                          If [], slvnvruntest uses the existing coverage 
%                          settings for model.
%                          Default: []
%
%       fastRestart        If true, perform iterative simulations without
%                          compiling a model or terminating the simulation
%                          each time.
%                          Default: true
%
%       useParallel        If true, simulate test cases in parallel.
%                          Default: false
%
%   Output Arguments:
%     OUTDATA : An array of Simulink.SimulationOutput objects generated 
%               from the simulation of test cases. Each
%               Simulink.SimulationOutput object has following data:
%
%               tout_slvnvruntest    : Simulation time.
%
%               xout_slvnvruntest    : State data.
%
%               yout_slvnvruntest    : Output signal data.
%
%               logsout_slvnvruntest : Signal logging data for signals 
%                                     connected to outports and signals 
%                                     that are configured for logging on the model.
%
%     COVDATA : cvdata object that contains the model coverage data 
%               collected during simulation. 	
%
%   NOTES:
%     runOpts = slvnvruntestopts returns a runOpts structure 
%     with the default values for each field.
%
%     Use the methods of Simulink.SimulationOutput object to access the
%     data contained in it. For example, to reach the data for test case
%     index testIdx do:
%       outdata = slvnvruntest(model,datafile);
%       tout_slvnvruntest = outdata(testIdx).find('tout_slvnvruntest');
%       xout_slvnvruntest = outdata(testIdx).find('xout_slvnvruntest');
%       yout_slvnvruntest = outdata(testIdx).find('yout_slvnvruntest');
%       logsout_slvnvruntest = outdata(testIdx).find('logsout_slvnvruntest');
%
%   See also SLVNVRUNTESTOPTS, SLVNVLOGSIGNALS, SLVNVRUNCGVTEST, Simulink.SimulationOutput

%   Copyright 2010-2019 The MathWorks, Inc.

    if nargin<2 
        msg   = ['Invalid usage of slvnvruntest. ', ...
             'At least two inputs are expected.'];
        error('Slvnv:RUNTEST:InvalidNumInputs',msg);
    end        
    
    if nargin<3
        runOpts = slvnvruntestopts;   
    end
    
    errMsg = Sldv.RunTestCase.iscorrectRuntestOpts(runOpts);
    if ~isempty(errMsg)
        error('Sldv:RUNTEST:InvalidInput',errMsg);    
    end
        
    try         
        runTestObj = Sldv.RunTestCase(mfilename);
        [varargout{1}, varargout{2}] = ...
            runTestObj.simTestCases(model, dataFile, runOpts);                    
    catch Mex
        throw(Mex);
    end                   
end
