Example #1
0
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);
}
Example #2
0
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);
}
Example #3
0
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);
}
Example #4
0
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);
}
Example #5
0
/****************************************************************************************************************
 * 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;
}
Example #6
0
NFio_p Open_NCgrid(const char *url, NFtime_p beginTime, NFtime_p endTime, ut_system *utSystem) {
    int status, ncid;
    size_t i;
    const char *urlAddress;
    NCurlType urlType;
    NFio_p io = (NFio_p) NULL;
    NFtime_p timePtr = (NFtime_p) NULL;
    NFtime_p bundleTime = (NFtime_p) NULL;
    NFtimeUnit bundleTimeUnit;
    NFtimeStep_p bundleTimeStep = (NFtimeStep_p) NULL;
    NCgrid_p ncGrid = (NCgrid_p) NULL;
    ut_unit *baseTimeUnit = (ut_unit *) NULL;
    cv_converter *cvConverter = (cv_converter *) NULL;

    if ((baseTimeUnit = ut_parse(utSystem, "seconds since 2001-01-01 00:00:00", UT_ASCII)) == (ut_unit *) NULL) {
        CMmsgPrint(CMmsgAppError, "Total metal gebasz in %s:%d!\n", __FILE__, __LINE__);
        switch (ut_get_status()) {
            case UT_BAD_ARG:
                CMmsgPrint(CMmsgAppError, "System or string is NULL!\n");
                break;
            case UT_SYNTAX:
                CMmsgPrint(CMmsgAppError, "String contained a syntax error!n");
                break;
            case UT_UNKNOWN:
                CMmsgPrint(CMmsgAppError, "String contained an unknown identifier!\n");
                break;
            default:
                CMmsgPrint(CMmsgSysError, "System error in %s:%d!n", __FILE__, __LINE__);
        }
        goto Abort;
    }
    if ((bundleTime = NFtimeCreate()) == (NFtime_p) NULL) {
        CMmsgPrint(CMmsgAppError, "Time object creation error in %s:%d!\n", __FILE__, __LINE__);
        goto Abort;
    }
    if ((bundleTimeStep = NFtimeStepCreate()) == (NFtimeStep_p) NULL) {
        CMmsgPrint(CMmsgAppError, "Timestep object creation error in %s:%d!\n", __FILE__, __LINE__);
        goto Abort;

    }
    bundleTimeUnit = NCurlGetBundleTimeUnit(url);
    if (((urlType = NCurlGetType(url)) == NCurlInvalid) ||
        ((urlAddress = NCurlGetAddress(url)) == (const char *) NULL)) {
        CMmsgPrint(CMmsgAppError, "Ivalid URL: %s!\n", url);
        goto Abort;
    }
    if ((io = NFioCreate()) == (NFio_p) NULL) {
        CMmsgPrint(CMmsgAppError, "Layout creation error in: %s:%d\n", __FILE__, __LINE__);
        goto Abort;
    }
    if ((ncGrid = _NCgridCreate()) == (NCgrid_p) NULL) {
        CMmsgPrint(CMmsgSysError, "Plugin data allocation error in: %s:%d\n", __FILE__, __LINE__);
        goto Abort;
    }
    ncGrid->FileNames[0] = CMstrDuplicate(urlAddress);
    if (bundleTimeUnit != NFtimeUnitUnset) {
        ncGrid->FileNames[0] = NCcompleteURLaddress(urlAddress, ncGrid->FileNames[0], bundleTimeUnit, beginTime);
        NFtimeStepSet(bundleTimeStep, bundleTimeUnit, 1); // TODO handle return value
    }

    if ((status = nc_open(ncGrid->FileNames[0], NC_NOWRITE, &(ncGrid->NCid))) != NC_NOERR) {
        CMmsgPrint(CMmsgAppError, "NetCDF (%s) Openining error \"%s\"!\n", ncGrid->FileNames[0], nc_strerror(status));
        goto Abort;
    }
    ncGrid->Open = 0;
    if (!NCaxisInitialize(ncGrid->NCid, ncGrid->X[0], NCaxisX, utSystem)) goto Abort;
    if (!NCaxisInitialize(ncGrid->NCid, ncGrid->Y[0], NCaxisY, utSystem)) goto Abort;
    if (!NCaxisInitialize(ncGrid->NCid, ncGrid->Z[0], NCaxisZ, utSystem)) goto Abort;
    if (!NCaxisInitialize(ncGrid->NCid, ncGrid->Time[0], NCaxisTime, utSystem)) goto Abort;

    io->ItemNum = ncGrid->X[0]->N * ncGrid->Y[0]->N * ncGrid->Z[0]->N;
    io->ItemBoxMin.X = ncGrid->X[0]->IntervalMin;
    io->ItemBoxMin.Y = ncGrid->Y[0]->IntervalMin;
    io->ItemBoxMax.X = ncGrid->X[0]->IntervalMax;
    io->ItemBoxMax.Y = ncGrid->Y[0]->IntervalMax;
    io->Extent.LowerLeft.X = ncGrid->X[0]->Bounds[ncGrid->X[0]->N * 2 - 1] - ncGrid->X[0]->Bounds[0];
    io->Extent.LowerLeft.Y = ncGrid->Y[0]->Bounds[ncGrid->Y[0]->N * 2 - 1] - ncGrid->Y[0]->Bounds[0];

    if ((cvConverter = ut_get_converter(ncGrid->Time[0]->Unit, baseTimeUnit)) == (cv_converter *) NULL) {
        CMmsgPrint(CMmsgAppError, "Time converter error!n");
        switch (ut_get_status()) {
            case UT_BAD_ARG:
                CMmsgPrint(CMmsgAppError, "unit1 or unit2 is NULL.\n");
                break;
            case UT_NOT_SAME_SYSTEM:
                CMmsgPrint(CMmsgAppError, "unit1 and unit2 belong to different unit-systems.");
                break;
            default:
                CMmsgPrint(CMmsgAppError, "Conversion between the units is not possible.");
                break;
        }
    }
    io->TimeLine = NCtimeLineExpand(ncGrid->Time[0], beginTime, endTime, cvConverter, io->TimeLine);
    if (io->TimeLine == (NFtimeLine_p) NULL) {
        CMmsgPrint(CMmsgAppError, "Timeline expansion error in %s:%d!\n", __FILE__, __LINE__);
        goto Abort;
    }
    cv_free(cvConverter);
    if ((ncGrid->TimeBundleIDs = (size_t *) realloc(ncGrid->TimeBundleIDs,
                                                    io->TimeLine->TimeStepNum * sizeof(size_t))) == (size_t *) NULL) {
        CMmsgPrint(CMmsgSysError, "Memory allocation error in %s:%d!\n", __FILE__, __LINE__);
        goto Abort;
    }
    for (i = 0; i < io->TimeLine->TimeStepNum; ++i) ncGrid->TimeBundleIDs[i] = 0;
    if (bundleTimeUnit != NFtimeUnitUnset) {
        NFtimeCopy(beginTime, bundleTime); // TODO handle return value
        if ((ncGrid = _NCgridRealloc(ncGrid)) == (NCgrid_p) NULL) goto Abort;

        for (NFtimeAdvance(bundleTime, bundleTimeStep);
             NFtimeCompare(bundleTime, endTime) < 0; NFtimeAdvance(bundleTime, bundleTimeStep)) {

            ncGrid->FileNames[ncGrid->FileNum - 1] = NCcompleteURLaddress(urlAddress, CMstrDuplicate(urlAddress),
                                                                          bundleTimeUnit, bundleTime);
            if ((status = nc_open(ncGrid->FileNames[ncGrid->FileNum - 1], NC_NOWRITE, &ncid)) != NC_NOERR) {
                CMmsgPrint(CMmsgAppError, "NetCDF (%s) Openining error \"%s\"!\n",
                           ncGrid->FileNames[ncGrid->FileNum - 1], nc_strerror(status));
                goto Abort;
            }
            if (!NCaxisInitialize(ncid, ncGrid->X[ncGrid->FileNum - 1], NCaxisX, utSystem)) goto Abort;
            if (!NCaxisInitialize(ncid, ncGrid->Y[ncGrid->FileNum - 1], NCaxisY, utSystem)) goto Abort;
            if (!NCaxisInitialize(ncid, ncGrid->Z[ncGrid->FileNum - 1], NCaxisZ, utSystem)) goto Abort;
            if (!NCaxisInitialize(ncid, ncGrid->Time[ncGrid->FileNum - 1], NCaxisTime, utSystem)) goto Abort;
            nc_close(ncid);
            if ((ncGrid->X[0]->N != ncGrid->X[ncGrid->FileNum - 1]->N) ||
                (ncGrid->Y[0]->N != ncGrid->Y[ncGrid->FileNum - 1]->N) ||
                (ncGrid->Z[0]->N != ncGrid->Z[ncGrid->FileNum - 1]->N) ||
                (ncGrid->Time[0]->N != ncGrid->Time[ncGrid->FileNum - 1]->N)) {
                CMmsgPrint(CMmsgUsrError, "Inconsisten NetCDF [%s] bundle!\n", urlAddress);
                goto Abort;
            }
            if ((cvConverter = ut_get_converter(ncGrid->Time[ncGrid->FileNum - 1]->Unit, baseTimeUnit)) ==
                (cv_converter *) NULL) {
                CMmsgPrint(CMmsgAppError, "Time converter error!n");
                switch (ut_get_status()) {
                    case UT_BAD_ARG:
                        CMmsgPrint(CMmsgAppError, "unit1 or unit2 is NULL.\n");
                        break;
                    case UT_NOT_SAME_SYSTEM:
                        CMmsgPrint(CMmsgAppError, "unit1 and unit2 belong to different unit-systems.");
                        break;
                    default:
                        CMmsgPrint(CMmsgAppError, "Conversion between the units is not possible.");
                        break;
                }
            }
            io->TimeLine = NCtimeLineExpand(ncGrid->Time[ncGrid->FileNum - 1], beginTime, endTime, cvConverter,
                                            io->TimeLine);
            if (io->TimeLine == (NFtimeLine_p) NULL) {
                CMmsgPrint(CMmsgAppError, "Timeline expansion error in %s:%d!\n", __FILE__, __LINE__);
                goto Abort;
            }
            cv_free(cvConverter);
            if ((ncGrid->TimeBundleIDs = (size_t *) realloc(ncGrid->TimeBundleIDs,
                                                            io->TimeLine->TimeStepNum * sizeof(size_t))) ==
                (size_t *) NULL) {
                CMmsgPrint(CMmsgSysError, "Memory allocation error in %s:%d!\n", __FILE__, __LINE__);
                goto Abort;
            }
            for (; i < io->TimeLine->TimeStepNum; ++i) ncGrid->TimeBundleIDs[i] = ncGrid->FileNum - 1;
        }
    }
    io->PluginData = (void *) ncGrid;
    io->GetItem = _NCgridGetItem;
    io->GetItemList = _NCgridGetItemList;
    io->GetVertexes = _NCgridGetVertexes;
    io->ProjectXY2UV = NFioDefaultProjectXY2UV; // TODO Handle proj4 entries
    io->Close = _NCgridClose;
    io->VarHandleFunc = _NCgridVariableHandle;
    io->VarTypeFunc = _NCgridVariableType;
    io->VarLoadFunc = _NCgridVariableLoad;
    NFtimeFree(timePtr);
    NFtimeFree(bundleTime);
    NFtimeStepFree(bundleTimeStep);
    ut_free(baseTimeUnit);
    return (io);
    Abort:
    nc_close(ncGrid->NCid);
    if (ncGrid != (NCgrid_p) NULL) _NCgridFree(ncGrid);
    if (io != (NFio_p) NULL) NFioFree(io);
    if (timePtr != (NFtime_p) NULL) NFtimeFree(timePtr);
    if (bundleTime != (NFtime_p) NULL) NFtimeFree(bundleTime);
    if (bundleTimeStep != (NFtimeStep_p) NULL) NFtimeStepFree(bundleTimeStep);
    if (baseTimeUnit != (ut_unit *) NULL) ut_free(baseTimeUnit);
    return ((NFio_p) NULL);
}
Example #7
0
/****************************************************************************************************************
 * Object
*****************************************************************************************************************/
NFobject_p NFobjectCreate(const char *name, NFobjType objType) {
    CMreturn ret;
    size_t size;
    NFobject_p object;

    if ((size = _NFobjectSize(objType)) == CMfailed) {
        CMmsgPrint(CMmsgAppError, "Invalid object in: %s:%d\n", __FILE__, __LINE__);
        return ((NFobject_p) NULL);
    }
    if ((object = (NFobject_p) malloc(size)) == (NFobject_p) NULL) {
        CMmsgPrint(CMmsgSysError, "Memory allocation in %s:%d\n", __FILE__, __LINE__);
        return ((NFobject_p) NULL);
    }
    if ((object->Name = CMstrDuplicate(name)) == (char *) NULL) {
        CMmsgPrint(CMmsgAppError, "Name string duplication error in %s:%d\n", __FILE__, __LINE__);
        free(object);
        return ((NFobject_p) NULL);
    }
    object->Type = objType;
    object->Notes = (char *) NULL;

    switch (objType) {
        case NFcompAggregate:
            ret = _NFcompAggregateInit(object);
            break;
        case NFcompContainer:
            ret = _NFcompContainerInit(object);
            break;
        case NFcompInput:
            ret = _NFcompInputInit(object);
            break;
        case NFcompModel:
            ret = _NFcompModelInit(object);
            break;
        case NFcompRegion:
            ret = _NFcompRegionInit(object);
            break;
        case NFmodDerivative:
            ret = _NFmodDerivativeInit(object);
            break;
        case NFmodEquation:
            ret = _NFmodEquationInit(object);
            break;
        case NFmodInterface:
            ret = _NFmodInterfaceInit(object);
            break;
        case NFmodProcess:
            ret = _NFmodProcessInit(object);
            break;
        case NFmodRoute:
            ret = _NFmodRouteInit(object);
            break;
        case NFnumInitial:
            ret = _NFnumVariableInit(object);
            break;
        case NFnumParameter:
            ret = _NFnumParameterInit(object);
            break;
        case NFnumVariable:
            ret = _NFnumVariableInit(object);
            break;
        case NFobjAlias:
            ret = _NFobjAliasInit(object);
            break;
        case NFobjCategory:
            ret = _NFobjCategoryInit(object);
            break;
        case NFobjOutput:
            ret = _NFobjOutputInit(object);
            break;
        case NFobjPlugin:
            ret = _NFobjPluginInit(object);
            break;
    }
    if (ret != CMsucceeded) {
        free(object->Name);
        return ((NFobject_p) NULL);
    }
    else
        return (object);
}