gusucode.com > private工具箱matlab源码程序 > private/code_chart_source_file_sfun.m
function code_chart_source_file_sfun(fileNameInfo, chart, specsIdx) % Copyright 1995-2013 The MathWorks, Inc. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%% GLOBAL VARIABLES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%% Coding options global gTargetInfo gChartInfo gMachineInfo chartNumber = sf('get',chart,'chart.number'); chartUniqueName = sf('CodegenNameOf',chart); fileName = fullfile(fileNameInfo.targetDirName,fileNameInfo.chartSourceFiles{chartNumber+1}{specsIdx}); sf_echo_generating('Coder',fileName); file = fopen(fileName,'Wt'); if file<3 construct_coder_error([],sprintf('Failed to create file: %s.',fileName),1); return; end fprintf(file,'/* Include files */\n'); % include simstruc & fixedpoint header files if dataset signal logging is % enabled because in this case we might generate cpp % files and c++ compiler is not able to build the generated sfun code without these header % files - g890413 if ( ~isempty(sf('find', gMachineInfo.mainMachineId, '.sigLogFormat', 'SIGLOG_DATASET')) && ... gChartInfo.hasLoggedSignals ) fprintf(file,'#include "simstruc.h"\n'); fprintf(file,'#include "fixedpoint.h"\n'); fprintf(file,'#include "simtarget/slSimTgtLogLoadBlocksSfcnBridge.h"\n'); end if ~isempty(fileNameInfo.openMPIncludeFile) fprintf(file,'#include "%s"\n',fileNameInfo.openMPIncludeFile); end fprintf(file,'#include "%s"\n',[fileNameInfo.machineHeaderFile(1:end-length(fileNameInfo.headerExtension)),'.h']); fprintf(file,'#include "%s"\n',[fileNameInfo.chartHeaderFiles{chartNumber+1}{specsIdx}(1:end-length(fileNameInfo.headerExtension)),'.h']); % Make sure all recorded TFL header files are included into the source file tfl = get_param(gMachineInfo.mainMachineName, 'SimTargetFcnLibHandle'); tflHeaders = tfl.getRecordedUsedHeaders; for fileIdx = 1:length(tflHeaders) fprintf(file,'#include %s\n',tflHeaders{fileIdx}); end tfl.resetUsageCounts; if(gChartInfo.codingDebug) fprintf(file,'#define CHARTINSTANCE_CHARTNUMBER (%schartNumber)\n',gChartInfo.chartInstanceVarName); fprintf(file,'#define CHARTINSTANCE_INSTANCENUMBER (%sinstanceNumber)\n',gChartInfo.chartInstanceVarName); fprintf(file,'#include "%s"\n',fileNameInfo.sfDebugMacrosFile); end if gTargetInfo.leavingCtrlCChecks if gChartInfo.codingDebug fprintf(file,'#define _SF_MEX_LISTEN_FOR_CTRL_C(S) sf_mex_listen_for_ctrl_c_with_debugger(S, %s);\n',gMachineInfo.debugInstanceStructName); else fprintf(file,'#define _SF_MEX_LISTEN_FOR_CTRL_C(S) sf_mex_listen_for_ctrl_c(S);\n'); end end if(gChartInfo.codingDebug) fprintf(file,'static void chart_debug_initialization(SimStruct *S, unsigned int fullDebuggerInitialization);\n'); fprintf(file,'static void chart_debug_initialize_data_addresses(SimStruct *S);\n'); end if(gChartInfo.codingDebug) && slmessages fprintf(file,'static const mxArray* sf_opaque_get_hover_data_for_msg(void *chartInstance, int32_T msgSSID);\n'); end file = dump_module(fileName,file,chart,'source'); if file < 3 return; end file = code_sfun_glue_code(fileNameInfo,file,chart,chartUniqueName,specsIdx); fclose(file); try_indenting_file(fileName);