MCPcopy Create free account
hub / github.com/Cantera/cantera / findInputFile

Method findInputFile

src/base/application.cpp:313–376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

311}
312
313string Application::findInputFile(const string& name)
314{
315 std::unique_lock<std::mutex> dirLock(dir_mutex);
316 string::size_type islash = name.find('/');
317 string::size_type ibslash = name.find('\\');
318 string::size_type icolon = name.find(':');
319 vector<string>& dirs = inputDirs;
320
321 // Expand "~/" to user's home directory, if possible
322 if (name.find("~/") == 0 || name.find("~\\") == 0) {
323 char* home = getenv("HOME"); // POSIX systems
324 if (!home) {
325 home = getenv("USERPROFILE"); // Windows systems
326 }
327 if (home) {
328 string full_name = home + name.substr(1, npos);
329 std::ifstream fin(full_name);
330 if (fin) {
331 return full_name;
332 } else {
333 throw CanteraError("Application::findInputFile",
334 "Input file '{}' not found", name);
335 }
336 }
337 }
338
339 // If this is an absolute path, just look for the file there
340 if (islash == 0 || ibslash == 0
341 || (icolon == 1 && (ibslash == 2 || islash == 2)))
342 {
343 std::ifstream fin(name);
344 if (fin) {
345 return name;
346 } else {
347 throw CanteraError("Application::findInputFile",
348 "Input file '{}' not found", name);
349 }
350 }
351
352 // Search the Cantera data directories for the input file, and return
353 // the full path if a match is found
354 size_t nd = dirs.size();
355 for (size_t i = 0; i < nd; i++) {
356 string full_name = dirs[i] + "/" + name;
357 std::ifstream fin(full_name);
358 if (fin) {
359 return full_name;
360 }
361 }
362 string msg = "\nInput file " + name + " not found in director";
363 msg += (nd == 1 ? "y " : "ies ");
364 for (size_t i = 0; i < nd; i++) {
365 msg += "\n'" + dirs[i] + "'";
366 if (i+1 < nd) {
367 msg += ", ";
368 }
369 }
370 msg += "\n\n";

Callers 1

findInputFileFunction · 0.80

Calls 2

CanteraErrorClass · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected