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