📄 backvalve_.c
字号:
v[0] = v[29]+v[32]+v[27];
v[1] = v[30]+v[33]+v[28];
v[34] = v[2] /* Duplicate variable. */;
v[26] = v[2] /* Duplicate variable. */;
v[37] = v[38] /* Duplicate variable. */;
v[8] = v[38] /* Duplicate variable. */;
v[40] = v[36]+v[10];
n = 1;
*oldflag = *newflag = sflag;
hl04_(&n, &v[24], &dot[2], &v[25], &v[35], &dot[5], &v[37]
, &v[41], &v[42], &v[43], &v[44], &v[45], r13, I13, c13
, J13, &sflag);
if(sflag < 3)sflag = getnfg_();
resdis(flag, &sflag, &oflag, "HL04", 1, &panic);
n = 2;
*oldflag = *newflag = sflag;
hl04_(&n, &v[20], &dot[1], &v[21], &v[29], &dot[3], &v[31]
, &v[46], &v[47], &v[48], &v[49], &v[50], r18, I18, c18
, J18, &sflag);
if(sflag < 3)sflag = getnfg_();
resdis(flag, &sflag, &oflag, "HL04", 2, &panic);
n = 1;
*oldflag = *newflag = sflag;
ha001_(&n, &v[2], &dot[0], &v[0], &v[3], &v[4], &v[5], r0, I0
, c0, J0, &sflag);
if(sflag < 3)sflag = getnfg_();
resdis(flag, &sflag, &oflag, "HA001", 1, &panic);
n = 1;
*oldflag = *newflag = sflag;
rv00_(&n, &v[7], &v[6], &v[8], &v[11], r1, J1, &sflag);
if(sflag < 3)sflag = getnfg_();
resdis(flag, &sflag, &oflag, "RV00", 1, &panic);
v[9] = -v[7] /* Duplicate variable. */;
n = 1;
*oldflag = *newflag = sflag;
pt001_(&n, &v[26], &v[23], r10);
if(sflag < 3)sflag = getnfg_();
resdis(flag, &sflag, &oflag, "PT001", 1, &panic);
v[39] = v[35]+v[9];
n = 3;
*oldflag = *newflag = sflag;
hl04_(&n, &v[38], &dot[6], &v[39], &v[32], &dot[4], &v[34]
, &v[51], &v[52], &v[53], &v[54], &v[55], r19, I19, c19
, J19, &sflag);
if(sflag < 3)sflag = getnfg_();
resdis(flag, &sflag, &oflag, "HL04", 3, &panic);
/* Set interface outputs here. */
output[0] = v[23];
if (*flag == 0)
{
/* A restart has been initiated and the user is
permitted to change the state variables. */
ChangeState(&y[0], v[2]);
ChangeState(&y[2], v[24]);
ChangeState(&y[5], v[35]);
ChangeState(&y[1], v[20]);
ChangeState(&y[3], v[29]);
ChangeState(&y[6], v[38]);
ChangeState(&y[4], v[32]);
}
UpFECount();
first_call = 0;
}
/*****************************************************************
* *
* OutputResults outputs numerical results if required *
* *
* (i) to the screen and/or *
* (ii) to the file:- *
backvalve_.results.
* *
* *
******************************************************************/
static void OutputResults
#ifdef _NO_PROTO
(t)
double t;
#else
(double t)
#endif
{
#ifndef NORESULTFILE
char line[PATH_MAX+128];
static int isize=sizeof(int), dsize=sizeof(double);
/* Local variables */
static double buf[2*NUMVARS+2];
int numsaved=0;
int i;
static time_t last_flush_time=0;
static time_t tt1;
/* Function Body */
if(fd_results == -1)
{
/* No output required, the file not open etc so nothing to do. */
return;
}
if(iwrite != 2)
{
/* Output time to screen. */
ameprintf("Time = %g\n",t);
tt1 = time(NULL);
if(difftime(tt1, last_flush_time) > 0.5)
{
fflush(stderr);
fflush(stdout);
last_flush_time = tt1;
}
}
/* Write time & variables to backvalve_.results. This is now
done in one single write statement. We first fill the
buffer array (buf) with the stuff we want to write */
/* First position ourselfs at the end of the data */
lseek(fd_results, (long)(position*dsize+HeaderSize), 0);
/* Fill the buffer with the normal writes */
buf[0] = t;
numsaved=1;
for(i=0;i<NUMVARS;i++)
{
/* Write value to results file only if it is enabled. */
if(SaveFlags[i] != 0)
{
buf[numsaved]=v[i];
numsaved++;
}
}
/* Update the position count, this is only
for the "normal" output. The trailer below
must not be counted */
position = position + numsaved;
/* If this is a selective save run (not all variables are saved) we
need (for a restart) to have a complete set of variable values
at the end of the file. This will be updated for each output
point so we must not update the position count here. */
if(NumToSave != NUMVARS)
{
buf[numsaved]=t;
numsaved++;
for(i=0;i<NUMVARS;i++)
{
buf[numsaved]=v[i];
numsaved++;
}
}
/* Write the buffer */
if(write(fd_results, buf, dsize*numsaved) != dsize*numsaved)
{
sprintf(line,"Cannot write to file `%s'", GetResultsFileName());
DisplayMessage(line);
}
/* Write number of points calculated. */
points++;
lseek(fd_results, 0L, 0);
if(write(fd_results, (char *)(&points), isize) != isize)
{
sprintf(line,"Cannot write to file `%s'", GetResultsFileName());
DisplayMessage(line);
}
#endif
}
/**********************************************************************
* *
* WriteErrorCount - A dummy for resolving unresolved references *
* *
**********************************************************************/
extern void WriteErrorCount
#ifdef _NO_PROTO
(close)
int close;
#else
(int close)
#endif
{
}
/**********************************************************************
* *
* SummarizeErrors - A dummy for resolving unresolved references *
* *
**********************************************************************/
extern void SummarizeErrors()
{
}
/*******************************************************************
* *
* isactivity_ returns true if this option is selected in *
* the Run parameters and isprint_ returns true. It returns false *
* otherwise. *
* *
*******************************************************************/
extern int isactivity_()
{
return (activityindex && isprint_());
}
/* ***************************************************************** */
/* */
/* Simulink special code below */
/* */
/* ***************************************************************** */
/******* Simulink interface specific declarations ********/
#ifndef NRT
#ifndef RT
#ifndef MATLAB_MEX_FILE
#define MATLAB_MEX_FILE
#endif
#endif
#endif
#define S_FUNCTION_NA\
ME backvalve_
#define S_FUNCTION_LEVEL 2
/*
* Need to include simstruc.h for the definition of the SimStruct and
* its associated macro definitions.
*/
#include "simstruc.h"
static double zerocrossingflag=-0.5;
static char **ameGetCharVectorFromSParam(const mxArray *pVal, int *vectorsize, int *rowsize, int *colsize);
static double *ameGetRealVectorFromSParam(const mxArray *pVal, int *vectorsize);
static int ameSimOptions(SimStruct *S, struct ameSimOptionsStruct *AS);
static int ameSetGlobalParams(SimStruct *S);
static void ameDealWithInputArgs(SimStruct *S, struct ameSimOptionsStruct *AS);
/******* End of Simulink interface specific declarations ********/
/********************************************************************
* *
* ameSimulinkfprintf is a function that is called from amewarning *
* and amemessage (and amefprintf) to deal with outputs to screen *
* By defining this function in the template one can simply *
* redirect screen output to some conenient place *
* *
********************************************************************/
static int ameSimulinkfprintf(FILE *fp, const char *fmt, va_list ap)
{
int ans=0;
char tmpstr[8000];
if( (fp == stdout) || (fp == stderr) )
{
ans = vsprintf(tmpstr, fmt, ap);
#ifdef MATLAB_MEX_FILE
mexPrintf(tmpstr);
#else
AMEssPrintf(tmpstr);
#endif
}
else
{
#ifndef AMEHAVENOSTDIO
ans=vfprintf(fp, fmt, ap);
#endif
}
return ans;
}
/********************************************************************
* *
* AmeExit is the function that submodel and utilities should call *
* instead of exit. This version is using Matlab/Simulink code *
* to print an error message. *
* *
********************************************************************/
void AmeExit
#ifdef _NO_PROTO
(status)
int status;
#else
(int status)
#endif
{
static char messstr[512];
char sfuncname[128];
AmeCallAtEnd(status);
#ifdef MATLAB_MEX_FILE
strcpy(sfuncname,mexFunctionName());
#else
strcpy(sfuncname,GetCircuitName());
#endif
if(status)
{
sprintf(messstr,"AMESim mexfunction %s did an abnormal exit!\n%s", sfuncname,
"Check Matlab Command Window for more error messages");
}
else
{
sprintf(messstr,"AMESim mexfunction %s terminated normally (but early)", sfuncname);
}
#ifdef MATLAB_MEX_FILE
mexErrMsgTxt(messstr);
#else
AMEssPrintf(messstr);
exit(1);
#endif
}
/******************************************************************
* DisplayMessage is a replacement for the DisplayMessage *
* in the library. This is necessary since on Windows no stdio *
* is visible on screen. *
******************************************************************/
void DisplayMessage(char *str)
{
static char messstr[512];
char sfuncname[128];
AmeCallAtEnd(1);
#ifdef MATLAB_MEX_FILE
strcpy(sfuncname,mexFunctionName());
#else
strcpy(sfuncname,GetCircuitName());
#endif
sprintf(messstr,"In AMESim mexfunction: %s, AMESim fatal error '%s', EXIT\n %s",
sfuncname, str, "Check Matlab Command Window for more error messages");
#ifdef MATLAB_MEX_FILE
mexErrMsgTxt(messstr);
#else
AMEssPrintf(messstr);
exit(1);
#endif
}
/******************************************************
* *
* reset_real_integer_stores resets the real *
* and integer stores to zero. *
* *
******************************************************/
static void reset_real_integer_stores()
{
/* START of generated code for 'InsertInterfaceReset C IC' */
J0[0] = J0[1] = 0;
c0[0] = c0[1] = c0[2] = c0[3] = c0[4] = 0.0;
J1[0] = J1[1] = 0;
J6[0] = J6[1] = J6[2] = 0;
c9[0] = 0.0;
J13[0] = J13[1] = J13[2] = J13[3] = 0;
{
int i;
for (i=0; i<15; i++) {
c13[i] = 0;
}
}
J18[0] = J18[1] = J18[2] = J18[3] = 0;
{
int i;
for (i=0; i<15; i++) {
c18[i] = 0;
}
}
J19[0] = J19[1] = J19[2] = J19[3] = 0;
{
int i;
for (i=0; i<15; i++) {
c19[i] = 0;
}
}
/* END of generated code for 'InsertInterfaceReset C IC' */
;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -