void EnergyPlusJob::getFiles(const Files &t_files, const JobParams &t_params) const { // This function works with mutable local objects // because it's used to cache looked up variables if (!m_idf) { if (t_params.has("filename") && !t_params.get("filename").children.empty()) { // first, see if we can get a filename that was specifically requested by the job creation std::string filename = t_params.get("filename").children[0].value; LOG(Info, "Looking for filename: " << filename); std::vector<FileInfo> files = t_files.getAllByFilename(filename).files(); if (!files.empty()) { m_idf = files.back(); } else { // a filename param was provided, but the file hasn't been generated ... yet } } else { // if not, try to get any old IDF that was passed in std::vector<FileInfo> files = t_files.getAllByExtension("idf").files(); if (!files.empty()) { m_idf = files.back(); } else { // there are not any idf files at all } } } }
ParallelEnergyPlusSplitJob::ParallelEnergyPlusSplitJob(const UUID &t_uuid, const Tools &tools, const JobParams ¶ms, const Files &files, const JobState &t_restoreData) : Job_Impl(t_uuid, JobType::ParallelEnergyPlusSplit, tools, params, files, t_restoreData), m_numSplits(boost::lexical_cast<int>(params.get("numsplits").children.at(0).value)), m_offset(boost::lexical_cast<int>(params.get("offset").children.at(0).value)) { try { m_input = files.getLastByExtension("idf"); resetFiles(m_files, m_input); } catch (const std::runtime_error &) { } m_description = buildDescription("idf"); }
void DakotaJob::getFiles(const Files &t_files, const JobParams &t_params) const { // This function works with mutable local objects // because it's used to cache looked up variables if (!m_inFile) { try { // first, see if we can get a filename that was specifically requested by the job creation m_inFile = t_files.getLastByFilename(t_params.get("filename").value); } catch (const std::runtime_error &) { // if not, try to get any old .in that was passed in try { m_inFile = t_files.getLastByExtension("in"); } catch (const std::runtime_error &) {} } } }
openstudio::path WeatherFileFinder::find(const JobParams &t_params, const boost::optional<std::string> &t_filelocationname, const boost::optional<std::string> &t_weatherfilename) { openstudio::path epwdir; try { if (t_params.has("epwfile")) { openstudio::path epwfile = toPath(t_params.get("epwfile").children.at(0).value); if (!epwfile.empty() && boost::filesystem::exists(epwfile)) { LOG(Info, "Valid epwfile found, returning: " << openstudio::toString(epwfile)); return epwfile; } } else { LOG(Info, "No epwfile found in params, moving on for other methods of finding weather file"); } } catch (const std::exception &) { // No epw dir set in params LOG(Info, "Error with epwfile found in params, moving on for other methods of finding weather file"); } try { if (t_params.has("epwdir")) { epwdir = toPath(t_params.get("epwdir").children.at(0).value); } } catch (const std::exception &) { // No epw dir set in params LOG(Info, "No EPWDir known finding weather file will be much harder"); } if (epwdir.empty() || !boost::filesystem::exists(epwdir) || !boost::filesystem::is_directory(epwdir)) { LOG(Info, "The configured EPWDir either does not exist or is not a directory: " << toString(epwdir)); } if (t_weatherfilename) { openstudio::path p = toPath(*t_weatherfilename); if (!boost::filesystem::exists(p)) { p = epwdir / toPath(*t_weatherfilename); if (!boost::filesystem::exists(p)) { LOG(Info, "Weather file discovered from comment header cannot be found at: " << toString(p)); } else { return p; } LOG(Info, "Weather file discovered from comment header cannot be found at: " << *t_weatherfilename); } else { return p; } } if (t_filelocationname) { LOG(Info, "attempting to find weather file from location name: " << *t_filelocationname); // We did not have an epw set, so let's try to find one try { QDir dir(openstudio::toQString(epwdir), "*.epw"); QFileInfoList files = dir.entryInfoList(); std::set<std::string> desiredname = getNameComponents(*t_filelocationname); openstudio::path bestmatch; size_t matchsize = 0; for (QFileInfoList::const_iterator itr = files.begin(); itr != files.end(); ++itr) { std::set<std::string> foundname = getNameComponents(openstudio::toString(itr->fileName())); std::vector<std::string> matches; std::set_intersection(desiredname.begin(), desiredname.end(), foundname.begin(), foundname.end(), std::back_inserter(matches)); if (matches.size() > matchsize) { matchsize = matches.size(); bestmatch = openstudio::toPath(itr->absoluteFilePath()); } } if (matchsize > 2) { LOG(Info, "Adding best match epw from the list found: " << toString(bestmatch)); return bestmatch; } else { LOG(Info, "No best match epw file found, continuing with no epw set"); } } catch (const std::exception &) { LOG(Info, "No EPw file set and no epwdir provided. We are continuing, but EnergyPlus will likely fail"); } } else { LOG(Info, "No EPw file set and no location information parsed from IDF. We are continuing, but EnergyPlus will likely fail"); } LOG(Info, "No weather file found"); return openstudio::path(); }