Example #1
0
int main(int argc,const char **argv)
{
	int returnVal = 0;

	g_Logger.Start("gmParser.log", true);
	LOG("gmParser");

	if(argc < 2)
	{
		PrintUsage();
		ERROR_RETURN;
	}	

	Timer tme, totaltime;
	

	const char *FolderIn = argv[1];
	//const char *FolderOut = argv[2];

	if(!FileSystem::InitRawFileSystem(FolderIn))
	{
		std::cout << "Unable to Initialize File System." << std::endl;
		ERROR_RETURN;
	}

	if(!FileSystem::Mount(FolderIn,""))
	{
		std::cout << "Unable to Mount Root Folder." << std::endl;
		ERROR_RETURN;
	}

	if(!FileSystem::SetWriteDirectory(fs::path(FolderIn,fs::native)))
	{
		std::cout << "Unable to Set Write Folder." << std::endl;
		ERROR_RETURN;
	}

	// find all files to parse
	tme.Reset();
	boost::regex ex("test.*.cpp");
	DirectoryList dl;
	FileSystem::FindAllFiles("",dl,ex,true);
	std::cout << "Found " << dl.size() << " files in " << tme.GetElapsedSeconds() << " seconds." << std::endl;;

	// parse files
	tme.Reset();
	typedef std::vector<FileParser> FileParserList;
	FileParserList parsers;
	parsers.reserve(dl.size());
	for(obuint32 i = 0; i < dl.size(); ++i)
	{
		parsers.push_back(FileParser(dl[i].string()));
	}

	const int numParsers = parsers.size();

#pragma omp parallel for
	for(int i = 0; i < numParsers; ++i)
	{
		parsers[i].ParseFile();
		std::cout << "*";
	}

	std::cout << std::endl;
	std::cout << "Parsed " << numParsers << " files in " << tme.GetElapsedSeconds() << " seconds." << std::endl;

	// merge all to a master function list
	FunctionList allFunctions;
	allFunctions.reserve(2048);
	for(obuint32 i = 0; i < (obuint32)numParsers; ++i)
	{
		allFunctions.insert(allFunctions.end(),parsers[i].Functions.begin(),parsers[i].Functions.end());

		for(obuint32 e = 0; e < parsers[i].Info.size(); ++e)
		{
			std::cout << parsers[i].Info[e] << std::endl;
		}
	}
	std::cout << "Found " << allFunctions.size() << " functions..." << std::endl;

	// write the function bindings out to files.
	tme.Reset();
	const int numFiles = WriteFunctions(allFunctions);
	std::cout << "Wrote " << numFiles << " files in " << tme.GetElapsedSeconds() << " seconds." << std::endl;

	std::cout << "Finished in " << totaltime.GetElapsedSeconds() << " seconds." << std::endl;

	return 0;
}
Example #2
0
bool DistributeInterpolate::loadDataAsSerie(std::string FilePath, SeriePreprocess SPpcs, DateTimeSerie *Serie)
{
  ColumnTextParser FileParser("%");
  bool IsOK;

  IsOK = true;

  long int Year, Month, Day, Hour, Min, Sec;
  double Value;
  double CumValue, ValueToAdd;
  openfluid::core::DateTime ZeDT;


  Serie->clear();


  if (FileParser.loadFromFile(FilePath) && (FileParser.getLinesCount() > 0) && (FileParser.getColsCount() == 7))
  {
    int i = 0;
    CumValue = 0;

    while (i<FileParser.getLinesCount() && IsOK)
    {
      if (FileParser.getLongValue(i,0,&Year) && FileParser.getLongValue(i,1,&Month) &&
          FileParser.getLongValue(i,2,&Day) && FileParser.getLongValue(i,3,&Hour) &&
          FileParser.getLongValue(i,4,&Min) && FileParser.getLongValue(i,5,&Sec) &&
          FileParser.getDoubleValue(i,6,&Value))
      {

        if (!boost::math::isnan(Value) && !boost::math::isinf(Value))
        {

          ZeDT = openfluid::core::DateTime(Year,Month,Day,Hour,Min,Sec);

          CumValue +=  Value;

          if (SPpcs == SERIEPREPCS_CUMULATE) ValueToAdd = CumValue;
          else ValueToAdd = Value;


          if (!boost::math::isnan(ValueToAdd) && !boost::math::isinf(ValueToAdd))
          {
            if (!Serie->addValue(ZeDT,ValueToAdd))
            {
              IsOK = false;
            }
          }
          else
          {
            IsOK = false;
          }
        }
      }
      else
      {
        IsOK = false;
      }

      i++;
    }
  }
  else
  {
    IsOK = false;
  }


  return IsOK;

}