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); }