1

I'd like to add a directory to IDL Path, and use:

pref_set,'IDL_PATH','+/home/mydirectory/Tools/IDL/:<IDL_DEFAULT>',/COMMIT

It works, but when I exit from IDL and start it again, and I input:

.run myfile

"myfile" is one in "mydirectory", and an error says:

% Error opening file. File: myfile

I need to do pref_set ... every time I start IDL to make it work. Why is that? I use Ubuntu 14.04 and bash. IDL 8.4.

Luckily, my colleague helped me to find a solution. To add the path in .bashrc.

export IDL_PATH= '+/mydirectory/IDL:<IDL_DEFAULT>'

Note the single quotes and + are important here. It's IDL syntax not the bash one. Hope it may help anyone meeting the same question. ;)

Cy Rossignol
  • 16,216
  • 4
  • 57
  • 83
Schawn
  • 57
  • 1
  • 9

2 Answers2

1

This should work for you. Check the !path system variable after starting IDL again:

IDL> print, !path

Your directory should be the first entry.

Also, check the preferences file to see if it is actually being changed. After you use PREF_SET, exit IDL and check the file:

cat ~/.idl/idl/pref-10-idl_8_4-unix

There should be an entry in for IDL_PATH in the file.

mgalloy
  • 2,356
  • 1
  • 12
  • 10
  • I do as what you said. `print,!path` really adds my path to the first position, and `cat`command said `pref-10...`is a directory, I look into it, there is a file called cidl.pref`, with one line in it: `IDL_PATH : +/mydirectory/Tools/IDL/:`. I think it means everything is working well. But actually, I start `IDL` again, `.run myfile` still doesn't work and the error comes out. `print,!path` excludes my added path, but 'idl.pref' is still there. – Schawn Jan 14 '15 at 10:55
  • Do you have a startup file? i.e., do you set the IDL_STARTUP preference or environment variable? That might be messing with IDL_PATH when you restart. – mgalloy Jan 14 '15 at 22:24
  • No, I'm new to `IDL`, where should it be? In my home directory as `.bashrc` and `.profile` or some special place for `IDL`? – Schawn Jan 15 '15 at 09:27
  • No, I thought something in a startup file might be destroying your path every time you start IDL. But if you don't have a startup file, that's not it. – mgalloy Jan 15 '15 at 17:20
  • One last thing to try: 1) change your path with `PREF_SET`, 2) exit IDL 3) start IDL 4) exit IDL 5) start IDL again. Now check your `!path`, is it OK? – mgalloy Jan 15 '15 at 17:22
1

It actually depends on the version of IDL you are using. If you are using an IDL version between 6.2 and 7.0.3, then you use PREF_SET to control the paths. Prior to 6.2 you can set environment variables in Ubuntu and modify the IDL setup bash file (should come with IDL). After v7.0.3, you can explicitly set the value for !PATH as a string.

You will want to know what the search path separator is for your OS. If you are using IDL v5.5 or greater, then you can define:

sepath_sep = PATH_SEP(/SEARCH_PATH)

which is probably going to be : for Linux (it is for Unix at least). You will also want to know your current working directory, which can be defined in the following way:

vern           = !VERSION.RELEASE       ;;  e.g., '7.1.1'
test           = (vern[0] GE '6.0')
IF (test[0]) THEN cwd_char = FILE_DIRNAME('',/MARK_DIRECTORY) ELSE cwd_char = '.'+slash[0]
cur_wdir       = FILE_EXPAND_PATH(cwd_char[0])
;;  Check for a trailing slash and add it if need be...

To then find all the subdirectories within your current working directory, you can do the following:

t_path0        = EXPAND_PATH('+'+cur_wdir[0],/ARRAY)
t_path         = STRJOIN(t_path0,sepath_sep[0],/SINGLE)

Generally, I do more than one thing to ensure that IDL can find my files. I set an environment variable and I specify the !PATH system variable (I have v7.1.1). You can do this in IDL in the following way:

;;  First define the location of the IDL libraries
def_idldir     = !DIR                         ;;  e.g., '/Applications/itt/idl71'
test           = (GETENV('IDL_DIR') EQ '')
IF (test) THEN env_idldir = def_idldir[0] ELSE env_idldir = GETENV('IDL_DIR')
;;  Again, check for trailing slash here and add if absent
IF (test) THEN SETENV,'IDL_DIR='+env_idldir[0]
;;  First check whether an initial path exists
;;    --> If not, set one
idlpath        = GETENV('IDL_PATH')
test_idl       = (idlpath[0] EQ '')
IF (test_idl) THEN new_path = t_path[0] ELSE new_path = t_path[0]+sepath_sep[0]+idlpath[0]
IF (test_idl) THEN SETENV,'IDL_PATH='+new_path[0]
;;  Test to see if after version 7.0.3 and/or after version 6.2
test__62       = (vern[0] GE '6.2') AND (vern[0] LT '7.0.3')
test_703       = (vern[0] GE '7.0.3')
IF (test__62) THEN PREF_SET,'IDL_PATH',new_path[0],/COMMIT
IF (test_703) THEN !PATH = EXPAND_PATH(new_path[0])

This should give you the correct path specifications.

honeste_vivere
  • 308
  • 5
  • 11
  • In which file do you write all of the above stuff? In `.bashrc` or `idl.pref` in the corresponding directory? Additionally, I use `IDL 8.4` and I found another way to add the path successfully. I will edit my question to make it easy for everyone to see. Thank you for your detailed answer. – Schawn Jan 14 '15 at 17:59
  • I use a startup routine that I source like a batch file called `startup_idl.pro`. For example, I do the following on startup: `IDL> @startup_idl`. You can also enter it manually by hand. I also set some of these paths in my `.bash_profile` and the IDL bash startup. – honeste_vivere Jan 14 '15 at 18:04
  • Note that if you added an `export` statement in your `.bash_profile` or `.bashrc` file that defined the `IDL_PATH` environment variable, you should not need to redefine the paths each time. I only do this each time on startup because I have multiple libraries with routines that have the same name, so I define different paths for different purposes. – honeste_vivere Jan 14 '15 at 18:07
  • @honeste_vivere You can set the IDL_STARTUP preference or environment variable to automatically run your startup batch file every time you start an IDL session. – mgalloy Jan 14 '15 at 22:22
  • @mgalloy - I use a bash function that does this and sources different startup files. – honeste_vivere Jan 14 '15 at 22:48