NFobject_p NFparseObjAliasCreate(XML_Parser parser, NFobject_p parent, const char *name, const char **attr) { const char *attrib; NFobjAlias_p alias = (NFobjAlias_p) NULL; if ((parent->Type != NFcompRegion) && (parent->Type != NFmodEquation) && (parent->Type != NFmodProcess)) { CMmsgPrint(CMmsgAppError, "This shouldn't have happened in %s%d.\n", __FILE__, __LINE__); goto Abort; } if ((alias = (NFobjAlias_p) NFobjectCreate(name, NFobjAlias)) == (NFobjAlias_p) NULL) { CMmsgPrint(CMmsgAppError, "Alias creation error in %s:%d.\n", __FILE__, __LINE__); goto Abort; } attrib = NFparseGetAttribute(attr, NFattrValueStr, NFkeyVariableStr); if ((strcmp(attrib, NFkeyVariableStr) != 0) && (strcmp(attrib, NFkeyParameterStr) != 0)) { CMmsgPrint(CMmsgUsrError, "Invalid alias type in line %d!\n", XML_GetCurrentLineNumber(parser)); goto Abort; } alias->AliasType = strcmp(attrib, NFkeyVariableStr) == 0 ? NFaliasVariable : NFaliasParameter; if ((attrib = NFparseGetAttribute(attr, NFobjAliasStr, (char *) NULL)) == (char *) NULL) { CMmsgPrint(CMmsgUsrError, "Missing alias attribute URL in line %d!\n", XML_GetCurrentLineNumber(parser)); goto Abort; } alias->Alias = CMstrDuplicate(attrib); alias->Parent = parent; return ((NFobject_p) alias); Abort: if (alias != (NFobjAlias_p) NULL) NFobjectFree((NFobject_p) alias); return ((NFobject_p) NULL); }
NFobject_p NFparseModProcessCreate (XML_Parser parser,NFobject_p parent,const char *name, const char **attr) { const char *attrib; NFmodProcess_p module = (NFmodProcess_p) NULL; NFcompModel_p model; NFobjPlugin_p plugin = (NFobjPlugin_p) NULL; if (parent->Type != NFcompContainer) { CMmsgPrint (CMmsgAppError, "This shouldn't have happened in %s%d.\n",__FILE__,__LINE__); goto Abort; } if ((module = (NFmodProcess_p) NFobjectCreate (name,NFmodProcess)) == (NFmodProcess_p) NULL) { CMmsgPrint (CMmsgAppError, "Process module creation error in %s:%d\n",__FILE__,__LINE__); goto Abort; } if ((attrib = NFparseGetAttribute (attr, NFobjPluginStr, (char *) NULL)) == (char *) NULL) { CMmsgPrint (CMmsgUsrError, "Missing process [%s] plugi in line %d!\n",name, XML_GetCurrentLineNumber (parser)); goto Abort; } model = (NFcompModel_p) NFobjectRoot (parent); if ((plugin = NFpluginGet (model->ModPlugins,attrib)) == (NFobjPlugin_p) NULL) { CMmsgPrint (CMmsgUsrError, "Modules plugin [%s] loading error in line %d!\n",attrib, XML_GetCurrentLineNumber (parser)); goto Abort; } if ((attrib = NFparseGetAttribute (attr, NFattrMethodStr, (char *) NULL)) == (char *) NULL) { CMmsgPrint (CMmsgUsrError, "Missing plugin [%s] method in line %d!\n",plugin->Name, XML_GetCurrentLineNumber (parser)); goto Abort; } if ((module->Initialize = (NFinitializeFunc) NFpluginFunction (plugin, NFfuncInitializeStr, attrib)) == (NFinitializeFunc) NULL) { CMmsgPrint (CMmsgUsrError, "Error loding plugin [%s] function [%s] in line %d!\n",plugin->Name, attrib, XML_GetCurrentLineNumber (parser)); goto Abort; } if ((module->Execute = (NFexecuteFunc) NFpluginFunction (plugin, NFfuncExecuteStr, attrib)) == (NFexecuteFunc) NULL) { CMmsgPrint (CMmsgUsrError, "Error loding plugin [%s] function [%s] in line %d!\n",plugin->Name, attrib, XML_GetCurrentLineNumber (parser)); goto Abort; } if ((module->Finalize = (NFfinalizeFunc) NFpluginFunction (plugin, NFfuncFinalizeStr, attrib)) == (NFfinalizeFunc) NULL) { CMmsgPrint (CMmsgUsrError, "Error loading plugin [%s] function [%s] in line %d!\n",plugin->Name, attrib, XML_GetCurrentLineNumber (parser)); goto Abort; } module->Initialize (module->Context); if ((module->Context->UserData = (void *) malloc (module->Context->UserDataSize)) == (void *) NULL) { CMmsgPrint (CMmsgSysError, "Memory allocation errord in %s:%d\n",__FILE__,__LINE__); goto Abort; } module->Parent = parent; CMmsgPrint (CMmsgInfo,"Parameter num: %d Variable num: %d\n", module->Context->ParameterNum, module->Context->VariableNum); return ((NFobject_p) module); Abort: if (module != (NFmodProcess_p) NULL) NFobjectFree ((NFobject_p) module); return ((NFobject_p) NULL); }
NFobject_p NFparseCompModelCreate(XML_Parser parser, const char *name, const char **attr) { NFcompModel_p model = (NFcompModel_p) NULL; if ((model = (NFcompModel_p) NFobjectCreate(name, NFcompModel)) == (NFcompModel_p) NULL) { CMmsgPrint(CMmsgAppError, "Creating model in %s:%d\n", __FILE__, __LINE__); goto Abort; } if (NFtimeSetFromString(model->Begin, NFparseGetAttribute(attr, NFattrBeginStr, "0000-01-01")) == false) { CMmsgPrint(CMmsgAppError, "Begin time setting error in %s:%d!\n", __FILE__, __LINE__); goto Abort; } if (NFtimeSetFromString(model->End, NFparseGetAttribute(attr, NFattrEndStr, "0000-12-31")) == false) { CMmsgPrint(CMmsgAppError, "End time setting error in %s:%d!\n", __FILE__, __LINE__); goto Abort; } model->Version = CMstrDuplicate(NFparseGetAttribute(attr, NFattrVersionStr, "noversion")); return ((NFobject_p) model); Abort: if (model != (NFcompModel_p) NULL) NFobjectFree((NFobject_p) model); return ((NFobject_p) NULL); }
NFobject_p NFparseCompContainerCreate(XML_Parser parser, NFobject_p parent, const char *name, const char **attr) { const char *attrib; NFcompContainer_p component = (NFcompContainer_p) NULL; NFcompModel_p model; NFcomponent_p sibling; NFobjList_p componentList; NFtimeStep_p timeStep; if ((parent->Type != NFcompModel) && (parent->Type != NFcompContainer)) { CMmsgPrint(CMmsgAppError, "This shouldn't have happened in %s%d\n", __FILE__, __LINE__); goto Abort; } if ((component = (NFcompContainer_p) NFobjectCreate(name, NFcompContainer)) == (NFcompContainer_p) NULL) { CMmsgPrint(CMmsgAppError, "Component creation error in %s:%d\n", __FILE__, __LINE__); goto Abort; } attrib = NFparseGetAttribute(attr, NFcompLayoutStr, NFkeyInheritStr); if (strcmp(attrib, NFkeyInheritStr) == 0) { if (parent->Type == NFcompContainer) component->Domain = ((NFcomponent_p) parent)->Domain; else { CMmsgPrint(CMmsgUsrError, "Container [%s] in model can't inherit layout in line %d!\n", name, XML_GetCurrentLineNumber(parser)); goto Abort; } } else { switch (parent->Type) { case NFcompContainer: componentList = ((NFcompContainer_p) parent)->Components; break; case NFcompModel: componentList = ((NFcompModel_p) parent)->Components; break; default: CMmsgPrint(CMmsgUsrError, "This shouldn't have happened in %s,%d!\n", __FILE__, __LINE__); goto Abort; } if ((sibling = (NFcomponent_p) NFobjListFindItemByName(componentList, attrib)) == (NFcomponent_p) NULL) { CMmsgPrint(CMmsgUsrError, "Invalid container [%s] layout [%s] in line %d.\n", name, attrib, XML_GetCurrentLineNumber(parser)); goto Abort; } component->Domain = sibling->Domain; } model = (NFcompModel_p) NFobjectRoot(parent); attrib = NFparseGetAttribute(attr, NFattrTimeStepStr, "inherit"); if (strcmp(attrib, NFkeyInheritStr) == 0) { switch (parent->Type) { case NFcompContainer: case NFcompModel: component->TimeStep = ((NFcomponent_p) parent)->TimeStep; break; default: CMmsgPrint(CMmsgAppError, "This shouldn't have happened in %s%d!\n", __FILE__, __LINE__); goto Abort; } } else { if (NFtimeStepSetFromString(component->TimeStep, attrib) == false) { CMmsgPrint(CMmsgAppError, "Time step [%s] error in %d!\n", attrib, XML_GetCurrentLineNumber(parser)); goto Abort; } if ((timeStep = NFmodelAddTimeStep(model, component->TimeStep)) != component->TimeStep) { NFtimeStepFree(component->TimeStep); component->TimeStep = timeStep; } } if ((attrib = NFparseGetAttribute(attr, NFattrStatesStr, (char *) NULL)) == (char *) NULL) { CMmsgPrint(CMmsgUsrError, "Missing container state in line %d\n", XML_GetCurrentLineNumber(parser)); goto Abort; } component->States = CMstrDuplicate(attrib); component->Parent = parent; return ((NFobject_p) component); Abort: if (component != (NFcompContainer_p) NULL) NFobjectFree((NFobject_p) component); return ((NFobject_p) NULL); }
NFobject_p NFparseModInterfaceCreate (XML_Parser parser,NFobject_p parent,const char *name, const char **attr) { const char *attrib; NFmodInterface_p module = (NFmodInterface_p) NULL; NFnumVariable_p inputVar; NFobject_p component; NFobjList_p list; if ((parent->Type != NFcompContainer) || (parent->Parent == (NFobject_p) NULL)) { CMmsgPrint (CMmsgAppError, "This shouldn't have happened in %s%d.\n",__FILE__,__LINE__); goto Abort; } if ((attrib = NFparseGetAttribute (attr, NFattrRelationStr, (char *) NULL)) == (char *) NULL) { CMmsgPrint (CMmsgUsrError, "Missing interface [%s] relation in %d!\n",name, XML_GetCurrentLineNumber (parser)); goto Abort; } if (strcmp (attrib,NFkeyRootStr) == 0) { component = NFobjectRoot (parent); if (component->Type == NFcompModel) list = ((NFcompModel_p) component)->Components; else { CMmsgPrint (CMmsgAppError, "This shouldn't have happened in %s%d.\n",__FILE__,__LINE__); goto Abort; } } else if (strcmp (attrib,NFkeyParentStr) == 0) { component = parent->Parent; switch (component->Type) { case NFcompModel: list = ((NFcompModel_p) component)->Components; break; case NFcompContainer: list = ((NFcompContainer_p) component)->Components; break; default: CMmsgPrint (CMmsgAppError, "This shouldn't have happened in %s%d.\n",__FILE__,__LINE__); goto Abort; } } else if (strcmp (attrib,NFkeyOwnStr) == 0) list = ((NFcompModel_p) parent)->Components; if ((attrib = NFparseGetAttribute (attr, NFcomponentStr, (char *) NULL)) == (char *) NULL) { CMmsgPrint (CMmsgUsrError, "Missing interface [%s] component in %d!\n",name, XML_GetCurrentLineNumber (parser)); goto Abort; } if ((component = NFobjListFindItemByName (list,attrib)) == (NFobject_p) NULL) { CMmsgPrint (CMmsgUsrError, "Invalid interface [%s] component [%s] in line %d!\n",name, attrib, XML_GetCurrentLineNumber (parser)); goto Abort; } if ((attrib = NFparseGetAttribute (attr, NFcomponentStr, (char *) NULL)) == (char *) NULL) { CMmsgPrint (CMmsgUsrError, "Missing interface [%s] component in %d!\n",name, XML_GetCurrentLineNumber (parser)); goto Abort; } if ((component = NFobjListFindItemByName (list,attrib)) == (NFobject_p) NULL) { CMmsgPrint (CMmsgUsrError, "Invalid interface [%s] component [%s] in line %d!\n",name, attrib, XML_GetCurrentLineNumber (parser)); goto Abort; } if ((attrib = NFparseGetAttribute (attr, NFnumVariableStr, (char *) NULL)) == (char *) NULL) { CMmsgPrint (CMmsgUsrError, "Missing interface [%s] variable in line %d!\n",name,XML_GetCurrentLineNumber (parser)); goto Abort; } switch (component->Type) { case NFcompAggregate: inputVar = (NFnumVariable_p) NFobjListFindItemByName (((NFcompAggregate_p) component)->Variables,attrib); break; case NFcompInput: inputVar = (NFnumVariable_p) NFobjListFindItemByName (((NFcompInput_p ) component)->Variables,attrib); break; case NFcompContainer: inputVar = (NFnumVariable_p) NFobjListFindItemByName (((NFcompContainer_p) component)->Variables,attrib); break; default: CMmsgPrint (CMmsgAppError, "This shouldn't have happened in %s%d.\n",__FILE__,__LINE__); goto Abort; } if (inputVar == (NFnumVariable_p) NULL) { CMmsgPrint (CMmsgUsrError, "Missing interface [%s] variable [%s] in line %d!\n",name, attrib, XML_GetCurrentLineNumber (parser)); goto Abort; } if ((module = (NFmodInterface_p) NFobjectCreate (name,NFmodInterface)) == (NFmodInterface_p) NULL) { CMmsgPrint (CMmsgAppError, "Interface module creation error in %s:%d.\n",__FILE__,__LINE__); goto Abort; } if ((module->Variable = (NFnumVariable_p) NFobjectCreate (name,NFnumVariable)) == (NFnumVariable_p) NULL) { CMmsgPrint (CMmsgAppError, "Derivative variable creation error in %s:%d.\n",__FILE__,__LINE__); goto Abort; } if ((attrib = NFparseGetAttribute (attr, NFattrCouplerStr, (char *) NULL)) != (char *) NULL) { if (strcmp (attrib,NFkeyCouplerFluxStr) == 0) module->CouplerType = NFcouplerFlux; else if (strcmp (attrib,NFkeyCouplerPointStr) == 0) module->CouplerType = NFcouplerPoint; else if (strcmp (attrib,NFkeyCouplerSurfStr) == 0) module->CouplerType = NFcouplerSurface; // TODO set interface weight when the coupler type is point! } module->Component = (NFcomponent_p) component; module->Variable->Parent = (NFobject_p) module; module->Variable->StandardName = CMstrDuplicate (inputVar->StandardName); module->Variable->UnitString = CMstrDuplicate (inputVar->UnitString); module->InputVar = inputVar; module->Parent = parent; return ((NFobject_p) module); Abort: if (module != (NFmodInterface_p) NULL) { if (module->Variable != (NFnumVariable_p) NULL) NFobjectFree ((NFobject_p) module->Variable); NFobjectFree ((NFobject_p) module); } return ((NFobject_p) NULL); }
/**************************************************************************************************************** * Entry start *****************************************************************************************************************/ static void XMLCALL _NFentryStart (void *argPtr, const char *entry, const char **attr) { const char *name; const char *modelChildren [] = { NFcompAggregateStr, NFcompContainerStr, NFcompInputStr, NFcompRegionStr, NFnumParameterStr, (char *) NULL }; const char *containerChildren [] = { NFcompAggregateStr, NFcompContainerStr, NFcompRegionStr, NFnumParameterStr, NFnumInitialStr, NFnumVariableStr, NFmodDerivativeStr, NFmodEquationStr, NFmodInterfaceStr, NFmodProcessStr, NFmodRouteStr, NFobjOutputStr, (char *) NULL }; const char *ioChildren [] = { NFnumVariableStr, (char *) NULL }; const char *regionChildren [] = { NFobjAliasStr, (char *) NULL }; const char *aggregateChildren [] = { NFobjCategoryStr, (char *) NULL }; const char *moduleChildren [] = { NFobjAliasStr, NFnumParameterStr, (char *) NULL }; NFdata_t *data; NFobject_p object, parent; XML_Parser parser = (XML_Parser) argPtr; data = (NFdata_t *) XML_GetUserData (parser); if (data->Skip) { if (strcmp (data->SkipName,entry) == 0) data->SkipLevel++; return; } if (data->Stack + 1 >= data->StackSize) { data->Objects = (NFobject_p *) realloc (data->Objects, (data->StackSize + 1) * sizeof (NFobject_p)); if (data->Objects == (NFobject_p *) NULL) { CMmsgPrint (CMmsgSysError, "Memory allocation error in %s:%d\n",__FILE__,__LINE__); goto Abort; } data->Objects [data->StackSize] = (NFobject_p) NULL; data->StackSize++; } if ((name = NFparseGetAttribute (attr, NFattrNameStr, (const char *) NULL)) == (char *) NULL) { CMmsgPrint (CMmsgWarning,"Skipping unnamed %s section in line: %d\n",entry, XML_GetCurrentLineNumber (parser)); goto Skip; } if (data->Stack == 0) { // Document root level if (strcmp (entry,NFcompModelStr) == 0) { if (data->Objects [data->Stack] != (NFobject_p) NULL) { CMmsgPrint (CMmsgWarning, "Skipping second model [%s] section [%s] in line: %d\n",entry, name, XML_GetCurrentLineNumber (parser)); goto Skip; } if ((data->Objects [data->Stack] = NFparseCompModelCreate (parser,name,attr)) == (NFobject_p) NULL) { CMmsgPrint (CMmsgAppError, "Model creation error in %s:%d\n",__FILE__,__LINE__); goto Abort; } data->Model = (NFcompModel_p) data->Objects [data->Stack]; } else { CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in line: %d\n",entry, name, XML_GetCurrentLineNumber (parser)); goto Skip; } } else { parent = data->Objects [data->Stack - 1]; switch (parent->Type) { case NFcompAggregate: if (CMoptLookup (aggregateChildren, entry, true) == CMfailed) { CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in %s [%s]\n",entry, name, NFobjTypeName (parent->Type), parent->Name); goto Skip; } break; case NFcompContainer: if (CMoptLookup (containerChildren, entry, true) == CMfailed) { CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in %s [%s]\n",entry, name, NFobjTypeName (parent->Type), parent->Name); goto Skip; } break; case NFcompInput: if (CMoptLookup (ioChildren, entry, true) == CMfailed) { CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in %s [%s]\n",entry, name, NFobjTypeName (parent->Type), parent->Name); goto Skip; } break; case NFcompModel: if (CMoptLookup (modelChildren, entry, true) == CMfailed) { CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in %s [%s]\n",entry, name, NFobjTypeName (parent->Type), parent->Name); goto Skip; } break; case NFcompRegion: if (CMoptLookup (regionChildren, entry, true) == CMfailed) { CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in %s [%s]\n",entry, name, NFobjTypeName (parent->Type), parent->Name); goto Skip; } break; case NFnumInitial: CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in %s [%s]\n",entry, name, NFobjTypeName (parent->Type), parent->Name); goto Skip; case NFnumParameter: CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in %s [%s]\n",entry, name, NFobjTypeName (parent->Type), parent->Name); goto Skip; case NFnumVariable: CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in %s [%s]\n",entry, name, NFobjTypeName (parent->Type), parent->Name); goto Skip; case NFmodDerivative: CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in %s [%s]\n",entry, name, NFobjTypeName (parent->Type), parent->Name); goto Skip; case NFmodEquation: if (CMoptLookup (moduleChildren, entry, true) == CMfailed) { CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in %s [%s]\n",entry, name, NFobjTypeName (parent->Type), parent->Name); goto Skip; } break; case NFmodInterface: CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in %s [%s]\n",entry, name, NFobjTypeName (parent->Type), parent->Name); goto Skip; case NFmodProcess: if (CMoptLookup (moduleChildren, entry, true) == CMfailed) { CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in %s [%s]\n",entry, name, NFobjTypeName (parent->Type), parent->Name); goto Skip; } break; case NFmodRoute: CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in %s [%s]\n",entry, name, NFobjTypeName (parent->Type), parent->Name); goto Skip; case NFobjAlias: CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in %s [%s]\n",entry, name, NFobjTypeName (parent->Type), parent->Name); goto Skip; case NFobjCategory: CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in %s [%s]\n",entry, name, NFobjTypeName (parent->Type), parent->Name); goto Skip; case NFobjOutput: if (CMoptLookup (ioChildren, entry, true) == CMfailed) { CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in %s [%s]\n",entry, name, NFobjTypeName (parent->Type), parent->Name); goto Skip; } break; case NFobjPlugin: CMmsgPrint (CMmsgWarning,"Skipping [%s] section [%s] in %s [%s]\n",entry, name, NFobjTypeName (parent->Type), parent->Name); goto Skip; } if (strcmp (entry, NFdimensionStr) == 0) { } else if (strcmp (entry, NFextentStr) == 0) { } else { switch (NFobjTypeCode (entry)) { case NFcompAggregate: object = NFparseCompAggregateCreate (parser,parent,name,attr); break; case NFcompContainer: object = NFparseCompContainerCreate (parser,parent,name,attr); break; case NFcompInput: object = NFparseCompInputCreate (parser,parent,name,attr); break; case NFcompModel: CMmsgPrint (CMmsgAppError, "This should never happen! %s:%d\n",__FILE__,__LINE__); goto Skip; case NFcompRegion: object = NFparseCompRegionCreate (parser,parent,name,attr); break; case NFnumInitial: object = NFparseNumVariableCreate (parser,parent,name,attr); break; case NFnumParameter: object = NFparseNumParameterCreate (parser,parent,name,attr); break; case NFnumVariable: object = NFparseNumVariableCreate (parser,parent,name,attr); break; case NFmodDerivative: object = NFparseModDerivativeCreate (parser,parent,name,attr); break; case NFmodEquation: object = NFparseModEquationCreate (parser,parent,name,attr); break; case NFmodInterface: object = NFparseModInterfaceCreate (parser,parent,name,attr); break; case NFmodProcess: object = NFparseModProcessCreate (parser,parent,name,attr); break; case NFmodRoute: object = NFparseModRouteCreate (parser,parent,name,attr); break; case NFobjAlias: object = NFparseObjAliasCreate (parser,parent,name,attr); break; case NFobjCategory: object = NFparseObjCategoryCreate (parser,parent,name,attr); break; case NFobjOutput: object = NFparseObjOutputCreate (parser,parent,name,attr); break; case NFobjPlugin: CMmsgPrint (CMmsgAppError, "This should never happen! %s:%d\n",__FILE__,__LINE__); goto Skip; } if (object == (NFobject_p) NULL) goto Abort; data->Objects [data->Stack] = object; } } data->Stack++; return; Abort: data->Abort = true; Skip: data->SkipName = CMstrDuplicate (entry); data->Skip = true; data->SkipLevel = 1; return; }