A Cardiovascular Simulator for Research 1.0.0
(1,597 bytes)
/* The function read_key.c, which is periodically called by simulate.m,
checks the standard input to determine whether or not the user would
like to pause and then resume the simulation (eg., for purpose of
parameter updating or scrolling backwards).
Function arguments: none
Function output:
X - flag indicating whether pause/resume has been requested
= 0 pause/resume not requested
= 1 pause/resume requested */
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include </usr/include/fcntl.h>
#include <string.h>
#include <matlab.h>
mxArray *mlfRead_key()
{
/* Declaring variables */
int fd;
mxArray *X;
char buf[1];
/* Opening standard input file */
fd = open("/dev/tty", O_NONBLOCK);
/* If standard input is empty, returninig a 0 to simulate.m */
if (read(fd,buf,1) == -1)
{
close(fd);
X = mlfScalar(0);
return X;
}
/* If standard input contains "p", then pausing the program through
an infinite while-loop. Each iteration of the loop, the program
will be reading the standard input. The loop will terminate and
return a 1 to simulate.m once an "r" has been read. */
if (!strncmp(buf,"p",1))
{
while (1)
{
if (read(fd,buf,1) != -1 & !strncmp(buf,"r",1))
{
close(fd);
X = mlfScalar(1);
return X;
}
}
}
/* Closing standard input file. */
close(fd);
/* If standard input is not empty and does not include "p", then
returning a 0 to simulate.m */
X = mlfScalar(0);
return X;
}