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 } } } }
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(); }