Exemplo n.º 1
0
VOID CMMControlThread::InputCommand()
{
	DWORD dwRet;

	char szInputBuf[64] = { 0 };

	Usage();
	while (::gets_s(szInputBuf)) {
		std::string strInput = szInputBuf;
		if (strInput.size() < 5) {
			if (strInput.find("stop") || strInput.find("STOP")) {
				dwRet = CheckInputData(strInput, 2);
				if (dwRet != E_RET_SUCCESS) {
					::memset(szInputBuf, 0x00, sizeof(szInputBuf));
					continue;
				}
			}
			SetCommand(strInput);
		}
		else {
			if (strInput.find("start") || strInput.find("START")) {
				dwRet = CheckInputData(strInput, 1);
				if (dwRet != E_RET_SUCCESS) {
					::memset(szInputBuf, 0x00, sizeof(szInputBuf));
					continue;
				}
				SetCommand(strInput);
			}
		}
		Usage();
		::memset(szInputBuf, 0x00, sizeof(szInputBuf));
	}
}
Exemplo n.º 2
0
int MUSLE_AS::Execute()
{
    CheckInputData();
    initialOutputs();
#pragma omp parallel for
    for (int i = 0; i < m_nCells; i++)
    {
        if (m_surfaceRunoff[i] < 0.0001f || m_streamLink[i] > 0)
            m_sedimentYield[i] = 0.f;
        else
        {
            float q = getPeakRunoffRate(i); //equation 2 in memo, peak flow
            float Y = 11.8f * pow(m_surfaceRunoff[i] * m_cellAreaKM * 1000.0f * q, 0.56f)
                      * m_usle_k[i][0] * m_usle_ls[i] * m_usle_c[i] * m_usle_p[i];    //equation 1 in memo, sediment yield

            if (m_snowAccumulation[i] > 0.0001f)
                Y /= exp(3.f * m_snowAccumulation[i] / 25.4f);  //equation 4 in memo, the snow pack effect
            m_sedimentYield[i] = Y * 1000.f; /// kg
		}
		//if(i == 1000) cout << m_sedimentYield[i] << "," << m_surfaceRunoff[i] << endl;
		/// particle size distribution of sediment yield
		m_sandYield[i] = m_sedimentYield[i] * m_detachSand[i];
		m_siltYield[i] = m_sedimentYield[i] * m_detachSilt[i];
		m_clayYield[i] = m_sedimentYield[i] * m_detachClay[i];
		m_smaggreYield[i] = m_sedimentYield[i] * m_detachSmAggre[i];
		m_lgaggreYield[i] = m_sedimentYield[i] * m_detachLgAggre[i];
    }
    return 0;
}
Exemplo n.º 3
0
int DepressionFS::Execute()
{
	initalOutputs();

	if(m_checkInput)
	{
		CheckInputData();	
		m_checkInput = false;
	}

	#pragma omp parallel for
	for (int i = 0; i < m_size; ++i)
	{
		// sr is temporarily used to stored the water depth including the depression storage
		float hWater = m_sr[i];
		if (hWater <= m_depCap[i])
		{
			m_sd[i] = hWater;
			m_sr[i] = 0.f;
		}
		else
		{
			m_sd[i] = m_depCap[i];
			m_sr[i] = hWater - m_depCap[i];
		}
		
		m_storageCapSurplus[i] = m_depCap[i] - m_sd[i];

	}

	return 0;
}
Exemplo n.º 4
0
int main(int argc, char **argv){
	fflush(stdout);
	fprintf(stdout, "\nProgram that generates training, evaluation and test sets for the OPF classifier\n");
	fprintf(stdout, "\nIf you have any problem, please contact: ");
	fprintf(stdout, "\n- [email protected]");
	fprintf(stdout, "\n- [email protected]\n");
	fprintf(stdout, "\nLibOPF version 2.0 (2009)\n");
	fprintf(stdout, "\n"); fflush(stdout);

	if(argc != 6){
		fprintf(stderr, "\nusage opf_split <P1> <P2> <P3> <P4> <P5>");
		fprintf(stderr, "\nP1: input dataset in the OPF file format");
		fprintf(stderr, "\nP2: percentage for the training set size [0,1]");
		fprintf(stderr, "\nP3: percentage for the evaluation set size [0,1] (leave 0 in the case of no learning)");
		fprintf(stderr, "\nP4: percentage for the test set size [0,1]");
		fprintf(stderr, "\nP5: normalize features? 1 - Yes  0 - No\n\n");
		exit(-1);
	}
	Subgraph *g = NULL, *gAux = NULL, *gTraining = NULL, *gEvaluating = NULL, *gTesting = NULL;
	float training_p = atof(argv[2]), evaluating_p = atof(argv[3]), testing_p = atof(argv[4]);
	int normalize = atoi(argv[5]);

	CheckInputData(training_p, evaluating_p, testing_p);

	fprintf(stdout, "\nReading data set ..."); fflush(stdout);
	g = ReadSubgraph(argv[1]);
	fprintf(stdout, " OK"); fflush(stdout);

	if(normalize) opf_NormalizeFeatures(g);

	fprintf(stdout, "\nSplitting data set ..."); fflush(stdout);
	opf_SplitSubgraph(g, &gAux, &gTesting, training_p+evaluating_p);

	if (evaluating_p > 0)
	  opf_SplitSubgraph(gAux, &gTraining, &gEvaluating, training_p/(training_p+evaluating_p));
	else gTraining = CopySubgraph(gAux);

	fprintf(stdout, " OK"); fflush(stdout);

	fprintf(stdout, "\nWriting data sets to disk ..."); fflush(stdout);
	WriteSubgraph(gTraining, "training.dat");
	WriteSubgraphPrototype(gTraining, "trainingp.dat");
	if (evaluating_p > 0) {
		WriteSubgraph(gEvaluating, "evaluating.dat");
		WriteSubgraphPrototype(gEvaluating, "evaluatingp.dat");
	}
	WriteSubgraph(gTesting, "testing.dat");
	WriteSubgraphPrototype(gTesting, "testingp.dat");
	fprintf(stdout, " OK"); fflush(stdout);

	fprintf(stdout, "\nDeallocating memory ...");
	DestroySubgraph(&g);
	DestroySubgraph(&gAux);
	DestroySubgraph(&gTraining);
	DestroySubgraph(&gEvaluating);
	DestroySubgraph(&gTesting);
	fprintf(stdout, " OK\n");

	return 0;
}
Exemplo n.º 5
0
/*
 *	メール送信スレッド
 */
DWORD WINAPI SendMailThread(LPVOID lpParam)
{
	MAILDATA mdat;
	HWND hDlg;
	char attach_filepath[MAX_PATH];
	BOOL attach_exist;
	int mailbody_len;			/*本文の長さ*/
	int subject_len;			/*件名の長さ*/

	hDlg = (HWND)lpParam;

	if(CheckInputData(hDlg) != TRUE){
		return 0;
	}

	InitMailData(&mdat);

	GetDlgItemText(hDlg,IDC_SENDER,mdat.sender,sizeof(mdat.sender));
	GetDlgItemText(hDlg,IDC_MAILFROM,mdat.from,sizeof(mdat.from));
	GetDlgItemText(hDlg,IDC_MAILTO,mdat.to,sizeof(mdat.to));
	GetDlgItemText(hDlg,IDC_MAILPRIORITY,mdat.priority,sizeof(mdat.priority));
	GetDlgItemText(hDlg,IDC_PCNAME,mdat.pc_name,sizeof(mdat.pc_name));
	strcpy(mdat.mailer,"SMILE MAILER");
	strcpy(mdat.reply,mdat.from);

	/*添付ファイルを読み込む、*/
	GetDlgItemText(hDlg,IDC_ATTACHFILENAME,attach_filepath,sizeof(attach_filepath));
	attach_exist = CheckFileExist(attach_filepath);
	if(attach_exist == TRUE){
		/*関数内部でメモリを割り当てるので、必ず後で解放すること。*/
		if(ReadAttachFile(attach_filepath,&mdat) == FALSE){
			StringTableSendMessageBeep(hDlg,WM_SENDMAIL,
					IDS_ERROR_READ_ATTACH_FILE,MB_ICONEXCLAMATION);
		}
	}

	/*本文をダイアログボックスから読み込む、解放を忘れずに*/
	mailbody_len = GetWindowTextLength(GetDlgItem(hDlg,IDC_MAILBODY));
	mdat.body = (char *)GlobalAlloc(GMEM_FIXED,mailbody_len + 1);
	GetDlgItemText(hDlg,IDC_MAILBODY,mdat.body,mailbody_len + 1);

	/*件名をダイアログボックスから読み込む、解放を忘れずに*/
	subject_len = GetWindowTextLength(GetDlgItem(hDlg,IDC_MAILSUBJECT));
	mdat.subject = (char *)GlobalAlloc(GMEM_FIXED,subject_len + 1);
	GetDlgItemText(hDlg,IDC_MAILSUBJECT,mdat.subject,subject_len + 1);

	GetMXAndSendMail(hDlg,&mdat,attach_exist);

	GlobalFree(mdat.attach);
	GlobalFree(mdat.body);
	GlobalFree(mdat.subject);

	return 0;
}
Exemplo n.º 6
0
int IUH_OL::Execute() {
    CheckInputData();
    InitialOutputs();
    // delete value of last time step
    for (int n = 0; n <= m_nSubbsns; n++) {
        m_Q_SBOF[n] = 0.f;
    }
#pragma omp parallel for
    for (int i = 0; i < m_nCells; i++) {
        //forward one time step
        for (int j = 0; j < m_cellFlowCols - 1; j++) {
            m_cellFlow[i][j] = m_cellFlow[i][j + 1];
        }
        m_cellFlow[i][m_cellFlowCols - 1] = 0.f;

        if (m_surfRf[i] <= 0.f) continue;

        int min = CVT_INT(m_iuhCell[i][0]);
        int max = CVT_INT(m_iuhCell[i][1]);
        int col = 2;
        for (int k = min; k <= max; k++) {
            m_cellFlow[i][k] += m_surfRf[i] * 0.001f * m_iuhCell[i][col] * m_cellArea / m_TimeStep;
            col++;
        }
    }
    // See https://github.com/lreis2415/SEIMS/issues/36 for more descriptions. By lj
#pragma omp parallel
    {
        float* tmp_qsSub = new float[m_nSubbsns + 1];
        for (int i = 0; i <= m_nSubbsns; i++) {
            tmp_qsSub[i] = 0.f;
        }
#pragma omp for
        for (int i = 0; i < m_nCells; i++) {
            tmp_qsSub[CVT_INT(m_subbsnID[i])] += m_cellFlow[i][0]; //get new value
            m_OL_Flow[i] = m_cellFlow[i][0];
            m_OL_Flow[i] = m_OL_Flow[i] * m_TimeStep * 1000.f / m_cellArea; // m3/s -> mm
        }
#pragma omp critical
        {
            for (int i = 1; i <= m_nSubbsns; i++) {
                m_Q_SBOF[i] += tmp_qsSub[i];
            }
        }
        delete[] tmp_qsSub;
        tmp_qsSub = nullptr;
    } /* END of #pragma omp parallel */

    for (int n = 1; n <= m_nSubbsns; n++) {
        //get overland flow routing for entire watershed.
        m_Q_SBOF[0] += m_Q_SBOF[n];
    }
    return 0;
}
Exemplo n.º 7
0
int SNO_SP::Execute() {
    CheckInputData();
    InitialOutputs();
    /// determine the shape parameters for the equation which describes area of
    /// snow cover as a function of amount of snow
    if (m_snowCoverCoef1 == NODATA_VALUE || m_snowCoverCoef2 == NODATA_VALUE) {
        GetScurveShapeParameter(0.5f, 0.95f, m_snowCover50, 0.95f, &m_snowCoverCoef1, &m_snowCoverCoef2);
    }
    /// adjust melt factor for time of year, i.e., smfac in snom.f
    // which only need to computed once.
    float sinv = CVT_FLT(sin(2.f * PI / 365.f * (m_dayOfYear - 81.f)));
    float cmelt = (m_csnow6 + m_csnow12) * 0.5f + (m_csnow6 - m_csnow12) * 0.5f * sinv;
#pragma omp parallel for
    for (int rw = 0; rw < m_nCells; rw++) {
        /// estimate snow pack temperature
        m_packT[rw] = m_packT[rw] * (1 - m_lagSnow) + m_meanTemp[rw] * m_lagSnow;
        /// calculate snow fall
        m_SA[rw] += m_snowAccum[rw] - m_SE[rw];
        if (m_meanTemp[rw] < m_snowTemp) {
            /// precipitation will be snow
            m_SA[rw] += m_kblow * m_netPcp[rw];
            m_netPcp[rw] *= (1.f - m_kblow);
        }

        if (m_SA[rw] < 0.01) {
            m_snowMelt[rw] = 0.f;
        } else {
            float dt = m_maxTemp[rw] - m_t0;
            if (dt < 0) {
                m_snowMelt[rw] = 0.f; //if temperature is lower than t0, the snowmelt is 0.
            } else {
                //calculate using eq. 1:2.5.2 SWAT p58
                m_snowMelt[rw] = cmelt * ((m_packT[rw] + m_maxTemp[rw]) * 0.5f - m_t0);
                // adjust for areal extent of snow cover
                float snowCoverFrac = 0.f; //fraction of HRU area covered with snow
                if (m_SA[rw] < m_snowCoverMax) {
                    float xx = m_SA[rw] / m_snowCoverMax;
                    snowCoverFrac = xx / (xx + exp(m_snowCoverCoef1 = m_snowCoverCoef2 * xx));
                } else {
                    snowCoverFrac = 1.f;
                }
                m_snowMelt[rw] *= snowCoverFrac;
                if (m_snowMelt[rw] < 0.f) m_snowMelt[rw] = 0.f;
                if (m_snowMelt[rw] > m_SA[rw]) m_snowMelt[rw] = m_SA[rw];
                m_SA[rw] -= m_snowMelt[rw];
                m_netPcp[rw] += m_snowMelt[rw];
                if (m_netPcp[rw] < 0.f) m_netPcp[rw] = 0.f;
            }
        }
    }
    return 0;
}
Exemplo n.º 8
0
int DepressionFSDaily::Execute() {
    CheckInputData();
    InitialOutputs();
#pragma omp parallel for
    for (int i = 0; i < m_nCells; i++) {
        //////////////////////////////////////////////////////////////////////////
        // runoff
        if (m_depCap[i] < 0.001f) {
            m_sr[i] = m_pe[i];
            m_sd[i] = 0.f;
        } else if (m_pe[i] > 0.f) {
            float pc = m_pe[i] - m_depCap[i] * log(1.f - m_sd[i] / m_depCap[i]);
            float deltaSd = m_pe[i] * exp(-pc / m_depCap[i]);
            if (deltaSd > m_depCap[i] - m_sd[i]) {
                deltaSd = m_depCap[i] - m_sd[i];
            }
            m_sd[i] += deltaSd;
            m_sr[i] = m_pe[i] - deltaSd;
        } else {
            m_sd[i] += m_pe[i];
            m_sr[i] = 0.f;
        }

        //////////////////////////////////////////////////////////////////////////
        // evaporation
        if (m_sd[i] > 0) {
            /// TODO: Is this logically right? PET is just potential, which include
            ///       not only ET from surface water, but also from plant and soil.
            ///       Please Check the corresponding theory. By LJ.
            // evaporation from depression storage
            if (m_pet[i] - m_ei[i] < m_sd[i]) {
                m_ed[i] = m_pet[i] - m_ei[i];
            } else {
                m_ed[i] = m_sd[i];
            }
            m_sd[i] -= m_ed[i];
        } else {
            m_ed[i] = 0.f;
            m_sd[i] = 0.f;
        }
        if (m_impoundTriger != nullptr && FloatEqual(m_impoundTriger[i], 0.f)) {
            if (m_potVol != nullptr) {
                m_potVol[i] += m_sr[i];
                m_potVol[i] += m_sd[i];
                m_sr[i] = 0.f;
                m_sd[i] = 0.f;
            }
        }
    }
    return true;
}
Exemplo n.º 9
0
//Execute module
int SOL_WB::Execute()
{	
	CheckInputData();

	if(m_subbasinList == NULL)
	{
		m_subbasinSelectedCount = 1;
		m_subbasinSelected = new float[1];
		m_subbasinSelected[0] = 0;
		getSubbasinList(m_nCells, m_subbasin, m_subbasinSelectedCount, m_subbasinSelected);
		delete m_subbasinSelected;
	}

	return 0;
}
Exemplo n.º 10
0
//! 
int clsPI_STORM::Execute()
{
#pragma omp parallel for
    for (int i = 0; i < m_nCells; ++i)
    {
        //m_P[i] = m_P[i] * m_dt / 3600;
        if (m_P[i] > 0.f)
            m_P[i] = m_P[i] * m_dt / 3600.f * cos(atan(m_s0[i]));
        else
            m_P[i] = 0.f;
    }

    //initial the state variable
    if (this->m_interceptionLast == NULL)
    {
        CheckInputData();

        m_interceptionLast = new float[m_nCells];
        //this->m_evaporation = new float[m_nCells];
        this->m_interceptionLoss = new float[m_nCells];
        this->m_netPrecipitation = new float[m_nCells];
#pragma omp parallel for
        for (int i = 0; i < this->m_nCells; i++)
        {
            m_interceptionLast[i] = this->m_Init_IS;
        }
    }
    int jday = JulianDay(this->m_date);
#pragma omp parallel for
    for (int i = 0; i < this->m_nCells; i++)
    {
        //float PE = this->m_PET[i] * this->m_K_pet;

        //evaporation
        //if(this->m_interceptionLast[i] <= 0)			this->m_evaporation[i] = 0.0f;
        //else if(this->m_interceptionLast[i] > PE)	this->m_evaporation[i] = PE;
        //else														this->m_evaporation[i] = this->m_interceptionLast[i];

        //interception storage capacity
        //int julian = 100;
        double degree = 2 * PI * (jday - 87) / 365.f;
        float min = this->m_minInterception[i];
        float max = this->m_maxInterception[i];
        double capacity = min + (max - min) * pow(0.5 + 0.5 * sin(degree), double(this->m_Pi_b));

        //interception
        //double availableSpace = capacity - this->m_interceptionLast[i] + this->m_evaporation[i];
        double availableSpace = capacity - this->m_interceptionLast[i];
        if (availableSpace < this->m_P[i])
            this->m_interceptionLoss[i] = float(availableSpace);
        else
            this->m_interceptionLoss[i] = this->m_P[i];

        //net precipitation
        this->m_netPrecipitation[i] = m_P[i] - m_interceptionLoss[i];

        //override the interception storage of last time step
        //this->m_interceptionLast[i] += this->m_interceptionLoss[i] - this->m_evaporation[i];
        m_interceptionLast[i] += m_interceptionLoss[i];
    }
    return 0;
}
Exemplo n.º 11
0
int YLD::Execute()
{
    CheckInputData();
    initialOutputs();

    struct tm timeinfo;
    LocalTime(m_date, &timeinfo);
    timeinfo.tm_mon = 0;
    timeinfo.tm_mday = 0;
    timeinfo.tm_hour = 0;
    timeinfo.tm_min = 0;
    timeinfo.tm_sec = 0;
    timeinfo.tm_isdst = false;
    time_t tYear = mktime(&timeinfo);

    time_t harvestDate = tYear + m_harvestDate;

#pragma omp parallel for
    for (int i = 0; i < m_nCells; i++)
    {
        if (m_date > harvestDate && !m_harvested)
        {
            m_harvested = true;
            m_common->m_classification = (int) (m_classification[i]);
            //Harvest index
            //float harvestIndex = 0.0f;// potential harvest index for a given day
            //float totalPlantET = 0.0f;//actual ET simulated during life of plant
            //float totalPlantPET = 0.0f;//potential ET simulated during life of plant
            ////get total ET and PET(see grow.f Line 289-292) from zhiqiang
            if (m_frPHU[i] > 0.5 && m_frPHU[i] < m_frDeclineLAI[i])
            {
                m_totalPlantET[i] += m_totalWaterUptake[i] + m_soilET[i];
                m_totalPlantPET[i] += m_PET[i];
            }
            // water deficiency factor
            m_wur[i] = 100.0f;
            if (m_totalPlantPET[i] > 10)
                m_wur[i] *= m_totalPlantET[i] / m_totalPlantPET[i];

            //get optimal harvest index, p309 5:2.4.1
            m_HI[i] = m_HiOpt[i] * 100.0f * m_frPHU[i] / (100.0f * m_frPHU[i] + exp(11.1f - 10.0f * m_frPHU[i]));
            m_Hiact[i] = m_HI[i] - m_HiMin[i] * (m_wur[i] / (m_wur[i] + exp(6.13f - 0.0883f * m_wur[i]))) + m_HiMin[i];

            m_HI[i] = min(m_HI[i], m_Hiact[i]);
            //float yield = 0.0f;
            if (m_HiOpt[i] > 1.001)
                m_yield[i] = m_biomass[i] * (1.0f - 1.0f / (1.0f + m_HI[i]));
            else
                m_yield[i] = m_biomassAG[i] * m_HI[i];
            m_yield[i] = max(0.0f, m_yield[i]);
            m_harvestEfficiency[i] = 0.5f; //harvestEfficiency read from database
            //IsGrain should read from database
            if (m_common->IsGrain())//grain harvest, no residue, see harvgrainop.f
            {
                m_yield[i] *= m_harvestEfficiency[i];
                m_yieldN[i] = max(0.0f, min(m_yield[i] * m_frNyld[i], 0.85f * m_biomassN[i]));
                m_yieldP[i] = max(0.0f, min(m_yield[i] * m_frPyld[i], 0.85f * m_biomassP[i]));

                m_biomass[i] -= m_yield[i];
            }
            else //biomass harvest, has residue, residue redistribute to soil layer, see harvestop.f
            {
                //divide yield to two parts:clip and yield
                m_clip[i] = m_yield[i] * (1 - m_harvestEfficiency[i]);
                m_yield[i] -= m_clip[i];
                m_clip[i] = max(0.0f, m_clip[i]);
                m_yield[i] = max(0.0f, m_yield[i]);

                //harvest index override  read from database
                //get N&P in clip and yield[i]
                m_yieldN[i] = max(0.0f, min(m_yield[i] * m_frNyld[i], 0.8f * (m_biomassN[i])));
                m_yieldP[i] = max(0.0f, min(m_yield[i] * m_frPyld[i], 0.8f * (m_biomassP[i])));
                m_clipN[i] = max(0.0f, min(m_clip[i] * m_frNyld[i], m_biomassN[i] -
                                                                    m_yieldN[i])); //N in clip residual,needed by nitrient cycling module
                m_clipP[i] = max(0.0f, min(m_clip[i] * m_frPyld[i], m_biomassP[i] -
                                                                    m_yieldP[i])); //P in clip residual,needed by nitrient cycling module
                //reset LAI, frPHU and root fraction
                m_removeFraction[i] = 1.0f; //the fraction of remove part to aboveground part
                if (m_biomass[i] - m_biomassRoot[i] > 1.0e-6)
                    m_removeFraction[i] = (m_yield[i] + m_clip[i]) / (m_biomass[i] - m_biomassRoot[i]);
                m_removeFraction[i] = min(1.0f, m_removeFraction[i]);

                //root part
                m_rootFraction[i] = m_biomassRoot[i] / m_biomass[i];
                m_rootLeft[i] = (m_biomass[i] - m_biomassRoot[i]) * (1 - m_removeFraction[i]) * m_rootFraction[i] /
                                (1.0f - m_rootFraction[i]);
                m_rootRemove[i] = m_biomassRoot[i] - m_rootLeft[i];  //removed root as residual
                m_rootRemoveFraction[i] = 0.0f;
                if (m_biomassRoot[i] > 1.0e-6) m_rootRemoveFraction[i] = m_rootRemove[i] / (m_biomassRoot[i]);
                m_rootRemoveN[i] = m_rootRemoveFraction[i] * (m_biomassN[i]);
                m_rootRemoveP[i] = m_rootRemoveFraction[i] * (m_biomassP[i]);

                //remove aboveground and root biomass from total biomass
                //change the LAI and growth step
                if (m_biomass[i] > 0.001)
                {
                    m_LAI[i] *= 1.0f - m_removeFraction[i];
                    if (m_frPHU[i] < 0.999)
                        m_frPHU[i] *= 1.0f - m_removeFraction[i];

                    m_biomass[i] -= m_yield[i] + m_clip[i] + m_rootRemove[i];
                    m_biomassN[i] -= m_yieldN[i] + m_clipN[i] + m_rootRemoveN[i];
                    m_biomassP[i] -= m_yieldP[i] + m_clipP[i] + m_rootRemoveP[i];

                    m_biomass[i] = min(0.0f, m_biomass[i]);
                    m_biomassN[i] = min(0.0f, m_biomassP[i]);
                    m_biomassP[i] = min(0.0f, m_biomassP[i]);

                    m_biomassRoot[i] = m_biomass[i] * (0.4f - 0.2f * m_frPHU[i]);
                }
                else
                {
                    m_biomass[i] = 0.0f;
                    m_biomassN[i] = 0.0f;
                    m_biomassP[i] = 0.0f;
                    m_biomassRoot[i] = 0.0f;

                    m_LAI[i] = 0.0f;
                    m_frPHU[i] = 0.0f;
                }
            }
        }
    }

    //m_lastSWE = m_swe;
    return 0;
}
Exemplo n.º 12
0
int PER_PI::Execute()
{
	CheckInputData();

	if(m_perc == NULL) 
	{
		m_perc = new float*[m_nCells];

		#pragma omp parallel for
		for (int i = 0; i < m_nCells; i++)
		{
			m_perc[i] = new float[m_nSoilLayers];
			for (int j = 0; j < m_nSoilLayers; j++)
				m_perc[i][j] = 0.f;
		}
	}
	if(m_upSoilDepth == NULL)
		m_upSoilDepth = new float[m_nSoilLayers];
	#pragma omp parallel for
	for (int i = 0; i < m_nCells; i++)
	{
		float k, maxSoilWater, fcSoilWater, swater;
		// Update soil layers from solid two layers to multi-layers by m_nSoilLayers. By LJ
		int curSoilLayers = -1, j;
		m_upSoilDepth[0] =	m_soilDepth[i][0];
		for(j = 1; j < m_nSoilLayers; j++)
		{
			if(!FloatEqual(m_soilDepth[i][j],NODATA_VALUE))
				m_upSoilDepth[j] = m_soilDepth[i][j] - m_soilDepth[i][j-1];
			else
				break;
		}
		curSoilLayers = j;

		m_somo[i][0] += m_infil[i] / m_upSoilDepth[0];
		for (int j = 0; j < curSoilLayers; j++)
		{
			//No movement if soil moisture is below field capacity
			m_perc[i][j] = 0.f;
			// for the upper two layers, soil may be frozen
			if(j == 0 && m_soilT[i] <= m_frozenT) 
				continue;
			if (m_somo[i][j] > m_fc[i][j])
			{
				maxSoilWater = m_upSoilDepth[j] * m_porosity[i][j];
				swater = m_upSoilDepth[j] * m_somo[i][j];

				fcSoilWater = m_upSoilDepth[j] * m_fc[i][j];
				
				//the moisture content can exceed the porosity in the way the algorithm is implemented
				if (m_somo[i][j] > m_porosity[i][j])
					k = m_ks[i][j];
				else
				{
					float dcIndex = 2.f/m_poreIndex[i][j] + 3.f; // pore disconnectedness index
					k = m_ks[i][j] * pow(m_somo[i][j]/m_porosity[i][j], dcIndex);
				}

				m_perc[i][j] = k * m_dt/3600.f;

				if(swater - m_perc[i][j] < fcSoilWater)
					m_perc[i][j] = swater - fcSoilWater;
				else if(swater - m_perc[i][j] > maxSoilWater)
					m_perc[i][j] = swater - maxSoilWater;

				//Adjust the moisture content in the current layer, and the layer immediately below it
				m_somo[i][j] -= m_perc[i][j]/m_upSoilDepth[j];

				if(j < curSoilLayers-1)
					m_somo[i][j+1] += m_perc[i][j]/m_upSoilDepth[j+1];

				if(m_somo[i][j] != m_somo[i][j] || m_somo[i][j] < 0.f)
				{
					cout << MID_PER_PI<<" CELL:" << i <<", Layer: "<<j<< "\tPerco:" << swater << "\t" << 
						fcSoilWater << "\t" << m_perc[i][j] << "\t" << m_upSoilDepth[j] << "\tValue:" << m_somo[i][j] << endl;
					throw ModelException(MID_PER_PI, "Execute", "moisture is less than zero.");
				}
			}
		}
	}
	return 0;
}
Exemplo n.º 13
0
int PER_PI::Execute()
{
    CheckInputData();
	initialOutputs();
    
//#pragma omp parallel for
    for (int i = 0; i < m_nCells; i++)
    {
        float k = 0.f, maxSoilWater = 0.f, fcSoilWater = 0.f;
		float swater = 0.f;//, wpSoilWater = 0.f;        
        /// firstly, assume all infiltrated water is added to the first soil layer.
		m_soilStorage[i][0] += m_infil[i];
		/// secondly, model water percolation across layers
        for (int j = 0; j < (int)m_nSoilLayers[i]; j++)
        {
            // for the upper two layers, soil may be frozen
            // No movement if soil moisture is below field capacity
            if (j == 0 && m_soilT[i] <= m_frozenT) 
                continue;
			swater = m_soilStorage[i][j];
			maxSoilWater = m_sat[i][j];
			fcSoilWater = m_fc[i][j];
			//wpSoilWater = m_wp[i][j];

            if (swater > fcSoilWater)
            {
                //the moisture content can exceed the porosity in the way the algorithm is implemented
                if (swater > maxSoilWater)
                    k = m_ks[i][j];
                else
                {
                    float dcIndex = 2.f / m_poreIndex[i][j] + 3.f; // pore disconnectedness index
					k = m_ks[i][j] * pow(swater / maxSoilWater, dcIndex);
                }

                m_perc[i][j] = k * m_dt / 3600.f;  /// mm
				
                if (swater - m_perc[i][j] > maxSoilWater)
                    m_perc[i][j] = swater - maxSoilWater;
                else if (swater - m_perc[i][j] < fcSoilWater)
                    m_perc[i][j] = swater - fcSoilWater;

                //Adjust the moisture content in the current layer, and the layer immediately below it
                m_soilStorage[i][j] -= m_perc[i][j];// / m_soilThick[i][j];
                if (j < m_nSoilLayers[i] - 1)
                    m_soilStorage[i][j + 1] += m_perc[i][j];// / m_soilThick[i][j + 1];

				
                //if (m_soilStorage[i][j] != m_soilStorage[i][j] || m_soilStorage[i][j] < 0.f)
                //{
                //    cout << MID_PER_PI << " CELL:" << i << ", Layer: " << j << "\tPerco:" << swater << "\t" <<
                //    fcSoilWater << "\t" << m_perc[i][j] << "\t" << m_soilThick[i][j] << "\tValue:" << m_soilStorage[i][j] <<
                //    endl;
                //    throw ModelException(MID_PER_PI, "Execute", "moisture is less than zero.");
                //}
            }
			else
			{
				for (int j = 0; j < (int)m_nSoilLayers[i]; j++)
					m_perc[i][j] = 0.f;
			}
			/// update total soil water content
			m_soilStorageProfile[i] = 0.f;
			for (int ly = 0; ly < (int)m_nSoilLayers[i]; ly++)
				m_soilStorageProfile[i] += m_soilStorage[i][ly];
        }
    }
    return 0;
}
Exemplo n.º 14
0
int ReservoirMethod::Execute()
{
	// check the data
	if (!CheckInputData()) 
		return -1;
	
	//read subbasin information
	if(m_subbasinList.size() == 0) 
		getSubbasinList();

	//initial results
	if(m_D_Revap == NULL) 
		m_D_Revap = new float[m_nCells];

	int nLen = m_subbasinList.size() + 1;

	if(m_T_RG == NULL) 
	{
		m_T_RG = new float[nLen];
		m_T_QG = new float[nLen];
		m_petSubbasin = new float[nLen];
		m_gwStore = new float[nLen];
	}

	//if(m_T_GWWB == NULL && m_subbasinSelectedCount > 0 && m_subbasinSelected != NULL) 
	//{
	//	m_T_GWWB = new float*[m_subbasinSelectedCount];
	//	for(int i=0; i<m_subbasinSelectedCount; i++) 
	//		m_T_GWWB[i] = new float[6];
	//}
	//cout << "nSubbasins:\t" << m_nSubbasins << endl;
	for(int i = 0; i < m_nSubbasins; i++)
	{
		int subbasinID = i+1;
		subbasin *sub = m_subbasinList[i];
		//cout << "subbasin ID: " << subbasinID << "\t" << sub << endl;

		float gwBank = 0.0f;
		if(m_VgroundwaterFromBankStorage != NULL)//at the first time step m_VgroundwaterFromBankStorage is null 
			gwBank = m_VgroundwaterFromBankStorage[subbasinID];

		sub->setInputs(m_D_PET, m_D_EI, m_D_ED, m_D_ES, m_perc, gwBank);	//caculate
		m_T_RG[subbasinID] = sub->getRG();				//get rg of specific subbasin
		m_T_QG[subbasinID] = sub->getQG();				//get qg of specific subbasin
		m_petSubbasin[subbasinID] = sub->getPET();
		m_gwStore[subbasinID] = sub->getGW();
	}
	
	m_T_RG[0] = subbasin::subbasin2basin("RG", &m_subbasinList);  // get rg of entire watershed
	m_T_QG[0] = subbasin::subbasin2basin("QG", &m_subbasinList);  // get qg of entire watershed
	m_petSubbasin[0] = subbasin::subbasin2basin("PET", &m_subbasinList);
	m_gwStore[0] = subbasin::subbasin2basin("GW", &m_subbasinList);

	//get D_Revap
	for(int i = 0; i < m_nSubbasins; i++)
	{
		subbasin* sub = m_subbasinList[i];
		if(!(sub->getIsRevapChanged())) //if the revap is the same with last time step, do not set its value to m_D_Revap.
			continue; 

		int* cells = sub->getCells();
		int nCells = sub->getCellCount();
		int index = 0;
		for(int i = 0; i < nCells; i++)
		{
			index = cells[i];
			float depth2 = m_rootDepth[index] - m_upSoilDepth;
			m_soilMoisture[index][m_nSoilLayers-1] += sub->getEG()/depth2;
		}
	}

	return 0;
}
Exemplo n.º 15
0
int ReservoirMethod::Execute()
{
    if (!CheckInputData()) return -1;
	initialOutputs();
    float QGConvert = 1.f * m_CellWidth * m_CellWidth / (m_TimeStep) / 1000.f; // mm ==> m3/s
	for (vector<int>::iterator it = m_subbasinIDs.begin(); it!=m_subbasinIDs.end();it++)
    {
		int subID = *it;
		Subbasin *curSub = m_subbasinsInfo->GetSubbasinByID(subID);

		// get percolation from the bottom soil layer at the subbasin scale
		int curCellsNum = curSub->getCellCount();
		int *curCells = curSub->getCells();
		float perco = 0.f;
#pragma omp parallel for reduction(+:perco)
		for (int i = 0; i < curCellsNum; i++)
		{
			int index = 0;
			index = curCells[i];
			perco += m_perc[index][(int)m_soilLayers[index]-1];
		}
		perco /= curCellsNum; // mean mm
		/// percolated water ==> vadose zone ==> shallow aquifer ==> deep aquifer
		/// currently, for convenience, we assume a small portion of the percolated water
		/// will enter groundwater. By LJ. 2016-9-2
		float ratio2gw = 1.f;
		perco *= ratio2gw;
		curSub->setPerco(perco);

		//if (perco > 0.f)
		//{
		//	cout << "subID: "<<subID<<", perco mean: "<<perco << endl;
		//}

		//calculate EG, i.e. Revap
		float revap = 0.f;
		float fPET = 0.f;
		float fEI = 0.f;
		float fED = 0.f;
		float fES = 0.f;
		float plantEP = 0.f;
		fPET = Sum(curCellsNum, curCells, m_D_PET) / curCellsNum;
		fEI = Sum(curCellsNum, curCells, m_D_EI) / curCellsNum;
		fED = Sum(curCellsNum, curCells, m_D_ED) / curCellsNum;
		fES = Sum(curCellsNum, curCells, m_D_ES) / curCellsNum;
		plantEP = Sum(curCellsNum, curCells, m_plantEP) / curCellsNum;

		curSub->setPET(fPET);
		
		//if percolation < 0.01, EG will be 0. if percolation >= 0.01, EG will be calculated by equation (why? this is not used currently. Junzhi Liu 2016-08-14).
		//if (perco >= 0.01f)
		//{
			revap = (fPET - fEI - fED - fES - plantEP) * m_gwStore[subID] / m_GWMAX;
			if (revap != revap)
				cout <<"fPET: "<<fPET<<", fEI: "<<fEI<<", fED: "<<fED<<", fES: "<<fES<<", plantEP: "<<plantEP
				<<"gwStore: "<<subID<<","<<m_gwStore[subID]<<endl;
			revap = max(revap, 0.f);
			revap = min(revap, perco);
		//}
		//float prevRevap = curSub->getEG();
		//if (prevRevap != revap)
		//{
		//	curSub->setEG(revap);
		//	curSub->setIsRevapChanged(true);
		//}
		//else
		//	curSub->setIsRevapChanged(false);		
		curSub->setEG(revap);
		
		//deep percolation
		float percoDeep = perco * m_dp_co; 
		curSub->setPerde(percoDeep);

		// groundwater runoff (mm)
		float slopeCoef = curSub->getSlopeCoef();
		float kg = m_Kg * slopeCoef;
		float groundRunoff = kg * pow(m_gwStore[subID], m_Base_ex); //mm
		if (groundRunoff  != groundRunoff )
			cout << groundRunoff;

		float groundQ = groundRunoff * curCellsNum * QGConvert; // groundwater discharge (m3/s)

		float groundStorage = m_gwStore[subID];
		groundStorage += (perco - revap - percoDeep - groundRunoff);

		//add the ground water from bank storage, 2011-3-14
		float gwBank = 0.f;
		// at the first time step m_VgroundwaterFromBankStorage is NULL
		if (m_VgroundwaterFromBankStorage != NULL)
			gwBank = m_VgroundwaterFromBankStorage[subID];
		groundStorage += gwBank / curSub->getArea() * 1000.f;

		groundStorage = max(groundStorage, 0.f);
		if (groundStorage > m_GWMAX)
		{
			groundRunoff += (groundStorage - m_GWMAX);
			groundQ = groundRunoff * curCellsNum * QGConvert; // groundwater discharge (m3/s)
			groundStorage = m_GWMAX;
		}
		curSub->setRG(groundRunoff);
		curSub->setGW(groundStorage);
		curSub->setQG(groundQ);
		if (groundStorage != groundStorage)
		{
			ostringstream oss;
			oss << perco << "\t" << revap << "\t" << percoDeep << "\t" << groundRunoff << "\t" << m_gwStore[subID] << "\t" << m_Kg << "\t" <<
				m_Base_ex << "\t" << slopeCoef << endl;
			throw ModelException("Subbasin", "setInputs", oss.str());
		}
		m_T_Perco[subID] = curSub->getPerco();
		m_T_Revap[subID] = curSub->getEG();
		m_T_PerDep[subID] = curSub->getPerde();
        m_T_RG[subID] = curSub->getRG();                //get rg of specific subbasin
        m_T_QG[subID] = curSub->getQG();                //get qg of specific subbasin
        m_petSubbasin[subID] = curSub->getPET();
        m_gwStore[subID] = curSub->getGW();
    }

	m_T_Perco[0] = m_subbasinsInfo->subbasin2basin(VAR_PERCO);
	m_T_Revap[0] = m_subbasinsInfo->subbasin2basin(VAR_REVAP);
	m_T_PerDep[0] = m_subbasinsInfo->subbasin2basin(VAR_PERDE);
	m_T_RG[0] = m_subbasinsInfo->subbasin2basin(VAR_RG);  // get rg of entire watershed
	m_gwStore[0] = m_subbasinsInfo->subbasin2basin(VAR_GW_Q);
	m_T_QG[0] = m_subbasinsInfo->subbasin2basin(VAR_QG);  // get qg of entire watershed

	// output to GWWB
	for (int i = 0; i <= m_nSubbasins; i++)
	{
		m_T_GWWB[i][0] = m_T_Perco[i];
		m_T_GWWB[i][1] = m_T_Revap[i];
		m_T_GWWB[i][2] = m_T_PerDep[i];
		m_T_GWWB[i][3] = m_T_RG[i];
		m_T_GWWB[i][4] = m_gwStore[i];
		m_T_GWWB[i][5] = m_T_QG[i];
	}

	// update soil moisture
	for (vector<int>::iterator it = m_subbasinIDs.begin(); it!=m_subbasinIDs.end();it++)
	{
		Subbasin *sub = m_subbasinsInfo->GetSubbasinByID(*it);
        int *cells = sub->getCells();
        int nCells = sub->getCellCount();
        int index = 0;
        for (int i = 0; i < nCells; i++)
        {
            index = cells[i];
            m_soilStorage[index][(int)m_soilLayers[index] - 1] += sub->getEG();
			// TODO: Is it need to allocate revap to each soil layers??? By LJ
        }
    }
    return 0;
}
XBOX::VError VChromeDbgHdlPage::TreatMsg()
{		
	XBOX::VError		l_err;
	XBOX::VString		l_cmd;
	XBOX::VString		l_resp;
	bool				l_found;
	sBYTE*				l_id;
	ChrmDbgMsg_t		l_msg;
	bool				l_msg_found;

	l_err = VE_OK;

	l_cmd = K_UNKNOWN_CMD;
	l_found = false;
	l_err = CheckInputData();

	VString l_trace("VChromeDbgHdlPage::TreatMsg Method=");
	l_trace += fMethod;
	if (fParams)
	{
		l_trace += " ,";
		VString l_params = "params=<";
		l_params.AppendCString(fParams);
		l_params += ">";
		l_trace += l_params;
	}
	sPrivateLogHandler->Put( (l_err != VE_OK ? WAKDBG_ERROR_LEVEL : WAKDBG_INFO_LEVEL),l_trace);

	if (!l_err)
	{
		DebugMsg("VChromeDbgHdlPage::TreatMsg Method='%S', Id='%s',Params='%s'\n",&fMethod,fId,(fParams ? fParams : "."));
	}
	else
	{
		DebugMsg("VChromeDbgHdlPage::TreatMsg CheckInputData pb !!!!\n");
	}

	l_cmd = K_APP_CAC_GET_FRA_WIT_MAN;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_APP_CAC_GET_FRA_WIT_MAN_STR1);
	}
#if 1
	l_cmd = K_APP_CAC_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	

		l_resp = K_APP_CAC_ENA_STR1;
		l_err = SendMsg(l_resp);
		if (!l_err)
		{
			l_err = SendResult(K_EMPTY_STR);
		}
	}

	l_cmd = K_DBG_REM_BRE;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		sBYTE	*l_end;
		sBYTE	*l_tmp;
		l_tmp = strstr(fParams,K_BRK_PT_ID_STR);
		if (l_tmp)
		{
			l_tmp += strlen(K_BRK_PT_ID_STR)+1;// +1 to skip the '"'

			l_end = strchr(l_tmp,'"');
			if (l_end)
			{
				*l_end = 0;
				/*if (strstr(l_tmp,K_FILE_STR) == l_tmp)
				{
					l_tmp += strlen(K_FILE_STR);
				}*/
				l_end = strchr(l_tmp,':');
				if (l_end)
				{
					sscanf(l_end,":%d:",&l_msg.data.Msg.fLineNumber);
					*l_end = 0;
					l_msg.type = SEND_CMD_MSG;
					l_msg.data.Msg.fType = WAKDebuggerServerMessage::SRV_REMOVE_BREAKPOINT_MSG;
					l_msg.data.Msg.fSrcId = fSrcId;
					//l_msg.data.Msg.fUrl[fURL.ToBlock(l_msg.data.Msg.fUrl,K_MAX_FILESIZE-1,VTC_UTF_8,false,false)] = 0;
					l_err = fOutFifo.Put(l_msg);
					if (testAssert( l_err == VE_OK ))
					{
						// we answer as success since wakanda is not able to return a status regarding bkpt handling
						l_err = SendResult(K_EMPTY_STR);
					}
				}
			}
		}
	}

	l_cmd = K_DBG_EVA_ON_CAL_FRA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		sBYTE*		l_tmp_exp;
		sBYTE*		l_ord;
		l_tmp_exp = strstr(fParams,K_EXPRESSION_STR);
		l_ord = strstr(fParams,K_ORDINAL_STR);
		if (l_tmp_exp && l_ord)
		{
			l_tmp_exp += strlen(K_EXPRESSION_STR);
			sBYTE *l_end_str;
			l_end_str = strchr(l_tmp_exp,'"');
			if (l_end_str)
			{
				l_msg.data.Msg.fLineNumber = atoi(l_ord+strlen(K_ORDINAL_STR));
				*l_end_str = 0;
				VString l_exp(l_tmp_exp);
				DebugMsg("requiring value of '%S'\n",&l_exp);
				//l_resp = CVSTR("\"result\":{\"type\":\"number\",\"value\":3,\"description\":\"3\"}");
				l_msg.type = SEND_CMD_MSG;
				l_msg.data.Msg.fType = WAKDebuggerServerMessage::SRV_EVALUATE_MSG;
				l_msg.data.Msg.fSrcId = fSrcId;
				l_msg.data.Msg.fString[l_exp.ToBlock(l_msg.data.Msg.fString,K_MAX_FILESIZE-1,VTC_UTF_8,false,false)] = 0;
				l_err = fOutFifo.Put(l_msg);
				if (testAssert( l_err == VE_OK ))
				{
					l_err = fFifo.Get(&l_msg,&l_msg_found,0);
					if (testAssert( l_err == VE_OK ))
					{
						if (l_msg_found && (l_msg.type == EVAL_MSG))
						{
						}
						else
						{
							l_err = VE_INVALID_PARAMETER;
							xbox_assert(false);
						}
					}
				}
				l_resp = l_msg.data._dataStr;
				VString		l_hdr = CVSTR("\"result\":{\"value\":{");
				VString		l_sub;
				if (l_resp.GetLength() > l_hdr.GetLength())
				{
					l_resp.GetSubString(l_hdr.GetLength(),l_resp.GetLength()-l_hdr.GetLength()+1,l_sub);
				}
				l_resp = CVSTR("\"result\":");
				l_resp += l_sub;
				if (!l_err)
				{
					l_err = SendResult(l_resp);
				}
			}
			else
			{
				l_err = VE_INVALID_PARAMETER;
			}
		}
		else
		{
			l_err = VE_INVALID_PARAMETER;
		}
	}

	l_cmd = K_DBG_SET_BRE_BY_URL;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		sBYTE	*l_line_nb;
		sBYTE	*l_col_nb;
		sBYTE	*l_url;
		l_err = GetBrkptParams(fParams,&l_url,&l_col_nb,&l_line_nb);

		if (!l_err)
		{
			l_msg.type = SEND_CMD_MSG;
			l_msg.data.Msg.fType = WAKDebuggerServerMessage::SRV_SET_BREAKPOINT_MSG;
			l_msg.data.Msg.fSrcId = fSrcId;
			l_msg.data.Msg.fLineNumber = atoi(l_line_nb);
			//l_msg.data.Msg.fUrl[fURL.ToBlock(l_msg.data.Msg.fUrl,K_MAX_FILESIZE-1,VTC_UTF_8,false,false)] = 0;
			l_err = fOutFifo.Put(l_msg);
			xbox_assert( l_err == VE_OK );
		}
		if (!l_err)
		{
			l_resp = K_DBG_SET_BRE_BY_URL_STR1;
			l_url[strlen(l_url)-1] = 0;// -1 is aimed to remove the final '"'
			l_resp += l_url;
			l_resp += ":";
			l_resp += l_line_nb;
			l_resp += ":";
			l_resp += l_col_nb;
			l_resp += K_DBG_SET_BRE_BY_URL_STR2;
			l_resp += fId;
			l_resp += "}";
			// we answer as success since wakanda is not able to return a status regarding bkpt handling
			l_err = SendMsg(l_resp);
		}
	}

	l_cmd = K_NET_GET_RES_BOD;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_resp = K_NET_GET_RES_BOD_STR1;
		l_resp += K_LINE_1;
		l_resp += K_LINE_2;
		l_resp += K_LINE_3;
		l_resp += K_LINE_4;
		l_resp += K_LINE_5;
		l_resp += K_LINE_6;
		l_resp += K_NET_GET_RES_BOD_STR2;
		l_resp += fId;
		l_resp += "}";
		l_err = SendMsg(l_resp);
	}
	
	l_cmd = K_PAG_GET_RES_CON;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_resp = K_PAG_GET_RES_CON_STR1;
		l_resp += K_LINE_1;
		l_resp += K_LINE_2;
		l_resp += K_LINE_3;
		l_resp += K_LINE_4;
		l_resp += K_LINE_5;
		l_resp += K_LINE_6;
		l_resp += K_PAG_GET_RES_CON_STR2;
		l_resp += fId;
		l_resp += "}";
		l_err = SendMsg(l_resp);
	}

	l_cmd = K_DOM_SET_INS_MOD_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_DOM_PUS_NOD_BY_PAT_TO_FRO_END;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_resp = K_DOM_PUS_NOD_BY_PAT_TO_FRO_END_STR1;
		l_resp.AppendLong(fBodyNodeId);
		l_resp += K_ID_FMT_STR;
		l_resp += fId;
		l_resp += "}";
		l_err = SendMsg(l_resp);
	}
	
	l_cmd = K_PAG_REL;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		// page reload from CHrome not handled
		xbox_assert(false);
		l_err = VE_UNKNOWN_ERROR;
		return l_err;
#if 0

if (s_brkpt_line_nb.GetLength())
{
	return TreatPageReload(NULL);
	return l_err;
}
		l_resp = K_PAG_REL_STR1;
		l_err = SendMsg(l_resp);
		if (!l_err)
		{
			l_err = SendResult(K_EMPTY_STR);
		}
		if (!l_err)
		{
			l_resp = K_PAG_REL_STR2;
			l_err = SendMsg(l_resp);
		}
		if (!l_err)
		{
			l_resp = K_PAG_REL_STR3;
			l_err = SendMsg(l_resp);
		}
		if (!l_err)
		{
			l_resp = K_PAG_REL_STR4;
			l_err = SendMsg(l_resp);
		}
		if (!l_err)
		{
			l_resp = K_PAG_REL_STR5;
			l_err = SendMsg(l_resp);
		}
		if (!l_err)
		{
			l_resp = K_PAG_REL_STR6;
			l_err = SendMsg(l_resp);
		}

		if (!l_err)
		{
			l_resp = K_PAG_REL_STR7;
			l_err = SendMsg(l_resp);
		}

		if (!l_err)
		{
			l_resp = K_PAG_REL_STR8;
			l_err = SendMsg(l_resp);
		}
				if (!l_err)
		{
			l_resp = K_PAG_REL_STR9;
			l_err = SendMsg(l_resp);
		}

		if (!l_err)
		{
			l_resp = K_PAG_REL_STR10;
			l_err = SendMsg(l_resp);
		}		

		if (!l_err)
		{
			l_resp = K_PAG_REL_STR11;
			l_err = SendMsg(l_resp);
		}	
#endif
	}

	l_cmd = K_DBG_GET_SCR_SOU;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_id = strstr(fParams,K_SCRIPTID_ID_STR);
		if (!l_id)
		{
			DebugMsg("NO %s param found for %S\n",K_SCRIPTID_ID_STR,&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err)
		{
			l_id += strlen(K_SCRIPTID_ID_STR);
			sBYTE*	l_end = strchr(l_id,'"');
			if (l_end)
			{
				*l_end = 0;
				strncpy(l_msg.data.Msg.fString,l_id,K_STR_MAX_SIZE);
				l_msg.data.Msg.fString[K_STR_MAX_SIZE-1] = 0;
			}
			else
			{
				l_err = VE_INVALID_PARAMETER;
			}
		}
		l_resp = K_DBG_GET_SCR_SOU_STR1;

		if (!l_err)
		{
			for(VectorOfVString::iterator l_it = fSource.begin(); (l_it != fSource.end()); )
			{
				l_resp += *l_it;
				l_resp += K_LINE_FEED_STR;
				++l_it;
			}
		}
		else
		{
			l_resp += CVSTR(" NO SOURCE AVAILABLE ");
			l_resp += K_LINE_FEED_STR;
		}
		l_resp += "\"},\"id\":";
		l_resp += fId;
		l_resp += "}";
		l_err = SendMsg(l_resp);
	}
	
	l_cmd = K_RUN_GET_PRO;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_id = strstr(fParams,K_BACKSLASHED_ID_STR);
		if (!l_id)
		{
			DebugMsg("NO %s param found for %S\n",K_BACKSLASHED_ID_STR,&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err)
		{
			l_msg.type = SEND_CMD_MSG;
			l_msg.data.Msg.fType = WAKDebuggerServerMessage::SRV_LOOKUP_MSG;
			l_msg.data.Msg.fObjRef = atoi(l_id+strlen(K_BACKSLASHED_ID_STR));
			l_err = fOutFifo.Put(l_msg);
			if (testAssert( l_err == VE_OK ))
			{
				l_err = fFifo.Get(&l_msg,&l_msg_found,0);
				xbox_assert( l_err == VE_OK );
			}
			if (!l_err)
			{
				if (l_msg_found && (l_msg.type != LOOKUP_MSG))
				{
					l_err = VE_INVALID_PARAMETER;
				}
				xbox_assert(l_err == VE_OK);
			}
		}
		if (!l_err)
		{
			l_resp = l_msg.data._dataStr;
			l_resp += fId;
			l_resp += "}";
			l_err = SendMsg(l_resp);
		}
	}

	l_cmd = K_DOM_HIG_FRA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_DOM_HIG_NOD;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);

	}

	l_cmd = K_RUN_REL_OBJ_GRO;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_DOM_REQ_CHI_NOD;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_id = strstr(fParams,K_NODE_ID_STR);
		if (!l_id)
		{
			DebugMsg("NO %s param found for %S\n",K_NODE_ID_STR,&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err && (atoi(l_id+strlen(K_NODE_ID_STR)) != fBodyNodeId) )
		{
			DebugMsg("INCORRECT BODY node id for %S\n",&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err)
		{
			l_resp = K_DOM_REQ_CHI_NOD_STR1;
			l_resp.AppendLong(fBodyNodeId);
			l_resp += K_DOM_REQ_CHI_NOD_STR2;
			l_resp.AppendLong(s_node_id++);
			l_resp += K_DOM_REQ_CHI_NOD_STR3;
			l_resp.AppendLong(s_node_id++);
			l_resp += K_DOM_REQ_CHI_NOD_STR4A;
			//l_resp += K_DOM_REQ_CHI_NOD_STR4B;
			//l_resp += K_DOM_REQ_CHI_NOD_STR4C;
			//l_resp += K_DOM_REQ_CHI_NOD_STR4D;
#if 1
			l_resp += "n";
			/*VectorOfVString::const_iterator l_it = fSource.begin();
			for(; l_it != fSource.end(); l_it++)
			{
				l_resp += *l_it;
				l_resp += K_LINE_FEED_STR;
			}*/
			l_resp+= "\\";
#endif
			l_resp += K_DOM_REQ_CHI_NOD_STR4E;
			l_resp.AppendLong(s_node_id++);
			l_resp += K_DOM_REQ_CHI_NOD_STR5;
			l_resp.AppendLong(s_node_id++);
			l_resp += K_DOM_REQ_CHI_NOD_STR6;
			l_resp.AppendLong(s_node_id++);
			l_resp += K_DOM_REQ_CHI_NOD_STR7;
			l_resp.AppendLong(s_node_id++);
			l_resp += K_DOM_REQ_CHI_NOD_STR8;
			l_resp.AppendLong(s_node_id++);
			l_resp += K_DOM_REQ_CHI_NOD_STR9;
			l_resp.AppendLong(s_node_id++);
			l_resp += K_DOM_REQ_CHI_NOD_STR10;

			l_err = SendMsg(l_resp);

			if (!l_err)
			{
				l_err = SendResult(K_EMPTY_STR);
			}
		}

	}

	l_cmd = K_CON_ADD_INS_NOD;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_err = SendResult(K_EMPTY_STR);
	}
	
	l_cmd = K_CSS_GET_MAT_STY_FOR_NOD;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_id = strstr(fParams,K_NODE_ID_STR);
		if (!l_id)
		{
			DebugMsg("NO %s param found for %S\n",K_NODE_ID_STR,&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err && (atoi(l_id+strlen(K_NODE_ID_STR)) != fBodyNodeId) )
		{
			DebugMsg("INCORRECT BODY node id for %S\n",&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err)
		{
			l_resp.AppendBlock(_binary_getMatchedStylesForNode,sizeof(_binary_getMatchedStylesForNode),VTC_UTF_8);
			l_resp += fId;
			l_resp += "}";
			l_err = SendMsg(l_resp);
		}
	}

	l_cmd = K_CSS_GET_INL_STY_FOR_NOD;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_id = strstr(fParams,K_NODE_ID_STR);
		if (!l_id)
		{
			DebugMsg("NO %s param found for %S\n",K_NODE_ID_STR,&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err && (atoi(l_id+strlen(K_NODE_ID_STR)) != fBodyNodeId) )
		{
			DebugMsg("INCORRECT BODY node id for %S\n",&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err)
		{
			l_resp.AppendBlock(_binary_getInlineStylesForNode,sizeof(_binary_getInlineStylesForNode),VTC_UTF_8);
			l_resp += fId;
			l_resp += "}";
			l_err = SendMsg(l_resp);
		}
	}
	l_cmd = K_CSS_GET_COM_STY_FOR_NOD;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_id = strstr(fParams,K_NODE_ID_STR);
		if (!l_id)
		{
			DebugMsg("NO %s param found for %S\n",K_NODE_ID_STR,&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err && (atoi(l_id+strlen(K_NODE_ID_STR)) != fBodyNodeId) )
		{
			DebugMsg("INCORRECT BODY node id for %S\n",&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err)
		{
			l_resp.AppendBlock(_binary_getComputedStyleForNode,sizeof(_binary_getComputedStyleForNode),VTC_UTF_8);
			l_resp += fId;
			l_resp += "}";
			l_err = SendMsg(l_resp);
		}
	}
	
	l_cmd = K_DOM_GET_DOC;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {

		l_resp = K_GET_DOC_STR1;
		l_resp.AppendLong(s_node_id++);
		l_resp += K_GET_DOC_STR2;
		l_resp.AppendLong(s_node_id++);
		l_resp += K_GET_DOC_STR3;
		l_resp.AppendLong(s_node_id++);
		l_resp += K_GET_DOC_STR4;
		l_resp.AppendLong(s_node_id++);
		l_resp += K_GET_DOC_STR5;
		l_resp.AppendLong(s_node_id++);
		l_resp += K_GET_DOC_STR6;
		fBodyNodeId = s_node_id;
		l_resp.AppendLong(s_node_id++);
		l_resp += K_GET_DOC_STR7A;
		l_resp += fFileName;
		l_resp += K_GET_DOC_STR7B;
		l_resp += fId;
		l_resp += "}";

		l_err = SendMsg(l_resp);
	}

	l_cmd = K_DOM_HID_HIG;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_DBG_SET_PAU_ON_EXC;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_TIM_SET_INC_MEM_DET;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_CSS_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_CSS_GET_SUP_PRO;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_resp.AppendBlock(_binary_getSupportedCSSProperties,sizeof(_binary_getSupportedCSSProperties),VTC_UTF_8);
		l_resp += fId;
		l_resp += "}";
		l_err = SendMsg(l_resp);

	}	
	
	l_cmd = K_DOM_STO_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_DAT_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_INS_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		fEnabled = true;
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_CON_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_PRO_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_DBG_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_DBG_CAN_SET_SCR_SOU;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_RESULT_TRUE_STR);
	}

	l_cmd = K_WOR_SET_WOR_INS_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_NET_CAN_CLE_BRO_CAC;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_RESULT_TRUE_STR);
	}

	l_cmd = K_NET_CAN_CLE_BRO_COO;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_RESULT_TRUE_STR);
	}

	l_cmd = K_PAG_GET_RES_TRE;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_resp = K_PAG_GET_RES_TRE_STR1A;
		l_resp.AppendLong(fPageNb*K_FRAME_FACTOR);
		l_resp += K_PAG_GET_RES_TRE_STR1B;
		l_resp += fFileName;
		l_resp.AppendLong(fPageNb);
		l_resp += ".html";
		l_resp += K_PAG_GET_RES_TRE_STR1C;
		l_resp += fFileName;
		l_resp += K_PAG_GET_RES_TRE_STR1D;
		l_resp += fId;
		l_resp += "}";
		l_err = SendMsg(l_resp);

	}
	l_cmd = K_PAG_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_NET_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_PRO_HAS_HEA_PRO;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_RESULT_TRUE_STR);
	}

	l_cmd = K_PRO_IS_SAM;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_RESULT_TRUE_STR);
	}

	l_cmd = K_PRO_CAU_REC;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_err = SendResult(K_RESULT_FALSE_STR);
	}

	l_cmd = K_DBG_SUP_NAT_BRE;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_RESULT_TRUE_STR);
	}

	l_cmd = K_DBG_RES;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
		fState = RUNNING_STATE;
		if (!l_err)
		{
			l_resp = K_DBG_RES_STR;
			l_err = SendMsg(l_resp);
		}
		l_msg.type = SEND_CMD_MSG;
		l_msg.data.Msg.fType = WAKDebuggerServerMessage::SRV_CONTINUE_MSG;
		l_err = fOutFifo.Put(l_msg);
		xbox_assert( l_err == VE_OK );
	}
	l_cmd = K_DBG_STE_INT;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
		//fState = IJSWChrmDebugger::RUNNING_STATE;
		if (!l_err)
		{
			l_resp = K_DBG_RES_STR;
			l_err = SendMsg(l_resp);
		}
		l_msg.type = SEND_CMD_MSG;
		l_msg.data.Msg.fType = WAKDebuggerServerMessage::SRV_STEP_INTO_MSG;
		l_err = fOutFifo.Put(l_msg);
		xbox_assert( l_err == VE_OK );
	}
	l_cmd = K_DBG_STE_OUT;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
		//fState = IJSWChrmDebugger::RUNNING_STATE;
		if (!l_err)
		{
			l_resp = K_DBG_RES_STR;
			l_err = SendMsg(l_resp);
		}
		l_msg.type = SEND_CMD_MSG;
		l_msg.data.Msg.fType = WAKDebuggerServerMessage::SRV_STEP_OUT_MSG;
		l_err = fOutFifo.Put(l_msg);
		xbox_assert( l_err == VE_OK );
	}
	l_cmd = K_DBG_STE_OVE;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
		//fState = IJSWChrmDebugger::RUNNING_STATE;
		if (!l_err)
		{
			l_resp = K_DBG_RES_STR;
			l_err = SendMsg(l_resp);
		}
		l_msg.type = SEND_CMD_MSG;
		l_msg.data.Msg.fType = WAKDebuggerServerMessage::SRV_STEP_OVER_MSG;
		l_err = fOutFifo.Put(l_msg);
		xbox_assert( l_err == VE_OK );
	}
	l_cmd = K_DBG_CAU_REC;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_RESULT_FALSE_STR);
	}
	l_cmd = K_DBG_PAU;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}
	if (!l_found)
	{
		DebugMsg("VChromeDbgHdlPage::TreatMsg Method='%S' UNKNOWN!!!\n",&fMethod);
		exit(-1);
		return VE_OK;// --> pour l'instant on renvoit OK  !!! VE_INVALID_PARAMETER;
	}
#endif
	return l_err;

}
Exemplo n.º 17
0
int PER_STR::Execute()
{
    CheckInputData();
	initialOutputs();
	/*if (m_perc == NULL)
	{
	m_perc = new float *[m_nCells];

	#pragma omp parallel for
	for (int i = 0; i < m_nCells; i++)
	{
	m_perc[i] = new float[m_nSoilLayers];
	for (int j = 0; j < m_nSoilLayers; j++)
	m_perc[i][j] = 0.f;
	}
	}*/
#pragma omp parallel for
    for (int i = 0; i < m_nCells; i++)
    {
		float maxSoilWater = 0.f, fcSoilWater = 0.f;
		float swater = 0.f, wpSoilWater = 0.f;     
        //// Update soil layers from solid two layers to multi-layers by m_nSoilLayers. By LJ
        //int curSoilLayers = -1, j;
        //m_upSoilDepth[0] = m_soilDepth[i][0];
        //for (j = 1; j < m_nSoilLayers; j++)
        //{
        //    if (!FloatEqual(m_soilDepth[i][j], NODATA_VALUE))
        //        m_upSoilDepth[j] = m_soilDepth[i][j] - m_soilDepth[i][j - 1];
        //    else
        //        break;
        //}
        //curSoilLayers = j;

        //float depth[3];
        //depth[0] = m_upSoilDepth;
        //depth[1] = m_rootDepth[i] - m_upSoilDepth;
        //if(depth[1] < 0)
        //{
        //	ostringstream oss;
        //	oss << "The root depth at cell(" << i << ") is " << m_rootDepth[i] << ", and is less than the upper soil depth (" << m_upSoilDepth << endl;
        //	throw ModelException(MID_PER_STR, "Execute",  oss.str());
        //}


        m_somo[i][0] += m_infil[i] / m_soilThick[i][0];
        for (int j = 0; j < (int)m_soilLayers[i]; j++)
        {
            //No movement if soil moisture is below field capacity
            m_perc[i][j] = 0.f;

            // for the upper two layers, soil may be frozen
            if (j == 0 && m_soilT[i] <= m_frozenT)
                continue;

            if (m_somo[i][j] > m_fc[i][j])
            {
                maxSoilWater = m_soilThick[i][j] * m_porosity[i][j];
                swater = m_soilThick[i][j] * m_somo[i][j];
                fcSoilWater = m_soilThick[i][j] * m_fc[i][j];
				wpSoilWater = m_soilThick[i][j] * m_wp[i][j];
                //////////////////////////////////////////////////////////////////////////
                // method from swat
                float tt = 3600.f * (m_porosity[i][j] - m_fc[i][j]) * m_soilThick[i][j] / m_ks[i][j];
                m_perc[i][j] = swater * (1.f - exp(-m_dt / tt));

				if (swater - m_perc[i][j] > maxSoilWater)
					m_perc[i][j] = swater - maxSoilWater;
				else if (swater - m_perc[i][j] < fcSoilWater)
					m_perc[i][j] = swater - fcSoilWater;
				else if (swater - m_perc[i][j] < wpSoilWater)
					m_perc[i][j] = swater - wpSoilWater;
				else  /// percolation is not allowed!
					m_perc[i][j] = 0.f;
                //Adjust the moisture content in the current layer, and the layer immediately below it
                m_somo[i][j] -= m_perc[i][j] / m_soilThick[i][j];
                if (j < m_nSoilLayers - 1)
                    m_somo[i][j + 1] += m_perc[i][j] / m_soilThick[i][j + 1];


                //if (m_somo[i][j] != m_somo[i][j] || m_somo[i][j] < 0.f)
                //{
                //    cout << "PER_STR CELL:" << i << ", Layer: " << j << "\tPerco:" << soilWater << "\t" <<
                //    fcSoilWater << "\t" << m_perc[i][j] << "\t" << m_soilThick[i][j] << "\tValue:" << m_somo[i][j] <<
                //    endl;
                //    throw ModelException(MID_PER_STR, "Execute", "moisture is less than zero.");
                //}

            }
			else
			{
				for (int j = 0; j < (int)m_soilLayers[i]; j++)
					m_perc[i][j] = 0.f;
			}
			for (int j = (int)m_soilLayers[i]; j < m_nSoilLayers; j++)
				m_perc[i][j] = NODATA_VALUE;
        }
    }
    return 0;

}