function targDataMap = gettargdatamap(model, relBuildDir, name)
% GETTARGDATAMAP calls the generated  MATLAB file model_targ_data_map.m and returns
%  data type transition information about the target.
%


%   Copyright 2001-2018 The MathWorks, Inc.
  
origDir = pwd;

try
    isRaccel = false;
    cs = getActiveConfigSet(model);
    if ~isempty(cs)
        hRTW = get(getComponent(cs, 'Code Generation'));
        if ~isempty(hRTW)
            isRaccel = strcmp(hRTW.SystemTargetFile, 'raccel.tlc');
        end
    end
    
    fgCfg = Simulink.fileGenControl('getConfig');
    if isRaccel
        buildDir = fullfile(fgCfg.CacheFolder,relBuildDir);
    else
        buildDir = fullfile(fgCfg.CodeGenFolder,relBuildDir);
    end
    cd(buildDir);

    %
    % Force MATLAB to read the file from disk because it may have been changed
    % during RTW build process.  If we do not clear it, we may get a cached
    % version of the file with incorrect information.
    %
    eval(['clear ' name '.m']);
    
    targDataMap = feval(name);        
  
catch ME
    cd(origDir);
    rethrow(ME);
end

cd(origDir);

% LocalWords:  targ
