User`s guide

Step-by-Step Example of Fortran and xPC Targetâ„¢
Note This topic describes how to create a level 2 Fortran S-function for the
fortran_atmos_xpc model. Th is fi le is also provided in sfun_atmos .c.
1 Copy the file sfuntmpl_gate_f ortran.c to your w orking folder.
This is your C-MEX file for calling into your Fortran subroutine. It works
with a si mple Fortr an subroutine.
2 With a text editor of your choice, open sfuntmpl_gate_fortran .c.
3 Inspect the file. This is a self-documenting file.
This file contains placeholders for standard Fortran level 2 S-functions,
such as the S-function name specification and Simulink callback m ethods.
4 In the #define S_FUNCTION_NAME definition, add the name of y our
S-function. For example, edit thedefinitionlinetolooklike
#define S_FUNCTION_NAME sfun_atmos
5 In the file, read the commented documentation for fixed-step and
variable-step fixed algorithm support.
6 Delete or comment out the code for fixed-step and variable-step
fixed-algorithm support. You do not nee d these definitions fo r th is example.
7 Findthelinethatbeginsextern void nameofsub_. Specify the function
prototype for the Fortran subroutine. For the
sfun_atmos_sub.obj
executable, the Fortran subroutine is atmos_.Replace
extern void nameofsub_(float *sampleArgs, float *sampleOutput);
with
extern void atmos_(float *falt, float *fsigma, float *fd elta, float *ftheta);
Enter a #if defined/ #endif statement like the following for Windows
compilers.
#ifdef _WIN32
#define atmos_ atmos
13-9