Call a Fortran code in Matlab to get the result which I will use it in Matlab code

9 Ansichten (letzte 30 Tage)
I have a Fortran code and I want to run it in MATLAB, By this I will get the output from Fortran code and will use it in Matlab code. I was trying with system command but it is only opening Fortran interface with code not running.Please help me to do this.
  9 Kommentare
Sumit Pal
Sumit Pal am 28 Aug. 2015
Bearbeitet: Sumit Pal am 28 Aug. 2015
Okay got it. I am editing it. Please help me to solve the problem. have you checked it ?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 28 Aug. 2015
Once, not every time, you should execute
!msbuild "C:\Users\Sumit Pal\Desktop\Test\communicationtest\communicationtest.sln"
after that the code will be in compiled form and you will be able to system() the .exe, whatever it got named. For example it might be
system('C:\Users\Sumit Pal\Desktop\Test\communicationtest\main.exe')
You can pass input to the .exe by building an input file in MATLAB and redirecting input from the file. For example,
tinfile = tempname();
fid = fopen(tinfile, 'wt');
fprintf(fid, '%d\n', 3);
fprintf(fid, '%f\n', [7, 31, pi]);
fclose(fid);
executable = 'C:\Users\Sumit Pal\Desktop\Test\communicationtest\main.exe';
result = system( sprintf('%s < %s', executable, tinfile) );
resfile = 'out_plot.dat';
rfid = fopen(resfile, 'r');
... do something here ...
fclose(rfid);
At the moment I do not have the resources to investigate the format that the
write(20,*) V,f
is going to use in the file. I do not know if it would be text or if it would be binary. Try
data = fread(rfid);
as I suspect that might work.
  22 Kommentare
Sumit Pal
Sumit Pal am 2 Sep. 2015
Yes, I am a student. I installed Intel Visual Fortran Composer XE 2013 on my pc and also generated the mex file but this is showing an error. There is any thing missing again?
Sumit Pal
Sumit Pal am 2 Sep. 2015
previous problem is solved by changing mxCreateDoubleMatrix instead of mxCreateFull but a new problem is coming.
Please look at it.
MATLAB crash file:C:\Users\RANADE~1\AppData\Local\Temp\matlab_crash_dump.2288-1:
------------------------------------------------------------------------
Access violation detected at Wed Sep 02 19:56:04 2015
------------------------------------------------------------------------
Configuration:
Crash Decoding : Disabled
Default Encoding : windows-1252
MATLAB Architecture: win64
MATLAB Root : C:\Program Files\MATLAB\R2014a
MATLAB Version : 8.3.0.532 (R2014a)
Operating System : Microsoft Windows 7 Professional
Processor ID : x86 Family 6 Model 60 Stepping 3, GenuineIntel
Virtual Machine : Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
Window System : Version 6.1 (Build 7601: Service Pack 1)
Fault Count: 1
Abnormal termination:
Access violation
Register State (from fault):
RAX = 0000000000000008 RBX = 000000000402af40
RCX = 000000000402a030 RDX = 766d9fc071d03790
RSP = 000000000402a008 RBP = 000000000402b060
RSI = 000000000402b060 RDI = 000000000402af40
R8 = 0000000000000008 R9 = 0000000000000001
R10 = 0000000000000001 R11 = 000000000402a030
R12 = 000000000000127f R13 = 00000000686d6ed0
R14 = 0000000000000001 R15 = 000000000402b060
RIP = 0000000072e9bfbf EFL = 00010202
CS = 0033 FS = 0053 GS = 002b
Stack Trace (from fault):
[ 0] 0x0000000072e9bfbf C:\Program Files\MATLAB\R2014a\bin\win64\MSVCR100.dll+00245695 memmove+00000095
[ 1] 0x000007fef92f10ae C:\Users\Ranadev Dutta\Desktop\Test\communicationtest\timestwo.mexw64+00004270 MEXFUNCTION+00000174
[ 2] 0x00000000fc5ef700 C:\Program Files\MATLAB\R2014a\bin\win64\libmex.dll+00063232 mexRunMexFile+00000112
[ 3] 0x00000000fc5ee1e2 C:\Program Files\MATLAB\R2014a\bin\win64\libmex.dll+00057826 inSwapMexfileReader+00000226
[ 4] 0x00000000fc5ef294 C:\Program Files\MATLAB\R2014a\bin\win64\libmex.dll+00062100 _constructor_lm_mexmaci64+00001620
[ 5] 0x000000000458be4f C:\Program Files\MATLAB\R2014a\bin\win64\m_dispatcher.dll+00048719 Mfh_file::dispatch_fh+00000687
[ 6] 0x000000000458c77a C:\Program Files\MATLAB\R2014a\bin\win64\m_dispatcher.dll+00051066 Mfunction_handle::dispatch+00000810
[ 7] 0x0000000004705e04 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00744964 MathWorks::MException::MExceptionEnvelope::GetID+00539764
[ 8] 0x00000000046f0782 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00657282 MathWorks::MException::MExceptionEnvelope::GetID+00452082
[ 9] 0x00000000046e3f6f C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00606063 MathWorks::MException::MExceptionEnvelope::GetID+00400863
[ 10] 0x00000000046ccd43 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00511299 MathWorks::MException::MExceptionEnvelope::GetID+00306099
[ 11] 0x00000000046d644f C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00549967 MathWorks::MException::MExceptionEnvelope::GetID+00344767
[ 12] 0x00000000046e4962 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00608610 MathWorks::MException::MExceptionEnvelope::GetID+00403410
[ 13] 0x00000000046e192c C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00596268 MathWorks::MException::MExceptionEnvelope::GetID+00391068
[ 14] 0x00000000046f11c9 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+00659913 MathWorks::MException::MExceptionEnvelope::GetID+00454713
[ 15] 0x000000000458c00e C:\Program Files\MATLAB\R2014a\bin\win64\m_dispatcher.dll+00049166 Mfh_file::dispatch_fh+00001134
[ 16] 0x000000000458c77a C:\Program Files\MATLAB\R2014a\bin\win64\m_dispatcher.dll+00051066 Mfunction_handle::dispatch+00000810
[ 17] 0x0000000004764a0e C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+01133070 inValidateLoadedObject+00003486
[ 18] 0x000000000476bd95 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+01162645 inResetInterpreter+00005029
[ 19] 0x0000000004770a05 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+01182213 MathWorks::MException::MExceptionEnvelope::Copy+00010997
[ 20] 0x00000000047709d2 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+01182162 MathWorks::MException::MExceptionEnvelope::Copy+00010946
[ 21] 0x0000000004770997 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+01182103 MathWorks::MException::MExceptionEnvelope::Copy+00010887
[ 22] 0x0000000004b5e89c C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+05302428 inMexPutVariable+00004204
[ 23] 0x0000000004b5ebf6 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+05303286 inMexPutVariable+00005062
[ 24] 0x0000000004b5f02e C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+05304366 inMexPutVariable+00006142
[ 25] 0x0000000004b5f36c C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+05305196 inMexPutVariable+00006972
[ 26] 0x0000000004a70161 C:\Program Files\MATLAB\R2014a\bin\win64\m_interpreter.dll+04325729 inEvalCmdWithLocalReturn+00000065
[ 27] 0x00000000050cbecd C:\Program Files\MATLAB\R2014a\bin\win64\libmwbridge.dll+00048845 mnDebugPrompt+00000109
[ 28] 0x00000000050ccfaf C:\Program Files\MATLAB\R2014a\bin\win64\libmwbridge.dll+00053167 mnParser+00000735
[ 29] 0x00000000fd0afae4 C:\Program Files\MATLAB\R2014a\bin\win64\mcr.dll+00195300 mcrInstance::mnParser_on_interpreter_thread+00000036
[ 30] 0x00000000fd093af0 C:\Program Files\MATLAB\R2014a\bin\win64\mcr.dll+00080624 mcr::runtime::setInterpreterThreadToCurrent+00029488
[ 31] 0x00000000fd093b50 C:\Program Files\MATLAB\R2014a\bin\win64\mcr.dll+00080720 mcr::runtime::setInterpreterThreadToCurrent+00029584
[ 32] 0x00000000fab6e026 C:\Program Files\MATLAB\R2014a\bin\win64\uiw.dll+00581670 UIW_IsUserMessage+00000086
[ 33] 0x00000000fab6e705 C:\Program Files\MATLAB\R2014a\bin\win64\uiw.dll+00583429 UIW_SetGLIMUserMsg+00000117
[ 34] 0x00000000fab6e789 C:\Program Files\MATLAB\R2014a\bin\win64\uiw.dll+00583561 UIW_SetGLIMUserMsg+00000249
[ 35] 0x00000000773d87fe C:\Windows\system32\USER32.dll+00165886 GetMenuBarInfo+00000638
[ 36] 0x00000000773bf5fb C:\Windows\system32\USER32.dll+00062971 SystemParametersInfoW+00000235
[ 37] 0x00000000773c4895 C:\Windows\system32\USER32.dll+00084117 IsProcessDPIAware+00000465
[ 38] 0x000000007761dae5 C:\Windows\SYSTEM32\ntdll.dll+00318181 KiUserCallbackDispatcher+00000031
[ 39] 0x00000000773c908a C:\Windows\system32\USER32.dll+00102538 PeekMessageW+00000186
[ 40] 0x00000000773c50fe C:\Windows\system32\USER32.dll+00086270 GetKeyState+00000238
[ 41] 0x00000000773c3a6f C:\Windows\system32\USER32.dll+00080495 PeekMessageA+00000087
[ 42] 0x00000000fab1bd4b C:\Program Files\MATLAB\R2014a\bin\win64\uiw.dll+00245067 UIW_SetCurrentDialog+00000731
[ 43] 0x00000000fab6fbe2 C:\Program Files\MATLAB\R2014a\bin\win64\uiw.dll+00588770 ws_FreeSystemFont+00000482
[ 44] 0x00000001000e2ed0 C:\Program Files\MATLAB\R2014a\bin\win64\libmwservices.dll+00995024 services::system_events::PpeDispatchHook::~PpeDispatchHook+00053488
[ 45] 0x00000001000e36a5 C:\Program Files\MATLAB\R2014a\bin\win64\libmwservices.dll+00997029 services::system_events::PpeDispatchHook::~PpeDispatchHook+00055493
[ 46] 0x00000001000e4330 C:\Program Files\MATLAB\R2014a\bin\win64\libmwservices.dll+01000240 services::system_events::PpeDispatchHook::~PpeDispatchHook+00058704
[ 47] 0x00000001000ed4c6 C:\Program Files\MATLAB\R2014a\bin\win64\libmwservices.dll+01037510 sysq::removeProcessPendingEventsHook+00011030
[ 48] 0x00000001000ed7ca C:\Program Files\MATLAB\R2014a\bin\win64\libmwservices.dll+01038282 svWS_ProcessPendingEvents+00000138
[ 49] 0x00000000fd094b6d C:\Program Files\MATLAB\R2014a\bin\win64\mcr.dll+00084845 mcr::runtime::setInterpreterThreadToCurrent+00033709
[ 50] 0x00000000fd094e3b C:\Program Files\MATLAB\R2014a\bin\win64\mcr.dll+00085563 mcr::runtime::setInterpreterThreadToCurrent+00034427
[ 51] 0x00000000fd088b75 C:\Program Files\MATLAB\R2014a\bin\win64\mcr.dll+00035701 mcrInstantiationError::operator=+00003221
[ 52] 0x00000000fd08bea2 C:\Program Files\MATLAB\R2014a\bin\win64\mcr.dll+00048802 mcr_invoke_on_interpreter_thread+00001602
[ 53] 0x00000000fa7e6e5d C:\Program Files\MATLAB\R2014a\bin\win64\MVMLocal.dll+00159325 mvm_server::inproc::LocalFactory::createMVM+00040653
[ 54] 0x00000000051bafaa C:\Program Files\MATLAB\R2014a\bin\win64\mvm.dll+00569258 mvm::detail::SessionImpl::privateSession+00001754
[ 55] 0x00000000051bd32a C:\Program Files\MATLAB\R2014a\bin\win64\mvm.dll+00578346 mvm::detail::SessionImpl::privateSession+00010842
[ 56] 0x00000000051bce85 C:\Program Files\MATLAB\R2014a\bin\win64\mvm.dll+00577157 mvm::detail::SessionImpl::privateSession+00009653
[ 57] 0x0000000140004f79 C:\Program Files\MATLAB\R2014a\bin\win64\matlab.exe+00020345
[ 58] 0x0000000140006a07 C:\Program Files\MATLAB\R2014a\bin\win64\matlab.exe+00027143
[ 59] 0x00000000774c59cd C:\Windows\system32\kernel32.dll+00088525 BaseThreadInitThunk+00000013
[ 60] 0x00000000775fb981 C:\Windows\SYSTEM32\ntdll.dll+00178561 RtlUserThreadStart+00000033
This error was detected while a MEX-file was running. If the MEX-file
is not an official MathWorks function, please examine its source code
for errors. Please consult the External Interfaces Guide for information
on debugging MEX-files.
If this problem is reproducible, please submit a Service Request via:
http://www.mathworks.com/support/contact_us/
A technical support engineer might contact you with further information.
Thank you for your help.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB Compiler finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by