From: almmond on
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!
From: James Tursa on
"almmond " <allmmond(a)hotmail.com> wrote in message <hr94l9$qsq$1(a)fred.mathworks.com>...
> 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!

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
From: almmond on
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_with_a_k_not_a_c(a)hotmail.com> wrote in message <hr9ogs$3lb$1(a)fred.mathworks.com>...
> "almmond " <allmmond(a)hotmail.com> wrote in message <hr94l9$qsq$1(a)fred.mathworks.com>...
> > 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!
>
> 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
From: dpb on
almmond wrote:
>
....[top posting repaired; please don't do that]...

> "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message
> <hr9ogs$3lb$1(a)fred.mathworks.com>...
>> "almmond " <allmmond(a)hotmail.com> wrote in message
>> <hr94l9$qsq$1(a)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.

--
From: almmond on
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 <none(a)non.net> wrote in message <hra0a6$ckv$1(a)news.eternal-september.org>...

> 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.
>
> --