115 EPstart(
void *data,
const char *el,
const char **attr)
119 if( 0 ==
strcmp(el,
"BCVTB-variables") )
121 if( 0 ==
strcmp(el,
"variable") ) {
122 if( 0 ==
strcmp(attr[1],
"EnergyPlus") )
128 if( 0 ==
strcmp(el,
"EnergyPlus") ) {
130 for(i=0; attr[
i]; i++)i=i;
132 fprintf(stderr,
"Error: Variable configuration file invalid.\n"
133 " Expected two attribute values for source\n"
134 " of EnergyPlus: 'name' and 'type'.\n");
137 if ( 0 ==
strcmp(attr[0],
"name") && 0 ==
strcmp(attr[2],
"type") )
139 else if( 0 ==
strcmp(attr[2],
"name") && 0 ==
strcmp(attr[0],
"type"))
142 fprintf(stderr,
"Error: Variable configuration file not valide.\n"
143 " Expected two attribute values for source\n"
144 " of EnergyPlus: 'name' and 'type'.\n");
149 fprintf(stderr,
"Error: Not enough memory allocated for EnergyPlus output.\n"
150 " Allocated: %d.\n", *
strLen);
157 fprintf(stderr,
"Error: Not enough memory allocated for EnergyPlus output.\n"
158 " Allocated: %d.\n", *
strLen);
167 for( i=0; attr[
i]; i++)i=i;
169 fprintf(stderr,
"Error: Expecting one input variable in one\n"
170 " element in xml file.\n");
176 fprintf(stderr,
"Error: Memory allocated for parsed E+ input\n"
177 " variables name is not enough,\n"
178 " allocated: %d.\n", *
strLen);
188 if( numInputKeys == j) {
189 fprintf(stderr,
"Error: Unknown input variable type: %s.\n", attr[0]);
242 char*
const myOutputVarsName,
243 char*
const myOutputVarsType,
244 int*
const myNumOutputVars,
245 char*
const myInputKeys,
246 int*
const myNumInputKeys,
247 char*
const myInputVars,
248 int*
const myNumInputVars,
249 int*
const myInputVarsType,
250 int*
const myStrLen){
254 int i, j, count, ret;
259 fd = fopen(fileName,
"r");
261 fprintf(stderr,
"Error: Could not open file '%s' when getting EnergyPlus variables.\n", fileName);
264 p = XML_ParserCreate(NULL);
266 fprintf(stderr,
"Error: Could not allocate memory for parser in function 'getepvariables'.\n");
281 if(myInputKeys[count] ==
'\0') {
286 if(myInputKeys[count] ==
','){
296 fprintf(stderr,
"Error: Memory allocation failed in 'utilXml.c'\n");
304 fprintf(stderr,
"Error: Memory allocation failed in 'utilXml.c'.\n");
311 if((i+1) != *myNumInputKeys ){
313 "Error: Number of input variables keys found does not match:\nFound %d, expected %d\n",
314 i+1, * myNumInputKeys);
333 fprintf(stderr,
"Error when reading xml variables in '%s'.\n", fileName);
339 if (XML_Parse(p,
Buff, len, done) == XML_STATUS_ERROR
341 fprintf(stderr,
"Error: Parser error in file '%s':\n%s\n",
343 XML_ErrorString(XML_GetErrorCode(p)));
376 char*
const myOutputVarsName,
377 char*
const myOutputVarsType,
378 int*
const myNumOutputVars,
379 char*
const myInputKeys,
380 int*
const myNumInputKeys,
381 char*
const myInputVars,
382 int*
const myNumInputVars,
383 int*
const myInputVarsType,
384 int*
const myStrLen){
388 int i, j, count, ret;
393 fd = fopen(fileName,
"r");
395 fprintf(stderr,
"Error: Could not open file '%s' when getting EnergyPlus variables.\n", fileName);
398 p = XML_ParserCreate(NULL);
400 fprintf(stderr,
"Error: Could not allocate memory for parser in function 'getepvariables'.\n");
415 if(myInputKeys[count] ==
'\0') {
420 if(myInputKeys[count] ==
','){
430 fprintf(stderr,
"Error: Memory allocation failed in 'utilXml.c'\n");
438 fprintf(stderr,
"Error: Memory allocation failed in 'utilXml.c'.\n");
445 if((i+1) != *myNumInputKeys ){
447 "Error: Number of input variables keys found does not match:\nFound %d, expected %d\n",
448 i+1, * myNumInputKeys);
467 fprintf(stderr,
"Error when reading xml variables in '%s'.\n", fileName);
473 if (XML_Parse(p,
Buff, len, done) == XML_STATUS_ERROR
475 fprintf(stderr,
"Error: Parser error in file '%s':\n%s\n",
477 XML_ErrorString(XML_GetErrorCode(p)));
502 fprintf(stderr,
"Error: Memory allocation failed in 'utilXml.c'.\n");
518 fprintf(stderr,
"Error: Memory allocation failed in 'utilXml.c'");
523 fprintf(stderr,
"Error: Memory allocation failed in 'utilXml.c'");
552 int*
const myNumVals,
567 fd = fopen(fileName,
"r");
569 fprintf(stderr,
"Error: Could not open file '%s'.\n", fileName);
572 p = XML_ParserCreate(NULL);
574 fprintf(stderr,
"Error: Could not allocate memory for parser in function 'getxmlvalue'.\n");
578 if(!exp ||
'\0' == exp[0])
580 if( exp[0] !=
'/' || exp[1] !=
'/')
584 while(exp[i] !=
'\0'){
585 if( exp[i] ==
'/' || exp[i] ==
'[' || exp[i] ==
']') {
587 fprintf(stderr,
"Error when parsing expression in 'utilXml.c'.\n");
591 if(strchr(temp,
'@'))
600 temp = (
char*) realloc(temp,
sizeof(
char)*(j+1));
602 fprintf(stderr,
"Error: Memory allocation failed in 'utilXml.c'.\n");
611 att = (
char*) malloc(
sizeof(
char) * (strlen(temp) ) );
613 fprintf(stderr,
"Error: Memory allocation failed in 'utilXml.c'.\n");
617 for(i=1; i<strlen(temp); i++)
623 fprintf(stderr,
"Error when parsing expression in 'utilXml.c'.\n");
633 XML_SetElementHandler(p,
start,
end);
641 fprintf(stderr,
"Error when reading xml variables in '%s'.\n", fileName);
646 if (XML_Parse(p,
Buff, len, done) == XML_STATUS_ERROR) {
647 fprintf(stderr,
"Error: Parse error in file '%s':\n%s\n",
649 XML_ErrorString(XML_GetErrorCode(p)));
657 fprintf(stderr,
"Error: Did not find xml value\n for expression '%s'.\n in file '%s'\n",
675 start(
void *data,
const char *el,
const char **attr)
681 for(i=0; attr[
i]; i += 2) {
684 if( (strlen(
vals)+strlen(attr[i+1])+2) > *
strLen){
685 fprintf(stderr,
"Error: Memory allocated for parsed attribute\n"
686 " values is not enough, allocated: %d.\n",
693 strcat(
vals, attr[i+1]);
707 end(
void *data,
const char *el)
743 fprintf(stderr,
"Error: In getnumberofxmlvalues.\n");
794 if( -1 == ret || *nVal > *strLen )
796 if( strlen(str)+2 >= *strLen ) {
797 fprintf(stderr,
"Error: Not enough memory allocated for parsed xml\n"
798 " values in getxmlvaluesf, allocated: %zx.\n",
842 fprintf(stderr,
"Error: Error when attempting to parse file '%s'\n",fileName);
846 fprintf(stderr,
"Error: No xml value parsed in file '%s'\n",fileName);
850 fprintf(stderr,
"Error: More than one xml values parsed, \n"
851 " while expecting one value. \n"
852 " number of xml values parsed is: %d\n"
871 char *BCVTB_HOME, *dtdFileName;
876 const char *
const xmlPath =
"\\lib\\xml\\";
877 const char *
const jarPath =
"\\lib\\xml\\build\\jar\\DTDValidator.jar";
879 const char *
const xmlPath =
"/lib/xml/";
880 const char *
const jarPath =
"/lib/xml/build/jar/DTDValidator.jar";
883 BCVTB_HOME = getenv(
"BCVTB_HOME");
884 if(NULL == BCVTB_HOME){
885 fprintf(stderr,
"Error: Cannot get environment variable: BCVTB_HOME.\n");
888 command = (
char*) malloc(
sizeof(
char) *
889 ( strlen(BCVTB_HOME) +
891 strlen(
"variables.dtd")
896 if(NULL == command) {
897 fprintf(stderr,
"Error: Memory allocation failed in"
898 " check_variable_cfg_Validate"
899 " when parsing file '%s'.\n"
900 " Program aborting.\n", fileName);
903 dtdFileName = (
char*) malloc(
sizeof (
char) * ( strlen(BCVTB_HOME) + 30));
904 if(NULL == command) {
905 fprintf(stderr,
"Error: Memory allocation failed in"
906 " check_variable_cfg_Validate"
907 " when parsing file '%s'. \n"
908 " Program aborting.\n", fileName);
912 sprintf(dtdFileName,
"%s%s%s", BCVTB_HOME, xmlPath,
"variables.dtd");
913 dtdF = fopen(dtdFileName,
"r");
915 fprintf(stderr,
"Error: Cannot open '%s'.\n", dtdFileName);
919 sprintf(command,
"java -jar \"%s%s\" \"%s\" \"%s%s\"",
920 BCVTB_HOME, jarPath, fileName, BCVTB_HOME, xmlPath);
921 ret = system(command);
int * inputVarsType
the ineger array to store the types of each input variables
char Buff[BUFFSIZE]
Local buffer for reading in the xml file.
int getxmlvalues(char *const fileName, char *const exp, char *const myVals, int *const myNumVals, int const myStrLen)
static void XMLCALL EPstart(void *data, const char *el, const char **attr)
Call back functions that will be used by the expat xml parser.
int * numVals
Local global variable for function getxmlvalue.
int getepvariables(char *const fileName, char *const myOutputVarsName, char *const myOutputVarsType, int *const myNumOutputVars, char *const myInputKeys, int *const myNumInputKeys, char *const myInputVars, int *const myNumInputVars, int *const myInputVarsType, int *const myStrLen)
This method will return the input and output variable for EnergyPlus in sequence. ...
Stack expStk
Variables for getxmlvalue function.
int getepvariablesFMU(char *const fileName, char *const myOutputVarsName, char *const myOutputVarsType, int *const myNumOutputVars, char *const myInputKeys, int *const myNumInputKeys, char *const myInputVars, int *const myNumInputVars, int *const myInputVarsType, int *const myStrLen)
This method will return the input and output variable for EnergyPlus in sequence. ...
int * numOutputVars
the integer pointer to the number of output variables
char * outputVarsName
local global variables for function getepvariables
fprintf([' ', 'Trying to send client error from MATLAB to the BCVTB.'])
int PARSEVALUE
flag for parsing xml values 1 if parse, 0 if not parse
char * vals
Local global variable for function getxmlvalue.
int stackPushBCVTB(char *str)
Stack operation, will push one element into the stack and will allocate memory for the new element...
int check_variable_cfg_Validate(char *const fileName)
This method checks the validity of the variables configuration xml file for a given dtd file that is ...
int getnumberofxmlvalues(char *const fileName, char *const exp)
static void XMLCALL start(void *data, const char *el, const char **attr)
Call back functions that will be used by the expat xml parser.
int stackPopBCVTB()
Stack operation, this function will pop one element from stack and will free the resource unused...
static void XMLCALL end(void *data, const char *el)
Call back functions that will be used by the expat xml parser.
const int * strLen
the length of string parsed to this function
char * att
Local global variable for function getxmlvalue.
int numInputKeys
the number of input variable types
static void XMLCALL EPend(void *data, const char *el)
Call back functions that will be used by the expat xml parser.
int getxmlvaluesf(char *const fileName, char *const exp, char *const atrName, int *const nVal, char *const str, int *const strLen)
int ERROR_STATUS
flag for xml element handler error status settings
void freeResource(char **strArr, int n)
This method frees the local memory allocated.
int source
flag for function /c getepvariables 0=EnergyPlus, 1=Ptolemy
char * outputVarsType
the string pointer to the parsed output variable types
char ** inputKeys
the string array to store the types of input variable types
int * numInputVars
the integer pointer to the number of input variables
char * inputVars
the string pointer to the input variables
if strcmp(retVal, '') disp('Simulink is not installed on this computer.') disp('The Simulink library will not be compiled.') else makeSBlock
int getxmlvalue(char *const fileName, char *const exp, char *const str, int *const nVals, int const strLen)