function tclcmd = edgecmds_v(varargin)
% EDGECMDS_V Creates Tcl commands for  Verilog Edge Detection Model
%   The returned cell array can be passed as parameters ('cmd') to
%   VSIMULINK.  This will launch ModelSim, build the Verilog design and 
%   also has the commands for cosimulation with EDGE_DETECTION_VERILOG.MDL
%
%   EDGECMDS_V(Property,Value)
%   
%   Property :
%
%   'ProjDir'- Specify where to run the HDL simulator.  If unspecified, the
%        'TEMPDIR', a temporary directory will be created in which the HDL
%        simulator will run. 
%
%   Examples:
%   1. After opening edge_detection_Verilog.mdl type the following command in 
%   the MATLAB command window.
%   >>vsim('tclstart',edgecmds_v,'socketsimulink',4442)    "or"
%   >>vsim('tclstart',edgecmds_v('ProjDir','c:\tmp\'),'socketsimulink',4442)

%   See also VSIMULINK

%   Copyright 2005-2009 The MathWorks, Inc.

p = inputParser;              % Creating an instance of inputParser class.
p.addOptional('ProjDir','');  % This creates an optional parameter-value pair.
p.parse(varargin{:});         % Calling the parse method of the object to read and validate each argument.
projdir = p.Results.ProjDir;  % Saving ProjDir parameter value to projdir.

srcfile1 = fullfile(matlabroot,'toolbox','edalink','extensions','modelsim','modelsimdemos','vlog','sobeledgedetection','filter2d_v.v');

% Tcl requires using '/' as filename path delimiter
tclsrcfile1 = ['"' strrep(srcfile1,'\','/') '"'];

if isempty(projdir)
    if strcmp(computer,'PCWIN'),
        projdir = tempdir;
    else
        projdir = tempname;
        mkdir(tempdir,strrep(projdir,tempdir,''));
    end
end
tclprojdir = strrep(projdir,'\','/'); 

tclcmd = { ['cd ',tclprojdir],...            
           'vlib work',... %create library (if necessary)
           ['vlog ' tclsrcfile1],...             
           'vsimulink  work.filter2d_v',...      
           'add wave -height 100 -radix decimal -format analog-step -scale 0.3 -offset 0 sim:/filter2d_v/filter_in',...
           'add wave -height 100 -radix decimal -format analog-step -scale 0.3 -offset 0 sim:/filter2d_v/filter_out',...
           'add wave -height 100 -radix decimal -format analog-step -scale 0.3 -offset 0 sim:/filter2d_v/clk',...
           'add wave -height 100 -radix decimal -format analog-step -scale 0.3 -offset 0 sim:/filter2d_v/reset',...
         };
