Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to deal with fortran pause in matlab?

397 views
Skip to first unread message

almmond

unread,
Apr 28, 2010, 7:03:05 AM4/28/10
to
Hi, everyone

When I called fortran program with the "system()" function in matlab, I met these two problems in the programme running:
(1) When the fortran program can be completed successfully, there will be a prompt in matlab:

Fortran Pause - Enter command<CR> or <CR> to continue.

(2) When there is some error during the fortran program running, there will be prompts as the follows:

### Error Summary and Advice ###
------------------------

==> Check printed output files for more details <==

No. of occurrences of error number 1024 is 589

No. of occurrences of error number 1029 is 1

No. of occurrences of error number 1060 is 8


### End of summary: recorded error count is 598 ###

Fortran Pause - Enter command<CR> or <CR> to continue.

Now, if there is error in fortran program running, I want to quit this running and redefine input, ask matlab to call fortran program again; if the fortran program is completed successfully, I want to enter carriage return by matlab command and to execute the following codes. How can I do?

Thank you in advance!

James Tursa

unread,
Apr 28, 2010, 12:42:04 PM4/28/10
to
"almmond " <allm...@hotmail.com> wrote in message <hr94l9$qsq$1...@fred.mathworks.com>...

Here are a couple of ways to pause your Fortran program. The first uses mexEvalString to do the pause but does not return any data back into your Fortran. The second uses mexCallMATLAB to do the pause and it does return data back into your Fortran program to use via the lhs(1) mxArray variable. If you actually want to exit out of the Fortran program entirely and then restart it you will have to do that at the m-file level.

James Tursa

--------------------------------------------------

#include "fintrf.h"
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
implicit none
!-ARG
integer*4 nlhs, nrhs
mwPointer plhs(*), prhs(*)
!-FUN
integer*4, external :: mexEvalString
integer*4, external :: mexCallMATLAB
mwPointer, external :: mxCreateString
!-LOC
mwPointer rhs(1), lhs(1)
integer*4 k
!-----
!Pause with no input back into Fortran
k = mexEvalString("input('Press Enter to continue ');")
!Pause with input back into Fortran
rhs(1) = mxCreateString("Enter command ")
k = mexCallMATLAB(1, lhs, 1, rhs, "input")
call mxDestroyArray(rhs(1))
! lhs(1) contains the command, use it here
call mxDestroyArray(lhs(1))
end subroutine mexFunction

almmond

unread,
Apr 28, 2010, 2:12:04 PM4/28/10
to
Thank you very much for your reply, James Tursa!
I think maybe I didn't explain very clear what I want to solve. It is like that: In matlab I use "system" function to call a fortran executable program and when the fortran program finished, matlab didn't perform the following command line but display a line says "Fortran Pause - Enter command<CR> or <CR> to continue." So to let matlab to perform the following command line I need to enter the carrige return button. But I don't want to do it mannually, I would like to write some matlab command to let matlab perform the following command lines automatically after the fortran program is finished.

"James Tursa" <aclassyguy_wi...@hotmail.com> wrote in message <hr9ogs$3lb$1...@fred.mathworks.com>...

dpb

unread,
Apr 28, 2010, 2:53:05 PM4/28/10
to
almmond wrote:
>
...[top posting repaired; please don't do that]...

> "James Tursa" <aclassyguy_wi...@hotmail.com> wrote in message
> <hr9ogs$3lb$1...@fred.mathworks.com>...
>> "almmond " <allm...@hotmail.com> wrote in message
>> <hr94l9$qsq$1...@fred.mathworks.com>...
>> > Hi, everyone
>> > > When I called fortran program with the "system()" function in

...
>> ... if the fortran program is completed successfully, I want to

>> enter carriage return by matlab command and to execute the following
>> codes. How can I do? > > Thank you in advance!
>>
>> Here are a couple of ways to pause your Fortran program. The first
>> uses mexEvalString to do the pause but does not return any data back
>> into your Fortran. The second uses mexCallMATLAB to do the pause and

...> Thank you very much for your reply, James Tursa!


> I think maybe I didn't explain very clear what I want to solve. It is
> like that: In matlab I use "system" function to call a fortran
> executable program and when the fortran program finished, matlab didn't
> perform the following command line but display a line says "Fortran
> Pause - Enter command<CR> or <CR> to continue." So to let matlab to
> perform the following command line I need to enter the carrige return
> button. But I don't want to do it mannually, I would like to write some
> matlab command to let matlab perform the following command lines
> automatically after the fortran program is finished.

I figured that was the question.

AFAIK you'll have to have some mex file that uses system calls to stuff
the keyboard and don't know how much success you might have w/ that,
anyway, depending on the OS.

W/O somesuch trick, the only thing I can think might work (but probably
isn't what you're looking for as if it did work to enter the CR at the
right time the app wouldn't stop long enough for you to see the message
or allow any way to take different action by some means) would be to use
command line redirection.

If the program uses std i/o, then a redirected file containing the CR on
the command line _might_ work if the other input is from a file and
doesn't use default std i/o. But, if it does, as say above, it'll find
the CR and go on.

That is, try

yourprogram <FileContainingCR.Dat

from the command line and see if it terminates w/o an additional CR from
the keyboard. If so, that prevents the hangup but you have no way to
know which case occurred programmatically unless there's a return exit
code that distinguishes (and I forget whether you can get a return code
back from an app w/ the ML system call or not or whether it's the return
code of the shell rather than the app or all those caveats otomh)...

I don't think of any way w/o having control over the Fortran source
itself to get all of which you asked for as James says.

--

almmond

unread,
Apr 29, 2010, 7:40:20 AM4/29/10
to
Hi, thank you very much! dpb

Suppose I use the following line to call the fortran executable program:
system(['H:\Mat_cod\Program\ssvv.exe', ' ', '-f', ' ', 'H:\Mat_cod\folder_1\input.txt']);
and suppose the program will be performed successfully. Can you give me an example to write a command equivalent to press <CR> to let matlab carry out the following commands?

Thanks!

almmond


dpb <no...@non.net> wrote in message <hra0a6$ckv$1...@news.eternal-september.org>...

dpb

unread,
Apr 29, 2010, 9:14:43 AM4/29/10
to
almmond wrote:

...[top posting repaired -- please don't do that]...


> dpb <no...@non.net> wrote in message

...

>> If the program uses std i/o, then a redirected file containing the CR
>> on the command line _might_ work if the other input is from a file and
>> doesn't use default std i/o. But, if it does, as say above, it'll
>> find the CR and go on.
>>
>> That is, try
>>
>> yourprogram <FileContainingCR.Dat
>>
>> from the command line and see if it terminates w/o an additional CR
>> from the keyboard. If so, that prevents the hangup but you have no
>> way to know which case occurred programmatically unless there's a
>> return exit code that distinguishes (and I forget whether you can get
>> a return code back from an app w/ the ML system call or not or whether
>> it's the return code of the shell rather than the app or all those
>> caveats otomh)...
>>
>> I don't think of any way w/o having control over the Fortran source
>> itself to get all of which you asked for as James says.

...


> Hi, thank you very much! dpb
>
> Suppose I use the following line to call the fortran executable
> program:
> system(['H:\Mat_cod\Program\ssvv.exe', ' ', '-f', ' ',
> 'H:\Mat_cod\folder_1\input.txt']);
> and suppose the program will be performed successfully. Can you give
> me an example to write a command equivalent to press <CR> to let
> matlab carry out the following commands?

I said I don't think there _is_ a command equivalent to pressing <CR>
outside using OS system calls to spoof the keyboard input.

I suggested creating a file that simply contains the <CR> and using it
in input redirection in addition to the input file and see if the app
"eats" the <CR> at the end to satisfy the internal Fortran PAUSE
statement. If it won't work that way from the command line, it won't
from the ML system call, either.

AFAIK there isn't any way to get Matlab to spoof keystrokes into another
session keyboard buffer w/o, as said above, some very OS-specific hacks
(and not sure even then w/ the newer security in them; I've heard that
some things that used to work don't any longer in that regard and not
sure whether there are workarounds or not).

--

almmond

unread,
Apr 30, 2010, 12:49:04 PM4/30/10
to
Thank you again, dpb!
I wrote the following setence in dos command window:
H:\Mat_cod\Program\ssvv.exe &#8211;f H:\Mat_cod\folder_1\input.txt < H:\Mat_cod\folder_1\CR.txt
Here the file "CR.txt" is the file simply includes <CR>. And the program can run successfully, but at the end there will be continuous prompt says " Fortran Pause - Enter command<CR> or <CR> to continue".

In matlab, I wrote the line as follows:
system(['H:\Mat_cod\Program\ssvv.exe', ' ', '-f', ' ', 'H:\Mat_cod\folder_1\input.txt', ' ', '<', ' ', ' H:\Mat_cod\folder_1\CR.txt ']);
and it didn't run successfully.

Please tell me if I understood wrong.
I'm a beginner in using parallel computing toolbox. The reason why I would like to know if there is a command that is equivalent to entering the <CR> is because when I use matlabpool for parallel computing using 4 workers, I use parfor loop to call my fortran executable program but it can't stop even if I pressed the <CR> button.

The lines I wrote for that are as follows:
matlabpool(&#8216;open&#8217;, &#8216;jobmanagerconfig2&#8217;, 4);
parfor (i=1:4)
system(['H:\Mat_cod\Program\ssvv.exe', ' ', '-f', ' ', strcat('H:\Mat_cod\folder_', num2str(i), '\input.txt')]); % Parallel run 4 SHETRAN applications
end

My problem here is that I can run 4 workers at the same time, but after it finished matlab was stay busy and couldn't complete the loop and perform the following line.

By the way, I saw there is parameter for control run time in the simulink toolbox, so I think maybe I can also use simulink toolbox for my program running. My fortran program running is very time-consuming, I need at least half an hour to complete one run time and I need thousands of running to get my results. So I should consider doing them synchronously. However, this is totally new for me! Can you help me? Thank you very much!!!!

dpb <no...@non.net> wrote in message <hrc0rm$pjr$1...@news.eternal-september.org>..

dpb

unread,
Apr 30, 2010, 2:18:05 PM4/30/10
to
almmond wrote:
> Thank you again, dpb!
> I wrote the following setence in dos command window:
> H:\Mat_cod\Program\ssvv.exe &#8211;f H:\Mat_cod\folder_1\input.txt <
> H:\Mat_cod\folder_1\CR.txt
> Here the file "CR.txt" is the file simply includes <CR>. And the program
> can run successfully, but at the end there will be continuous prompt
> says " Fortran Pause - Enter command<CR> or <CR> to continue".

OK, that's bad sign...how did you create the file ie, are you sure it
does have the CR (ASCII x0D or 13 decimal) character and not a "<CR>"
literal string or something?

If that is so then the idea doesn't work and your only hope will be to
try the aforementioned route of trying to write an OS-specific mex-file
or use some other utility that can spoof keystrokes to the keyboard
buffer. As noted earlier, w/ later versions of Windows this has become
more difficult owing to more security and I've not fooled around trying
to do so since NT4 at the latest. Whatever is possible now is probably
most easily found on the MSDN site or on other Windows programming
fora--I've no additional useful input.

...

> I'm a beginner in using parallel computing toolbox. The reason why I
> would like to know if there is a command that is equivalent to entering
> the <CR> is because when I use matlabpool for parallel computing using 4
> workers, I use parfor loop to call my fortran executable program but it
> can't stop even if I pressed the <CR> button.

...
I have no experience w/ the parallel computing toolbox.

Practically, I think unless you can get access to the Fortran code and
modify its behavior you're likely trying the proverbial crude act up a
rope unless the point first raised turns out to have merit...

--

0 new messages