gusucode.com > private工具箱matlab源码程序 > private/code_machine_header_file_sfun.m

    function code_machine_header_file_sfun(fileNameInfo)
% CODE_MACHINE_HEADER_FILE(FILENAMEINFO)

%   Copyright 1995-2013 The MathWorks, Inc.
%     

	global gTargetInfo gMachineInfo
	
    function emit(format,varargin)
        fprintf(file,format,varargin{:});
    end

	fileName = fullfile(fileNameInfo.targetDirName,fileNameInfo.machineHeaderFile);
   sf_echo_generating('Coder',fileName);
   machine = gMachineInfo.machineId;
    
   file = fopen(fileName,'Wt');
   if file<3
      construct_coder_error([],sprintf('Failed to create file: %s.',fileName),1);
      return;
   end             
	
fprintf(file,'#ifndef __%s_%s_h__\n',gMachineInfo.machineName,gMachineInfo.targetName);
fprintf(file,'#define __%s_%s_h__\n',gMachineInfo.machineName,gMachineInfo.targetName);

fprintf(file,'\n');
fprintf(file,'/* Include files */   \n');
fprintf(file,'#define S_FUNCTION_NAME sf_sfun\n');
fprintf(file,'#include "sf_runtime/sfc_sf.h"\n');
fprintf(file,'#include "sf_runtime/sfc_mex.h"\n');
fprintf(file,'#include "sf_runtime/sf_runtime_errors.h"\n');
fprintf(file,'#include "rtwtypes.h"\n');
fprintf(file,'#include "simtarget/slSimTgtClientServerAPIBridge.h"\n');
fprintf(file,'#include "sf_runtime/sfc_sdi.h"\n');
fprintf(file,'#include "sf_runtime/sf_test_language.h"\n');
   if fileNameInfo.multiword_types
fprintf(file,'#include "multiword_types.h"\n');
   end

    if slfeature('SLSFMessages')
fprintf(file,'#include "sf_runtime/sfc_messages.h"        \n');
    end
    if gTargetInfo.codingDebug
fprintf(file,'#include "sf_runtime/sfcdebug.h"\n');
    end
fprintf(file,'\n');
fprintf(file,'#define rtInf (mxGetInf())\n');
fprintf(file,'#define rtMinusInf (-(mxGetInf()))\n');
fprintf(file,'#define rtNaN (mxGetNaN())\n');
fprintf(file,'#define rtIsNaN(X) ((int)mxIsNaN(X))\n');
fprintf(file,'#define rtIsInf(X) ((int)mxIsInf(X))\n');
fprintf(file,'\n');
   if gTargetInfo.codingDebug
       assert(isfield(gMachineInfo, 'debugInstanceStructName'));
fprintf(file,'struct SfDebugInstanceStruct;\n');
fprintf(file,'extern struct SfDebugInstanceStruct* %s;\n',gMachineInfo.debugInstanceStructName);
   end
fprintf(file,'\n');
if ~isempty(fileNameInfo.auxInfo.includeFiles)
    emit('/* Auxiliary Header Files */\n');
    for i=1:numel(fileNameInfo.auxInfo.includeFiles)
        includeFile = fileNameInfo.auxInfo.includeFiles{i};
        if includeFile(1) == '<' || includeFile(1) == '"'
            delim = '';
        else
            delim = '"';
        end
        emit('#include %s%s%s\n', delim, includeFile, delim);
    end
    emit('\n');
end

if ~gMachineInfo.ctxInfo.sfcnTgtCustomCodeInfo.hasExtraCustomCodeFiles
   % No extra file then emit the custom code
   % in the machine's header file
   customCodeSettings = get_custom_code_settings(gMachineInfo.target,gMachineInfo.parentTarget);
   customCodeString = customCodeSettings.customCode;
   if ~isempty(customCodeString)
      customCodeString = sfprivate('expand_double_byte_string',customCodeString);
fprintf(file,'/* Custom Code from Simulation Target dialog*/\n');
fprintf(file,'%s\n',customCodeString);
fprintf(file,'\n');
   end
else
   % Include the extra header file declaring the
   % custom code function/global
fprintf(file,'#include "%s"\n',fileNameInfo.customCodeHeaderFile);
end

   file = dump_module(fileName,file,machine,'header');
   if file < 3
     return;
   end

fprintf(file,'/* We load infoStruct for rtw_optimation_info on demand in mdlSetWorkWidths and\n');
fprintf(file,'  free it immediately in mdlStart. Given that this is machine-wide as\n');
fprintf(file,'  opposed to chart specific, we use NULL check to make sure it gets loaded\n');
fprintf(file,'  and unloaded once per machine even though the  methods mdlSetWorkWidths/mdlStart\n');
fprintf(file,'  are chart/instance specific. The following methods abstract this out. */\n');
fprintf(file,'extern mxArray* load_%s_optimization_info(boolean_T isRtwGen, boolean_T isModelRef, boolean_T isExternal);\n',gMachineInfo.machineName);
fprintf(file,'extern void unload_%s_optimization_info(void);\n',gMachineInfo.machineName);
fprintf(file,'#endif\n');
fprintf(file,'\n');

	fclose(file);
	try_indenting_file(fileName);
end