# Run OpenFAST S-Function from Matlab Script

**URL:** <https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280>\
**Category:** Controls\
**Created:** [December 13, 2022, 7:23am UTC](https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280 "2022-12-13T07:23:13Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Javier.Lopez](https://avatars.discourse-cdn.com/v4/letter/j/7cd45c/32.png) [@Javier.Lopez](https://forums.nlr.gov/u/Javier.Lopez)\
**Post date:** [December 13, 2022, 7:23am UTC](https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280/1 "2022-12-13T07:23:13Z")

</div>

Hello everyone,

I have read different Forum posts but I could not find anything related.

Of course, I have been able to run the OpenFAST S-Function via Simulink model. There is not any problem doing so.

But what I am looking for is to run the S-Function control development capabilities through a Matlab script.

Is it possible to call the S-Function from a Matlab Script without using the Simulink model?

Or using something similar to what it is done in openfast\_library.py for Python: [openfast/glue-codes/python at main · OpenFAST/openfast · GitHub](https://github.com/OpenFAST/openfast/tree/main/glue-codes/python)

Thank you so much in advance!

JL

---

<div class="post-metadata">

**Author:** ![Daniel.Zalkind](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@Daniel.Zalkind](https://forums.nlr.gov/u/Daniel.Zalkind)\
**Post date:** [December 13, 2022, 4:17pm UTC](https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280/2 "2022-12-13T16:17:05Z")

</div>

Hi Javier,

You could try this script/repository: [ROSCO/runFAST.m at main · NREL/ROSCO · GitHub](https://github.com/NREL/ROSCO/blob/main/Matlab_Toolbox/runFAST.m)

It will require updating some paths and maybe a few fixes along the way. We don’t test it as much as the other parts of the repository, but we keep it up there because it’s useful to some folks.

I hope this helps.

Best, Dan

---

<div class="post-metadata">

**Author:** ![Javier.Lopez](https://avatars.discourse-cdn.com/v4/letter/j/7cd45c/32.png) [@Javier.Lopez](https://forums.nlr.gov/u/Javier.Lopez)\
**Post date:** [December 14, 2022, 11:25am UTC](https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280/3 "2022-12-14T11:25:46Z")

</div>

Hello Daniel,

Thanks for your quick response!

I will have a look into it.

Best,

JL

---

<div class="post-metadata">

**Author:** ![Javier.Lopez](https://avatars.discourse-cdn.com/v4/letter/j/7cd45c/32.png) [@Javier.Lopez](https://forums.nlr.gov/u/Javier.Lopez)\
**Post date:** [December 20, 2022, 10:11am UTC](https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280/4 "2022-12-20T10:11:21Z")

</div>

Hello again,

I have checked carefully the script that Daniel provides here: [ROSCO/runFAST.m at main · NREL/ROSCO · GitHub](https://github.com/NREL/ROSCO/blob/main/Matlab_Toolbox/runFAST.m)

And it is not what I am looking for. That script runs a complete simulation of a model with ROSCO controller.

Maybe I need to explain myself a little bit clearer.

The main idea is to develop a controller in a matlab script and **call OpenFAST** as simulation model **each time step**. In a simple way, I am providing the inputs of the controller to OpenFAST simulation model and I would like to take the states from it to feedback them to my controller.

So, _is there any way to call OpenFAST each time step from a Matlab Script_?

In Python this can be done after loading the dynamic library and all the functions within it:

**Load OpenFAST library** :  
LoadLibrary(path + ‘/libopenfastlib.dylib’)

**Update the states based on the new control inputs** :  
fast\_update(iTurb, NumInputs, InputAry)

I tried this same structure in Matlab but does not work.

I would appreciate if someone have dealed with this before and could provide me some guide how to solve this.

Best,

JL

---

<div class="post-metadata">

**Author:** ![Daniel.Zalkind](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@Daniel.Zalkind](https://forums.nlr.gov/u/Daniel.Zalkind)\
**Post date:** [December 20, 2022, 4:11pm UTC](https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280/5 "2022-12-20T16:11:38Z")

</div>

Hi JL,

I think this is essentially what happens within the Simulink S\_Function. You can technically call `FAST_SFunc` from a Matlab script, but I haven’t heard of many people doing it that way. I think you will need to figure out from the OpenFAST source code and/or the Simulink model what the exact inputs to the S\_Function are and there are parameters loaded to the S\_Function in Simulink. You’ll need to figure out how to reproduce that to get the OpenFAST inputs to the S\_Function.

Best, Dan

```auto
>> FAST_SFunc(0,0,0,0)

ans =

           0
           0
           0
           0
           0
           0
           0
           3
           0
           0
           0 ...

```

---

<div class="post-metadata">

**Author:** ![Andy.Platt](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@Andy.Platt](https://forums.nlr.gov/u/Andy.Platt)\
**Post date:** [December 21, 2022, 8:06pm UTC](https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280/6 "2022-12-21T20:06:35Z")

</div>

Dear @Javier.Lopez,

There are two examples of Simulink calling OpenFAST v3.3.0 in the repository here: [openfast/glue-codes/simulink at v3.3.0 · OpenFAST/openfast · GitHub](https://github.com/OpenFAST/openfast/tree/v3.3.0/glue-codes/simulink). Note that this interface does change between versions (typically with additional control channels).

You will need to compile OpenFAST specifically for coupling to Simulink (`vs-build/OpenFAST-Simullink` for Windows + Visual Studio, or for `CMake` builds, add the `-DBUILD_OPENFAST_SIMULINK_API=On` option to the `CMake command` and build the `openfast` target).

There is a `create_FAST_SFunc.m` provided as well for creating the mex function (you will need the appropriate compilers installed that MATLAB can find).

For further information, there are multiple issues posted with hints on getting the compilation and linking to Simulink working here: [Issues · OpenFAST/openfast · GitHub](https://github.com/OpenFAST/openfast/issues?q=is%3Aissue+simulink)

Regards,  
Andy

---

<div class="post-metadata">

**Author:** ![Kaouthar.Othmani](https://avatars.discourse-cdn.com/v4/letter/k/a88e57/32.png) [@Kaouthar.Othmani](https://forums.nlr.gov/u/Kaouthar.Othmani)\
**Post date:** [December 10, 2024, 7:46pm UTC](https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280/7 "2024-12-10T19:46:54Z")

</div>

Hello,  
I’m trying to run the OpenFAST Simulink test case `Run_Test01_SIG` for validating the S-Function, but I’m encountering errors in both MATLAB and Simulink. Here’s the full error report:  
Errors in MATLAB:

Error while obtaining sizes from MEX S-function ‘FAST\_SFunc’ in ‘Test01\_SIG/FAST Nonlinear Wind Turbine/S-Function’.  
Invalid MEX-file ‘C:\Program Files\openfast-3.5.4\openfast-3.5.4\glue-codes\simulink\examples\FAST\_SFunc.mexw64’: Le module spécifié est introuvable.  
The expression: u(strmatch(‘LSSGagVxa’,OutList)) in ‘Test01\_SIG/Fcn’ has a syntax error.

Errors in Simulink:

S-Function Error:Error while obtaining sizes from MEX S-function ‘FAST\_SFunc’ in ‘Test01\_SIG/FAST Nonlinear Wind Turbine/S-Function’.  
Invalid MEX-file:Invalid MEX-file ‘C:\Program Files\openfast-3.5.4\openfast-3.5.4\glue-codes\simulink\examples\FAST\_SFunc.mexw64’: Le module spécifié est introuvable.

thank you

---

<div class="post-metadata">

**Author:** ![Jason.Jonkman](https://dub1.discourse-cdn.com/nrel/user_avatar/forums.nlr.gov/jason.jonkman/32/3086_2.png) [@Jason.Jonkman](https://forums.nlr.gov/u/Jason.Jonkman)\
**Post date:** [December 10, 2024, 7:58pm UTC](https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280/8 "2024-12-10T19:58:46Z")

</div>

Dear @Kaouthar.Othmani,

The syntax error regarding `LSSGagVxa` has been asked and answered on this forum before, e.g., see: [problem in running Test03 to Test25](https://forums.nlr.gov/t/problem-in-running-test03-to-test25/2524). Does that solve the issue?

Best regards,

---

<div class="post-metadata">

**Author:** ![Kaouthar.Othmani](https://avatars.discourse-cdn.com/v4/letter/k/a88e57/32.png) [@Kaouthar.Othmani](https://forums.nlr.gov/u/Kaouthar.Othmani)\
**Post date:** [December 10, 2024, 9:08pm UTC](https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280/9 "2024-12-10T21:08:47Z")

</div>

unfortunately no ,  
those are the errors in matlab :  
slight\_smile: Run\_Test01\_SIG  
Error using Run\_Test01\_SIG (line 36)  
Error due to multiple causes.  
Caused by:  
Error using Run\_Test01\_SIG (line 36)  
Error while obtaining sizes from MEX S-function ‘FAST\_SFunc’ in ‘Test01\_SIG/FAST Nonlinear Wind Turbine/S-Function’.  
Error using Run\_Test01\_SIG (line 36)  
Invalid MEX-file ‘C:\Program Files\openfast-3.5.4\openfast-3.5.4\glue-codes\simulink\examples\FAST\_SFunc.mexw64’: Le module spécifié est introuvable.  
Error using Run\_Test01\_SIG (line 36)  
The expression: u(strmatch(‘LSSGagVxa’,OutList))  
in ‘Test01\_SIG/Fcn’  
has a syntax error

---

<div class="post-metadata">

**Author:** ![Jason.Jonkman](https://dub1.discourse-cdn.com/nrel/user_avatar/forums.nlr.gov/jason.jonkman/32/3086_2.png) [@Jason.Jonkman](https://forums.nlr.gov/u/Jason.Jonkman)\
**Post date:** [December 10, 2024, 9:37pm UTC](https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280/10 "2024-12-10T21:37:13Z")

</div>

That is the same error you posted earlier. As asked in the forum post I linked to, does ElastoDyn output `LSSGagVxa` exist in your `OutList`?

---

<div class="post-metadata">

**Author:** ![Kaouthar.Othmani](https://avatars.discourse-cdn.com/v4/letter/k/a88e57/32.png) [@Kaouthar.Othmani](https://forums.nlr.gov/u/Kaouthar.Othmani)\
**Post date:** [December 10, 2024, 9:55pm UTC](https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280/11 "2024-12-10T21:55:40Z")

</div>

how i can know that?

---

<div class="post-metadata">

**Author:** ![Jason.Jonkman](https://dub1.discourse-cdn.com/nrel/user_avatar/forums.nlr.gov/jason.jonkman/32/3086_2.png) [@Jason.Jonkman](https://forums.nlr.gov/u/Jason.Jonkman)\
**Post date:** [December 10, 2024, 11:31pm UTC](https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280/12 "2024-12-10T23:31:15Z")

</div>

Dear @Kaouthar.Othmani,

`OutList` is an array generated by the OpenFAST S-Function that should be accessible within MATLAB/Simluink. Is `LSSGagVxa` in this array?

The `OutList` array is set in the various `OutList` sections of the OpenFAST input files for each module. `LSSGagVxa` is an output that could be added within ElastoDyn.

Best regards,

---

<div class="post-metadata">

**Author:** ![Kaouthar.Othmani](https://avatars.discourse-cdn.com/v4/letter/k/a88e57/32.png) [@Kaouthar.Othmani](https://forums.nlr.gov/u/Kaouthar.Othmani)\
**Post date:** [December 11, 2024, 8:28am UTC](https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280/13 "2024-12-11T08:28:09Z")

</div>

Hello everyone,

I’m new to programming, MATLAB, and OpenFAST, and I’m trying to learn how to use them together for a project. Please forgive me if I’m slow in understanding or if my questions seem basic—I’m still at the beginning of this journey!

I’m encountering a few issues and would really appreciate step-by-step guidance:  
About OutList I found an Excel file called `OutListParameters`, and I noticed that the variable `LSSGagVxa` isn’t listed there. When I try to check for `OutList` in MATLAB using `disp(OutList);`, I get the error:  
Unrecognized function or variable ‘OutList’.  
I also tried running the `FAST_SFunc` file directly in MATLAB, but I got the following error:  
Invalid MEX-file ‘C:\Program Files\openfast-3.5.4\openfast-3.5.4\glue-codes\simulink\examples\FAST\_SFunc.mexw64’: Le module spécifié est introuvable.

Could someone kindly explain:  
What exactly `OutList` is and how I can verify its contents?  
If `LSSGagVxa` is not in the `OutList`, what should I do to include it in OpenFAST?  
How to resolve the `FAST_SFunc` error? Is it a problem with my OpenFAST installation or a missing dependency?

Please keep in mind that I have a limited background in programming, so simpler, more detailed instructions would really help me.

Thank you so much for your patience and support!

Best regards,

---

<div class="post-metadata">

**Author:** ![Jason.Jonkman](https://dub1.discourse-cdn.com/nrel/user_avatar/forums.nlr.gov/jason.jonkman/32/3086_2.png) [@Jason.Jonkman](https://forums.nlr.gov/u/Jason.Jonkman)\
**Post date:** [December 11, 2024, 3:57pm UTC](https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280/14 "2024-12-11T15:57:56Z")

</div>

Dear @Kaouthar.Othmani,

Just a few comments:

- Each module of OpenFAST has a set of outputs that module generates, as specified in its `OutList` at the end of the module input file. When the OpenFAST S-Function is executed, all of these OpenFAST outputs are collected in an `OutList` array available in the MATLAB workspace.
- `LSSGagVxa` is an ElastoDyn output and can be found in the ElastoDyn sheet of the _OutListParameters.xlsx_ spreadsheet.
- If `LSSGagVxa` is not in the `OutList`, you can add to the `OutList` section at the bottom of the ElastoDyn input file.
- From your errors, it sounds like MATLAB cannot find the OpenFAST S-Function. Does the _FAST\_SFunc.mexw64_ file exist in the _C:\Program Files\openfast-3.5.4\openfast-3.5.4\glue-codes\simulink\examples_ directory you stated?

Best regards,

---

<div class="post-metadata">

**Author:** ![Kaouthar.Othmani](https://avatars.discourse-cdn.com/v4/letter/k/a88e57/32.png) [@Kaouthar.Othmani](https://forums.nlr.gov/u/Kaouthar.Othmani)\
**Post date:** [December 14, 2024, 11:15am UTC](https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280/15 "2024-12-14T11:15:17Z")

</div>

Dear @Jason.Jonkman ,

I have outlined the key problems I encountered:

1. **MEX File Error**

2. **Simulink S-Function Error**

3. **Output List Error**

4. **CMake Configuration Errors**

5. **MATLAB Compiler Setup Issues**

Given the above issues, I would appreciate guidance to solve those problems.

Best regards,

---

<div class="post-metadata">

**Author:** ![Jason.Jonkman](https://dub1.discourse-cdn.com/nrel/user_avatar/forums.nlr.gov/jason.jonkman/32/3086_2.png) [@Jason.Jonkman](https://forums.nlr.gov/u/Jason.Jonkman)\
**Post date:** [December 15, 2024, 1:53pm UTC](https://forums.nlr.gov/t/run-openfast-s-function-from-matlab-script/4280/16 "2024-12-15T13:53:50Z")

</div>

Dear @Kaouthar.Othmani,

I’m not familiar enough with CMake to answer your compiling questions. But I’m doubtful that you should have to recompile the S-Function.

My guess is your first error is triggering the others. For example, if the S-Function is not loading, the `OutList` variable will not be generated, which will trigger error (3).

Regarding (1), can you clarify–are you running Windows and is your version of MATLAB 64 bit? If so, can you clarify the steps you are using to download and execute the _Run\_Test01\_SIG.m_ script?

Best regards,
