From ddfc15bb77076a3e6ba92ec088b1b46037849b5b Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Fri, 12 Dec 2014 01:36:56 +0000 Subject: [PATCH] Allow CANTERA_DATA to include multiple directories --- doc/sphinx/cython/tutorial.rst | 9 +++++---- doc/sphinx/matlab/input-tutorial.rst | 7 ++++--- include/cantera/base/global.h | 6 ++++-- src/base/application.cpp | 25 +++++++++++++++++++------ 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/doc/sphinx/cython/tutorial.rst b/doc/sphinx/cython/tutorial.rst index 496e33ead..783c6135a 100644 --- a/doc/sphinx/cython/tutorial.rst +++ b/doc/sphinx/cython/tutorial.rst @@ -302,10 +302,11 @@ Files\\Cantera\\data`` on Windows or ``/usr/local/cantera/data/`` on Unix/Linux/Mac OS X machines, depending on how you installed Cantera and the options you specified. -If for some reason Cantera has difficulty finding where these files are on -your system, set environment variable ``CANTERA_DATA`` to the directory where -they are located. Alternatively, you can call function `add_directory` to add -a directory to the Cantera search path:: +If for some reason Cantera has difficulty finding where these files are on your +system, set environment variable ``CANTERA_DATA`` to the directory or +directories (separated using ``;`` on Windows or ``:`` on other operating +systems) where they are located. Alternatively, you can call function +`add_directory` to add a directory to the Cantera search path:: >>> ct.add_directory('/usr/local/cantera/my_data_files') diff --git a/doc/sphinx/matlab/input-tutorial.rst b/doc/sphinx/matlab/input-tutorial.rst index 9e4aef7a6..b16efe4c3 100644 --- a/doc/sphinx/matlab/input-tutorial.rst +++ b/doc/sphinx/matlab/input-tutorial.rst @@ -31,9 +31,10 @@ reaction mechanism, and a few surface reaction mechanisms. These files are kept in the ``data`` subdirectory within the Cantera installation directory. If for some reason Cantera has difficulty finding where these files are on your -system, set environment variable ``CANTERA_DATA`` to the directory where they -are located. Alternatively, you can call function ``addDirectory`` to add a -directory to the Cantera search path:: +system, set environment variable ``CANTERA_DATA`` to the directory or +directories (separated using ``;`` on Windows or ``:`` on other operating +systems) where they are located. Alternatively, you can call function +`add_directory` to add a directory to the Cantera search path:: addDirectory('/usr/local/cantera/my_data_files'); diff --git a/include/cantera/base/global.h b/include/cantera/base/global.h index b45d03ee6..05f3490aa 100644 --- a/include/cantera/base/global.h +++ b/include/cantera/base/global.h @@ -75,8 +75,10 @@ void popError(); * On the Mac, directory '/Applications/Cantera/data' is added to the * search path. * - * On any platform, if environment variable CANTERA_DATA is set to a - * directory name, then this directory is added to the search path. + * On any platform, if environment variable CANTERA_DATA is set to a directory + * name or a list of directory names separated with the OS-dependent path + * separator (i.e. ";" on Windows, ":" elsewhere), then these directories will + * be added to the search path. * * Finally, the location where the data files were installed when * %Cantera was built is added to the search path. diff --git a/src/base/application.cpp b/src/base/application.cpp index 2259339df..7c942a0b0 100644 --- a/src/base/application.cpp +++ b/src/base/application.cpp @@ -446,13 +446,26 @@ void Application::setDefaultDirectories() dirs.push_back("/Applications/Cantera/data"); #endif - // - // if environment variable CANTERA_DATA is defined, then add - // it to the search path - // + // if environment variable CANTERA_DATA is defined, then add it to the + // search path. CANTERA_DATA may include multiple directory, separated by + // the OS-dependent path separator (in the same manner as the PATH + // environment variable). +#ifdef _WIN32 + std::string pathsep = ";"; +#else + std::string pathsep = ":"; +#endif + if (getenv("CANTERA_DATA") != 0) { - string datadir = string(getenv("CANTERA_DATA")); - dirs.push_back(datadir); + string s = string(getenv("CANTERA_DATA")); + size_t start = 0; + size_t end = s.find(pathsep); + while(end != npos) { + dirs.push_back(s.substr(start, end-start)); + start = end + 1; + end = s.find(pathsep, start); + } + dirs.push_back(s.substr(start,end)); } // CANTERA_DATA is defined in file config.h. This file is written