Re: How to set the default working directory? [message #66028] |
Tue, 14 April 2009 05:52  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
rainingpeace@gmail.com writes:
> I am trying to use IDL to read and write CDF files. Now I am suffering
> a problem. I am trying to set my default working directory to "D:
> \IDLWorkspace\". And I set "Reference->IDL->Path" and add the "D:
> \IDLWorkspace" to the list and move it to the top. But it does not
> work.
> The reason why I want to set this directory is that otherwise every
> time I am trying to read a file, I have to write the full path. By
> setting a default working directory, I can just use
> id=cdf_open('ge_edb3sec_mgf_20000125_v01.cdf')
> instead of
> id=cdf_open('C:\ge_edb3sec_mgf_20000125_v01.cdf'). I believe such a
> small aim is achievable in such a powerful software like IDL. It is
> just that I do not know how to do that.
> This is just a simple example. My directory is much longer.
> So as mentioned, I failed at setting the working directory. I hope
> some one could help me.
You can always change your working directory with the
CD command:
IDL> CD, 'D:\IDLWorkspace\'
On Windows, I usually prefer to do this with XCD, which allows
me to point and click to move to directories. You can find
XCD here:
http://www.dfanning.com/programs/xcd.zip
But, most of the time, I prefer NOT to change directories,
but to let the directories come to me. If your data file is
in a directory in your IDL path, and there is a *.pro in that
directory, then I find the program Find_Resource_File more
intuitive and less a bother than FILE_SEARCH:
IDL> datafile = Find_Resource_File('ge_edb3sec_mgf_20000125_v01.cdf')
This program was originally designed to find resource files
like the Brewer color table file, but, as I say, it has become
more useful than that to me. You can find it among the other
Coyote Library files:
http://www.dfanning.com/documents/programs.html
Another thing I sometimes do, especially if I am always switching
from LINUX to Windows machines, is define default data directories
in my IDL startup file:
CatSetDefault, 'CDF_DATA_DIR', 'D:\Workspace\'
Then, in my programs, I get the name of the file I want like
this:
datafile = Filepath(ROOT_DIR=CatGetDefault('CDF_DATA_DIR'), $
'ge_edb3sec_mgf_20000125_v01.cdf')
The CatSetDefault and CatGetDefault programs are utility programs
in the Catalyst Library code.
http://www.dfanning.com/catalyst/howtoinstall.html
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|