Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Fortran - Database

Zulyrad_M_
Beginner
1,705 Views

Hello,

I am working on the development of a web application using C# (Microsoft Visual Studio) this application should call the executable of a software already created in Fortran (It is for processing and mathematical calculation).  The Fortran application needs to access a database to read/write data.

I kindly ask you as experts what you consider to be the most recommended database manager to use in this case, working in a web application development in C#(to capture de data and display the results) and with Fortran application (that need read and write information to the DBs)?

The version of Fortran that I am using is Intel Visual Fortran (Visual Studio Premiun 2013)

Beforehand I thank you for the collaboration you can give me, this would be a great help.

Best regard

Zulyrad

0 Kudos
8 Replies
FortranFan
Honored Contributor II
1,705 Views

@Zulyrad,

Please note Fortran is a relatively low-level language that offers no standard facility to work with databases.

What Fortran offers now is a standard way to interoperate with a C companion processor: please see this https://software.intel.com/en-us/fortran-compiler-18.0-developer-guide-and-reference-standard-fortran-and-c-interoperability

So if you really want the Fortran application to work directly with a database (a big design consideration where you should think through the pros and cons), then look into database options that offer APIs in terms of C language and work with the one that appears "best" in terms of C APIs while making use of above-mentioned standard interoperability features in Fortran.  One such example can be OCI for Oracle https://docs.oracle.com/cd/B10501_01/win.920/a95497/ch1.htm

 

0 Kudos
Eugene_E_Intel
Employee
1,705 Views

For an example of a database that can be accessible from C# and C, see SQLite.  Its C interface can be used from Fortran (do a web search for "sqlite fortran interface"), and it seems that there are C# bindings as well (see https://www.codeproject.com/Articles/22165/Using-SQLite-in-your-C-Application )

0 Kudos
Zulyrad_M_
Beginner
1,705 Views

Many thanks for your answers.  Just to try to be more clear with my question,  the main application of the project that i am working is a Fortran application already created.  My work now is to development a GUI for this Fortran application in a web environment using Visual C# (it is the software that they already chosen) and development a Database that can be read / write by the Fortran application directly.  I do not have experience with Fortran, even with C# however now I feel more confident with C#.  My understanding until now is that Fortran cannot connect directly to a Database, in this case how can i do it connection? and what is the more recommended Database to work with Fortran?

 

I really appreciate your help I am very confused and lost.

Many thanks

Zulyrad

 

0 Kudos
Johannes_Rieke
New Contributor III
1,705 Views

Hi Zulyrad M., IMHO there is no free available solution for interfacing to well known databases (MySQL, SQLite) in pure Fortran. As FortranFan mentioned, the Fortran-C Interface works good and is IMHO the best way. There is a solution called ForDBC from a German Fortran reseller, if a commercial option is what you seek (search on the web gives you more info).

I use an interface for MySQL since some years very successfully, which makes use of the C-API. This works really good. Here you can find some more information on my experience on this topic (https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/328310 and https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/344492). Don't try 32bit on Windows, or this will become nasty, if you're not familiar with different calling conventions.

I've not written the interface code myself, but used FLIBS mysql.f90 as a base (http://flibs.cvs.sourceforge.net/viewvc/flibs/ or https://github.com/philip-peterson/flibs) from Arjen Markus et. al. My version is attached in the second thread linked above. There is also an interface for SQLite in FLIBS.

Best regards, Johannes

 

0 Kudos
FortranFan
Honored Contributor II
1,705 Views

Zulyrad M. wrote:

..  I do not have experience with Fortran, .. I am very confused and lost. ..

@Zulyrad M.,

Given your statement about your background with Fortran, I suggest you take the time to closely review the materials in references such as those listed in this blog: https://software.intel.com/en-us/blogs/2013/12/30/doctor-fortran-in-its-a-modern-fortran-world

The book, "Modern Fortran in Practice - Arjen Markus - Cambridge University Press, 2012, ISBN 978-1-107-60347-9" also includes a section, if I recall correctly, on interfacing with MySQLLite and it also includes many other useful pointers.

Or you may also to consider getting experienced developers to do the work for you, you know to "outsource" all the work to those who know software development and have good experience.  Please keep in mind there are no shortcuts.

0 Kudos
Zulyrad_M_
Beginner
1,705 Views

Dear FortranFan,

Many thanks for your comments and help.

Now  I have clear that I have three option to link the fortran application with the Web GUI in Visual C#:

1) Invoke the Fortran console application (EXE) from C# using Process.Start and pass input and outputs using files (in this case the DataBase will be read/write from  C# application).

2) A more advanced option is to create a Fortran DLL and call from C# using P/Invoke (DllImport). With a DLL all inputs and outputs will be passed in memory (I can also use callbacks to report progress back to the C# calling code).

3) I think the most complicated is (the one that my supervisor wants) read/write the database from Fortran Application using ForDBC (from Polyhedron).

Please let me know your opinion as a Fortran expert.

Many thanks.

Zulyrad M.

 

 

0 Kudos
FortranFan
Honored Contributor II
1,705 Views

Zulyrad M. wrote:

..

2) A more advanced option is to create a Fortran DLL and call from C# using P/Invoke (DllImport). With a DLL all inputs and outputs will be passed in memory (I can also use callbacks to report progress back to the C# calling code).

..

Please let me know your opinion ..

I have a strong personal preference toward option 2 on your list and I state this based on our own experience, having tried all 3 options.  But please seek as much feedback as you see fit and think through your own situation and needs and finally, keep in mind the boss is always "right"!!! :-))

By the way, take a look at this thread for a fully worked example with the Fortran DLL option in .NET, it's Visual Basic but that doesn't really matter given how .NET really works:

https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/509148.

All the best,

 

0 Kudos
LRaim
New Contributor I
1,705 Views
==============================================================================================
Zulyrad M. wrote:

 

..

2) A more advanced option is to create a Fortran DLL and call from C# using P/Invoke (DllImport). With a DLL all inputs and outputs will be passed in memory (I can also use callbacks to report progress back to the C# calling code).


​=================================================================================================

Using DLL is not the only way to report progress, etc.
​In Windows, two .exe modules can exchange information using  messaging which is a core feature of the operating system.

One should also consider that to test a dll a calling program is required. Two .exe module can be tested independently.

Regards  

 

 

0 Kudos
Reply