10-04-2010 05:17 PM
For a project I have a finite volume code in Fortran that simulates magnetohydrodynamics and I want to use it as an observer in LabWindows. This code basically is going to simulate the system using the measurements taken.
What should I do? I heard something about creating a Fortran dll and using it in LabWindows. How can I do that?
10-05-2010 10:38 AM
Hello, You are on the right track, you can call into dll's created in other languages from LabWindows/CVI. However you cannot create a Fortran dll using LabWindows/CVI.
Thanks,
10-05-2010 11:50 AM
CVI ships with multiple example DLL projects that can help you understand how to create and call DLLs in CVI. In your case, as Anna said, you need to call functions in a DLL, not create a DLL in CVI. You need to use your Fortran compiler to create the DLL and .LIB file, and then you can use CVI to call functions in that DLL.
Look at the simple DLL example projects in C:\Documents and Settings\All Users\Documents\National Instruments\CVI90\samples\dll\simple\cvi. (Note: the directory may be different depending on your CVI installation and version.)
First you need to build the DLL. Open mydll.prj, then, from the CVI menu, select Build >> Create Debuggable Dynamic Link Library. This is the step in your real project that you will need to do using your Fortran compiler.
Then build the executable to call functions from your DLL. Open simple.prj, then Build >> Create Debuggable Executable. You can now run your project, and browse simple.c to see how it calls functions in your DLL.
Remember that for the purpose of this example, you're building a DLL in CVI, but for your real project, you'll be using your Fortran compiler to build your DLL and LIB. Copy the DLL and LIB files to your CVI project directory, add the LIB file to your CVI project, and in your .c file which will call the DLL functions, #include a .h file which contains the prototypes for the DLL functions you'll be calling.
10-05-2010 03:22 PM
The Fortran compiler may or may not generate the import library (the .LIB file). If it doesn't you may have to call the DLL file explicitly as detailed here:
http://zone.ni.com/devzone/cda/tut/p/id/8503
Alternatively you be able to use lib.exe to create the .LIB file once you have the .DLL (you may need to have MS Visual Studio installed to have access to lib.exe).
10-06-2010 10:53 AM
By the way, as long as you already have the .dll and .h files, CVI can generate the import library for you: open the .h file in CVI, and then select Options>>Generate DLL Import Library.
Luis
10-16-2010 03:21 PM
So I understand I need to use my Fortran compiler (Intel compiler) to create the DLL. How do I do that? I have found info online about how to create a Fortran DLL to be called from Visual Basic. Is the procedure any similar?
Felipe
10-18-2010 11:49 AM
If you need help on compiling the Fortran code, I would post such a question to a Fortan developers blog, as knowledge in this language is less common. Here on the CVI forums you will find C developers. Best of luck!
10-21-2010 10:33 AM
@chimbotano wrote:
So I understand I need to use my Fortran compiler (Intel compiler) to create the DLL. How do I do that? I have found info online about how to create a Fortran DLL to be called from Visual Basic. Is the procedure any similar?
Felipe
The proceedure to create the DLL with the Fortran compiler should be independent of the language used to call the DLL, so these instructions should be what you need on the Fortran side.
I've created DLLs in Delphi (Pascal) and called them from CVI.
10-21-2010 01:56 PM
I have already created a DLL using Intel Fortran Compiler for Windows and now I want to use implicit linking to call it from LabWindows. I understand that I need to provide three files: *.dll, *.h (header file) and *.lib (I can create this one as long as I have the DLL and the header).
The *.h file only needs to have the prototypes of the Fortran procedures that I plan to use, right?
10-21-2010 02:02 PM
Correct. The only prototypes you need are for the functions that you will be calling directly from CVI.