comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » File_Which What!?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
File_Which What!? [message #32920] Wed, 20 November 2002 20:28 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Folks,

Does anyone know how to get the File_Which command to work?
The documentation is, uh, typical.

I have a file somewhere on my IDL path. It's name is "fire.clt".
I'm in a directory NOT on my path (my home directory), but I
would like to know where this file is.

The documentation says that the first positional parameter
is the "path", and the second is the "file" you are searching
for. Then it says, if the "path" is missing, then the IDL
path is used instead. But, wait, if the first positional
parameter is "missing", isn't the "file" the first positional
parameter!? Here is a new trick!

In any case, File_Which is coming back to me with a
empty string. Not what I had in mind? :-(

Anyone figure this out?

Thanks,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: File_Which What!? [message #32979 is a reply to message #32920] Fri, 22 November 2002 11:16 Go to previous messageGo to next message
rigby is currently offline  rigby
Messages: 16
Registered: September 1995
Junior Member
"Mark Hadfield" <m.hadfield@niwa.co.nz> wrote in message news:<ark86l$d77$1@newsreader.mailgate.org>...
> "David Fanning" <david@dfanning.com> wrote in message
> news:MPG.1846c9eb188ae0b1989a3d@news.frii.com...
>> File_Which very sensibly does NOT search any
>> directory that does not contain either a .pro or
>> .sav file. (Why include directories on an IDL
>> search path that can't result in anything productive?
>> Slows everything down.)
>
> What?!
>
> This would be sensible, *if* FILE_WHICH was to be used only to search for
> .pro or .sav files. There is nothing in the documentation that says this is
> the case, and I (and David) have used it to search for files with other
> extensions. I'm just glad it was David who got tripped up by the hidden
> gotcha. (Not that I'm not sympathetic, David, but...)

I believe this isn't a FILE_WHICH problem, but a side effect of IDL's
expansion of the search PATH you requested. For UNIX (all I'm familiar
with) your IDL !PATH variable is built from your UNIX environment
variable PATH. You can prepend a "+" to a directory name in PATH to
ask that all its subdirectories be included in !PATH. But IDL excludes
subdirectories that don't contain .pro or .sav files; apparently IDL
does this path expansion and exclusion by calling Expand_Path() at
startup. (The documentation also says that even explicitly specified
directories in your PATH environment variable will be removed if the
have no .pro, etc, but that doesn't seem to be the case, at least on
my Solaris system.)

For Unix you can work around this by using the ALL_DIRS keyword in
Expand_Path():

IDL> print, getenv("IDL_PATH")
/home/rigby/idl:/home/rigby/idl/utilities:/home/phony2/s0/so ftware/idl5.5/idl_5.5/lib:+/home/rigby/working

;; I asked for /working and its subdirectories to be included, but ...

IDL> print, !path
/home/rigby/idl:/home/rigby/idl/utilities:/home/phony2/s0/so ftware/idl5.5/idl_5.5/lib

;; ... since there are no .pro files in /working or its
subdirectories, IDL
;; didn't include them in !path. The workaround is

IDL> !path = Expand_Path(getenv("IDL_PATH"),/all_dirs)

IDL> print, !path
/home/rigby/idl:/home/rigby/idl/utilities:/home/phony2/s0/so ftware/idl5.5/idl_5.5/lib:/home/rigby/working/subworking:/ho me/rigby/working

Maybe there's some similiar you can do in Windows.

--Wayne
Re: File_Which What!? [message #32986 is a reply to message #32920] Fri, 22 November 2002 07:54 Go to previous messageGo to next message
Jaco van Gorkom is currently offline  Jaco van Gorkom
Messages: 97
Registered: November 2000
Member
"David Fanning" <david@dfanning.com> wrote in message news:MPG.1847fc2115518cae989a43@news.frii.com...
> Jaco van Gorkom (j.c.van.gorkom@fz-juelich.de) writes:
>
>> Why are you using FILE_WHICH to *search* for files in the first
>> place? FILE_SEARCH (or FINDFILE) would seem a better candidate.
>
> Well, possibly. But for FILE_SEARCH to be useful
> here it would have to be combined with EXPAND_PATH,
> and have you looked at the number of keywords for
> these two routines!

Now that you mention it, there is one keyword that might
be of some use to you: /ALL_DIRS ;-)

> FILE_WHICH just seemed a whole lot easier. :-(

I might start using it myself actually. Using DIALOG_PICKFILE()
for each and every input file does get a bit annoying...

cheers,
Jaco
Re: File_Which What!? [message #32989 is a reply to message #32920] Fri, 22 November 2002 07:33 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jaco van Gorkom (j.c.van.gorkom@fz-juelich.de) writes:

> Why are you using FILE_WHICH to *search* for files in the first
> place? FILE_SEARCH (or FINDFILE) would seem a better candidate.

Well, possibly. But for FILE_SEARCH to be useful
here it would have to be combined with EXPAND_PATH,
and have you looked at the number of keywords for
these two routines! FILE_WHICH just seemed a whole
lot easier. :-(

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: File_Which What!? [message #32990 is a reply to message #32920] Fri, 22 November 2002 06:41 Go to previous messageGo to next message
Jaco van Gorkom is currently offline  Jaco van Gorkom
Messages: 97
Registered: November 2000
Member
"David Fanning" <david@dfanning.com> wrote in message news:MPG.184759add416747d989a42@news.frii.com...
> Mark Hadfield (m.hadfield@niwa.co.nz) writes:
>
>> This would be sensible, *if* FILE_WHICH was to be used only to search for
>> .pro or .sav files. There is nothing in the documentation that says this is
>> the case, and I (and David) have used it to search for files with other
>> extensions. I'm just glad it was David who got tripped up by the hidden
>> gotcha. (Not that I'm not sympathetic, David, but...)
>
> Well, maybe there should be an EVERYDARNONE keyword,
> to force it to search everything. Now that I think
> about it, why would you have files on your path that
> you didn't want to search? Maybe I'll revisit this
> with my source. :-)

Why are you using FILE_WHICH to *search* for files in the first
place? FILE_SEARCH (or FINDFILE) would seem a better candidate.
Anyway, FILE_WHICH should tell you exactly *which* file IDL would
find, if it should ever go looking for a fire.clt file on its path.
Directories without .pro or .sav files (at IDL startup time!!)
simply are not included in the IDL path, states the Help for !PATH.

sympathetically yours,
Jaco

PS: As I started using IDL, I frequently ran into problems that
I could only solve by exiting and restarting IDL. Later I
discovered many of the reasons, and this was one of them.
Re: File_Which What!? [message #32995 is a reply to message #32920] Thu, 21 November 2002 20:00 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Mark Hadfield (m.hadfield@niwa.co.nz) writes:

> This would be sensible, *if* FILE_WHICH was to be used only to search for
> .pro or .sav files. There is nothing in the documentation that says this is
> the case, and I (and David) have used it to search for files with other
> extensions. I'm just glad it was David who got tripped up by the hidden
> gotcha. (Not that I'm not sympathetic, David, but...)

Well, maybe there should be an EVERYDARNONE keyword,
to force it to search everything. Now that I think
about it, why would you have files on your path that
you didn't want to search? Maybe I'll revisit this
with my source. :-)

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: File_Which What!? [message #32996 is a reply to message #32920] Thu, 21 November 2002 19:21 Go to previous messageGo to next message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
"David Fanning" <david@dfanning.com> wrote in message
news:MPG.1846c9eb188ae0b1989a3d@news.frii.com...
> File_Which very sensibly does NOT search any
> directory that does not contain either a .pro or
> .sav file. (Why include directories on an IDL
> search path that can't result in anything productive?
> Slows everything down.)

What?!

This would be sensible, *if* FILE_WHICH was to be used only to search for
.pro or .sav files. There is nothing in the documentation that says this is
the case, and I (and David) have used it to search for files with other
extensions. I'm just glad it was David who got tripped up by the hidden
gotcha. (Not that I'm not sympathetic, David, but...)

--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
Re: File_Which What!? [message #33008 is a reply to message #32920] Thu, 21 November 2002 09:46 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning (david@dfanning.com) writes:

> Humm, well, further tests this morning show that the file
> can be found if the directory containing it
> is *explicitly* on the path. That is, the directory
> is named specifically in File->Preferences->Path.
> If the directory containing the file is implicitly
> on the path (I.e., I have selected a check box for
> the parent directory in File->Preferences->Path)
> then the file can't be found.

OK, here is the *real* story from someone who
knows (not me). :-)

File_Which very sensibly does NOT search any
directory that does not contain either a .pro or
.sav file. (Why include directories on an IDL
search path that can't result in anything productive?
Slows everything down.)

In my case, I was looking for color table files (*.clt)
in a sub-directory with no *.pro files. If my color
table sub-directory is *explicitly* on the path, File_Which
will find the file as expected. Or, I can just put a dummy
PRO file in the directory as a locater file, and File_Which
will also find the correct file. Neat!

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: File_Which What!? [message #33010 is a reply to message #32920] Thu, 21 November 2002 09:39 Go to previous messageGo to next message
R.G. Stockwell is currently offline  R.G. Stockwell
Messages: 363
Registered: July 1999
Senior Member
David Fanning wrote:


> Humm, well, further tests this morning show that the file
> can be found if the directory containing it
> is *explicitly* on the path. That is, the directory
> is named specifically in File->Preferences->Path.
> If the directory containing the file is implicitly
> on the path (I.e., I have selected a check box for
> the parent directory in File->Preferences->Path)
> then the file can't be found.
>
> Bummer. :-(
>
> Cheers,
>
> David


works ok here (idl 5.5a, redhat linux), and I do not have the path set explicitly.



IDL> print,file_which('file.clt')
/home/stockwel/idllib/boblib/cora/qscat/interpolation/3d/dev el/file.clt

I do notice though that is only finds one instance of the file, apparently the
first one it finds in the path.

Are you in idl 5.6? (ms-win?)

Cheers,
bob stockwell

PS I "agree" with the first position optional argument for this function.
It is natural to use this order (path,file) when calling it, and
path is indeed optional, in that I'd almost always use it without setting path.
Re: File_Which What!? [message #33012 is a reply to message #32920] Thu, 21 November 2002 06:04 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Nigel Wade (nmw@ion.le.ac.uk) writes:

> It works here, with IDL 5.5 on IRIX. (I created a file called "fire.clt" at
> some location in the IDL path and FILE_WHICH found it ok). Looking at the
> source, FILE_WHICH uses FILE_TEST to test for the file. It loops through
> each directory in the path testing for the file in that directory until it
> either succeeds or runs out of entries in the path. Does FILE_TEST indicate
> success if you use that with the full path?

Humm, well, further tests this morning show that the file
can be found if the directory containing it
is *explicitly* on the path. That is, the directory
is named specifically in File->Preferences->Path.
If the directory containing the file is implicitly
on the path (I.e., I have selected a check box for
the parent directory in File->Preferences->Path)
then the file can't be found.

Bummer. :-(

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: File_Which What!? [message #33017 is a reply to message #32920] Thu, 21 November 2002 03:56 Go to previous messageGo to next message
Nigel Wade is currently offline  Nigel Wade
Messages: 286
Registered: March 1998
Senior Member
David Fanning wrote:

> Folks,
>
> Does anyone know how to get the File_Which command to work?
> The documentation is, uh, typical.
>
> I have a file somewhere on my IDL path. It's name is "fire.clt".
> I'm in a directory NOT on my path (my home directory), but I
> would like to know where this file is.
>
> The documentation says that the first positional parameter
> is the "path", and the second is the "file" you are searching
> for. Then it says, if the "path" is missing, then the IDL
> path is used instead. But, wait, if the first positional
> parameter is "missing", isn't the "file" the first positional
> parameter!? Here is a new trick!
>

Has the documentation changed for 5.6?
I only have 5.5 and the docs for that show the syntax as:
Result = FILE_WHICH( [Path, ] File [, /INCLUDE_CURRENT_DIR] )
and don't make any mention of first and second positional parameters, but
this does indicate that "path" is optional.

> In any case, File_Which is coming back to me with a
> empty string. Not what I had in mind? :-(
>
> Anyone figure this out?

It works here, with IDL 5.5 on IRIX. (I created a file called "fire.clt" at
some location in the IDL path and FILE_WHICH found it ok). Looking at the
source, FILE_WHICH uses FILE_TEST to test for the file. It loops through
each directory in the path testing for the file in that directory until it
either succeeds or runs out of entries in the path. Does FILE_TEST indicate
success if you use that with the full path?


--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523568, Fax : +44 (0)116 2523555
Re: File_Which What!? [message #33018 is a reply to message #32920] Thu, 21 November 2002 00:27 Go to previous messageGo to next message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
David Fanning wrote:
> Folks,
>
> Does anyone know how to get the File_Which command to work?
> The documentation is, uh, typical.
>
> I have a file somewhere on my IDL path. It's name is "fire.clt".
> I'm in a directory NOT on my path (my home directory), but I
> would like to know where this file is.
>
> The documentation says that the first positional parameter
> is the "path", and the second is the "file" you are searching
> for. Then it says, if the "path" is missing, then the IDL
> path is used instead. But, wait, if the first positional
> parameter is "missing", isn't the "file" the first positional
> parameter!? Here is a new trick!
>
> In any case, File_Which is coming back to me with a
> empty string. Not what I had in mind? :-(
>
> Anyone figure this out?
>
> Thanks,
>
> David

If I search by file_which for a .pro file it works.

Reimar

--
Reimar Bauer

Institut fuer Stratosphaerische Chemie (ICG-I)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
------------------------------------------------------------ -------
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
============================================================ =======
Re: File_Which What!? [message #33052 is a reply to message #32920] Mon, 25 November 2002 14:40 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
JD Smith (jdsmith@as.arizona.edu) writes:

> My solution has been to
> place alongside the target files a special marker routine
> (e.g. irs_calib_dir_marker.pro). This dummy routine is compiled, and
> ROUTINE_INFO is used to get its source, from which the path is derived
> and placed in a common block.

Now there is a useful piece of code, although I'm
certain it can be speeded up with a Histogram
somehow. :-)

I'll write these little tips up when I get a minute.
I think this kind of problem is more common than
I thought.

Thanks, JD.

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: File_Which What!? [message #33053 is a reply to message #32990] Mon, 25 November 2002 14:00 Go to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Fri, 22 Nov 2002 07:41:22 -0700, Jaco van Gorkom wrote:

> "David Fanning" <david@dfanning.com> wrote in message
> news:MPG.184759add416747d989a42@news.frii.com...
>> Mark Hadfield (m.hadfield@niwa.co.nz) writes:
>>
>>> This would be sensible, *if* FILE_WHICH was to be used only to search
>>> for .pro or .sav files. There is nothing in the documentation that
>>> says this is the case, and I (and David) have used it to search for
>>> files with other extensions. I'm just glad it was David who got
>>> tripped up by the hidden gotcha. (Not that I'm not sympathetic,
>>> David, but...)
>>
>> Well, maybe there should be an EVERYDARNONE keyword, to force it to
>> search everything. Now that I think about it, why would you have files
>> on your path that you didn't want to search? Maybe I'll revisit this
>> with my source. :-)
>
> Why are you using FILE_WHICH to *search* for files in the first place?
> FILE_SEARCH (or FINDFILE) would seem a better candidate. Anyway,
> FILE_WHICH should tell you exactly *which* file IDL would find, if it
> should ever go looking for a fire.clt file on its path. Directories
> without .pro or .sav files (at IDL startup time!!) simply are not
> included in the IDL path, states the Help for !PATH.
>
> sympathetically yours,
> Jaco
>
> PS: As I started using IDL, I frequently ran into problems that I could
> only solve by exiting and restarting IDL. Later I discovered many of the
> reasons, and this was one of them.

FILE_WHICH simply scrubs through a list of paths and looks for the
first existing file specified in one of them. This is fine if you
know which file you're looking for. And FINDFILE (with FILEPATH) lets
you find any number of files by pattern (like '*.clt'), assuming you
know the directory(ies) they are in.

But what to do if you don't know where they are, but you need all
'.clt' files from some special directory? My solution has been to
place alongside the target files a special marker routine
(e.g. irs_calib_dir_marker.pro). This dummy routine is compiled, and
ROUTINE_INFO is used to get its source, from which the path is derived
and placed in a common block. Ugly, but pretty failsafe. It also
ensures you're getting exactly the files you meant to. I bundle it
all up into an include file, which I "@" at the top of any routine
which needs the directory. It looks like:


common irs_dir, irs_calib_dir
if n_elements(irs_calib_dir) eq 0 then begin
irs_calib_dir_marker
source=(routine_info('irs_calib_dir_marker',/SOURCE)).PATH
dir=strmid(source,0,strpos(source,path_sep(),/REVERSE_SEARCH ))
if NOT file_test(dir,/DIRECTORY) then $
message,'Cannot locate IRS calibration data directory: '+dir
irs_calib_dir=dir
endif
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Structure Pass By Reference?
Next Topic: Re: sec : U Re: De-sensitizing individual list elements

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:39:54 PDT 2025

Total time taken to generate the page: 0.00783 seconds