# Run Engine for Fortran DLLS

**URL:** <https://forum.inductiveautomation.com/t/run-engine-for-fortran-dlls/37166>\
**Category:** Ignition\
**Created:** [July 28, 2020, 6:29pm UTC](https://forum.inductiveautomation.com/t/run-engine-for-fortran-dlls/37166 "2020-07-28T18:29:40Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![MADHUR1989](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@MADHUR1989](https://forum.inductiveautomation.com/u/MADHUR1989)\
**Post date:** [July 28, 2020, 6:29pm UTC](https://forum.inductiveautomation.com/t/run-engine-for-fortran-dlls/37166/1 "2020-07-28T18:29:40Z")

</div>

Hi,  
Can Ignition platform act as an engine for Fortran dlls? Ideally, execute the dlls, monitor performance, log errors, sequence it in a proper fashion etc. If not within Ignition, any other partner apps for that?  
Thank you for your response.  
Madhur

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [July 28, 2020, 6:42pm UTC](https://forum.inductiveautomation.com/t/run-engine-for-fortran-dlls/37166/2 "2020-07-28T18:42:04Z")

</div>

> [@Device Simulator and ignition](http://forum.inductiveautomation.com/t/device-simulator-and-ignition/20514/14):
>
> We have developed a simulation module (UNISEMS) that can integrate with Ignition directly thru a GCM module or thru OPC-UA (you will have to expose all tags thru OPC UA interface for this). However the simulation models will have to be written in GNU FORTRAN. See [Introduction](https://youtu.be/XpPv2KWk4c0) and Demo of [UNISEMS](https://youtu.be/249R5l3rELs). of UNISEMS module. As you are writing your simulator in Python , UNISEMS will have to be slightly modified to suit your requirements.

@PRAMANJ

---

<div class="post-metadata">

**Author:** ![peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@peter](https://forum.inductiveautomation.com/u/peter)\
**Post date:** [July 28, 2020, 10:02pm UTC](https://forum.inductiveautomation.com/t/run-engine-for-fortran-dlls/37166/3 "2020-07-28T22:02:05Z")

</div>

The Ignition Jython installation supports the standard Python [ctypes](https://docs.python.org/2/library/ctypes.html) library. This provides:

> [`ctypes`](https://docs.python.org/2/library/ctypes.html#module-ctypes) is a foreign function library for Python. It provides C compatible data types, and allows calling functions in DLLs or shared libraries. It can be used to wrap these libraries in pure Python.

This would allow you to directly call your Fortran DLLs from Jython.

However I am not sure how well this works as this Stack Overflow question [Ctypes support in Jython](https://stackoverflow.com/questions/27901278/ctypes-support-in-jython) suggest the support may not be the best.

If it does work for you, then this Stack Overflow question [Using python-ctypes to interface fortran with python](https://stackoverflow.com/q/15875533/31326) provides a simple example

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 29, 2020, 1:58am UTC](https://forum.inductiveautomation.com/t/run-engine-for-fortran-dlls/37166/4 "2020-07-29T01:58:42Z")

</div>

Jython ctypes does not work. Java JNI is required to actually load DLLs (or \*nix shared objects) in Jython.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [July 29, 2020, 3:50am UTC](https://forum.inductiveautomation.com/t/run-engine-for-fortran-dlls/37166/5 "2020-07-29T03:50:55Z")

</div>

If you can let us know your use case it may be possible to use a different approach like using interprocess communication .

---

<div class="post-metadata">

**Author:** ![Kevin.McClusky](https://avatars.discourse-cdn.com/v4/letter/k/47e85d/32.png) [@Kevin.McClusky](https://forum.inductiveautomation.com/u/Kevin.McClusky)\
**Post date:** [July 29, 2020, 3:54am UTC](https://forum.inductiveautomation.com/t/run-engine-for-fortran-dlls/37166/6 "2020-07-29T03:54:47Z")

</div>

> [@pturmel](#):
>
> Jython ctypes does not work. Java JNI is required to actually load DLLs (or \*nix shared objects) in Jython.

Exactly. If you have enough expertise, you can write a module and use JNI/JNA to get access to DLLs / SOs. If you know Java, Ignition, and C, there's an example of JNA here. If you don't have expertise in all 3 of those things, this could be a tricky route. If there are other options, I'd explore those first. [GitHub - IgnitionModuleDevelopmentCommunity/JNAScriptingFunction: The JNA (Java Native Access) Example module provides users with two examples for using a Dynamic Link Library (DLL) in Ignition](https://github.com/IgnitionModuleDevelopmentCommunity/JNAScriptingFunction)

---

<div class="post-metadata">

**Author:** ![peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@peter](https://forum.inductiveautomation.com/u/peter)\
**Post date:** [July 29, 2020, 4:02pm UTC](https://forum.inductiveautomation.com/t/run-engine-for-fortran-dlls/37166/7 "2020-07-29T16:02:43Z")

</div>

> [@pturmel](#):
>
> Jython ctypes does not work. Java JNI is required to actually load DLLs (or \*nix shared objects) in Jython.

Caveat is that I have no practical experience in doing this, but from my research yesterday I saw that some ctypes functionality was reported as working under Jython. I would assume that the working functionality would still work under the Jython implementation used in Ignition.

When I was looking up JNI I also hit upon [JyNI](https://jyni.org):

> JyNI is a compatibility layer with the goal to enable Jython to use native CPython extensions like NumPy or SciPy. This way we aim to enable scientific Python code to run on Jython. Since Java is quite present in industry and Python is more present in science, JyNI will be an important step to lower the costs of using scientific code in industrial environments.

This seems to be a more general way to include DLLs in Jython code. However this seems to be predicated on running the JyNI.jar file as a part of the Jython.jar execution (See [JyNI on GitHub](https://github.com/Stewori/JyNI)) but in addressing my own question on Jython in Ignition, I'm guessing that this is not possible

---

<div class="post-metadata">

**Author:** ![MADHUR1989](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@MADHUR1989](https://forum.inductiveautomation.com/u/MADHUR1989)\
**Post date:** [July 29, 2020, 4:51pm UTC](https://forum.inductiveautomation.com/t/run-engine-for-fortran-dlls/37166/8 "2020-07-29T16:51:16Z")

</div>

Thank you for the responses, all. The application is in a closed loop Advanced Process Control (APC) software. The thought is that Ignition already has OPC capability which allows you to get all the I/O information, but then build proprietary modules in Fortran dlls so that there is IP protection. If Ignition could also execute these dlls on command (thus, acting like an engine), then that’s a full solution to build a proprietary closed loop control APC system, while not having to develop the platform side of things.  
Please note that the closed loop aspect is the key difference between our use case and above-mentioned ‘simulation’.

---

<div class="post-metadata">

**Author:** ![MADHUR1989](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@MADHUR1989](https://forum.inductiveautomation.com/u/MADHUR1989)\
**Post date:** [July 29, 2020, 4:52pm UTC](https://forum.inductiveautomation.com/t/run-engine-for-fortran-dlls/37166/9 "2020-07-29T16:52:50Z")

</div>

To add, developing ‘platform applications’ is a very different skillset for chemical engineers like me. Thus, the request about 3-p solutions to do just that.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [July 29, 2020, 4:53pm UTC](https://forum.inductiveautomation.com/t/run-engine-for-fortran-dlls/37166/10 "2020-07-29T16:53:57Z")

</div>

Probably the best bet for getting this working would be to also develop an Ignition module to go along with the DLLs that were developed that interfaced with them via JNI or JNA.

There’s nothing built in that’s going to get you there, though.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 29, 2020, 4:55pm UTC](https://forum.inductiveautomation.com/t/run-engine-for-fortran-dlls/37166/11 "2020-07-29T16:55:02Z")

</div>

Or just write your proprietary code in java, delivered as an Ignition module.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [July 29, 2020, 5:26pm UTC](https://forum.inductiveautomation.com/t/run-engine-for-fortran-dlls/37166/12 "2020-07-29T17:26:26Z")

</div>

Another alternative is to use FORTRAN from python [F2PY - Calling Fortran routines from Python](https://www.numfys.net/howto/F2PY/) using NumPy (_F2PY is a part of [NumPy](https://numpy.org/)_) which interfaces with Ignition using OPC calls or sockets! Presume you will access real time plant I/O data from Ignition to perform Advanced Process Control actions!
