Esempio n. 1
0
std::vector<std::string> unfoldVariable(const std::string &string)
{
	std::vector<std::string> result;
	size_t begin = string.find('$');

	if (begin == std::string::npos)
	{
		result.push_back(string);

		return result;
	}

	size_t end = begin+1;

	while (end < string.size() && (std::isalnum(string.at(end)) || string.at(end) == '_'))
	{
		++end;
	}

	std::string name = string.substr(begin+1, end-(begin+1));

	std::vector<std::string> values = getVariableValues(name);

	for (std::vector<std::string>::iterator value = values.begin(); value != values.end(); ++value)
	{
		result.push_back(string.substr(0, begin) + (*value) + string.substr(end));
	}

	return result;
}
Esempio n. 2
0
File: Grib.cpp Progetto: WFRT/Comps
grib_index* InputGrib::getIndex(const Key::Input& iKey, const std::string& iLocalVariable) const {
   std::string indexFilename = getIndexFilename(iKey);
   char* filename_index = new char[indexFilename.size()+1];
   std::strcpy(filename_index, indexFilename.c_str());
   FILE* fid0 = fopen(filename_index, "r");
   grib_index* gribIndex = NULL;

   if(fid0 != NULL) {
      int err = 0;
      gribIndex = grib_index_read(0, filename_index, &err);
      //std::cout << "reading" << std::endl;
      if(err != 0) {
         assert(gribIndex == NULL);
         std::stringstream ss;
         ss << "Input::Grib Error reading index file: " << indexFilename;
         Global::logger->write(ss.str(), Logger::warning);
      }
      fclose(fid0);
      delete filename_index;
   }

   if(gribIndex == NULL)
      return(NULL);

   std::string shortName;
   std::string levelType;
   std::string level;
   getVariableValues(iLocalVariable, shortName, levelType,level);

   char* shortNameChar = new char[shortName.size()+1];
   char* levelTypeChar = new char[levelType.size()+1];
   char* levelChar     = new char[level.size()+1];
   std::strcpy(shortNameChar, shortName.c_str());
   std::strcpy(levelTypeChar, levelType.c_str());
   std::strcpy(levelChar, level.c_str());
   // NOTE: If the grib file was partial, then the index file might not contain the key we
   // are searching for. In this case grib_handle_new_from_index will not create any handle
   // This is ok.
   grib_index_select_string(gribIndex, "levtype", levelTypeChar);
   grib_index_select_string(gribIndex, "levelist", levelChar);
   grib_index_select_string(gribIndex, "shortName", shortNameChar);
   delete shortNameChar;
   delete levelTypeChar;
   delete levelChar;
   return(gribIndex);
}
Esempio n. 3
0
std::vector<std::string> unfoldVariable(const std::string &string)
{
	std::vector<std::string> result;

	if (!match(string, "$"))
	{
		result.push_back(string);

		return result;
	}

	int begin = 0;

	while (string.at(begin) != '$')
	{
		++begin;
	}

	int end = begin+1;

	while (std::isalnum(string.at(end)) || string.at(end) == '_')
	{
		++end;
	}

	std::string name = string.substr(begin+1, end-(begin+1));

	std::vector<std::string> values = getVariableValues(name);

	for (std::vector<std::string>::iterator value = values.begin(); value != values.end(); ++value)
	{
		result.push_back(string.substr(0, begin) + (*value) + string.substr(end));
	}

	return result;
}