wiki:EditPath

Version 8 (modified by peter, 13 years ago) (diff)

--

Setting the path

There are vast amounts of atomic data that the code must reference in order to compute a model. These are the files that live in the data directory. The code must be able to find these data files. Their location is stored in a global string variable named chDataPath which is set in the file path.cpp. You need to change the string so that it gives the location of the data on your machine.

There are three ways to specify the path to the data files. The first method is by editing path.cpp, which should be done before you start compiling. The second method is to add an extra parameter to the compiler options, and the third method is to set an environment variable at runtime.


Method 1: Setting the path by editing path.cpp

Edit the file path.cpp (located in the source directory) and locate the variable chDataPath. There are two instances. You need to edit the second one. Change the string within the double quotes so that it gives the location of the data on your computer. Remember that this is C++ code and that a line ends with a semicolon.

The path would be a string within double quotes. On a Unix machine the result should look like this:

#ifdef LOCAL_DATA_PATH
/* the first branch was added by Robin Williams and allows you to specify
 * any path as an argument to the compiler */ 
char chDataPath[FILENAME_PATH_LENGTH]=LOCAL_DATA_PATH;/**/
#else
/* This is the version you need to change - the first is the format to use 
 * on a windows machine
 * remove or comment out if you don't want to use it */
/* sample path on a Unix box */
char chDataPath[FILENAME_PATH_LENGTH]="/usr/gary/cloudy/data/";
#endif

On a Windows machine the result should look like this:

#ifdef LOCAL_DATA_PATH
/* the first branch was added by Robin Williams and allows you to specify
 * any path as an argument to the compiler */ 
char chDataPath[FILENAME_PATH_LENGTH]=LOCAL_DATA_PATH;/**/
#else
/* This is the version you need to change - the first is the format to use 
 * on a windows machine
 * remove or comment out if you don't want to use it */
/* sample path on a windows box */
char chDataPath[FILENAME_PATH_LENGTH]="c:\\projects\\cloudy\\current\\data\\";
#endif

The double backslash is needed on Windows systems to prevent the character following the slash from being interpreted as an escape sequence.

The string giving the path MUST have the proper directory mark as the last character before the second quote. This would be a "/" in Unix, a "
" in Windows, and a "]" in VMS.

C++ syntax for the newcomer There must be two double-quotes. The path is the series of characters between them. The line must end with a semicolon.

If the path is longer than FILENAME_PATH_LENGTH characters then increase the size of FILENAME_PATH_LENGTH in cddefines.h and recompile the entire code. Remember that in C++ a string must have one extra byte for storing the end-of-string sentinel.

If you store your *.ini initialization files in the data directory then the ini files will be automatically found by the code.


Method 2: Setting the path with a compiler option

Robin Williams added a macro, LOCAL_DATA_PATH, that allows the path to be specified by the value of the macro. To use this you should not edit the file path.cpp, but add the following parameter to the compiler options:

-DLOCAL_DATA_PATH=\"/usr/gary/cloudy/data/\"

(for Unix) or

-DLOCAL_DATA_PATH=\"c:\\projects\\cloudy\\current\\data\\\"

(for Windows). So the complete line could e.g. be (this depends on the platform and compiler you are using, see CompileCode for more details):

g++ -ansi -c -O3 -Wall -DLOCAL_DATA_PATH=\"/usr/gary/cloudy/data/\" *.cpp

Method 3: Supplying the path at runtime

You can set the path to the data files at runtime before you start up Cloudy by setting the environment variable CLOUDY_DATA_PATH. This setting will always override any settings supplied with the previous two methods. On Unix platforms the method for setting the environment variable depends on the shell you are using. For csh/tcsh use:

setenv CLOUDY_DATA_PATH "/usr/gary/cloudy/data/"

For bash/sh/ksh/etc... you should use:

export CLOUDY_DATA_PATH="/usr/gary/cloudy/data/"  (no spaces around the '='!)

Next step: CompileCode - compile the code.

Return to StepByStep instructions

Return to nublado.org