Example #1
0
int MDRainSMoistChgDef () {
	int ret = 0;
	float par;
	const char *optStr;
	if (_MDOutSMoistChgID != MFUnset) return (_MDOutSMoistChgID);
	const char *soilTemperatureOptions [] = { "none", "calculate", (char *) NULL };

	int soilTemperatureID;
	if (((optStr = MFOptionGet (MDOptSoilTemperature))  == (char *) NULL) ||
	    ((soilTemperatureID = CMoptLookup (soilTemperatureOptions, optStr, true)) == CMfailed)) {
		CMmsgPrint(CMmsgUsrError," Soil TemperatureOption not specifed! Options = 'none' or 'calculate'\n");
		return CMfailed;
	}
	if (((optStr = MFOptionGet (MDParSoilMoistALPHA))  != (char *) NULL) && (sscanf (optStr,"%f",&par) == 1)) _MDSoilMoistALPHA = par;
	
	MFDefEntering ("Rainfed Soil Moisture");
	if (soilTemperatureID == MFcalculate ) {
		if (((ret                        = MDPermafrostDef()) == CMfailed) ||
		    ((_MDInRelativeIceContent    = MFVarGetID ("SoilIceContent_01",     "mm",   MFOutput,  MFState, MFBoundary)) == CMfailed) ||
			((_MDOutLiquidSoilMoistureID = MFVarGetID (MDVarLiquidSoilMoisture, "-",    MFOutput,  MFState, MFBoundary)) == CMfailed)) return CMfailed;
	}

	if ((ret = MDIrrGrossDemandDef ()) == CMfailed) return (CMfailed);
	if ((ret != MFUnset) && ((_MDInIrrAreaFracID = MDIrrigatedAreaDef ())==  CMfailed) ) return (CMfailed);

	if (((_MDInPrecipID            = MDPrecipitationDef     ()) == CMfailed) ||
	    ((_MDInSPackChgID          = MDSPackChgDef          ()) == CMfailed) ||
	    ((_MDInPotETID             = MDRainPotETDef         ()) == CMfailed) ||
	    ((_MDInInterceptID         = MDRainInterceptDef     ()) == CMfailed) ||
	    ((_MDInSoilAvailWaterCapID = MDSoilAvailWaterCapDef ()) == CMfailed) ||
	    ((_MDInAirTMeanID          = MFVarGetID (MDVarAirTemperature,             "degC", MFInput,  MFState, MFBoundary)) == CMfailed) ||
 	    ((_MDOutEvaptrsID          = MFVarGetID (MDVarRainEvapotranspiration,     "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
 	  	((_MDOutSoilMoistCellID    = MFVarGetID (MDVarRainSoilMoistureCell,       "mm",   MFOutput, MFState, MFInitial))  == CMfailed) ||
	    ((_MDOutSoilMoistID        = MFVarGetID (MDVarRainSoilMoisture,           "mm",   MFOutput, MFState, MFBoundary)) == CMfailed) ||
        ((_MDOutSMoistChgID        = MFVarGetID (MDVarRainSoilMoistChange,        "mm",   MFOutput, MFState, MFBoundary)) == CMfailed) ||
        (MFModelAddFunction (_MDRainSMoistChg) == CMfailed)) return (CMfailed);
	MFDefLeaving ("Rainfed Soil Moisture");
	return (_MDOutSMoistChgID);
}
Example #2
0
int MDCParamCDDef () {
	int optID = MFUnset;
	const char *optStr, *optName = MDVarCParamCD;
	const char *options [] = { MDInputStr, MDLookupStr, (char *) NULL };

	if (_MDOutCParamCDID != MFUnset) return (_MDOutCParamCDID);

	MFDefEntering ("CD");
	if ((optStr = MFOptionGet (optName)) != (char *) NULL) optID = CMoptLookup (options,optStr,true);

	switch (optID) {
		case MDinput:  _MDOutCParamCDID = MFVarGetID (MDVarCParamCD,  "kPa", MFInput, MFState, MFBoundary); break;
		case MDlookup:
			if (((_MDInCoverID = MDLandCoverDef ()) == CMfailed) ||
	    		 ((_MDOutCParamCDID = MFVarGetID (MDVarCParamCD, "kPa", MFOutput, MFState, MFBoundary)) == CMfailed) ||
	    		 (MFModelAddFunction (_MDCParamCD) == CMfailed)) return (CMfailed);
			break;
		default: MFOptionMessage (optName, optStr, options); return (CMfailed);
	}
	MFDefLeaving ("CD");
	return (_MDOutCParamCDID); 
}
Example #3
0
int MDReservoirDef () {
	int optID = MFUnset;
	const char *optStr, *optName = MDOptReservoirs;
	const char *options [] = { MDNoneStr, MDCalculateStr, "neuralnet", (char *) NULL };
 
	if ((optStr = MFOptionGet (optName)) != (char *) NULL) optID = CMoptLookup (options, optStr, true);
 
	if ((optID == MDnone) || (_MDOutResReleaseID != MFUnset)) return (_MDOutResReleaseID);

	MFDefEntering ("Reservoirs");
	switch (optID) {
		case MDcalculate:
			if (((_MDInDischMeanID      = MDDischMeanDef ())   == CMfailed) ||
			    ((_MDInDischargeID      = MDDischLevel2Def ()) == CMfailed) ||
			    ((_MDInResCapacityID    = MFVarGetID (MDVarReservoirCapacity,      "km3",  MFInput,  MFState, MFBoundary)) == CMfailed) ||
			    ((_MDOutResStorageID    = MFVarGetID (MDVarReservoirStorage,       "km3",  MFOutput, MFState, MFInitial))  == CMfailed) ||
			    ((_MDOutResStorageChgID = MFVarGetID (MDVarReservoirStorageChange, "km3",  MFOutput, MFState, MFBoundary)) == CMfailed) ||		//RJS, changed MFBoundary o MFIniial
			    ((_MDOutResReleaseID    = MFVarGetID (MDVarReservoirRelease,       "m3/s", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
			    (MFModelAddFunction (_MDReservoirDW) == CMfailed)) return (CMfailed);
			break;
        case MDneuralnet:
			if (((_MDInDischargeID      = MDDischLevel2Def ()) == CMfailed) ||
			    ((_MDInResCapacityID    = MFVarGetID (MDVarReservoirCapacity,      "m3",  MFInput,  MFState, MFBoundary)) == CMfailed) ||
			    ((_MDInDischMinID    = MFVarGetID (MDVarDischargeMin,      "m3/s",  MFInput,  MFState, MFBoundary)) == CMfailed) ||
			    ((_MDInDischMaxID    = MFVarGetID (MDVarDischargeMax,      "m3/s",  MFInput,  MFState, MFBoundary)) == CMfailed) ||
                ((_MDOutDisch_t_1_ID     = MFVarGetID(MDVarDischarge_t_1,      "m3/s",  MFOutput, MFState, MFInitial)) == CMfailed) ||
                ((_MDOutDisch_t_2_ID     = MFVarGetID(MDVarDischarge_t_2,      "m3/s",  MFOutput, MFState, MFInitial)) == CMfailed) ||
			    ((_MDOutResStorageID    = MFVarGetID (MDVarReservoirStorage,       "m3",  MFOutput, MFState, MFInitial))  == CMfailed) ||
			    ((_MDOutResStorageChgID = MFVarGetID (MDVarReservoirStorageChange, "m3",  MFOutput, MFState, MFBoundary)) == CMfailed) ||		//RJS, changed MFBoundary o MFIniial
			    ((_MDOutResReleaseID    = MFVarGetID (MDVarReservoirRelease,       "m3/s", MFOutput, MFFlux,  MFInitial)) == CMfailed) ||
			    ((_MDOutResRelease_t_1_ID    = MFVarGetID (MDVarReservoirRelease_t_1, "m3/s", MFOutput, MFFlux,  MFInitial)) == CMfailed) ||
			    (MFModelAddFunction (_MDReservoirNeuralNet) == CMfailed)) return (CMfailed);
			break;
		default: MFOptionMessage (optName, optStr, options); return (CMfailed);
	}
	MFDefLeaving ("Reservoirs");
	return (_MDOutResReleaseID); 
}
Example #4
0
int MDWaterBalanceDef() {
 
	MFDefEntering ("WaterBalance");
	if ((                                  MDAccumBalanceDef     ()  == CMfailed) ||
	    ((_MDInPrecipID                  = MDPrecipitationDef    ()) == CMfailed) ||
	    ((_MDInDischargeID               = MDDischargeDef        ()) == CMfailed) ||
	 
	    ((_MDInSnowPackChgID             = MDSPackChgDef         ()) == CMfailed) ||
	    ((_MDInSoilMoistChgID            = MDSoilMoistChgDef     ()) == CMfailed) ||
	    ((_MDInRunoffID                  = MDRunoffDef           ()) == CMfailed) ||
	    ((_MDInEvaptrsID                 = MFVarGetID (MDVarEvapotranspiration,      "mm",   MFInput,  MFFlux,  MFBoundary)) == CMfailed) ||
	    ((_MDInGrdWatChgID               = MFVarGetID (MDVarGroundWaterChange,       "mm",   MFInput,  MFFlux,  MFBoundary)) == CMfailed) ||
	    ((_MDInRunoffPoolChgID           = MFVarGetID (MDVarRunoffPoolChg,           "mm",   MFInput,  MFFlux,  MFBoundary)) == CMfailed) ||
	    ((_MDOutWaterBalanceID           = MFVarGetID (MDVarWaterBalance,            "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
	    (MFModelAddFunction(_MDWaterBalance) == CMfailed))
	    return (CMfailed);
	if ((_MDInIrrGrossDemandID           = MDIrrGrossDemandDef    ()) != MFUnset) {
		if ((_MDInIrrGrossDemandID == CMfailed) ||
	        ((_MDInIrrUptakeRiverID      = MDIrrUptakeRiverDef    ()) == CMfailed) ||
	        ((_MDInIrrUptakeGrdWaterID   = MDIrrUptakeGrdWaterDef ()) == CMfailed) ||
	        ((_MDInIrrSoilMoistChgID     = MDIrrSoilMoistChgDef   ()) == CMfailed) ||
	        ((_MDInIrrAreaFracID         = MDIrrigatedAreaDef    ())==  CMfailed) ||
	        ((_MDInIrrEvapotranspID      = MFVarGetID (MDVarIrrEvapotranspiration, "mm",   MFInput,  MFFlux,  MFBoundary)) == CMfailed) ||
	        ((_MDInIrrReturnFlowID       = MFVarGetID (MDVarIrrReturnFlow,         "mm",   MFInput,  MFFlux,  MFBoundary)) == CMfailed) || 
	        ((_MDInIrrUptakeExcessID     = MFVarGetID (MDVarIrrUptakeExcess,       "mm",   MFInput,  MFFlux,  MFBoundary)) == CMfailed) ||
		    ((_MDOutIrrUptakeBalanceID   = MFVarGetID (MDVarIrrUptakeBalance,      "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
		    ((_MDOutIrrWaterBalanceID    = MFVarGetID (MDVarIrrWaterBalance,       "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed))
	    	return (CMfailed);		
		if ((_MDInSmallResReleaseID        = MDSmallReservoirReleaseDef ()) != MFUnset) {
			if (( _MDInSmallResReleaseID == CMfailed) ||
			    ((_MDInSmallResEvapoID      = MFVarGetID (MDVarSmallResEvaporation,   "mm", MFInput, MFFlux,  MFBoundary)) == CMfailed) ||
			    ((_MDInSmallResStorageChgID = MFVarGetID (MDVarSmallResStorageChange, "mm", MFInput, MFState, MFInitial))  == CMfailed))
			    return (CMfailed);
		}
	}
	MFDefLeaving ("WaterBalance");
	return (_MDOutWaterBalanceID);	
}
Example #5
0
int MDRunoffVolumeDef () {
	int optID = MFUnset;
	const char *optStr, *optName = MDVarRunoffVolume;
	const char *options [] = { MDInputStr, MDCalculateStr, (char *) NULL };

	if (_MDOutRunoffVolumeID != MFUnset) return (_MDOutRunoffVolumeID);

	MFDefEntering ("Runoff Volume");
	if ((optStr = MFOptionGet (optName)) != (char *) NULL) optID = CMoptLookup (options, optStr, true);
	switch (optID) {
		case MDinput:
			_MDOutRunoffVolumeID = MFVarGetID (MDVarRunoffVolume, "m3/s", MFInput, MFState, MFBoundary);
			break;
		case MDcalculate:
			if (((_MDInRunoffID        = MDRunoffDef ()) == CMfailed) ||
			    ((_MDOutRunoffVolumeID = MFVarGetID (MDVarRunoffVolume, "m3/s", MFOutput, MFState, MFBoundary)) == CMfailed) ||
			    (MFModelAddFunction (_MDRunoffVolume) == CMfailed)) return (CMfailed);
			break;
		default: MFOptionMessage (optName, optStr, options); return (CMfailed);
	}
	MFDefLeaving  ("Runoff Volume");
	return (_MDOutRunoffVolumeID);
}
Example #6
0
int MDDischMeanDef () {
	int  optID = MFUnset;
	const char *optStr, *optName = MDVarDischMean;
	const char *options [] = { MDInputStr, MDCalculateStr, (char *) NULL };

	if (_MDOutDischMeanID != MFUnset) return (_MDOutDischMeanID);
	MFDefEntering ("Discharge Mean");

	if ((optStr = MFOptionGet (optName)) != (char *) NULL) optID = CMoptLookup (options, optStr, true);

	switch (optID) {
		case MDinput: _MDOutDischMeanID  = MFVarGetID (MDVarDischMean, "m3/s", MFInput,  MFState, MFBoundary); break;
		case MDcalculate:
			if (((_MDInAvgNStepsID       = MDAvgNStepsDef ())   == CMfailed) ||
			    ((_MDInAccumDischargeID  = MDAccumRunoffDef ()) == CMfailed) ||
			    ((_MDOutDischMeanID      = MFVarGetID (MDVarDischMean, "m3/s", MFOutput, MFState, MFInitial))  == CMfailed) ||
			    (MFModelAddFunction (_MDDischMean) == CMfailed)) return (CMfailed);
			break;
		default: MFOptionMessage (optName, optStr, options); return (CMfailed);
	}
	MFDefLeaving ("Discharge Mean");
	return (_MDOutDischMeanID);
}
Example #7
0
int MDSurfRunoffDef () {
    int ret;
    if (_MDOutSurfRunoffID != MFUnset) return (_MDOutSurfRunoffID);

    MFDefEntering ("Surface runoff");

    if (((ret = MDWetlandRunoffDef ()) != MFUnset) &&
            ((ret == CMfailed) ||
             ((_MDInWetlandUptakeID = MFVarGetID (MDVarWetlandSurfROUptake, "mm",   MFInput,  MFFlux, MFBoundary)) == CMfailed)))
        return (CMfailed);


    if (((ret = MDSmallReservoirReleaseDef ()) != MFUnset) &&
            ((ret == CMfailed) ||
             ((_MDInSmallResUptakeID = MFVarGetID (MDVarSmallResUptake, "mm",   MFInput,  MFFlux, MFBoundary)) == CMfailed)))
        return (CMfailed);

    if (((_MDInRainSurfRunoffID  = MDRainSurfRunoffDef ()) == CMfailed) ||
            ((_MDOutSurfRunoffID     = MFVarGetID (MDVarSurfRunoff,     "mm",   MFOutput, MFFlux,  MFBoundary))  == CMfailed) ||
            (MFModelAddFunction (_MDSurfRunoff) == CMfailed)) return (CMfailed);
    MFDefLeaving ("Surface runoff");
    return (_MDOutSurfRunoffID);
}
Example #8
0
int MDSmallReservoirReleaseDef () {

	if (_MDOutSmallResReleaseID != MFUnset) return (_MDOutSmallResReleaseID);

	if ((_MDInIrrGrossDemandID   = MDIrrGrossDemandDef         ()) == CMfailed) return (CMfailed);
	if  (_MDInIrrGrossDemandID   == MFUnset) return (MFUnset);
	if ((_MDInSmallResCapacityID = MDSmallReservoirCapacityDef ()) == CMfailed) return (CMfailed);
	if  (_MDInSmallResCapacityID == MFUnset) return (MFUnset);

	MFDefEntering("Small Reservoirs");
    if (((_MDInRainSurfRunoffID      = MDRainSurfRunoffDef   ()) == CMfailed) ||
    	((_MDInIrrAreaFracID         = MDIrrigatedAreaDef    ()) == CMfailed) ||
        ((_MDInPotEvapotransID       = MDIrrRefEvapotransDef ()) == CMfailed) ||
        ((_MDInSmallResStorageFracID = MFVarGetID (MDVarSmallReservoirStorageFrac, "-",  MFInput,  MFState, MFBoundary)) == CMfailed) ||
    	((_MDOutSmallResUptakeID     = MFVarGetID (MDVarSmallResUptake,            "mm", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
        ((_MDOutSmallResReleaseID    = MFVarGetID (MDVarSmallResRelease,           "mm", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
        ((_MDOutSmallResStorageID    = MFVarGetID (MDVarSmallResStorage,           "mm", MFOutput, MFState, MFInitial))  == CMfailed) ||
        ((_MDOutSmallResStorageID    = MFVarGetID (MDVarSmallResStorage,           "mm", MFOutput, MFState, MFInitial))  == CMfailed) ||
        ((_MDOutSmallResEvapoID      = MFVarGetID (MDVarSmallResEvaporation,       "mm", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
        ((_MDOutSmallResStorageChgID = MFVarGetID (MDVarSmallResStorageChange,     "mm", MFOutput, MFState, MFBoundary)) == CMfailed) ||
        ((MFModelAddFunction (_MDSmallReservoirRelease) == CMfailed))) return (CMfailed);
	MFDefLeaving("Small Reservoirs");
	return (_MDOutSmallResReleaseID);
}
int MDWTempSurfRunoffPoolDef () {
	int  optID = MDnone;	// was MFUnset
	const char *optStr, *optName = MDOptSurfRunoffPool;
	const char *options [] = { MDNoneStr, MDCalculateStr, MDInputStr, (char *) NULL };											// RJS 061312 added MDInputStr

	if ((optStr = MFOptionGet (optName)) != (char *) NULL) optID = CMoptLookup (options, optStr, true);

	MFDefEntering ("Surface Runoff Pool Temperature");

	switch (optID) {

	case MDcalculate:

	if (((_MDInWTempSurfRunoffID       = MDWTempSurfRunoffDef ()) == CMfailed) ||
		((_MDInRainSurfRunoffID        = MDRainSurfRunoffDef  ()) == CMfailed) ||
		((_MDInRunoffPoolID            = MFVarGetID (MDVarRunoffPool,            "mm", MFInput,  MFState, MFBoundary))  == CMfailed) ||
//		((_MDInRainSurfRunoffID        = MFVarGetID (MDVarRainSurfRunoff,        "mm", MFInput,   MFFlux, MFBoundary)) == CMfailed) ||
	    ((_MDOutWTempSurfRunoffPoolID  = MFVarGetID (MDVarWTempSurfRunoffPool, "degC", MFOutput, MFState, MFInitial)) == CMfailed) ||
	    (MFModelAddFunction (_MDWTempSurfRunoffPool) == CMfailed)) return (CMfailed);
		break;

	case MDnone:

	if (((_MDInWTempSurfRunoffID       = MDWTempSurfRunoffDef ()) == CMfailed) ||
		((_MDOutWTempSurfRunoffPoolID  = MFVarGetID (MDVarWTempSurfRunoffPool, "degC", MFOutput, MFState, MFInitial)) == CMfailed) ||
		(MFModelAddFunction (_MDWTempNoSurfRunoffPool) == CMfailed)) return (CMfailed);
		break;

	case MDinput:	_MDOutWTempSurfRunoffPoolID = MFVarGetID (MDVarWTempSurfRunoffPool, "degC", MFInput,  MFState, MFBoundary); break;		// RJS 061312	MFInitial changed to MFBoundary in order to read in																														// RJS 061312

	default: MFOptionMessage (optName, optStr, options); return (CMfailed);
	}

	MFDefLeaving ("Surface Runoff Pool Temperature");
	return (_MDOutWTempSurfRunoffPoolID);
}
Example #10
0
int MDSoilAvailWaterCapDef () {
	int  optID = MFUnset;
	const char *optStr, *optName = MDOptSoilAvailableWaterCapacity;
	const char *options [] = { MDInputStr, MDCalculateStr,  (char *) NULL };
	
	if (_MDOutSoilAvailWaterCapID != MFUnset) return (_MDOutSoilAvailWaterCapID);

	MFDefEntering ("Soil available water capacity");

	if ((optStr = MFOptionGet (optName)) != (char *) NULL) optID = CMoptLookup (options, optStr, true);
		switch (optID) {
		case MDinput: _MDOutSoilAvailWaterCapID = MFVarGetID (MDVarSoilAvailWaterCap,         "mm",     MFInput,  MFState, MFBoundary); break;
		case MDcalculate:
			if (((_MDInSoilFieldCapacityID  = MFVarGetID (MDVarSoilFieldCapacity, "mm/m", MFInput,  MFState, MFBoundary)) == CMfailed) ||
			    ((_MDInSoilWiltingPointID   = MFVarGetID (MDVarSoilWiltingPoint,  "mm/m", MFInput,  MFState, MFBoundary)) == CMfailed) ||
			    ((_MDInSoilRootingDepthID   = MFVarGetID (MDVarSoilRootingDepth,  "mm",   MFInput,  MFState, MFBoundary)) == CMfailed) ||
			    ((_MDOutSoilAvailWaterCapID = MFVarGetID (MDVarSoilAvailWaterCap, "mm",   MFOutput, MFState, MFBoundary)) == CMfailed) ||
			    (MFModelAddFunction (_MDSoilAvailWaterCap) == CMfailed)) return (CMfailed);
			break;
		default: MFOptionMessage (optName, optStr, options); return (CMfailed);
		}
	MFDefLeaving  ("Soil available water capacity");
	return (_MDOutSoilAvailWaterCapID);
}
Example #11
0
int MDSPackChgDef () {

	if (_MDOutSPackChgID != MFUnset) return (_MDOutSPackChgID);
	MFDefEntering ("Snow Pack Change");
	const char *optStr;
	const char *soilTemperatureOptions [] = { "none", "calculate", (char *) NULL };
	int soilTemperatureID;
	float par;
	if (((optStr = MFOptionGet (MDParSnowMeltThreshold))  != (char *) NULL) && (sscanf (optStr,"%f",&par) == 1))
		_MDSnowMeltThreshold = par;
	
	if (((optStr = MFOptionGet (MDParFallThreshold))  != (char *) NULL) && (sscanf (optStr,"%f",&par) == 1))
		_MDFallThreshold= par;

	if (((optStr = MFOptionGet (MDOptSoilTemperature))  == (char *) NULL) || ((soilTemperatureID = CMoptLookup (soilTemperatureOptions, optStr, true)) == CMfailed)) {
					CMmsgPrint(CMmsgUsrError," Soil TemperatureOption not specifed! Options = 'none' or 'calculate'\n");
					return CMfailed;
				}

	if (soilTemperatureID == 1 ){
		_MDCalculateSoilTempID=1;
		if ((_MDInWinterOnsetID    = MFVarGetID (MDVarWinterOnsetDoy, "DoY", MFInput,  MFState, MFBoundary)) == CMfailed) return CMfailed;
	}

	if (((_MDInPrecipID       = MDPrecipitationDef ()) == CMfailed) ||
	    ((_MDInAtMeanID       = MFVarGetID (MDVarAirTemperature, "degC", MFInput,  MFState, MFBoundary)) == CMfailed) ||
	    ((_MDOutSnowFallID    = MFVarGetID (MDVarSnowFall,       "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
	    ((_MDOutSnowMeltID    = MFVarGetID (MDVarSnowMelt,       "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
	    ((_MDOutSnowDensityID = MFVarGetID (MDVarSnowDensity,    "mm",   MFOutput, MFState, MFBoundary)) == CMfailed) ||
	    ((_MDOutSnowDepthID   = MFVarGetID (MDVarSnowDepth,      "mm",   MFOutput, MFState, MFBoundary)) == CMfailed) ||
	    ((_MDOutSnowPackID    = MFVarGetID (MDVarSnowPack,       "mm",   MFOutput, MFState, MFInitial))  == CMfailed) ||
	    ((_MDOutSPackChgID    = MFVarGetID (MDVarSnowPackChange, "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
	    (MFModelAddFunction (_MDSPackChg) == CMfailed)) return (CMfailed);
	MFDefLeaving ("Snow Pack Change");
	return (_MDOutSPackChgID);
}
Example #12
0
int MDDischargeDef() {
	int optID = MFUnset;
	const char *optStr, *optName = MDOptDischarge;
	const char *options [] = { MDInputStr, MDCalculateStr, "corrected", (char *) NULL };

	if (_MDOutDischargeID != MFUnset) return (_MDOutDischargeID);

	MFDefEntering ("Discharge");
	if ((optStr = MFOptionGet (optName)) != (char *) NULL) optID = CMoptLookup (options,optStr,true);
	switch (optID) {
		case MDinput: _MDOutDischargeID = MFVarGetID (MDVarDischarge,     "m3/s",  MFInput,  MFState, MFBoundary); break;
		case MDcorrected:
			if ((_MDInDischObservedID   = MFVarGetID (MDVarDischObserved, "m3/s",  MFInput,  MFState, MFBoundary)) == CMfailed)
				return (CMfailed);
		case MDcalculate:
			if (((_MDOutDischargeID     = MFVarGetID (MDVarDischarge,     "m3/s",  MFRoute,  MFState, MFBoundary)) == CMfailed) ||
				((_MDInDischLevel1ID    = MDDischLevel1Def ()) == CMfailed) ||
				(MFModelAddFunction (_MDDischarge) == CMfailed)) return (CMfailed);
			break;
		default: MFOptionMessage (optName, optStr, options); return (CMfailed);
	}
	MFDefLeaving  ("Discharge");
	return (_MDOutDischargeID);
}
Example #13
0
int MDRainSMoistChgLayeredSoilDef () {
	int ret = 0;
	float par;
	int i;
	char soilLiquidName [16];
	char soilSiltFractionName[22];
	char soilClayFractionName[22];
	char soilSandFractionName[22];
	char soilRelativeSoilMoistName[30];
		
	char soilIceName[20];
	char soilDepthName[20];
	const char *optStr;
	const char *soilTemperatureOptions [] = { "none", "calculate", (char *) NULL };

	if (_MDOutSMoistChgID != MFUnset) return (_MDOutSMoistChgID);


		if (((optStr = MFOptionGet (MDOptSoilTemperature))  == (char *) NULL) || ((soilTemperatureID = CMoptLookup (soilTemperatureOptions, optStr, true)) == CMfailed)) {
						CMmsgPrint(CMmsgUsrError," Soil TemperatureOption not specifed! Options = 'none' or 'calculate'\n");
						return CMfailed;
		}


		MFDefEntering ("Rainfed Layered Soil Moisture");
		if (soilTemperatureID ==1){
	//		printf ("SoilTemp is on before\n");
		
			if ((ret = MDPermafrostDef ()) == CMfailed) return (CMfailed);
			 
//			printf ("SoilTemp is on fater \n");
		//	 if ((_MDActiveLayerDepthID= MFVarGetID (MDVarActiveLayerDepth, "mm", MFOutput, MFState, MFBoundary))  == CMfailed) return CMfailed;	
			 if  ((_MDActiveLayerDepthID          = MFVarGetID (MDVarActiveLayerDepth,             "m", MFOutput,  MFState, MFBoundary)) == CMfailed)return CMfailed;
				 
		}
		
		
		
	if (((optStr = MFOptionGet (MDParSoilMoistALPHA))  != (char *) NULL) && (sscanf (optStr,"%f",&par) == 1)) _MDSoilMoistALPHA = par;
	if (((optStr = MFOptionGet ("SoilMoistureTimeSteps"))  != (char *) NULL) && (sscanf (optStr,"%f",&par) == 1)) _MDTimeSteps = par;
	if (((optStr = MFOptionGet ("SoilMoistureTimeSteps"))  != (char *) NULL) && (sscanf (optStr,"%f",&par) == 1)) _MDTimeSteps = par;

	if ((ret = MDIrrGrossDemandDef ()) == CMfailed) return (CMfailed);
	if ((ret != MFUnset)  &&
	  ((_MDInIrrAreaFracID         = MDIrrigatedAreaDef    ())==  CMfailed) )
		return (CMfailed);

		for (i = 0; i < _MDNumberOfSoilMoistureLayers; i++) {
			_MDInSoilDepthIDs = (int *) realloc (_MDInSoilDepthIDs, (i + 1) * sizeof (int));
			_MDOutSMLiquidIDs = (int *) realloc (_MDOutSMLiquidIDs, (i + 1) * sizeof (int));
			_MDOutSMIceDs	  = (int *) realloc (_MDOutSMIceDs,     (i + 1) * sizeof (int));
			_MDInSoilpctClayIDs  = (int *) realloc (_MDInSoilpctClayIDs,     (i + 1) * sizeof (int));
			_MDInSoilpctSandIDs  = (int *) realloc (_MDInSoilpctSandIDs,     (i + 1) * sizeof (int));
			_MDInSoilpctSiltIDs  = (int *) realloc (_MDInSoilpctSiltIDs,     (i + 1) * sizeof (int));
			_MDSoilRelativeSoilMoistIDs  = (int *) realloc (_MDSoilRelativeSoilMoistIDs,     (i + 1) * sizeof (int));
				
							
		//	printf ("Reading Layer  = %i of %i\n",i, _MDNumberOfSoilMoistureLayers);
			
			sprintf (soilDepthName,  "SoilDepth_%02d",  i + 1); //
			sprintf (soilLiquidName, "SoilLiquid_%02d", i + 1); //  
			sprintf (soilIceName, "SoilIce_%02d", i + 1); //  
			sprintf (soilSiltFractionName, "SoilSiltPercentage_%02d", i + 1); //  	
			sprintf (soilSandFractionName, "SoilSandPercentage_%02d", i + 1); //
			sprintf (soilClayFractionName, "SoilClayPercentage_%02d", i + 1); //
			sprintf (soilRelativeSoilMoistName, "SoilRelativeSoilMoisture_%02d", i + 1); //
			//printf ("SDepth = %s\n", soilLiquidName);
			//printf ("ID = %i\n",_MDInSoilDepthIDs [i]);
			
			if ((_MDInSoilDepthIDs [i] = MFVarGetID (soilDepthName, "mm", MFInput,  MFState, MFBoundary)) == CMfailed) {
				printf("CMfailed in MDInSoilInputDataID \n");
				CMmsgPrint (CMmsgUsrError, "CMfailed in MDInSoilDepth \n");
				return CMfailed;
			}
		 
			if ((_MDOutSMLiquidIDs [i] = MFVarGetID (soilLiquidName, "mm", MFOutput,  MFState, MFInitial)) == CMfailed) {
							printf("CMfailed in MDInSoilInputDataID \n");
							CMmsgPrint (CMmsgUsrError, "CMfailed in MDInSoilDepth \n");
							return CMfailed;
						}
			if ((_MDOutSMIceDs [i] = MFVarGetID (soilIceName, "mm", MFOutput,  MFState, MFInitial)) == CMfailed) {
							printf("CMfailed in MDInSoilInputDataID \n");
							CMmsgPrint (CMmsgUsrError, "CMfailed in MDInSoilDepth \n");
							return CMfailed;
						}
			
			if ((_MDInSoilpctSiltIDs [i] = MFVarGetID (soilSiltFractionName, "mm", MFInput,  MFState, MFBoundary)) == CMfailed) {
									printf("CMfailed in MDInSoilInputDataID \n");
									CMmsgPrint (CMmsgUsrError, "CMfailed in MDInSoilDepth \n");
									return CMfailed;
								}
			
			if ((_MDInSoilpctSandIDs [i] = MFVarGetID (soilSandFractionName, "mm", MFInput,  MFState, MFBoundary)) == CMfailed) {
											printf("CMfailed in MDInSoilInputDataID \n");
											CMmsgPrint (CMmsgUsrError, "CMfailed in MDInSoilDepth \n");
											return CMfailed;
										}
			
			
			if ((_MDInSoilpctClayIDs [i] = MFVarGetID (soilClayFractionName, "mm", MFInput,  MFState, MFBoundary)) == CMfailed) {
													printf("CMfailed in MDInSoilInputDataID \n");
													CMmsgPrint (CMmsgUsrError, "CMfailed in MDInSoilDepth \n");
													return CMfailed;
												}
			
			if ((_MDSoilRelativeSoilMoistIDs [i] = MFVarGetID (soilRelativeSoilMoistName, "mm", MFOutput,  MFState, MFBoundary)) == CMfailed) {
																printf("CMfailed in MDInSoilInputDataID \n");
																CMmsgPrint (CMmsgUsrError, "CMfailed in MDInSoilDepth \n");
																return CMfailed;
															}
		
			
			
			 
		}
		
		
			
	
	
	
	   if ((_MDOutRainInfiltrationID= MFVarGetID (MDVarRainInfiltration, "mm", MFOutput, MFState, MFBoundary))  == CMfailed) return CMfailed;	
	   if ((_MDOutSatExcessFlowID= MFVarGetID (MDVarSaturationExcessflow, "mm", MFOutput, MFState, MFBoundary))  == CMfailed) return CMfailed;	
	   if ((_MDOutSoilDebugID = MFVarGetID(MDVarOutSoilDebug,"mm", MFOutput, MFState, MFBoundary))  == CMfailed) return CMfailed;	
	
	if (((_MDInPrecipID            = MDPrecipitationDef     ()) == CMfailed) ||
	    ((_MDInSPackChgID          = MDSPackChgDef          ()) == CMfailed) ||
	    ((_MDInPotETID             = MDRainPotETDef         ()) == CMfailed) ||
	    ((_MDInInterceptID         = MDRainInterceptDef     ()) == CMfailed) ||
		((_MDOutWaterTableDepthID = MFVarGetID (MDVarWaterTableDepth,       "mm",   MFOutput, MFState,  MFBoundary)) == CMfailed) ||
	   ((_MDInSoilOrganicLayerID = MFVarGetID (MDVarSoilOrganicLayer,       "kg/m3",   MFInput, MFState,  MFBoundary)) == CMfailed) ||
			
	//    ((_MDInSoilAvailWaterCapID = MDSoilAvailWaterCapDef ()) == CMfailed) ||
	    ((_MDOutEvaptrsID          = MFVarGetID (MDVarRainEvapotranspiration,     "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
	    ((_MDInSoilRootingDepthID   = MFVarGetID (MDVarSoilRootingDepth,  "mm",   MFInput,  MFState, MFBoundary)) == CMfailed) ||
	    ((_MDInIsInitialID          = MFVarGetID (MDVarSoilMoistureIsInitial,             "m", MFOutput,  MFState, MFInitial)) == CMfailed) ||

 	     	((_MDOutSoilMoistCellID    = MFVarGetID (MDVarRainSoilMoistureCell,       "mm",   MFOutput, MFState, MFInitial))  == CMfailed) ||
	    ((_MDOutSoilMoistID        = MFVarGetID (MDVarRainSoilMoisture,           "mm",   MFOutput, MFState, MFBoundary)) == CMfailed) ||
	         
	    ((_MDOutSMoistChgID        = MFVarGetID (MDVarRainSoilMoistChange,        "mm",   MFOutput, MFState, MFBoundary)) == CMfailed) ||
        
        
        
        (MFModelAddFunction (_MDRainSMoistChg) == CMfailed)) return (CMfailed);

	MFDefLeaving ("Rainfed Layered Soil Moisture");
	return (_MDOutSMoistChgID);
}
Example #14
0
int MDThermalInputsDef () {
	int optID = MFUnset;
	const char *optStr, *optName = MDOptThermalInputs;
	const char *options [] = { MDNoneStr, MDInputStr, (char *) NULL };

	if ((optStr = MFOptionGet (optName)) != (char *) NULL) optID = CMoptLookup (options, optStr, true);

	MFDefEntering ("Thermal Inputs");
	switch (optID) {
		case MDinput:
			if (((_MDPlaceHolderID          = MDWTempRiverRouteDef ()) == CMfailed) ||
				((_MDInDischargeID          = MDDischLevel2Def ()) == CMfailed) ||
				((_MDInDischargeIncomingID  = MFVarGetID (MDVarDischarge0,          "m3/s", MFInput,  MFFlux,  MFBoundary)) == CMfailed) ||
				((_MDFluxMixing_QxTID       = MFVarGetID (MDVarFluxMixing_QxT, "m3*degC/d", MFRoute,  MFFlux,  MFBoundary)) == CMfailed)   ||
				((_MDFlux_QxTID             = MFVarGetID (MDVarFlux_QxT,       "m3*degC/d", MFRoute,  MFFlux,  MFBoundary)) == CMfailed)   ||
				((_MDInNamePlate1ID         = MFVarGetID (MDVarNamePlate1,          "MW", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDInNamePlate2ID         = MFVarGetID (MDVarNamePlate2,          "MW", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDInNamePlate3ID         = MFVarGetID (MDVarNamePlate3,          "MW", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDInNamePlate4ID         = MFVarGetID (MDVarNamePlate4,          "MW", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDInNamePlate5ID         = MFVarGetID (MDVarNamePlate5,          "MW", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDInNamePlate6ID         = MFVarGetID (MDVarNamePlate6,          "MW", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDInNamePlate7ID         = MFVarGetID (MDVarNamePlate7,          "MW", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDInNamePlate8ID         = MFVarGetID (MDVarNamePlate8,          "MW", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDInFuelType1ID          = MFVarGetID (MDVarFuelType1,          "MW", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDInFuelType2ID          = MFVarGetID (MDVarFuelType2,          "MW", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDInFuelType3ID          = MFVarGetID (MDVarFuelType3,          "MW", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDInFuelType4ID          = MFVarGetID (MDVarFuelType4,          "MW", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDInFuelType5ID          = MFVarGetID (MDVarFuelType5,          "MW", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDInFuelType6ID          = MFVarGetID (MDVarFuelType6,          "MW", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDInFuelType7ID          = MFVarGetID (MDVarFuelType7,          "MW", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDInFuelType8ID          = MFVarGetID (MDVarFuelType8,          "MW", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDInOptDeltaTID          = MFVarGetID (MDVarOptDeltaT,          "degC", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDInTempLimitID          = MFVarGetID (MDVarTempLimit,          "degC", MFInput, MFState, MFBoundary)) == CMfailed) ||
				((_MDOutTotalThermalWdlsID  = MFVarGetID (MDVarTotalThermalWdls, "m3", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutTotalOptThermalWdlsID = MFVarGetID (MDVarTotalOptThermalWdls, "m3", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDWTempMixing_QxTID      = MFVarGetID (MDVarWTempMixing_QxT,   "degC", MFOutput, MFState, MFBoundary)) == CMfailed) ||
				((_MDWTemp_QxTID            = MFVarGetID (MDVarWTemp_QxT,         "degC", MFOutput, MFState, MFBoundary)) == CMfailed) ||	//RJS 013112
				((_MDOutPowerOutput1ID      = MFVarGetID (MDVarPowerOutput1,       "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerOutput2ID      = MFVarGetID (MDVarPowerOutput2,       "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerOutput3ID      = MFVarGetID (MDVarPowerOutput3,       "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerOutput4ID      = MFVarGetID (MDVarPowerOutput4,       "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerOutput5ID      = MFVarGetID (MDVarPowerOutput5,       "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerOutput6ID      = MFVarGetID (MDVarPowerOutput6,       "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerOutput7ID      = MFVarGetID (MDVarPowerOutput7,       "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerOutput8ID      = MFVarGetID (MDVarPowerOutput8,       "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerDeficit1ID     = MFVarGetID (MDVarPowerDeficit1,       "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerDeficit2ID     = MFVarGetID (MDVarPowerDeficit2,       "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerDeficit3ID     = MFVarGetID (MDVarPowerDeficit3,       "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerDeficit4ID     = MFVarGetID (MDVarPowerDeficit4,       "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerDeficit5ID     = MFVarGetID (MDVarPowerDeficit5,       "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerDeficit6ID     = MFVarGetID (MDVarPowerDeficit6,       "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerDeficit7ID     = MFVarGetID (MDVarPowerDeficit7,       "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerDeficit8ID     = MFVarGetID (MDVarPowerDeficit8,       "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerPercent1ID     = MFVarGetID (MDVarPowerPercent1,       "MW", MFOutput, MFState, MFBoundary)) == CMfailed) ||
				((_MDOutPowerPercent2ID     = MFVarGetID (MDVarPowerPercent2,       "MW", MFOutput, MFState, MFBoundary)) == CMfailed) ||
				((_MDOutPowerPercent3ID     = MFVarGetID (MDVarPowerPercent3,       "MW", MFOutput, MFState, MFBoundary)) == CMfailed) ||
				((_MDOutPowerPercent4ID     = MFVarGetID (MDVarPowerPercent4,       "MW", MFOutput, MFState, MFBoundary)) == CMfailed) ||
				((_MDOutPowerPercent5ID     = MFVarGetID (MDVarPowerPercent5,       "MW", MFOutput, MFState, MFBoundary)) == CMfailed) ||
				((_MDOutPowerPercent6ID     = MFVarGetID (MDVarPowerPercent6,       "MW", MFOutput, MFState, MFBoundary)) == CMfailed) ||
				((_MDOutPowerPercent7ID     = MFVarGetID (MDVarPowerPercent7,       "MW", MFOutput, MFState, MFBoundary)) == CMfailed) ||
				((_MDOutPowerPercent8ID     = MFVarGetID (MDVarPowerPercent8,       "MW", MFOutput, MFState, MFBoundary)) == CMfailed) ||
				((_MDOutPowerOutputTotalID  = MFVarGetID (MDVarPowerOutputTotal,    "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerDeficitTotalID = MFVarGetID (MDVarPowerDeficitTotal,   "MW", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
				((_MDOutPowerPercentTotalID = MFVarGetID (MDVarPowerDeficitTotal,   "MW", MFOutput, MFState, MFBoundary)) == CMfailed) ||

//			    ((_MDInThermalWdlID     = MFVarGetID (MDVarThermalWdl,            "m3", MFInput, MFState, MFBoundary)) == CMfailed) ||
//			    ((_MDOutWdl_QxTID	    = MFVarGetID (MDVarWithdrawal_QxT,	      "m3*degC/d", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||
//			    ((_MDInWarmingTempID    = MFVarGetID (MDVarWarmingTemp,            "degC", MFInput, MFState, MFBoundary)) == CMfailed)	||

			    (MFModelAddFunction (_MDThermalInputs) == CMfailed)) return (CMfailed);
			break;
		default: MFOptionMessage (optName, optStr, options); return (CMfailed);
	}
	MFDefLeaving ("Thermal Inputs");
	return (_MDWTemp_QxTID);
}
Example #15
0
int MDDINDef () {


	float par1;		//RJS 032509
	float par2;		//RJS 032509
	float par3;		//RJS 032509
	float par4;		//RJS 032509
	float par5;		//RJS 032509
	float par6;		//RJS 033009
	float par7;		//RJS 033009

	const char *optStr1, *optStr2, *optStr3, *optStr4, *optStr5, *optStr6, *optStr7;		//RJS 032509

	if (((optStr1 = MFOptionGet (MDParAlphaSTS))  != (char *) NULL) && (sscanf (optStr1,"%f",&par1) == 1)) _MDAlphaSTS = par1;  // RJS 032509
	if (((optStr2 = MFOptionGet (MDParAlphaHTS))  != (char *) NULL) && (sscanf (optStr2,"%f",&par2) == 1)) _MDAlphaHTS = par2;  // RJS 032509
	if (((optStr3 = MFOptionGet (MDParASTSA))  != (char *) NULL) && (sscanf (optStr3,"%f",&par3) == 1)) _MDASTSA = par3;  // RJS 032509
	if (((optStr4 = MFOptionGet (MDParAHTSA))  != (char *) NULL) && (sscanf (optStr4,"%f",&par4) == 1)) _MDAHTSA = par4;  // RJS 032509
	if (((optStr5 = MFOptionGet (MDParUptakeKtMC))     != (char *) NULL) && (sscanf (optStr5,"%f",&par5) == 1)) _MDUptakeKtMC = par5; // RJS 033009
	if (((optStr6 = MFOptionGet (MDParUptakeKtSTS))     != (char *) NULL) && (sscanf (optStr6,"%f",&par6) == 1)) _MDUptakeKtSTS = par6; // RJS 033009
	if (((optStr7 = MFOptionGet (MDParUptakeKtHTS))     != (char *) NULL) && (sscanf (optStr7,"%f",&par7) == 1)) _MDUptakeKtHTS = par7; // RJS 033009


	MFDefEntering ("N Processing");



   // Input
	if (
		((_MDWTemp_QxTID 			= MDThermalInputs3Def ()) == CMfailed) ||		// comment out for no plants
//		((_MDWTemp_QxTID 				= MDWTempRiverRouteDef()) == CMfailed) ||
		((_MDInDischarge0ID             = MFVarGetID (MDVarDischarge0,    "m3/s",  MFRoute,  MFState, MFBoundary)) == CMfailed) ||					// RJS 01-06-09     includes local cells runoff
	    ((_MDInDischargeID              = MFVarGetID (MDVarDischarge,     "m3/s",  MFRoute,  MFState, MFBoundary)) == CMfailed) ||
	    ((_MDInRiverStorageID           = MFVarGetID (MDVarRiverStorage,           "m3/day",   MFInput,  MFState,  MFInitial)) == CMfailed)  ||		// RJS 01-06-09		m3/day instead of m3/s
	    ((_MDInRiverStorageChgID        = MFVarGetID (MDVarRiverStorageChg,        "m3/day",   MFInput,  MFState,  MFBoundary)) == CMfailed)  ||     // RJS 01-06-09
	    ((_MDInRiverOrderID          = MFVarGetID (MDVarRiverOrder,               "-",   MFInput,  MFState, MFBoundary)) == CMfailed)  ||			//RJS 112211
	    ((_MDInRiverWidthID             = MDRiverWidthDef ())   == CMfailed) ||
	    ((_MDInRiverDepthID		    = MFVarGetID (MDVarRiverDepth,   	   	    "m",   MFInput,  MFState, MFBoundary)) == CMfailed)  ||
	    ((_MDInLocalLoad_DINID	    = MDNitrogenInputsDef()) == CMfailed) ||	// RJS 091108
	    ((_MDInVfAdjustID           = MFVarGetID (MDVfAdjust,   "-",   MFInput, MFState, MFBoundary)) == CMfailed) ||
	    ((_MDFlux_DINID                 = MFVarGetID (MDVarFluxDIN,                "kg/day",   MFRoute,  MFFlux,  MFBoundary)) == CMfailed)  ||		// RJS 091408
	    ((_MDStoreWater_DINID           = MFVarGetID (MDVarStoreWaterDIN,          "kg/day",   MFOutput,  MFState,  MFInitial)) == CMfailed)  ||		// RJS 091108
	    ((_MDInRunoffVolID              = MFVarGetID (MDVarRunoffVolume, 		 "m3/s",   MFInput, MFState,  MFBoundary)) == CMfailed)  ||		// RJS 091108
	    ((_MDInTnQ10ID		    = MFVarGetID (MDVarTnQ10,               "-",     MFInput, MFState,  MFBoundary)) == CMfailed)  || 	//RJS 102410


   // Output
	    ((_MDOutPostConc_DINID		= MFVarGetID (MDVarPostConcDIN,	       "mg/L",   MFOutput,  MFState, MFBoundary))   == CMfailed) ||
	    ((_MDOutPreConc_DINID		= MFVarGetID (MDVarPreConcDIN,	       "mg/L",   MFOutput,  MFState, MFBoundary))   == CMfailed) ||
	    ((_MDOutTotalMassRemovedTS_DINID   	= MFVarGetID (MDVarTotalMassRemovedTSDIN,    "kg/day", MFOutput, MFFlux, MFBoundary))   == CMfailed) ||
	    ((_MDOutTotalMassRemovedDZ_DINID 	= MFVarGetID (MDVarTotalMassRemovedDZDIN,  "kg/day",   MFOutput, MFFlux, MFBoundary))   == CMfailed) ||
	    ((_MDOutTotalMassRemovedHZ_DINID 	= MFVarGetID (MDVarTotalMassRemovedHZDIN,  "kg/day",   MFOutput, MFFlux, MFBoundary))   == CMfailed) ||
	    ((_MDOutTotalMassRemovedMC_DINID 	= MFVarGetID (MDVarTotalMassRemovedMCDIN,  "kg/day",   MFOutput, MFFlux, MFBoundary))   == CMfailed) ||
	    ((_MDOutTotalMassRemoved_DINID      = MFVarGetID (MDVarTotalMassRemovedDIN,    "kg/day",   MFOutput, MFFlux, MFBoundary))   == CMfailed) ||		// RJS 032509
	    ((_MDOutTimeOfStorageDZID		= MFVarGetID (MDVarTimeOfStorageDZ,          "days",   MFOutput, MFState, MFBoundary))   == CMfailed) ||
	    ((_MDOutTimeOfStorageHZID		= MFVarGetID (MDVarTimeOfStorageHZ,          "days",   MFOutput, MFState, MFBoundary))   == CMfailed) ||
	    ((_MDOutTimeOfStorageMCID		= MFVarGetID (MDVarTimeOfStorageMC,          "days",   MFOutput, MFState, MFBoundary))   == CMfailed) ||	// RJS 120608
	    ((_MDOutTransferDZID		= MFVarGetID (MDVarTransferDZ,               "m3/s",   MFOutput, MFState, MFBoundary))   == CMfailed) ||
	    ((_MDOutTransferHZID		= MFVarGetID (MDVarTransferHZ,               "m3/s",   MFOutput, MFState, MFBoundary))   == CMfailed) ||
	    ((_MDOutPreFlux_DINID               = MFVarGetID (MDVarPreFluxDIN,               "kg/day", MFOutput, MFState, MFBoundary))   == CMfailed) || 	//RJS 050911
	    ((_MDOutWaterDZID			= MFVarGetID (MDVarWaterDZ, 				    "m3",   MFOutput, MFState, MFBoundary))   == CMfailed) ||
	    ((_MDOutWaterHZID			= MFVarGetID (MDVarWaterHZ, 				    "m3",   MFOutput, MFState, MFBoundary))   == CMfailed) ||
	    ((_MDOutUptakeVfID               	= MFVarGetID (MDVarUptakeVf,                 "m/day",   MFOutput, MFState, MFBoundary))   == CMfailed) ||	// RJS 090508
	    ((_MDFluxMixing_DINID		= MFVarGetID (MDVarFluxMixingDIN,  		"	kg/day",    MFRoute,  MFFlux, MFBoundary))   == CMfailed) ||	// RJS 091108
	    ((_MDStoreWaterMixing_DINID      	= MFVarGetID (MDVarStoreWaterMixingDIN,    "kg/day",   MFOutput, MFState, MFInitial))   == CMfailed) ||	// RJS 091108
	    ((_MDOutTotalMassPre_DINID       	= MFVarGetID (MDVarTotalMassPreDIN,        "kg/day",   MFOutput, MFFlux, MFBoundary))   == CMfailed) ||	// RJS 091408
	    ((_MDOutConcMixing_DINID         	= MFVarGetID (MDVarConcMixing,    		      "mg/L",   MFOutput, MFState, MFBoundary))   == CMfailed) ||	// RJS 091108
	    ((_MDOutMassBalance_DINID		= MFVarGetID (MDVarMassBalanceDIN,          "kg/kg",   MFOutput, MFState, MFBoundary))   == CMfailed) ||	// RJS 110308
	    ((_MDOutMassBalanceMixing_DINID	= MFVarGetID (MDVarMassBalanceMixingDIN,    "kg/kg",   MFOutput, MFState, MFBoundary))   == CMfailed) ||	// RJS 110308
	    ((_MDOutRemovalDZID              	= MFVarGetID (MDVarRemovalDZ,               "kg/kg",   MFOutput, MFState, MFBoundary))   == CMfailed) ||	// RJS 110708
	    ((_MDOutRemovalHZID              	= MFVarGetID (MDVarRemovalHZ,               "kg/kg",   MFOutput, MFState, MFBoundary))   == CMfailed) ||	// RJS 110708
	    ((_MDOutRemovalMCID              	= MFVarGetID (MDVarRemovalMC,               "kg/kg",   MFOutput, MFState, MFBoundary))   == CMfailed) ||	// RJS 110708
	    ((_MDOutRemovalTotalID              = MFVarGetID (MDVarRemovalTotal,            "kg/kg",   MFOutput, MFState, MFBoundary))   == CMfailed) || 	// RJS 030109
	    ((_MDOutAsDZID                   	= MFVarGetID (MDVarAsDZ,                       "m2",   MFOutput, MFState, MFBoundary))   == CMfailed) ||   // RJS 110808
	    ((_MDOutAsHZID                   	= MFVarGetID (MDVarAsHZ,                       "m2",   MFOutput, MFState, MFBoundary))   == CMfailed) ||   // RJS 110808
	    ((_MDOutAaID                     	= MFVarGetID (MDVarAa,                         "m2",   MFOutput, MFState, MFBoundary))   == CMfailed) ||   // RJS 110808
	    ((_MDOutVelocityID                  = MFVarGetID (MDVarVelocity,                  "m/s",   MFOutput, MFState, MFBoundary))   == CMfailed) ||   // RJS 112108
	    ((_MDOutDINVfID                     = MFVarGetID (MDVarDINVf,                       "-",   MFOutput, MFState, MFBoundary))   == CMfailed) ||	// RJS 112210
	    ((_MDOutDINKtID                     = MFVarGetID (MDVarDINKt,                       "-",   MFOutput, MFState, MFBoundary))   == CMfailed) ||	// RJS 112210
  	    ((_MDDeltaStoreWater_DINID       	= MFVarGetID (MDVarDeltaStoreWaterDIN,    	 "kg/day", MFOutput, MFState, MFBoundary)) == CMfailed) ||   // RJS 112008
	    ((_MDDeltaStoreWaterMixing_DINID    = MFVarGetID (MDVarDeltaStoreWaterMixingDIN,  "kg/day", MFOutput, MFState, MFBoundary)) == CMfailed) ||   // RJS 112008
	    ((_MDFlowPathRemoval_DINID       	= MFVarGetID (MDVarFlowPathRemovalDIN,      	"kg/day", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||   // RJS 112008
	    ((_MDFlowPathRemovalMixing_DINID    = MFVarGetID (MDVarFlowPathRemovalMixingDIN,  "kg/day", MFOutput, MFFlux, MFBoundary)) == CMfailed) ||   // RJS 112008


	(MFModelAddFunction (_MDNProcessing) == CMfailed)) return (CMfailed);

	MFDefLeaving ("N Processing");

	return (_MDFlux_DINID);		// RJS 091408
}
Example #16
0
int MDIrrGrossDemandDef () {
	int optID = MFUnset;
	const char *optStr, *optName = MDOptIrrigation;
	const char *options [] = { MDNoneStr, MDInputStr, MDCalculateStr, (char *) NULL };
	const char *mapOptions   [] = { "FAO", "IWMI", (char *) NULL };
	const char *distrOptions [] = { "FirstSeason","Distributed", (char *) NULL }; 
	 
	int i;

	char varname [20];
	char cropETName [20];
	char cropGrossDemandName[20];
	int mapOptionID = MFUnset;

	int irrDistribuedID = MFUnset;

	if ((optStr = MFOptionGet (optName)) != (char *) NULL) optID = CMoptLookup (options,optStr,true);

	if ((optID == MDnone) || (_MDOutIrrGrossDemandID != MFUnset)) return (_MDOutIrrGrossDemandID);
   
	
	MFDefEntering ("Irrigation Gross Demand");

	switch (optID) {
		case MDinput:
			 if(((_MDOutIrrGrossDemandID = MFVarGetID (MDVarIrrGrossDemand,        "mm", MFInput,  MFFlux,  MFBoundary)) == CMfailed) ||
		    	((_MDOutIrrReturnFlowID  = MFVarGetID (MDVarIrrReturnFlow,         "mm", MFInput,  MFFlux,  MFBoundary)) == CMfailed) ||
				((_MDOutIrrEvapotranspID = MFVarGetID (MDVarIrrEvapotranspiration, "mm", MFInput,  MFFlux,  MFBoundary)) == CMfailed))
				return (CMfailed);
			break;
		case MDcalculate:		
			if (((optStr = MFOptionGet (MDOptIrrIntensity)) == (char *) NULL) || ((irrDistribuedID = CMoptLookup (distrOptions, optStr, true)) == CMfailed)) {
				CMmsgPrint(CMmsgUsrError,"Irrigation Distribution not specifed! Options = 'Distributed' or 'FirstSeason'\n");
				return (CMfailed);
			}
			if (((optStr = MFOptionGet (MDOptIrrigatedAreaMap))  == (char *) NULL) || ((mapOptionID = CMoptLookup (mapOptions, optStr, true)) == CMfailed)) {
				CMmsgPrint(CMmsgUsrError,"Typ of Irr Area not specifed! Options = 'FAO' or 'IWMI'\n");
				return (CMfailed);
			}
			_MDIrrigatedAreaMap=mapOptionID;
	
			if (_MDIrrigatedAreaMap == 1) { //read irrArea for both seasons from IWMI data; Irr Intensity not needed!
				_MDIntensityDistributed = true; //Distributed ; 					
			}
			else { // FAO irrigated Area Map; read Irr Area and Intensity
				if (((optStr = MFOptionGet (MDOptIrrIntensity)) == (char *) NULL) || ((irrDistribuedID = CMoptLookup (distrOptions, optStr, true)) == CMfailed)) {
					CMmsgPrint(CMmsgUsrError,"Irrigation Distribution not specifed! Options = 'Distributed' or 'FirstSeason'\n");
					return CMfailed;
				}
				_MDIntensityDistributed = irrDistribuedID == 0 ? false : true;

				if (((_MDInIrrIntensityID = MFVarGetID (MDVarIrrIntensity,           "-",    MFInput,  MFState, MFBoundary)) == CMfailed)) return (CMfailed);
			}
			if ((optStr = MFOptionGet (MDParIrrigationCropFileName)) != (char *) NULL) CropParameterFileName = optStr;
			if (readCropParameters (CropParameterFileName) == CMfailed) {
				CMmsgPrint(CMmsgUsrError,"Error reading crop parameter file   : %s \n", CropParameterFileName);
				return CMfailed;
			}
			if (((_MDInPrecipID              = MDPrecipitationDef    ()) == CMfailed) ||	 
			    ((_MDInSPackChgID            = MDSPackChgDef         ()) == CMfailed) ||
			    ((_MDInIrrRefEvapotransID    = MDIrrRefEvapotransDef ()) == CMfailed) ||
			    ((_MDInIrrAreaFracID         = MDIrrigatedAreaDef    ())==  CMfailed) ||
			    ((_MDInWltPntID              = MFVarGetID (MDVarSoilWiltingPoint,       "mm/m", MFInput,  MFState, MFBoundary)) == CMfailed) ||
			    ((_MDInFldCapaID             = MFVarGetID (MDVarSoilFieldCapacity,      "mm/m", MFInput,  MFState, MFBoundary)) == CMfailed) ||
			    ((_MDGrowingSeason1ID        = MFVarGetID (MDVarIrrGrowingSeason1Start, "DoY",  MFInput,  MFState, MFBoundary)) == CMfailed) ||
			    ((_MDGrowingSeason2ID        = MFVarGetID (MDVarIrrGrowingSeason2Start, "DoY",  MFInput,  MFState, MFBoundary)) == CMfailed) ||
				((_MDNonIrrFractionID        = MFVarGetID (MDNonIrrigatedFraction, "-",  MFOutput ,  MFState, MFBoundary)) == CMfailed) ||
				((_MDRicePercolationRateID = MFVarGetID (MDVarIrrDailyRicePerolationRate, "mm/day",  MFInput ,  MFState, MFBoundary)) == CMfailed) ||
				((_MDInIrrEfficiencyID       = MFVarGetID (MDVarIrrEfficiency,          "-",    MFInput,  MFState, MFBoundary)) == CMfailed) ||
			    ((_MDOutIrrGrossDemandID     = MFVarGetID (MDVarIrrGrossDemand,         "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
			    ((_MDOutIrrReturnFlowID      = MFVarGetID (MDVarIrrReturnFlow,          "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
			    ((_MDOutIrrNetDemandID       = MFVarGetID (MDVarIrrNetWaterDemand,      "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
			    ((_MDOutIrrSoilMoistID       = MFVarGetID (MDVarIrrSoilMoisture,        "mm",   MFOutput, MFState, MFBoundary)) == CMfailed) ||
			    ((_MDRicePoindingDepthID     = MFVarGetID (MDVarIrrRicePondingDepth,    "mm",   MFInput, MFState, MFBoundary)) == CMfailed)||
			    ((_MDOutIrrSMoistChgID       = MFVarGetID (MDVarIrrSoilMoistChange,     "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
			    ((_MDOutIrrEvapotranspID     = MFVarGetID (MDVarIrrEvapotranspiration,  "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed))
				return (CMfailed);

			for (i = 0; i < _MDNumberOfIrrCrops; i++) {
				sprintf (varname, "CropFraction_%02d", i + 1); // Input Fraction of crop type per cell
				if ((_MDInCropFractionIDs [i] = MFVarGetID (varname, "mm", MFInput,  MFState, MFBoundary)) == CMfailed) {
					CMmsgPrint (CMmsgUsrError, "CMfailed in MDInCropFractionID \n");
					return CMfailed;
				}
			}
			for (i = 0; i < _MDNumberOfIrrCrops + 1;i++) {
				sprintf (cropETName, "CropET%02d", i + 1);  // Keep track of crop ET for each crop seperately z
				sprintf (cropGrossDemandName, "CropGrossDemand%02d", i + 1);  // Keep track of crop ET for each crop seperately z
				sprintf (varname, "CropSMDeficiency%02d", i + 1);  // Output Soil Moisture Deficit, crop ET and WithDrawal per croptype
			    if ((_MDOutCropETIDs[i]     = MFVarGetID (cropETName,  "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed)return CMfailed;
			    if ((_MDOutCropGrossDemandIDs[i]     = MFVarGetID (cropGrossDemandName,  "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed)return CMfailed;
			    
			    if ((_MDOutCropDeficitIDs [i] = MFVarGetID (varname, "mm", MFOutput, MFState, MFInitial))  == CMfailed) return CMfailed;	
			}
			if (MFModelAddFunction (_MDIrrGrossDemand) == CMfailed) return (CMfailed);
			break;
		default: MFOptionMessage (optName, optStr, options); return (CMfailed);
	}
	MFDefLeaving("Irrigation Gross Demand");
	return (_MDOutIrrGrossDemandID);
}
Example #17
0
int MDRainSMoistChgDef () {
	int ret = 0;
	float par;
	const char *optStr;
    /*    
        // Test if the percolation pathway is active (if its not - PercolationBETA should not be in the Options)
        if ((optStr = MFOptionGet(MDParSoilPercolationBETA)) != (char *) NULL) {        
            if ((_MDOutPercolationID = MFVarGetID (MDVarSoilPercolation,     "mm", MFInput, MFFlux,   MFBoundary)) == CMfailed) return (CMfailed); // SZ 10212014
        }
        */
	if (_MDOutSMoistChgID != MFUnset) return (_MDOutSMoistChgID);
	const char *soilTemperatureOptions [] = { "none", "calculate", (char *) NULL };

	int soilTemperatureID;
	if (((optStr = MFOptionGet (MDOptSoilTemperature))  == (char *) NULL) ||
	    ((soilTemperatureID = CMoptLookup (soilTemperatureOptions, optStr, true)) == CMfailed)) {
		CMmsgPrint(CMmsgUsrError," Soil TemperatureOption not specifed! Options = 'none' or 'calculate'\n");
		return CMfailed;
	}
	if (((optStr = MFOptionGet (MDParSoilMoistALPHA))  != (char *) NULL) && (sscanf (optStr,"%f",&par) == 1)) _MDSoilMoistALPHA = par;
	if (((optStr = MFOptionGet (MDParSoilPercolationBETA)) != (char *) NULL) && (sscanf (optStr,"%f",&par) ==1)) _MDparPercolation = par;
        
	MFDefEntering ("Rainfed Soil Moisture");
	if (soilTemperatureID == MFcalculate ) {
		if (((ret                        = MDPermafrostDef()) == CMfailed) ||
		    ((_MDInRelativeIceContent    = MFVarGetID ("SoilIceContent_01",     "mm",   MFOutput,  MFState, MFBoundary)) == CMfailed) ||
			((_MDOutLiquidSoilMoistureID = MFVarGetID (MDVarLiquidSoilMoisture, "-",    MFOutput,  MFState, MFBoundary)) == CMfailed)) return CMfailed;
	}

	if ((ret = MDIrrGrossDemandDef ()) == CMfailed) return (CMfailed);
	if ((ret != MFUnset) && ((_MDInIrrAreaFracID = MDIrrigatedAreaDef ())==  CMfailed) ) return (CMfailed);

	if (((_MDInPrecipID            = MDPrecipitationDef     ()) == CMfailed) ||
	    ((_MDInSPackChgID          = MDSPackChgDef          ()) == CMfailed) ||
	    ((_MDInPotETID             = MDRainPotETDef         ()) == CMfailed) ||
	    ((_MDInInterceptID         = MDRainInterceptDef     ()) == CMfailed) ||
	    ((_MDInSoilAvailWaterCapID = MDSoilAvailWaterCapDef ()) == CMfailed) ||
	    ((_MDInAirTMeanID          = MFVarGetID (MDVarAirTemperature,             "degC", MFInput,  MFState, MFBoundary)) == CMfailed) ||
	    ((_MDInRunoffToPervID      = MDStormRunoffDef ())  == CMfailed) ||  								// RJS 082812
 //	    ((_MDInH2OFractionID       = MFVarGetID (MDVarH2OFracSpatial,             "mm",   MFInput,  MFState, MFBoundary)) == CMfailed) ||   // RJS 082812
        ((_MDInStormRunoffTotalID  = MFVarGetID (MDVarStormRunoffTotal,           "mm",   MFInput,  MFFlux,  MFBoundary)) == CMfailed) ||	// RJS 082812
	    ((_MDInImpFractionID       = MFVarGetID (MDVarImpFracSpatial,             "-",   MFInput,  MFState, MFBoundary)) == CMfailed) ||   // RJS 082812
 	    ((_MDInH2OFractionID       = MFVarGetID (MDVarH2OFracSpatial,             "-",   MFInput,  MFState, MFBoundary)) == CMfailed) ||   // RJS 082812
            ((_MDOutEvaptrsID          = MFVarGetID (MDVarRainEvapotranspiration,     "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
 	    ((_MDOutExcessID           = MFVarGetID (MDVarExcess,                     "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||	// RJS 091813
 	    ((_MDOutExcessNotScaledID  = MFVarGetID (MDVarExcessNotScaled,            "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||	// RJS 091813
 	    ((_MDOutEvaptrsNotScaledID = MFVarGetID (MDVarRainETnotScaled,            "mm",   MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||	// RJS 082812
	    ((_MDOutSoilMoistNotScaledID    = MFVarGetID (MDVarRainSoilMoistureNotScaled,       "mm",   MFOutput, MFState, MFInitial))  == CMfailed) ||
	    ((_MDOutSoilMoistID        = MFVarGetID (MDVarRainSoilMoisture,           "mm",   MFOutput, MFState, MFBoundary)) == CMfailed) ||
	    ((_MDOutSMoistChgNotScaledID   = MFVarGetID (MDVarRainSoilMoistureChangeNotScaled,       "mm",   MFOutput, MFState, MFInitial))  == CMfailed) ||
	    ((_MDOutSMoistChgID        = MFVarGetID (MDVarRainSoilMoistChange,        "mm",   MFOutput, MFState, MFBoundary)) == CMfailed) ||
        (MFModelAddFunction (_MDRainSMoistChg) == CMfailed)) return (CMfailed);
        
        const char *snowImpervMeltOptions [] = { MDNoneStr, MDCalculateStr,(char *) NULL };
        int impervSnowMeltCalcID;
        if ((optStr = MFOptionGet (MDOptImperviousMeltCalc) ) == (char *) NULL) {
            optStr = MDNoneStr;
            //CMmsgPrint(CMmsgWarning," Impervious Snow Fall runoff method not specified - defaulting to none (RainSMoistChgDef).\n");
        } 
        if ((impervSnowMeltCalcID = CMoptLookup (snowImpervMeltOptions,optStr,true)) == CMfailed) {
            CMmsgPrint(CMmsgUsrError," Impervious Snow Fall runoff method incorrectly specified. Options are 'none' or 'calculate'.\n");
            return (CMfailed);
        }
        switch (impervSnowMeltCalcID) {
            case MFnone:
                // Nothing to be done
                break;
            case MFcalculate:
                if (((_MDInImpSnowFallROID    = MFVarGetID ( MDVarImpSnowFallRunoff,"mm",   MFInput, MFFlux,  MFBoundary)) == CMfailed)
                    ) return (CMfailed);
                break;
            default: MFOptionMessage (MDOptImperviousMeltCalc, optStr, snowImpervMeltOptions); return (CMfailed);
        }
        
	MFDefLeaving ("Rainfed Soil Moisture");
	return (_MDOutSMoistChgID);
}
Example #18
0
int MDRainInfiltrationDef () {
	int  optID = MFUnset;
	int ret =0;
	const char *optStr, *optName = MDVarRainInfiltration;
	const char *options [] = { MDInputStr, "simple", "varying","spatially" ,(char *) NULL };
	float par;
	//printf ("THE framework = greatest time sink ever invented\n");
	if (_MDOutRainInfiltrationID != MFUnset) return (_MDOutRainInfiltrationID);

	
	const char *soilMoistureOptions [] = { "bucket", "layers", (char *) NULL };
		int soilMoistureOptionID;
		 //TODO Add baseflow from layered SM to infiltration!
			if (((optStr = MFOptionGet (MDOptSoilMoisture))  == (char *) NULL) || ((soilMoistureOptionID = CMoptLookup (soilMoistureOptions, optStr, true)) == CMfailed)) {
						CMmsgPrint(CMmsgUsrError," Soil Moisture mode not specifed! Options = 'bucket' or 'layers'\n");
						return CMfailed;
					}
		
	
	MFDefEntering ("Rainfed Infiltration");
	 
	if ((optStr = MFOptionGet (optName)) != (char *) NULL) optID = CMoptLookup (options, optStr, true);
	
	//if ((ret = MDPermafrostDef())                == CMfailed) return CMfailed;
	
	if (soilMoistureOptionID ==1){ //layer is the soil moisture option infiltration will be calculated differently. 
		//if ((_MDInRainWaterSurplusID = MDRainWaterSurplusDef ()) == CMfailed) return (CMfailed);
		
		
		if ((ret = MDRainSMoistChgLayeredSoilDef()) == CMfailed) return CMfailed;
		if ((_MDOutRainSurfRunoffID       = MFVarGetID (MDVarRainSurfRunoff,       "mm", MFOutput, MFFlux, MFBoundary)) == CMfailed)return CMfailed; 
		if ((_MDOutRainInfiltrationID     = MFVarGetID (MDVarRainInfiltration,           "mm", MFOutput, MFFlux, MFBoundary)) == CMfailed) return CMfailed;
		if ((_MDInSaturationExcessRunoffID       = MFVarGetID (MDVarSaturationExcessflow,       "mm", MFInput, MFFlux, MFBoundary)) == CMfailed)return CMfailed; 
		if ((_MDInRainInfiltrationID     = MFVarGetID (MDVarRainInfiltration,           "mm", MFInput, MFFlux, MFBoundary)) == CMfailed) return CMfailed;
		
		
		if (MFModelAddFunction (_MDRainInfiltrationSaturation) == CMfailed) return CMfailed;
		MFDefLeaving  ("Rainfed Infiltration");
		return (_MDOutRainInfiltrationID);

	}
	
	
	
	switch (optID) {
		case MDinput:
			_MDOutRainInfiltrationID = MFVarGetID (MDVarRainInfiltration, "mm", MFInput, MFFlux, MFBoundary);
			break;
		case MDSpatially:
			_MDInfiltrationFractionID = MFVarGetID (MDParInfiltrationFracSpatial, "mm", MFInput, MFState, MFBoundary);
		case MDsimple:
		case MDvarying:
			if ((_MDInRainWaterSurplusID = MDRainWaterSurplusDef ()) == CMfailed) return (CMfailed);
			if (_MDInfiltrationFractionID != MFUnset) {
				if (((optStr = MFOptionGet (MDParInfiltrationFrac))  != (char *) NULL) &&
				    (sscanf (optStr,"%f",&par) == 1))
					_MDInfiltrationFrac = par;
				else goto Stop;
			}
			if ((_MDOutRainSurfRunoffID       = MFVarGetID (MDVarRainSurfRunoff,       "mm", MFOutput, MFFlux, MFBoundary)) == CMfailed) return CMfailed;
			if ((_MDOutRainInfiltrationID     = MFVarGetID (MDVarRainInfiltration,     "mm", MFOutput, MFFlux, MFBoundary)) == CMfailed) return CMfailed;
			if  (MFModelAddFunction (_MDRainInfiltrationSimple) == CMfailed) return (CMfailed);
			break;
		default: MFOptionMessage (optName, optStr, options); return (CMfailed);
	}
	MFDefLeaving  ("Rainfed Infiltration");
	return (_MDOutRainInfiltrationID);
Stop:
	MFOptionMessage (optName, optStr, options);
	return (CMfailed);
}
Example #19
0
int MDWaterBalanceDef() {
        enum { MDaccumulate, MDmuskingum, MDcascade };
        int  RoptID = MFUnset;
        const char *RoptStr, *RoptName = MDOptRouting;
        const char *Roptions [] = { "accumulate", "muskingum", "cascade", (char *) NULL };
        if ((RoptStr = MFOptionGet (RoptName)) != (char *) NULL) RoptID = CMoptLookup (Roptions, RoptStr, true);
        
        enum { MDinput, MDcalculate, MDinput2};
        int  optID = MFUnset;
	const char *optStr, *optName = MDVarRunoff;
	const char *options [] = { MDInputStr, MDCalculateStr, MDInput2Str, (char *) NULL };
        
	MFDefEntering ("WaterBalance");
        if ((optStr = MFOptionGet (optName)) != (char *) NULL) optID = CMoptLookup (options, optStr, true);
        switch (optID) {
        
        case MDcalculate:
            // Build the calculation hierarchy
        if ((                                  MDAccumBalanceDef     ()  == CMfailed) ||
	    ((_MDInPrecipID                  = MDPrecipitationDef    ()) == CMfailed) ||
	    ((_MDInDischargeID               = MDDischargeDef        ()) == CMfailed) || 
	    ((_MDInSnowPackChgID             = MDSPackChgDef         ()) == CMfailed) ||
	    ((_MDInSoilMoistChgID            = MDSoilMoistChgDef     ()) == CMfailed) ||
	    ((_MDInRunoffID                  = MDRunoffDef           ()) == CMfailed)
            ) return (CMfailed);
            // Fill in the routing parameters            
            switch (RoptID) {
                case MDaccumulate:
                    //Nothing to do
                    break;
                case MDmuskingum:
                    if (
                       ((_MDInMuskingumC0ID                  = MFVarGetID(MDVarMuskingumC0, MFNoUnit,MFInput,  MFState,  MFBoundary)) == CMfailed) ||
                       ((_MDInMuskingumC1ID                  = MFVarGetID(MDVarMuskingumC1, MFNoUnit,MFInput,  MFState,  MFBoundary)) == CMfailed) ||
                       ((_MDInMuskingumC2ID                  = MFVarGetID(MDVarMuskingumC2, MFNoUnit,MFInput,  MFState,  MFBoundary)) == CMfailed)
                        )    return (CMfailed);
                    break;
                case MDcascade:
                    if (
                       ((_MDInCascadeC0ID                  = MFVarGetID(MDVarCascadeC0, MFNoUnit,MFInput,  MFState,  MFBoundary)) == CMfailed)
                       ) return (CMfailed);
                    break;
            }
            // Continue with remaining parameters and add function
	if (
//	    ((_MDInEvaptrsID                 = MFVarGetID (MDVarEvapotranspiration,      	"mm",   MFInput,  MFFlux,  MFBoundary)) == CMfailed) ||    
	    ((_MDInGrdWatChgID               = MFVarGetID (MDVarGroundWaterChange,       	"mm",   MFInput,  MFFlux,  MFBoundary)) == CMfailed) ||
	    ((_MDInRunoffPoolChgID           = MFVarGetID (MDVarRunoffPoolChg,           	"mm",   MFInput,  MFFlux,  MFBoundary)) == CMfailed) ||
	    ((_MDInRunoffPoolID              = MFVarGetID (MDVarRunoffPool,         		"mm", MFInput, MFState, MFInitial))  == CMfailed) ||
	    ((_MDInRunoffPoolRechargeID      = MFVarGetID (MDVarRunoffPoolRecharge, 		"mm", MFInput, MFFlux,  MFBoundary)) == CMfailed) ||
	    ((_MDInRunoffPoolReleaseID       = MFVarGetID (MDVarRunoffPoolRelease,  		"mm", MFInput, MFFlux,  MFBoundary)) == CMfailed) ||
	    ((_MDInStormRunoffImpID    		 = MFVarGetID (MDVarStormRunoffImp,  			"mm",   MFInput, MFFlux,  MFBoundary)) == CMfailed) ||
	    ((_MDInStormRunoffH2OID    		 = MFVarGetID (MDVarStormRunoffH2O,  			"mm",   MFInput, MFFlux,  MFBoundary)) == CMfailed) ||
	    ((_MDInPrecipPervID        		 = MFVarGetID (MDVarPrecipPerv,      			"mm",   MFInput, MFFlux, MFBoundary)) == CMfailed) ||
	    ((_MDInStormRunoffTotalID  		 = MFVarGetID (MDVarStormRunoffTotal,			"mm",   MFInput, MFFlux, MFBoundary))  == CMfailed) ||
	    ((_MDInRunofftoPervID      		 = MFVarGetID (MDVarRunofftoPerv,    			"mm",   MFInput, MFFlux, MFBoundary))  == CMfailed) ||
 	    ((_MDInPetID                        = MFVarGetID (MDVarRainPotEvapotrans,                  "mm",   MFInput, MFFlux,  MFBoundary)) == CMfailed) ||
            ((_MDInEvaptrsID         		 = MFVarGetID (MDVarRainEvapotranspiration,     "mm",   MFInput, MFFlux,  MFBoundary)) == CMfailed) ||
 	    ((_MDInEvaptrsNotScaledID		 = MFVarGetID (MDVarRainETnotScaled,            "mm",   MFInput, MFFlux,  MFBoundary)) == CMfailed) ||	// RJS 082812
	    ((_MDInSoilMoistNotScaledID		 = MFVarGetID (MDVarRainSoilMoistureNotScaled,  "mm",   MFInput, MFState, MFInitial))  == CMfailed) ||
	    ((_MDInSoilMoistChgNotScaledID	 = MFVarGetID (MDVarRainSoilMoistureChangeNotScaled,  "mm",   MFInput, MFState, MFInitial))  == CMfailed) ||
	    ((_MDInSoilMoistID       		 = MFVarGetID (MDVarRainSoilMoisture,           "mm",   MFInput, MFState, MFBoundary)) == CMfailed) ||
	    ((_MDInSoilAvailWaterCapID 	 	 = MFVarGetID (MDVarSoilAvailWaterCap,          "mm",   MFInput,  MFFlux, MFInitial)) == CMfailed) ||
 	    ((_MDInExcessID           		 = MFVarGetID (MDVarExcess,                     "mm",   MFInput, MFFlux,  MFBoundary)) == CMfailed) ||	// RJS 091813
 	    ((_MDInExcessNotScaledID    	 = MFVarGetID (MDVarExcessNotScaled,            "mm",   MFInput, MFFlux,  MFBoundary)) == CMfailed) ||	// RJS 091813
 	    ((_MDInImpFractionID       		 = MFVarGetID (MDVarImpFracSpatial,             "-",    MFInput,  MFState, MFBoundary)) == CMfailed) ||   // RJS 082812
	    ((_MDInH2OFractionID       	 	 = MFVarGetID (MDVarH2OFracSpatial,             "-",    MFInput,  MFState, MFBoundary)) == CMfailed) ||   // RJS 082812
	    ((_MDInQPreID       	 	 = MFVarGetID (MDVarQPre,                     "m3/s",   MFInput,  MFState, MFInitial)) == CMfailed) ||   // RJS 100213
	    ((_MDInQCurID       	 	 = MFVarGetID (MDVarQCur,                     "m3/s",   MFInput,  MFState, MFInitial)) == CMfailed) ||   // RJS 100213
            ((_MDInQOutID       	 	 = MFVarGetID (MDVarQOut,                     "m3/s",   MFInput,  MFState, MFInitial)) == CMfailed) ||   // RJS 100213
            ((_MDInDischRJSID                    = MFVarGetID (MDVarDischRJS,                 "m3/s",   MFInput,  MFState, MFInitial)) == CMfailed) ||   // RJS 100213
            ((_MDInRiverStorChgID                = MFVarGetID (MDVarRiverStorageChg,  "m3",     MFInput, MFFlux,  MFBoundary)) == CMfailed) ||          // RJS 100213
	    ((_MDInRiverStorageID                = MFVarGetID (MDVarRiverStorage,     "m3",     MFInput, MFState, MFInitial))  == CMfailed) ||          // RJS 100213
            ((_MDInRunoffVolumeID                = MFVarGetID (MDVarRunoffVolume,      "m3/s", MFInput, MFState, MFBoundary)) == CMfailed) ||
	    ((_MDInRainWaterSurplusID            = MFVarGetID (MDVarRainWaterSurplus,     		"mm", MFInput, MFFlux, MFBoundary)) == CMfailed) ||  
            ((_MDInRainSurfRunoffID            = MFVarGetID (MDVarRainSurfRunoff,     		"mm", MFInput, MFFlux, MFBoundary)) == CMfailed) ||            
            ((_MDInRainInfiltrationID            = MFVarGetID (MDVarRainInfiltration,     		"mm", MFInput, MFFlux, MFBoundary)) == CMfailed) ||
	    ((_MDInGrdWatID                	 = MFVarGetID (MDVarGroundWater,         		"mm", MFInput, MFState, MFInitial))  == CMfailed) ||
            ((_MDInGrdWatRechargeID        	 = MFVarGetID (MDVarGroundWaterRecharge, 		"mm", MFInput, MFFlux,  MFBoundary)) == CMfailed) ||
	    ((_MDInBaseFlowID              	 = MFVarGetID (MDVarBaseFlow,            		"mm", MFInput, MFFlux,  MFBoundary)) == CMfailed) ||
	    ((_MDInSnowFallID    			 = MFVarGetID (MDVarSnowFall,       			"mm",   MFInput, MFFlux,  MFBoundary)) == CMfailed) ||
	    ((_MDInSnowMeltID   			 = MFVarGetID (MDVarSnowMelt,       			"mm",   MFInput, MFFlux,  MFBoundary)) == CMfailed) ||
	    ((_MDInSnowPackID   			 = MFVarGetID (MDVarSnowPack,       			"mm",   MFInput, MFState, MFInitial))  == CMfailed) ||
            ((_MDInTotalSurfRunoffID 		 = MFVarGetID (MDVarTotalSurfRunoff, 			"mm",   MFInput, MFFlux,  MFBoundary)) == CMfailed) ||
            ((_MDInPropROStormWaterID      = MFVarGetID (MDVarPropROStormWater,    "-",   MFInput, MFState, MFBoundary)) == CMfailed) ||       // RJS 100313
            ((_MDInPropROSurfaceWaterID    = MFVarGetID (MDVarPropROSurfaceWater,  "-",   MFInput, MFState, MFBoundary)) == CMfailed) ||       // RJS 100313 
            ((_MDInPropROGroundWaterID     = MFVarGetID (MDVarPropROGroundWater,   "-",   MFInput, MFState, MFBoundary)) == CMfailed) ||   
            ((_MDInQStormWaterID         = MFVarGetID (MDVarQStormWater,    "m3/s",    MFInput, MFState, MFBoundary)) == CMfailed) ||       // RJS 100313
            ((_MDInQSurfaceWaterID       = MFVarGetID (MDVarQSurfaceWater,  "m3/s",    MFInput, MFState, MFBoundary)) == CMfailed) ||       // RJS 100313 
            ((_MDInQGroundWaterID        = MFVarGetID (MDVarQGroundWater,   "m3/s",    MFInput, MFState, MFBoundary)) == CMfailed) ||       // RJS 100313  
	    ((_MDInPropRSStormWaterID        = MFVarGetID (MDVarPropRSStormWater,   "-",   MFInput, MFState, MFInitial)) == CMfailed) ||       // RJS 100313
            ((_MDInPropRSSurfaceWaterID      = MFVarGetID (MDVarPropRSSurfaceWater, "-",   MFInput, MFState, MFInitial)) == CMfailed) ||       // RJS 100313 
            ((_MDInPropRSGroundWaterID       = MFVarGetID (MDVarPropRSGroundWater,  "-",   MFInput, MFState, MFInitial)) == CMfailed) ||       // RJS 100313  	    
            ((_MDInPropQinStormWaterID    = MFVarGetID (MDVarPropQinStormWater,   "-",   MFInput, MFState, MFBoundary)) == CMfailed) ||       // RJS 100313
            ((_MDInPropQinSurfaceWaterID  = MFVarGetID (MDVarPropQinSurfaceWater,   "-", MFInput, MFState, MFBoundary)) == CMfailed) ||       // RJS 100313
            ((_MDInPropQinGroundWaterID   = MFVarGetID (MDVarPropQinGroundWater,   "-",  MFInput, MFState, MFBoundary)) == CMfailed) ||       // RJS 100313
            ((_MDInPropRSinStormWaterID   = MFVarGetID (MDVarPropRSinStormWater,   "-",  MFInput, MFState, MFBoundary)) == CMfailed) ||       // RJS 100313
            ((_MDInPropRSinSurfaceWaterID = MFVarGetID (MDVarPropRSinSurfaceWater,  "-", MFInput, MFState, MFBoundary)) == CMfailed) ||       // RJS 100313
            ((_MDInPropRSinGroundWaterID  = MFVarGetID (MDVarPropRSinGroundWater,   "-", MFInput, MFState, MFBoundary)) == CMfailed) ||       // RJS 100313            
            ((_MDInPropROFlagID           = MFVarGetID (MDVarPropROFlag,          "-",   MFInput, MFState, MFBoundary)) == CMfailed) ||
            ((_MDInQFlagID                = MFVarGetID (MDVarQFlag,            "m3/s",   MFInput, MFState, MFBoundary)) == CMfailed) ||
            ((_MDInPropRSFlagID           = MFVarGetID (MDVarPropRSFlag,       "-",      MFInput, MFState, MFInitial)) == CMfailed) || 
            ((_MDInPropQinFlagID          = MFVarGetID (MDVarPropQinFlag,      "-",      MFInput, MFState, MFBoundary))  == CMfailed) ||
            ((_MDInPropRSinFlagID         = MFVarGetID (MDVarPropRSinFlag,     "-",      MFInput, MFState, MFBoundary))  == CMfailed) ||
            ((_MDOutWaterBalanceID        = MFVarGetID (MDVarWaterBalance,      "mm",    MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
	    (MFModelAddFunction(_MDWaterBalance) == CMfailed))
	    return (CMfailed);
        
        break;
        
        case MDinput: 																										       			// RJS 061312
        if (((_MDInRunoffID               = MDRunoffDef           ()) == CMfailed) ||			
            ((_MDOutWaterBalanceID        = MFVarGetID (MDVarWaterBalance,      "mm",    MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
            (MFModelAddFunction (_MDWaterBalanceInput) == CMfailed)) return (CMfailed);														// RJS 061312
        break;	
        case MDinput2: 																										       			// RJS 061312
        if (((_MDInRunoffID               = MDRunoffDef           ()) == CMfailed) ||			
            ((_MDOutWaterBalanceID        = MFVarGetID (MDVarWaterBalance,      "mm",    MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
            (MFModelAddFunction (_MDWaterBalanceInput) == CMfailed)) return (CMfailed);														// RJS 061312
        break;	
        default: MFOptionMessage (optName, optStr, options); return (CMfailed);
        }
	MFDefLeaving ("WaterBalance");
	return (_MDOutWaterBalanceID);	
}