fast-rainflow 3.0.1
A fast rainflow counting algorithm in accordance with ASTM E1049-85(2017) programmed in C.
Requires Python: >=3.8

# Rainflow
### A fast rainflow counting algorithm in accordance with ASTM E1049-85(2017) programmed in C.
### Use it in MATLAB, Python, or Excel! See instructions below.

![cover](https://github.com/carlos-souto/rainflow/assets/83190503/0e39ceb5-bdb9-48d6-9c72-020383828277)

This is an implementation of the rainflow counting algorithm in accordance with the [ASTM E1049-85(2017)](https://www.doi.org/10.1520/E1049-85R17).
The code is written in C and compiled into a dynamic-link library (DLL), which can be used from MATLAB, Python, and Excel.
This approach allows the use of the same code base across multiple platforms.
Additionally, because this is a compiled DLL, written in C, it outperforms alternatives written directly in MATLAB, Python, or Excel VBA (see the performance note below).

You may also look at this project as a reference on interoperability between MATLAB, Python, or Excel VBA with a compiled DLL.

If you use this work, please cite the following reference:

C. Souto, J. Correia, A. de Jesus, R. Calçada, Fatigue Damage Tool (FDT) - A tool for fatigue damage assessment according to design codes, Procedia Structural Integrity 22 (2019) 376-385. doi:10.1016/j.prostr.2020.01.047.

## For MATLAB users
1. Download the "for_matlab_users.zip" file from [here](https://github.com/carlos-souto/rainflow/releases/tag/latest) and extract the files into the same directory.
2. Run the "example.m" file from MATLAB.

Note: to use the rainflow function, the files "rainflow.dll", "rainflow.h", and "rainflow_wrapper.m" must be placed into the current working directory (usually, in the same directory as your main *.m file).

## For Python users
### Option A: Install via pip
1. Install the [fast-rainflow package](https://pypi.org/project/fast-rainflow/) from PyPI using the following command: `pip install fast-rainflow`.
2. Download the [example.py](https://github.com/carlos-souto/rainflow/blob/master/example.py) file and run it.

### Option B: No installation required
1. Download the "for_python_users.zip" file from [here](https://github.com/carlos-souto/rainflow/releases/tag/latest) and extract the files into the same directory.
2. Run the "example.py" file using Python.

Note: to use the rainflow function, the files "rainflow.dll" and "rainflow_wrapper.py" must be placed into the current working directory (usually, in the same directory as your main *.py file).

## For Excel users
1. Download the "for_excel_users.zip" file from [here](https://github.com/carlos-souto/rainflow/releases/tag/latest) and extract the files into the same directory.
2. Open the "example.xlsm" file in Excel. Read the notes below.

The "example.xlsm" file is an Excel macro-enabled workbook.
To enable the rainflow macro you must right click the "example.xlsm" file and open the file properties. Then, check the "Unblock" check box under "Security":

![prop](https://github.com/carlos-souto/rainflow/assets/83190503/ecdcdf59-284e-410c-b919-c2bfc06f6bf9)

After that, content must be enabled after opening the file in Excel:

![excel](https://github.com/carlos-souto/rainflow/assets/83190503/a41fa8f5-81b0-4eab-a1ea-bdc999de6133)

You can then press Alt+F11 to view the VBA source code, which is a wrapper for the "rainflow.dll".

To run the macro, first update the load-time history (yellow cells) with your input data (the output cells do not need to be cleared manually).
Then, press Alt+F8 and run the "RainflowCounting" macro. The output is then updated (green cells).

## Performance
Because the same DLL is used for the MATLAB, Python, and Excel platforms, performance is similar across the board, except for the overhead of calling the DLL.
Regardless, performance should be more than adequate for most applications.
See the images below on how this project compares against the "rainflow" function from [MATLAB's Signal Processing Toolbox](https://www.mathworks.com/help/signal/index.html) and the "rainflow.count_cycles" function from the [rainflow package](https://pypi.org/project/rainflow/) from PyPI.

![matlab](https://github.com/carlos-souto/rainflow/assets/83190503/b60a4006-45cd-4c25-baef-cd51bb5714e4)

![python](https://github.com/carlos-souto/rainflow/assets/83190503/e68a0705-87ac-4119-81a5-c8aa4f4b0387)