32 #include "utilSocket.h"
36 int main(
int argc,
char *argv[]){
40 const char *
const simCfgFilNam =
"socket.cfg";
42 const int cliErrFla = -1;
60 double endTim = 6.*3600;
69 double UA = Q0Hea / 20;
71 double C[] = {tau*UA, 2*tau*UA};
72 double TRoo[] = {TIni, TIni};
78 printf(
"Usage: %s simulation_timestep_in_seconds\n", argv[0]);
81 delTim = atof(argv[1]);
82 fprintf(stderr,
"Simulation model has time step %8.5g\n", delTim);
83 fprintf(stderr,
"Simulation model has end time %8.5g\n", endTim);
86 printf(
"Error: End time must be bigger than zero.\n");
87 printf(
"Usage: %s simulation_timestep_in_seconds end_time_in_seconds\n", argv[0]);
92 nSte = (int)floor((endTim/delTim) + 0.5);
93 if (abs(nSte*delTim-endTim) > 1E-10*endTim){
94 printf(
"Error: End time divided by time step must be an integer.\n");
95 printf(
" Number of time steps is %d.\n", nSte);
96 printf(
"Usage: %s simulation_timestep_in_seconds end_time_in_seconds\n", argv[0]);
104 fprintf(stderr,
"Error: Failed to obtain socket file descriptor. sockfd=%d.\n", sockfd);
110 for(iSte=0; iSte < nSte+1; iSte++){
112 simTimWri = (double)iSte*delTim;
116 dblValWri[i]=TRoo[i];
122 &simTimWri, dblValWri,
123 &simTimRea, dblValRea);
128 printf(
"Simulator received value %d when reading from socket. Exit simulation.\n", retVal);
134 printf(
"Simulator received end of simulation signal from server. Exit simulation.\n");
140 printf(
"Simulator received flag = %d from server. Exit simulation.\n", flaRea);
147 printf(
"Simulator received nDblRea = %d from server, but expected 2. Exit simulation.\n",
155 for(i=0; i < nRoo; i++)
161 for(i=0; i < nRoo; i++)
162 TRoo[i] = TRoo[i] + delTim/C[i] * ( UA * (TOut-TRoo[i] ) + Q0Hea * y[i] );
int exchangedoubleswithsocket(const int *sockfd, const int *flaWri, int *flaRea, const int *nDblWri, int *nDblRea, double *simTimWri, double dblValWri[], double *simTimRea, double dblValRea[])
Exchanges data with the socket.
int main(int argc, char *argv[])
Main function.
int establishclientsocket(const char *const docname)
Establishes a connection to the socket.
fprintf([' ', 'Trying to send client error from MATLAB to the BCVTB.'])
int sendclientmessage(const int *sockfd, const int *flaWri)
Writes a message flag to the socket stream.
end Get return values from pointers flaRea
int closeipc(int *sockfd)
Closes the inter process communication socket.