[英]How can I use a Fortran file in a C# application?
我有英特爾®Parallel Studio XE,它為Microsoft Visual Studio提供了Fortran編譯器(我使用2013 Ultimate版本)。 是否可以在C#應用程序中執行Fortran文件,或者它必須是C / C ++應用程序? 我該怎么做?
他們都不能使用fortran,您必須創建一個fortran項目,不能混合語言。 一個可能的解決方案是創建一個DLL並將其與DLLImport接口,這可能對您有所幫助:
您可以通過兩種方式從C#調用Fortran。
1)創建一個Fortran控制台應用程序(EXE)。 使用Process.Start從C#調用,並使用文件傳遞輸入和輸出。 我建議從這種方法開始。
var startInfo = new ProcessStartInfo();
startInfo.FileName = "MyFortranApp.exe";
startInfo.Arguments = @"C:\temp\input_file.txt C:\temp\output_file.txt";
Process.Start(startInfo);
2)一種更高級的方法是創建一個Fortran DLL,並使用P / Invoke(DllImport)從C#進行調用。 使用DLL,所有輸入和輸出都在內存中傳遞。 您還可以使用回調將進度報告回C#調用代碼。
public static class FortranLib
{
private const string _dllName = "FortranLib.dll";
[DllImport(_dllName, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern void DoStuff([In] double[] vector, ref int n, [In, Out] double[,] matrix);
}
http://www.luckingtechnotes.com/calling-fortran-dll-from-csharp/ http://www.luckingtechnotes.com/calling-fortran-from-c-monitoring-progress-using-callbacks/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.