Esempio n. 1
0
float subbasin::getAverage(string key)
{
    if (StringMatch(key, "P"))
        return m_P / m_cells.size();
    else if (StringMatch(key, "NetP"))
        return m_pNet / m_cells.size();
    else if (StringMatch(key, "Interception"))
        return m_Interception / m_cells.size();
    else if (StringMatch(key, "InterceptionET"))
        return m_interceptionET / m_cells.size();
    else if (StringMatch(key, "DepressionET"))
        return m_DepressionET / m_cells.size();
    else if (StringMatch(key, "Infiltration"))
        return m_Infiltration / m_cells.size();
    else if (StringMatch(key, "Total_ET"))
        return m_TotalET / m_cells.size();
    else if (StringMatch(key, "Soil_ET"))
        return m_soilET / m_cells.size();
    else if (StringMatch(key, "Net_Percolation"))
        return m_NetPercolation / m_cells.size();
    else if (StringMatch(key, "Revap"))
        return m_Revap / m_cells.size();
    else if (StringMatch(key, "RS"))
        return m_RS / m_cells.size();
    else if (StringMatch(key, "RI"))
        return m_RI / m_cells.size();
    else if (StringMatch(key, "RG"))
        return m_RG / m_cells.size();
    else if (StringMatch(key, "R"))
        return m_R / m_cells.size();
    else if (StringMatch(key, "S_MOI"))
        return m_S_MOI / m_cells.size();
    else if (StringMatch(key, "T"))
        return m_T / m_cells.size();
    else if (StringMatch(key, "Soil_T"))
        return m_Soil_T / m_cells.size();
    else if (StringMatch(key, "MoistureDepth"))
        return m_moistureDepth / m_cells.size();
    else
        return -1.0f;
}
Esempio n. 2
0
void YLD::Set1DData(const char *key, int n, float *data)
{
    //check the input data
    string s(key);

    CheckInputSize(key, n);
    if (StringMatch(s, "CNYLD"))
        m_frNyld = data;
    else if (StringMatch(s, "CPYLD"))
        m_frPyld = data;
    else if (StringMatch(s, "IDC"))
        m_classification = data;
    else if (StringMatch(s, "DLAI"))
        m_frDeclineLAI = data;
    else if (StringMatch(s, "HVSTI"))
        m_HiOpt = data;
    else if (StringMatch(s, "WSYF"))
        m_HiMin = data;
    else if (StringMatch(s, "D_PET"))
        m_PET = data;
    else if (StringMatch(s, "D_SOET"))
        m_soilET = data;
    else if (StringMatch(s, "Fr_PHU"))
        m_frPHU = data;
    else if (StringMatch(s, "BIOMASS"))
        m_biomass = data;
    else if (StringMatch(s, "BIOMASS_N"))
        m_biomassN = data;
    else if (StringMatch(s, "BIOMASS_P"))
        m_biomassP = data;
    else if (StringMatch(s, "BIOMASS_AG"))
        m_biomassAG = data;
    else if (StringMatch(s, "BIOMASS_ROOT"))
        m_biomassRoot = data;
    else if (StringMatch(s, "LAI"))
        m_LAI = data;
    else if (StringMatch(s, "Total_WaterUptake"))
        m_totalWaterUptake = data;
    else
        throw ModelException("Yield", "Set1DData", "Parameter " + s +
                                                   " does not exist in Yield method. Please contact the module developer.");
}
Esempio n. 3
0
bool SettingsOutput::ParseOutputSettings(int subBasinID)
{
    PrintInfo *pi = NULL;
    ostringstream oss;
    oss << subBasinID << "_";
    string strSubbasinID = oss.str();

    for (size_t i = 0; i < m_Settings.size(); i++)
    {
        // Sample output entries from the FILE.OUT file
        // placed here for reference
        //OUTPUTID  | PET_TS
        //INTERVAL  | 24 | HOURS
        //SITECOUNT | 2
        //SITENAME  | 720_pet
        //STARTTIME | 2000/01/01/00
        //ENDTIME   | 2000/12/31/00
        //FILENAME  | PET_720.txt
        //SITENAME  | 736_pet
        //STARTTIME | 2001/01/01/00
        //ENDTIME   | 2001/12/31/00
        //FILENAME  | 736_PET.txt

        //OUTPUTID  | D_PREC
        //TYPE      | SUM
        //COUNT     | 2
        //STARTTIME | 2000/01/01/00
        //ENDTIME   | 2000/01/31/00
        //FILENAME  | D_PREC_1.asc
        //STARTTIME | 2000/02/01/00
        //ENDTIME   | 2000/02/28/00
        //FILENAME  | D_PREC_2.asc

        // OUTPUTID starts a new PrintInfo
        if (StringMatch(m_Settings[i][0], Tag_OutputID))
        {
            // is this the first PrintInfo or not
            if (pi != NULL)
            {
                // not the first PrintInfo so add this one to the list before starting a new one
                m_printInfos.push_back(pi);
            }
            // reset the pointer
            pi = NULL;
            // start a new PrintInfo
            pi = new PrintInfo();
            // set the OUTPUTID for the new PrintInfo
            pi->setOutputID(m_Settings[i][1]);

            // for QOUTLET or QTotal or SEDOUTLET or DissovePOutlet or AmmoniumOutlet or NitrateOutlet
            if (StringMatch(m_Settings[i][1], TAG_OUT_QOUTLET) || StringMatch(m_Settings[i][1], TAG_OUT_QTOTAL) ||
                StringMatch(m_Settings[i][1], TAG_OUT_SEDOUTLET)
                || StringMatch(m_Settings[i][1], Tag_DisPOutlet) || StringMatch(m_Settings[i][1], Tag_AmmoOutlet)
                || StringMatch(m_Settings[i][1], Tag_NitrOutlet))
            {
                string starttm = "";
                string endtm = "";
                string fname = "";
                string suffix = "";
                // check to see if we have all 4 values we need
                for (int flag = 0; flag < 4; flag++)
                {
                    i++;
                    if (StringMatch(m_Settings[i][0], Tag_Interval))
                    {
                        // set the interval length
                        pi->setInterval(atoi(m_Settings[i][1].c_str()));
                        // set the interval units
                        pi->setIntervalUnits(m_Settings[i][2].c_str());
                    }
                    else if (StringMatch(m_Settings[i][0], Tag_StartTime))
                    {
                        // get the start time
                        starttm = m_Settings[i][1];
                    }
                    else if (StringMatch(m_Settings[i][0], Tag_EndTime))
                    {
                        // get the end time
                        endtm = m_Settings[i][1];
                    }
                    else if (StringMatch(m_Settings[i][0], Tag_FileName))
                    {
                        // get the filename, but not include the suffix.
                        // modified by ZhuLJ, 2015/6/16
                        fname = strSubbasinID + GetCoreFileName(m_Settings[i][1]);
                        suffix = GetSuffix(m_Settings[i][1]);
                    }
                }
                pi->AddPrintItem(starttm, endtm, fname, suffix);
            }
        }
        // INTERVAL is used only for the PET_TS output
        if (StringMatch(m_Settings[i][0], Tag_Interval))
        {
            // check that an object exists
            if (pi != NULL)
            {
                // set the interval length
                pi->setInterval(atoi(m_Settings[i][1].c_str()));
                // set the interval units
                pi->setIntervalUnits(m_Settings[i][2].c_str());
            }
        }
        // SITECOUNT is used only for the time series output for sites
        if (StringMatch(m_Settings[i][0], Tag_SiteCount))
        {
            string sitename = "";
            string starttm = "";
            string endtm = "";
            string fname = "";
            string suffix = "";
            // get the number of sites in the list
            int cnt = atoi(m_Settings[i][1].c_str());
            // for each site in the list
            for (int idx = 0; idx < cnt; idx++)
            {
                // reset values
                sitename = "";
                endtm = "";
                starttm = "";
                fname = "";

                // check to see if we have all 4 values we need
                for (int flag = 0; flag < 4; flag++)
                {
                    i++;
                    if (StringMatch(m_Settings[i][0], Tag_SiteID))
                    {
                        // get the sitename
                        sitename = m_Settings[i][1];
                    }
                    else if (StringMatch(m_Settings[i][0], Tag_StartTime))
                    {
                        // get the start time
                        starttm = m_Settings[i][1];
                    }
                    else if (StringMatch(m_Settings[i][0], Tag_EndTime))
                    {
                        // get the end time
                        endtm = m_Settings[i][1];
                    }
                    else if (StringMatch(m_Settings[i][0], Tag_FileName))
                    {
                        // get the filename
                        fname = strSubbasinID + GetCoreFileName(m_Settings[i][1]);
                        //get suffix
                        suffix = GetSuffix(m_Settings[i][1]);
                    }
                }

                // check to see if there is a site to save
                if (sitename.size() > 0)
                {
                    // add the print item
                    pi->AddPrintItem(starttm, endtm, fname, sitename, suffix, m_conn, m_outputGfs, false);
                }
            }
        }
        // SUBBASINCOUNT is used only for the time series output for subbasins
        if (StringMatch(m_Settings[i][0], Tag_SubbasinCount) ||
            StringMatch(m_Settings[i][0], Tag_ReservoirCount))
        {
            string subbasinname = "";
            string starttm = "";
            string endtm = "";
            string fname = "";
            string suffix = "";
            // get the number of sites in the list
            int cnt = atoi(m_Settings[i][1].c_str());
            // for each site int he list
            for (int idx = 0; idx < cnt; idx++)
            {
                // reset values
                subbasinname = "";
                endtm = "";
                starttm = "";
                fname = "";
                suffix = "";
                // check to see if we have all 4 values we need
                for (int flag = 0; flag < 4; flag++)
                {
                    i++;
                    if (StringMatch(m_Settings[i][0], Tag_SubbasinId) ||
                        StringMatch(m_Settings[i][0], Tag_ReservoirId))
                    {
                        // get the sitename
                        subbasinname = m_Settings[i][1];
                    }
                    else if (StringMatch(m_Settings[i][0], Tag_StartTime))
                    {
                        // get the start time
                        starttm = m_Settings[i][1];
                    }
                    else if (StringMatch(m_Settings[i][0], Tag_EndTime))
                    {
                        // get the end time
                        endtm = m_Settings[i][1];
                    }
                    else if (StringMatch(m_Settings[i][0], Tag_FileName))
                    {
                        // get the filename
                        fname = strSubbasinID + GetCoreFileName(m_Settings[i][1]);
                        // get the suffix
                        suffix = GetSuffix(m_Settings[i][1]);
                    }
                }

                // check to see if there is a site to save
                if (subbasinname.size() > 0)
                {
                    // add the print item
                    pi->AddPrintItem(starttm, endtm, fname, subbasinname, suffix, m_conn, m_outputGfs, true);
                }
            }
        }
        if (StringMatch(m_Settings[i][0], Tag_Count))
        {
            string type = "";
            string starttm = "";
            string endtm = "";
            string fname = "";
            string suffix = "";
            // get the number of sites in the list
            int cnt = atoi(m_Settings[i][1].c_str());
            // for each site int he list
            for (int idx = 0; idx < cnt; idx++)
            {
                endtm = "";
                starttm = "";
                fname = "";
                suffix = "";
                // check to see if we have all 3 values we need
                for (int flag = 0; flag < 4; flag++)
                {
                    i++;
                    if (StringMatch(m_Settings[i][0], Tag_AggType))
                    {
                        // get the type
                        type = m_Settings[i][1];
                    }
                    else if (StringMatch(m_Settings[i][0], Tag_StartTime))
                    {
                        // get the start time
                        starttm = m_Settings[i][1];
                    }
                    else if (StringMatch(m_Settings[i][0], Tag_EndTime))
                    {
                        // get the end time
                        endtm = m_Settings[i][1];
                    }
                    else if (StringMatch(m_Settings[i][0], Tag_FileName))
                    {
                        // get the filename
                        fname = strSubbasinID + GetCoreFileName(m_Settings[i][1]);
                        // get the suffix
                        suffix = GetSuffix(m_Settings[i][1]);
                    }
                }

                // check to see if there is a site to save
                if (starttm.size() > 0)
                {
                    // add the print item
                    pi->AddPrintItem(type, starttm, endtm, fname, suffix, m_conn, m_outputGfs);
                }
            }
        }
    }

    if (pi != NULL)
    {
        // add the last one.
        m_printInfos.push_back(pi);
        pi = NULL;
    }
    return true;
}
Esempio n. 4
0
bool SettingsOutput::LoadSettingsOutputFromMongoDB(int subBasinID)
{
    bson_t *b = bson_new();
    bson_t *child1 = bson_new();
    BSON_APPEND_DOCUMENT_BEGIN(b, "$query", child1);
    bson_append_document_end(b, child1);
    bson_destroy(child1);

    mongoc_cursor_t *cursor;
    const bson_t *bsonTable;
    mongoc_collection_t *collection;

    collection = mongoc_client_get_collection(m_conn, m_dbName.c_str(), DB_TAB_FILEOUT);
    cursor = mongoc_collection_find(collection, MONGOC_QUERY_NONE, 0, 0, 0, b, NULL, NULL);

    bson_iter_t itertor;
    while (mongoc_cursor_more(cursor) && mongoc_cursor_next(cursor, &bsonTable))
    {
        int use = -1;
		string modCls = "", outputID = "", descprition = "";
		string outFileName = "", aggType = "", unit = "", subBsn = "";
		string dataType = "", intervalUnit = "";
		int interval = -1;
		string sTimeStr = "", eTimeStr = "";
        if (bson_iter_init_find(&itertor, bsonTable, Tag_OutputUSE))
            use = GetIntFromBSONITER(&itertor);
        if (bson_iter_init_find(&itertor, bsonTable, Tag_MODCLS))
			modCls = GetStringFromBSONITER(&itertor);
		if (bson_iter_init_find(&itertor, bsonTable, Tag_OutputID))
			outputID = GetStringFromBSONITER(&itertor);
		if (bson_iter_init_find(&itertor, bsonTable, Tag_OutputDESC))
			descprition = GetStringFromBSONITER(&itertor);
		if (bson_iter_init_find(&itertor, bsonTable, Tag_FileName))
			outFileName = GetStringFromBSONITER(&itertor);
		string coreFileName = GetCoreFileName(outFileName);
		string suffix = GetSuffix(outFileName);
		if (bson_iter_init_find(&itertor, bsonTable, Tag_AggType))
			aggType = GetStringFromBSONITER(&itertor);
		if (bson_iter_init_find(&itertor, bsonTable, Tag_OutputUNIT))
			unit = GetStringFromBSONITER(&itertor);
		if (bson_iter_init_find(&itertor, bsonTable, Tag_OutputSubbsn))
			subBsn = GetStringFromBSONITER(&itertor);
		if (bson_iter_init_find(&itertor, bsonTable, Tag_StartTime))
			sTimeStr = GetStringFromBSONITER(&itertor);
		if (bson_iter_init_find(&itertor, bsonTable, Tag_EndTime))
			eTimeStr = GetStringFromBSONITER(&itertor);
		if (bson_iter_init_find(&itertor, bsonTable, Tag_Interval))
			interval = GetIntFromBSONITER(&itertor);
		if (bson_iter_init_find(&itertor, bsonTable, Tag_IntervalUnit))
			intervalUnit = GetStringFromBSONITER(&itertor);
		if(use <= 0)
			continue;
		/// First, if OutputID does not existed in m_printInfos, then create a new one.
		if(m_printInfosMap.find(outputID) == m_printInfosMap.end())
		{
			m_printInfosMap[outputID] = new PrintInfo();
			m_printInfosMap[outputID]->setOutputID(outputID);/// set the OUTPUTID for the new PrintInfo
		}
		PrintInfo *pi = NULL; /// reset the pointer
		pi = m_printInfosMap[outputID];

		ostringstream oss;
		oss << subBasinID << "_";
		string strSubbasinID = oss.str();
		bool isRaster = false;
		string gtiff(GTiffExtension);
		if (gtiff.find(suffix) != gtiff.npos)
			isRaster = true;
		/// Check Tag_OutputSubbsn first
		if (StringMatch(subBsn, Tag_Outlet)) /// Output of outlet, such as Qoutlet, SEDoutlet, etc.
		{
			pi->setInterval(interval);
			pi->setIntervalUnits(intervalUnit);
			pi->AddPrintItem(sTimeStr, eTimeStr, strSubbasinID + coreFileName, ValueToString(m_outletID), suffix, m_conn, m_outputGfs, true);
			//pi->AddPrintItem(sTimeStr, eTimeStr, strSubbasinID + coreFileName, suffix);
		}
		else if (StringMatch(subBsn, Tag_AllSubbsn) && isRaster) 
		{
			/// Output of all subbasins of DT_Raster1D or DT_Raster2D
			vector<string> aggTypes = utils::SplitString(aggType, ',');
			for(vector<string>::iterator it = aggTypes.begin(); it != aggTypes.end(); it++)
				pi->AddPrintItem(*it, sTimeStr, eTimeStr, strSubbasinID + coreFileName, suffix, m_conn, m_outputGfs);
		}
		else // subbasin IDs is provided
		{
			pi->setInterval(interval);
			pi->setIntervalUnits(intervalUnit);
			vector<string> subBsns;
			if (StringMatch(subBsn, Tag_AllSubbsn))
			{
				for(int i = 0; i <= m_nSubbasins; i++)
					subBsns.push_back(ValueToString(i));
				vector<string>(subBsns).swap(subBsns);
			}
			else
				subBsns = utils::SplitString(subBsn, ',');
			for(vector<string>::iterator it = subBsns.begin(); it != subBsns.end(); it++)
				pi->AddPrintItem(sTimeStr, eTimeStr, strSubbasinID + coreFileName, *it, suffix, m_conn, m_outputGfs, true);
		}
    }
	for (map<string, PrintInfo*>::iterator it = m_printInfosMap.begin(); it != m_printInfosMap.end(); it++)
	{
		m_printInfos.push_back(it->second);
	}
	vector<PrintInfo*>(m_printInfos).swap(m_printInfos);
    bson_destroy(b);
    mongoc_collection_destroy(collection);
    mongoc_cursor_destroy(cursor);
    return true;
}
Esempio n. 5
0
bool CFilterManager::FilenameFilteredByFilter(const CFilter& filter, const wxString& name, const wxString& path, bool dir, wxLongLong size, int attributes, CDateTime const& date)
{
	if (dir && !filter.filterDirs)
		return false;
	else if (!dir && !filter.filterFiles)
		return false;

	for (std::vector<CFilterCondition>::const_iterator iter = filter.filters.begin(); iter != filter.filters.end(); ++iter)
	{
		bool match = false;
		const CFilterCondition& condition = *iter;

		switch (condition.type)
		{
		case filter_name:
			match = StringMatch(name, condition.strValue, condition.condition, filter.matchCase, condition.pRegEx);
			break;
		case filter_path:
			match = StringMatch(path, condition.strValue, condition.condition, filter.matchCase, condition.pRegEx);
			break;
		case filter_size:
			if (size == -1)
				continue;
			switch (condition.condition)
			{
			case 0:
				if (size > condition.value)
					match = true;
				break;
			case 1:
				if (size == condition.value)
					match = true;
				break;
			case 2:
				if (size != condition.value)
					match = true;
				break;
			case 3:
				if (size < condition.value)
					match = true;
				break;
			}
			break;
		case filter_attributes:
#ifndef __WXMSW__
			continue;
#else
			if (!attributes)
				continue;

			{
				int flag = 0;
				switch (condition.condition)
				{
				case 0:
					flag = FILE_ATTRIBUTE_ARCHIVE;
					break;
				case 1:
					flag = FILE_ATTRIBUTE_COMPRESSED;
					break;
				case 2:
					flag = FILE_ATTRIBUTE_ENCRYPTED;
					break;
				case 3:
					flag = FILE_ATTRIBUTE_HIDDEN;
					break;
				case 4:
					flag = FILE_ATTRIBUTE_READONLY;
					break;
				case 5:
					flag = FILE_ATTRIBUTE_SYSTEM;
					break;
				}

				int set = (flag & attributes) ? 1 : 0;
				if (set == condition.value)
					match = true;
			}
#endif //__WXMSW__
			break;
		case filter_permissions:
#ifdef __WXMSW__
			continue;
#else
			if (attributes == -1)
				continue;

			{
				int flag = 0;
				switch (condition.condition)
				{
				case 0:
					flag = S_IRUSR;
					break;
				case 1:
					flag = S_IWUSR;
					break;
				case 2:
					flag = S_IXUSR;
					break;
				case 3:
					flag = S_IRGRP;
					break;
				case 4:
					flag = S_IWGRP;
					break;
				case 5:
					flag = S_IXGRP;
					break;
				case 6:
					flag = S_IROTH;
					break;
				case 7:
					flag = S_IWOTH;
					break;
				case 8:
					flag = S_IXOTH;
					break;
				}

				int set = (flag & attributes) ? 1 : 0;
				if (set == condition.value)
					match = true;
			}
#endif //__WXMSW__
			break;
		case filter_date:
			if (date.IsValid()) {
				int cmp = date.Compare( condition.date );
				switch (condition.condition)
				{
				case 0: // Before
					match = cmp < 0;
					break;
				case 1: // Equals
					match = cmp == 0;
					break;
				case 2: // Not equals
					match = cmp != 0;
					break;
				case 3: // After
					match = cmp > 0;
					break;
				}
			}
			break;
		default:
			wxFAIL_MSG(_T("Unhandled filter type"));
			break;
		}
		if (match) {
			if (filter.matchType == CFilter::any)
				return true;
			else if (filter.matchType == CFilter::none)
				return false;
		}
		else {
			if (filter.matchType == CFilter::all)
				return false;
		}
	}

	if (filter.matchType != CFilter::any || filter.filters.empty())
		return true;

	return false;
}
Esempio n. 6
0
d_points * _pnts_load_shp(const char * filename, const char * pntsname, const char * param) {

	SHPHandle hSHP;
	DBFHandle hDBF;
	
	hSHP = SHPOpen(filename, "rb");
	if( hSHP == NULL ) {
		writelog(LOG_ERROR, "Unable to open:%s", filename );
		return NULL;
	}

	int shpType;
	int Entities;
	SHPGetInfo(hSHP, &Entities, &shpType, NULL, NULL);

	if (shpType != SHPT_POINT) {
		SHPClose( hSHP );
		writelog(LOG_ERROR, "%s : Wrong shape type!", filename);
		return NULL;
	}

	hDBF = DBFOpen(filename, "rb");
	if( hDBF == NULL ) {
		SHPClose(hSHP);
		writelog(LOG_ERROR, "Unable to open DBF for %s", filename );
		return NULL;
	}

	int name_field = DBFGetFieldIndex( hDBF, "NAME" );
	if (name_field == -1)
		writelog(LOG_WARNING,"can't find field named \"NAME\"");

	int val_field = DBFGetFieldIndex( hDBF, param );
	
	if (val_field == -1) 
		writelog(LOG_WARNING, "Cannot find parameter \"%s\" in DBF file", param);
		
	int dbf_records = DBFGetRecordCount( hDBF );

	Entities = MIN(dbf_records, Entities);

	vec * X = create_vec(Entities, 0, 0);
	vec * Y = create_vec(Entities, 0, 0);
	
	int i;
	for (i = 0; i < Entities; i++) {
		SHPObject * shpObject = SHPReadObject( hSHP, i );
		if (shpObject == NULL)
			continue;

		const char * name = NULL;
		if (name_field != -1) {
			name = DBFReadStringAttribute( hDBF, i, name_field );
			if (pntsname != NULL) {
				if ( StringMatch(pntsname, name) == false )
					continue;
			}
		}

		(*X)(i) = *(shpObject->padfX);
		(*Y)(i) = *(shpObject->padfY);
		SHPDestroyObject(shpObject);
	}

	vec * Z = create_vec(Entities, 0, 0);
	for (i = 0; i < Entities; i++) {
		if (val_field != -1)
			(*Z)(i) = DBFReadDoubleAttribute( hDBF, i, val_field );
		else
			(*Z)(i) = 0;
	}

	DBFClose( hDBF );
	SHPClose( hSHP );

	char * fname = get_name(filename);
	d_points * res = create_points(X, Y, Z, fname);
	sstuff_free_char(fname);
	return res;

};
Esempio n. 7
0
void SOL_WB::Set1DData(const char* key, int nRows, float* data)
{
	string s(key);
	if(StringMatch(s, Tag_SubbasinSelected))
	{
		m_subbasinSelected = data;
		m_subbasinSelectedCount = nRows;
		return;
	}

	if(StringMatch(s, VAR_T_RG))
	{
		m_RG = data;
		m_subbasinTotalCount = nRows;		

		return;
	}

	CheckInputSize(key,nRows);

	if(StringMatch(s, VAR_INLO))				
		m_Interception = data;
	else if(StringMatch(s, VAR_PRECI))			
		m_Precipitation = data;
	else if(StringMatch(s, VAR_INET))		
		m_EI = data;
	else if(StringMatch(s, VAR_DPST))		
		m_Depression = data;
	else if(StringMatch(s, VAR_DEET))		
		m_ED = data;	
	else if(StringMatch(s, VAR_INFIL))
		m_Infil = data;
	else if(StringMatch(s, VAR_SOET))	
		m_ES = data;
	else if(StringMatch(s, VAR_REVAP))		
		m_Revap = data;	
	else if(StringMatch(s, VAR_SURU))		
		m_RS = data;
	else if(StringMatch(s, VAR_T_RG))			
		m_RG = data;
	else if(StringMatch(s, VAR_SNSB))		
		m_SE = data;
	else if(StringMatch(s, VAR_TMIN))		
		m_tMin = data;	
	else if(StringMatch(s, VAR_TMAX))		
		m_tMax = data;	
	else if(StringMatch(s, VAR_SOTE))		
		m_SoilT = data;
	else if(StringMatch(s, VAR_SUBBSN))		
		m_subbasin = data;
	else if(StringMatch(s, VAR_SOILDEPTH))		
		m_Rootdepth = data;	
	else if(StringMatch(s, VAR_NEPR))	
		m_pNet = data;
	else
		throw ModelException("SOL_WB", "Set1DData", "Parameter " + s + " does not exist in the SOL_WB module.");

}
Esempio n. 8
0
void UnsaturatedFlow::Set1DData(const char* key, int nRows, float* data)
{
	string s(key);

	this->CheckInputSize(key,nRows);

	if(StringMatch(s,"Fieldcap"))			this->m_FieldCap = data;
	else if(StringMatch(s,"Wiltingpoint"))	this->m_WiltPoint = data;
	else if(StringMatch(s,"RootDepth"))		this->m_rootDepth = data;
	else if(StringMatch(s,"D_INET"))		this->m_EI = data;
	else if(StringMatch(s,"D_PET"))			this->m_PET = data;	
	else if(StringMatch(s,"D_DEET"))		this->m_ED = data;
	else if(StringMatch(s,"D_SOMO"))		this->m_Moist = data;	
	else if(StringMatch(s,"D_SOTE"))		this->m_SoilT = data;
	else if(StringMatch(s,"D_GRRE"))		this->m_percolation = data;	
	else if(StringMatch(s,"D_INFIL"))		this->m_infiltration = data;
	else if(StringMatch(s,"D_SSRU"))		this->m_interflow = data;
	else									throw ModelException("UnsaturatedFlow","SetValue","Parameter " + s + " does not exist in UnsaturatedFlow method. Please contact the module developer.");

}
Esempio n. 9
0
bool _curv_load_shp(const char * filename, const char * curvname) {

	SHPHandle hSHP;
	DBFHandle hDBF;
	
	hSHP = SHPOpen(filename, "rb");
	if( hSHP == NULL ) {
		writelog(LOG_ERROR, "Unable to open:%s", filename );
		return false;
	}

	int shpType;
	int Entities;
	SHPGetInfo(hSHP, &Entities, &shpType, NULL, NULL);

	if (shpType != SHPT_ARC) {
		SHPClose( hSHP );
		writelog(LOG_ERROR, "%s : Wrong shape type! Should be SHTP_ARC.", filename);
		return false;
	}

	hDBF = DBFOpen(filename, "rb");
	if( hDBF == NULL ) {
		SHPClose(hSHP);
		writelog(LOG_ERROR, "Unable to open DBF for %s", filename );
		return false;
	}

	int name_field = DBFGetFieldIndex( hDBF, "NAME" );
	int dbf_records = DBFGetRecordCount( hDBF );

	Entities = MIN(dbf_records, Entities);

	int i, j;
	for (i = 0; i < Entities; i++) {
		SHPObject * shpObject = SHPReadObject( hSHP, i );

		if (shpObject->nParts != 1) {
			SHPDestroyObject(shpObject);
			continue;
		}
			
		const char * name = NULL;
		if (name_field != -1)
			name = DBFReadStringAttribute( hDBF, i, name_field );

		if (curvname != NULL) {
			if ( StringMatch(curvname, name) == false )
				continue;
		}

		writelog(LOG_MESSAGE,"loading curve \"%s\" from ESRI shape file %s",
			name?name:"noname",filename);

		vec * X = create_vec(shpObject->nVertices,0,0);
		vec * Y = create_vec(shpObject->nVertices,0,0);
		
		for (j = 0; j < shpObject->nVertices; j++) {
			(*X)(j) = *(shpObject->padfX + j);
			(*Y)(j) = *(shpObject->padfY + j);
		}
		
		d_curv * res = create_curv(X, Y, name);

		surfit_curvs->push_back(res);
	}

	DBFClose( hDBF );
	SHPClose( hSHP );

	return true;
};
Esempio n. 10
0
void MUSLE_AS::Set1DData(const char *key, int n, float *data)
{

    CheckInputSize(key, n);
    string s(key);
    if (StringMatch(s, VAR_USLE_C)) m_usle_c = data;
    else if (StringMatch(s, VAR_USLE_P)) m_usle_p = data;
    else if (StringMatch(s, VAR_ACC)) m_flowacc = data;
    else if (StringMatch(s, VAR_SLOPE)) m_slope = data;
    //else if (StringMatch(s, VAR_SUBBSN)) m_subbasin = data;
	//else if (StringMatch(s, VAR_SURU)) m_surfaceRunoff = data;
	else if (StringMatch(s, VAR_OLFLOW))m_surfaceRunoff = data;
    else if (StringMatch(s, VAR_SNAC)) m_snowAccumulation = data;
    else if (StringMatch(s, VAR_STREAM_LINK))m_streamLink = data;
	else if (StringMatch(s, VAR_DETACH_SAND)) m_detachSand = data;
	else if (StringMatch(s, VAR_DETACH_SILT)) m_detachSilt = data;
	else if (StringMatch(s, VAR_DETACH_CLAY)) m_detachClay = data;
	else if (StringMatch(s, VAR_DETACH_SAG)) m_detachSmAggre = data;
	else if (StringMatch(s, VAR_DETACH_LAG)) m_detachLgAggre = data;
    else
        throw ModelException(MID_MUSLE_AS, "Set1DData", "Parameter " + s + " does not exist.");
}
Esempio n. 11
0
void VMMain(int argc, char *argv[]){
    int DirDescriptor, FileDescriptor, Length;
    char LineBuffer[1024];
    char DirectoryName[VM_FILE_SYSTEM_MAX_PATH];
    SVMDirectoryEntry DirectoryEntry;
    int CharactersIn = 0;
    int Mil, Kil, One;
    
    while(1){
        VMDirectoryCurrent(DirectoryName);
        VMPrint("%s> ",DirectoryName);
        CharactersIn = 0;
        while(1){
            Length = 1;
            VMFileRead(0, LineBuffer + CharactersIn, &Length);
            if('\n' == LineBuffer[CharactersIn]){
                LineBuffer[CharactersIn] = '\0';
                break;
            }
            if((0 == CharactersIn)&&(' ' == LineBuffer[CharactersIn])){
                continue;
            }
            CharactersIn++;
        }
        
        while(0 < CharactersIn){
            CharactersIn--;
            if(' ' != LineBuffer[CharactersIn]){
                CharactersIn++;
                break;
            }
            LineBuffer[CharactersIn] = '\0';
        }
        if(StringMatch(LineBuffer,"exit")){
            break;
        }
        else if(StringMatch(LineBuffer,"ls")){
            
            if(VM_STATUS_SUCCESS == VMDirectoryOpen(DirectoryName, &DirDescriptor)){
                VMPrint("   DATE   |  TIME  | TYPE |    SIZE   |    SFN      |  LFN\n");
                while(VM_STATUS_SUCCESS == VMDirectoryRead(DirDescriptor, &DirectoryEntry)){
                    VMPrint("%04d/%02d/%02d %02d:%02d %s ",DirectoryEntry.DModify.DYear, DirectoryEntry.DModify.DMonth, DirectoryEntry.DModify.DDay, (DirectoryEntry.DModify.DHour % 12) ? (DirectoryEntry.DModify.DHour % 12) : 12 , DirectoryEntry.DModify.DMinute, DirectoryEntry.DModify.DHour >= 12 ? "PM" : "AM");
                    VMPrint("%s ", DirectoryEntry.DAttributes & VM_FILE_SYSTEM_ATTR_DIRECTORY ? "<DIR> " : "<FILE>");
                    Mil = DirectoryEntry.DSize / 1000000;
                    Kil = (DirectoryEntry.DSize / 1000) % 1000;
                    One = DirectoryEntry.DSize % 1000;
                    if(Mil){
                        VMPrint("%3d,%03d,%03d ",Mil, Kil, One);   
                    }
                    else if(Kil){
                        VMPrint("    %3d,%03d ", Kil, One);
                    }
                    else if(0 == (DirectoryEntry.DAttributes & VM_FILE_SYSTEM_ATTR_DIRECTORY)){
                        VMPrint("        %3d ",One);
                    }
                    else{
                        VMPrint("            ");   
                    }
                    VMPrint("%-13s %s\n",DirectoryEntry.DShortFileName, DirectoryEntry.DLongFileName);
                }
                VMDirectoryClose(DirDescriptor);
            }
            else{
                VMPrint("Failed to open directory %s!\n", DirectoryName);   
            }
        }
        else if(StringMatchN(LineBuffer,"cd ",3)){
            CharactersIn = 2;
            while(' ' == LineBuffer[CharactersIn]){
                CharactersIn++;
            }
            if('\0' == LineBuffer[CharactersIn]){
                CharactersIn--;
                LineBuffer[CharactersIn] = '/';
            }
            if(VM_STATUS_SUCCESS != VMDirectoryChange(LineBuffer + CharactersIn)){
                VMPrint("Failed to change directory to %s!\n", LineBuffer + CharactersIn);
            }
        }
        else if(StringMatchN(LineBuffer,"rm ",3)){
            CharactersIn = 2;
            while(' ' == LineBuffer[CharactersIn]){
                CharactersIn++;
            }
            if('\0' == LineBuffer[CharactersIn]){
                CharactersIn--;
                LineBuffer[CharactersIn] = '/';
            }
            if(VM_STATUS_SUCCESS != VMDirectoryUnlink(LineBuffer + CharactersIn)){
                VMPrint("Failed to remove node %s!\n", LineBuffer + CharactersIn);
            }
        }
        else if(StringMatchN(LineBuffer,"mkdir ",6)){
            CharactersIn = 5;
            while(' ' == LineBuffer[CharactersIn]){
                CharactersIn++;
            }
            if('\0' == LineBuffer[CharactersIn]){
                CharactersIn--;
                LineBuffer[CharactersIn] = '/';
            }
            if(VM_STATUS_SUCCESS != VMDirectoryCreate(LineBuffer + CharactersIn)){
                VMPrint("Failed to create directory %s!\n", LineBuffer + CharactersIn);
            }
        }
        else if(StringMatchN(LineBuffer,"cat ",4)){
            CharactersIn = 3;
            while(' ' == LineBuffer[CharactersIn]){
                CharactersIn++;
            }
            if(VM_STATUS_SUCCESS == VMFileOpen(LineBuffer + CharactersIn, O_RDONLY, 0644, &FileDescriptor)){
                Length = sizeof(LineBuffer);
                while(VM_STATUS_SUCCESS == VMFileRead(FileDescriptor, LineBuffer, &Length)){
                    if(Length){
                        VMFileWrite(1,LineBuffer,&Length);
                    }
                    if(Length < sizeof(LineBuffer)){
                        break;
                    }
                    Length = sizeof(LineBuffer);
                }
                VMFileClose(FileDescriptor);
            }
            else{
                VMPrint("Failed to open file %s!\n", LineBuffer + CharactersIn);
            }
        }
    }
}
Esempio n. 12
0
void SUR_GA::Set1DData(const char *key, int n, float *data)
{

    this->CheckInputSize(key, n);

    //set the value
    string sk(key);

    if (StringMatch(sk, "Conductivity"))
    {
        m_Conductivity = data;
    }
    else if (StringMatch(sk, "porosity"))
    {
        m_porosity = data;
    }
    else if (StringMatch(sk, "clay"))
    {
        m_clay = data;
    }
    else if (StringMatch(sk, "sand"))
    {
        m_sand = data;
    }
    else if (StringMatch(sk, "rootDepth"))
    {
        m_rootDepth = data;
    }
    else if (StringMatch(sk, "cn2"))
    {
        m_CN2 = data;
    }
    else if (StringMatch(sk, "D_NEPR"))
    {
        m_P_NET = data;
    }
    else if (StringMatch(sk, "fieldCap"))
    {
        m_fieldCap = data;
    }
    else if (StringMatch(sk, "wiltingPoint"))
    {
        m_wiltingPoint = data;
    }
    else if (StringMatch(sk, "D_SOMO"))
    {
        m_soilMoisture = data;
    }
        //else if (StringMatch(sk,"INFRate_In"))
        //{
        //	m_INFRate = data;
        //}
        /*else if (StringMatch(sk,"S_M_frozen"))
        {
            m_Sfrozen = data;
        }*/
        /*else if (StringMatch(sk,"depression"))
        {
            m_Depression = data;
        }*/
    else if (StringMatch(sk, "D_DPST"))
    {
        m_SD = data;
    }
    else if (StringMatch(sk, "D_TMin"))
    {
        m_tMin = data;
    }
    else if (StringMatch(sk, "D_TMax"))
    {
        m_tMax = data;
    }
    else if (StringMatch(sk, "D_SNME"))
    {
        m_SM = data;
    }
    else if (StringMatch(sk, "D_SNAC"))
    {
        m_SA = data;
    }
    else if (StringMatch(sk, "D_SOTE"))
    {
        m_TS = data;
    }
    else
        throw ModelException("SUR_GA", "SetValue", "Parameter " + sk +
                                                   " does not exist in SUR_GA method. Please contact the module developer.");

}
Esempio n. 13
0
int
find_oligos(GapIO *io,
	    int num_contigs,
	    contig_list_t *contig_array,
	    float mis_match,
	    char *string,
	    int consensus_only,
	    int in_cutoff)
{
    int i;
    int *pos1 = NULL;
    int *pos2 = NULL;
    int *score = NULL;
    int *length = NULL;
    tg_rec *c1 = NULL;
    tg_rec *c2 = NULL;
    int max_matches, abs_max;
    int seq_len;
    int n_matches;
    int max_clen;
    char **cons_array = NULL;

    /* Calculate maximum contig length and total contig length */
    for (max_matches = 0, max_clen = 0, i=0; i<num_contigs; i++) {
	if (io_clength(io, contig_array[i].contig) > max_clen)
	    max_clen = io_clength(io, contig_array[i].contig);
	max_matches += io_clength(io, contig_array[i].contig);
    }
    max_matches *= 2; /* both strands */

    abs_max = get_default_int(GetInterp(), gap5_defs, "FINDOLIGO.MAX_MATCHES");

    if (max_matches > abs_max)
	max_matches = abs_max;

    if (NULL == (pos1 = (int *)xmalloc((max_matches + 1) * sizeof(int))))
	goto error;
    if (NULL == (pos2 = (int *)xmalloc((max_matches + 1) * sizeof(int))))
	goto error;
    if (NULL == (score = (int *)xmalloc((max_matches + 1) * sizeof(int))))
	goto error;
    if (NULL == (length = (int *)xmalloc((max_matches + 1) * sizeof(int))))
	goto error;
    if (NULL == (c1 = (tg_rec *)xmalloc((max_matches + 1) * sizeof(tg_rec))))
	goto error;
    if (NULL == (c2 = (tg_rec *)xmalloc((max_matches + 1) * sizeof(tg_rec))))
	goto error;

    /* save consensus for each contig */
    if (NULL == (cons_array = (char **)xmalloc(num_contigs * sizeof(char *))))
	goto error;

    for (i = 0; i < num_contigs; i++) {
	seq_len = contig_array[i].end - contig_array[i].start + 1;
	if (NULL == (cons_array[i] = (char *)xmalloc(seq_len + 1)))
	    goto error;

	calculate_consensus_simple(io, contig_array[i].contig,
				   contig_array[i].start, contig_array[i].end,
				   cons_array[i], NULL);

	cons_array[i][seq_len] = '\0';
    }

    /* do match on either tag(s) or string */
    if (string && *string) {
	n_matches = StringMatch(io, num_contigs, contig_array,
				cons_array, string, mis_match, pos1, pos2,
				score, length, c1, c2, max_matches,
				consensus_only, in_cutoff);
	if (-1 == RegFindOligo(io, SEQUENCE, pos1, pos2, score, length, c1,
			       c2, n_matches))
	    goto error;
    } else {
	/*
	if (-1 == (n_matches = TagMatch(io, max_clen, num_contigs,
					contig_array, cons_array,
					mis_match, pos1, pos2,
					score, length, c1, c2, max_matches)))
	    goto error;
	if (-1 == RegFindOligo(io, TAG, pos1, pos2, score, length, c1, c2,
			       n_matches))
	*/
	    goto error;
    }

    for (i = 0; i < num_contigs; i++) {
	if (cons_array[i])
	    xfree(cons_array[i]);
    }
    xfree(cons_array);
    xfree(c1);
    xfree(c2);
    xfree(pos1);
    xfree(pos2);
    xfree(score);
    xfree(length);
    return 0;

 error:
    if (c1)
	xfree(c1);
    if (c2)
	xfree(c2);
    if (cons_array)
	xfree(cons_array);
    if (pos1)
	xfree(pos1);
    if (pos2)
	xfree(pos2);
    if (score)
	xfree(score);
    if (length)
	xfree(length);

    return -1;
}