Ejemplo n.º 1
0
int MDSmallReservoirCapacityDef () {

	int  optID = MFUnset;
	const char *optStr, *optName = MDVarSmallResCapacity;
	const char *options [] = { MDNoneStr, MDInputStr, MDCalculateStr, (char *) NULL };

	if ((optStr = MFOptionGet (optName)) != (char *) NULL) optID = CMoptLookup (options, optStr, true);
		
	if ((optID == MDnone) || (_MDOutSmallResCapacityID != MFUnset)) return (_MDOutSmallResCapacityID);

	MFDefEntering("SmallReservoirCapacity");
	if ((_MDInIrrGrossDemandID = MDIrrGrossDemandDef  ()) != MFUnset) {
		switch (optID) {
			case MDinput:
			    if ((_MDOutSmallResCapacityID       = MFVarGetID (MDVarSmallResCapacity,          "mm",   MFInput, MFState, MFBoundary))  == CMfailed)
			    	return (CMfailed);
			    break;
			case MDcalculate:
				if ((_MDInIrrGrossDemandID == CMfailed) ||
				    ((_MDInIrrAreaID                    = MDIrrigatedAreaDef ())==  CMfailed) ||
				    ((_MDInRainSurfRunoffID             = MFVarGetID (MDVarRainSurfRunoff,            "mm",  MFInput,  MFFlux,  MFBoundary)) == CMfailed) ||
				    ((_MDOutRainSurfRunoffAccumulatedID = MFVarGetID ("__SurfaceROAccumulated",       "mm",  MFOutput, MFState, MFInitial))  == CMfailed) ||
				    ((_MDOutIrrGrossDemandAccumulatedID = MFVarGetID ("__GrossDemandAccumulated",     "mm",  MFOutput, MFState, MFInitial))  == CMfailed) ||
				    ((_MDInSmallResStorageFractionID    = MFVarGetID (MDVarSmallReservoirStorageFrac, "-",   MFInput,MFState,MFBoundary))  == CMfailed) ||
				    ((_MDOutSmallResCapacityID          = MFVarGetID (MDVarSmallResCapacity,          "mm",  MFOutput, MFState, MFInitial))  == CMfailed) ||
				    (MFModelAddFunction (_MDSmallReservoirCapacity) == CMfailed)) return (CMfailed);
				break;
			default: MFOptionMessage (optName, optStr, options); return (CMfailed);
		}
	}
	MFDefLeaving("SmallReservoirCapacity");
	return (_MDOutSmallResCapacityID);
}
Ejemplo n.º 2
0
int MDBaseFlowDef () {
    float par;
    const char *optStr;

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

    MFDefEntering ("Base flow");
    if (((optStr = MFOptionGet (MDParGroundWatBETA))  != (char *) NULL) && (sscanf (optStr,"%f",&par) == 1)) _MDGroundWatBETA = par;

    if (((_MDInRechargeID       = MDRainInfiltrationDef ()) == CMfailed) ||
            ((_MDInIrrGrossDemandID = MDIrrGrossDemandDef   ()) == CMfailed)) return (CMfailed);

    if ( _MDInIrrGrossDemandID != MFUnset) {
        if (((_MDInSmallResReleaseID    = MDSmallReservoirReleaseDef ()) == CMfailed) ||
                ((_MDInIrrAreaFracID        = MDIrrigatedAreaDef         ()) ==  CMfailed) ||
                ((_MDInIrrReturnFlowID      = MFVarGetID (MDVarIrrReturnFlow,     "mm", MFInput,  MFFlux,  MFBoundary)) == CMfailed) ||
                ((_MDOutIrrUptakeExternalID = MFVarGetID (MDVarIrrUptakeExternal, "mm", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
                ((_MDOutIrrUptakeGrdWaterID = MDIrrUptakeGrdWaterDef     ()) == CMfailed))
            return CMfailed;
    }
    if (((_MDOutGrdWatID                = MFVarGetID (MDVarGroundWater,         "mm", MFOutput, MFState, MFInitial))  == CMfailed) ||
            ((_MDOutGrdWatChgID             = MFVarGetID (MDVarGroundWaterChange,   "mm", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
            ((_MDOutGrdWatRechargeID        = MFVarGetID (MDVarGroundWaterRecharge, "mm", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
            ((_MDOutGrdWatUptakeID          = MFVarGetID (MDVarGroundWaterUptake,   "mm", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
            ((_MDOutBaseFlowID              = MFVarGetID (MDVarBaseFlow,            "mm", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
            (MFModelAddFunction (_MDBaseFlow) == CMfailed)) return (CMfailed);

    MFDefLeaving ("Base flow ");
    return (_MDOutBaseFlowID);
}
Ejemplo n.º 3
0
int MDBaseFlowDef () {
	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 ((_MDInSoilPercolationID = MFVarGetID (MDVarSoilPercolation,     "mm", MFInput, MFFlux,   MFBoundary)) == CMfailed) return (CMfailed); // SZ 10212014
        }
        
        int  optID = MFUnset;                                                                                   // RJS 060214
	const char *optName = MDVarRunoff;                                                                      // RJS 060214
	const char *options [] = { "spatially", MDCalculateStr, MDPnETStr, (char *) NULL };                                // RJS 060214

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

	MFDefEntering ("Base flow");

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

        switch (optID) {
            case MDspatial:
                if ((_MDInGroundWatBETAID     = MFVarGetID(MDParGroundWatBETA,       "1/d", MFInput, MFState, MFBoundary)) == CMfailed) return (CMfailed);
             case MDcalculate: 	
                 if (_MDInGroundWatBETAID == MFUnset) {
                    if (((optStr = MFOptionGet (MDParGroundWatBETA))  != (char *) NULL) && (sscanf (optStr,"%f",&par) == 1)) _MDGroundWatBETA = par;
                 }
                if (((_MDInRechargeID       = MDRainInfiltrationDef ()) == CMfailed) ||
                    ((_MDInIrrGrossDemandID = MDIrrGrossDemandDef   ()) == CMfailed)) return (CMfailed);

                if ( _MDInIrrGrossDemandID != MFUnset) {
                        if (((_MDInSmallResReleaseID    = MDSmallReservoirReleaseDef ()) == CMfailed) ||
                            ((_MDInIrrAreaFracID        = MDIrrigatedAreaDef         ()) ==  CMfailed) ||
                            ((_MDInIrrReturnFlowID      = MFVarGetID (MDVarIrrReturnFlow,     "mm", MFInput,  MFFlux,  MFBoundary)) == CMfailed) ||
                            ((_MDOutIrrUptakeExternalID = MFVarGetID (MDVarIrrUptakeExternal, "mm", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
                            ((_MDOutIrrUptakeGrdWaterID = MDIrrUptakeGrdWaterDef     ()) == CMfailed))
                            return CMfailed;
                 }
                if (((_MDOutGrdWatID                = MFVarGetID (MDVarGroundWater,         "mm", MFOutput, MFState, MFInitial))  == CMfailed) ||
                    ((_MDOutGrdWatChgID             = MFVarGetID (MDVarGroundWaterChange,   "mm", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
                    ((_MDOutGrdWatRechargeID        = MFVarGetID (MDVarGroundWaterRecharge, "mm", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
                    ((_MDOutGrdWatUptakeID          = MFVarGetID (MDVarGroundWaterUptake,   "mm", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
                    ((_MDOutBaseFlowID              = MFVarGetID (MDVarBaseFlow,            "mm", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
                     (MFModelAddFunction (_MDBaseFlow) == CMfailed)) return (CMfailed);
                break;
            case MDPnET:
                if (_MDInGroundWatBETAID == MFUnset) {
                    if (((optStr = MFOptionGet (MDParGroundWatBETA))  != (char *) NULL) && (sscanf (optStr,"%f",&par) == 1)) _MDGroundWatBETA = par;
                 }
                 if (((_MDInRechargeID               = MDRainInfiltrationDef ()) == CMfailed) ||
                     ((_MDOutGrdWatID                = MFVarGetID (MDVarGroundWater,         "mm", MFOutput, MFState, MFInitial))  == CMfailed) ||
                     ((_MDOutGrdWatChgID             = MFVarGetID (MDVarGroundWaterChange,   "mm", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
                     ((_MDOutGrdWatRechargeID        = MFVarGetID (MDVarGroundWaterRecharge, "mm", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
                     ((_MDOutGrdWatUptakeID          = MFVarGetID (MDVarGroundWaterUptake,   "mm", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
                     ((_MDOutBaseFlowID              = MFVarGetID (MDVarBaseFlow,            "mm", MFOutput, MFFlux,  MFBoundary)) == CMfailed) ||
                     (MFModelAddFunction (_MDBaseFlow2) == CMfailed)) return (CMfailed);														// RJS 061312
                break;	      
        }
	MFDefLeaving ("Base flow ");
	return (_MDOutBaseFlowID);
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
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);	
}
Ejemplo n.º 6
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);
}
Ejemplo n.º 7
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);
}
Ejemplo n.º 8
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);
}
Ejemplo n.º 9
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);
}