Fortran read *,x,y,z in Matlab mex files

2 views (last 30 days)
Brian
Brian on 18 Apr 2014
Commented: dpb on 18 Apr 2014
Hey all,
If I have a fortran file that will do a
read(5,*)x,y,z
5 is no longer standard input in matlab like in fortran, so this does not work in matlab when mexing, Is there a way around this? Hopefully without changing the original file?
I know I can do an
open(unit=5,file="inputfile")
read(5,*)x,y,z
but is there a way to have it work much like read *,x,y,z in fortran where I can type in a popup or command line when asked, Instead of having the file ready before running? Basically I'm looking for a 'popup(commandline)' user input that you can mex into object files.
This sorta came about with a previous question I had the other day about write(6,...) http://www.mathworks.com/matlabcentral/answers/126000-why-does-fortran-write-6-not-show-in-matlab-window#answer_133591
Thanks, Brian
  2 Comments
dpb
dpb on 18 Apr 2014
Directly again w/o redirection or the like, "no", for the same reason--the mex function as a dll is not operating in the same context as a standalone executable.
It is possible to use various of the Windows SDK tools in a Fortran console app w/o actually being a Windows-aware app for a limited subset because they have their own message loop. I've not tried it to know just what you get into trying to link via just a DLL/mex w/o Fortran startup code, but if you're adamant to try to avoid the file redirection route I think it's the only direction other than calling back to Matlab functions from the mex and retrieving a Matlab return variable.
dpb
dpb on 18 Apr 2014
IMO a mex really should be just about the computations and i/o (other than file) should be divorced therefrom. (I do grok you're trying to use existing code, but it doesn't really seem to fit the model).

Sign in to comment.

Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!