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

Home » Public Forums » archive » Re: path to .sav file
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
Re: path to .sav file [message #50909] Mon, 23 October 2006 14:21
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
JD Smith writes:

> I use a modification of this method: create a
> little batch file (e.g. project_directory.pro) with something like:
>
> common my_project_dir, proj_dir
> if n_elements(proj_dir) eq 0 then begin
> resolve_routine,'myproj',/NO_RECOMPILE
> proj_dir=(routine_info('myproj',/SOURCE)).PATH
> ps=path_sep()
> if strmid(proj_dir, 0,1) ne ps then $ ;relative filename
> proj_dir=file_expand_path(proj_dir)
> endif
>
> Then in any routine where you need to know the project directory, just
>
> @project_dir
>
> at the top. More real world examples would locate the interesting
> relative paths within the distribution. You can use anything for
> 'myproj', just pick a routine which is in a known useful location. This
> works for source, compiled SAV's, anything. For maximum usefulness, have
> the relative location of the routine (in source distributions) and the
> .sav file (in binary distributions) the same.

I've tried distributing files that I @filename
into the code, but this always causes me grief
when people try to run the code because it requires
that the directory where the @ files are located
be on the PATH (or in the local directory).

For some reason, people with UNIX machines have
a *great* many problems getting their paths set
up properly, in my experience. More often than not,
my files are in 5 different directories on their
machines, and I can easily spend an entire day
getting things on their path sorted out. :-(

> Looks like 1 line to me ;)

I think it was two. But I try not to let the facts
get in the way of making a point, whenever possible. :-)

(For some reason, I was thinking of TV and TVIMAGE
when I wrote that response. It's true that TVIMAGE
uses ONLY built-in IDL commands.)

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.")
Re: path to .sav file [message #50911 is a reply to message #50909] Mon, 23 October 2006 13:22 Go to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Mon, 23 Oct 2006 10:27:46 -0600, David Fanning wrote:

> David Fanning writes:
>
>> Indeed. As either of those two programs would prove to you. :-)
>
> Some people just insist on using one well-named program
> when 8-10 lines of code would do just fine. As Coyote
> says, "It's a damn commie plot!"

Looks like 1 line to me ;). I use a modification of this method: create a
little batch file (e.g. project_directory.pro) with something like:

common my_project_dir, proj_dir
if n_elements(proj_dir) eq 0 then begin
resolve_routine,'myproj',/NO_RECOMPILE
proj_dir=(routine_info('myproj',/SOURCE)).PATH
ps=path_sep()
if strmid(proj_dir, 0,1) ne ps then $ ;relative filename
proj_dir=file_expand_path(proj_dir)
endif

Then in any routine where you need to know the project directory, just

@project_dir

at the top. More real world examples would locate the interesting
relative paths within the distribution. You can use anything for
'myproj', just pick a routine which is in a known useful location. This
works for source, compiled SAV's, anything. For maximum usefulness, have
the relative location of the routine (in source distributions) and the
.sav file (in binary distributions) the same.

JD
Re: path to .sav file [message #50914 is a reply to message #50911] Mon, 23 October 2006 09:27 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> Indeed. As either of those two programs would prove to you. :-)

Some people just insist on using one well-named program
when 8-10 lines of code would do just fine. As Coyote
says, "It's a damn commie plot!"

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.")
Re: path to .sav file [message #50915 is a reply to message #50914] Mon, 23 October 2006 09:22 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Douglas G. Dirks writes:

> Nothing against SOURCEPATH or PROGRAMROOTDIR, but if all you want
> is to know the path from which a routine was compiled, you can do
> it with IDL internal routines.

Indeed. As either of those two programs would prove to you. :-)

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.")
Re: path to .sav file [message #50917 is a reply to message #50915] Mon, 23 October 2006 09:06 Go to previous message
Douglas G. Dirks is currently offline  Douglas G. Dirks
Messages: 10
Registered: October 2006
Junior Member
Ben Tupper wrote:
> greg michael wrote:
>> I'm sure there must be any easy answer to this, but I can't figure it
>> out...
>>
>> If a VM program is run with something like:
>>
>> idl -vm=...path.../myprog.sav
>>
>> how can I get that path from within the program?
>>
>> Greg
>>
> Hello,
>
> I think you want somethong like Jim Pendleton's SOURCEPATH.pro which you
> can find at http://www.ittvis.com/codebank
>
> Ben

ROUTINE_INFO will give you the path to the source of any compiled
routine, provided you know its name, and it works all the way back
to IDL 5.0:

routinepath = ROUTINE_INFO('myprog', /SOURCE)

(assuming that myprog.sav has a main routine called 'myprog'...)

Add in FILE_DIRNAME (IDL 6.0 or later) and you've got what you want,
I think:

routinedir = FILE_DIRNAME(routinepath.path)

You can use the MARK_DIRECTORY keyword to FILE_DIRNAME to get a
trailing directory separator.

Nothing against SOURCEPATH or PROGRAMROOTDIR, but if all you want
is to know the path from which a routine was compiled, you can do
it with IDL internal routines.

Doug
Re: path to .sav file [message #50925 is a reply to message #50917] Mon, 23 October 2006 06:57 Go to previous message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
David Fanning wrote:
> greg michael writes:
>
>> Seems Jim's has been updated to use Scope_Traceback(), which probably
>> makes it more robust than the 'help'-based methods.
>
> Certainly makes it a lot simpler to write the code!
> I do notice, though, that the path that comes back
> doesn't have a file separator on the end of the path.
> You will have to remember to append this is you are
> going to use the path to locate another file, etc.
>

Hi,

Jim added the _EXTRA keyword which is passed to FILE_DIRNAME so you can
simply pass the keyword /MARK_DIRECTORY in to have it done for you.

Ben
Re: path to .sav file [message #50928 is a reply to message #50925] Mon, 23 October 2006 06:41 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
greg michael writes:

> Seems Jim's has been updated to use Scope_Traceback(), which probably
> makes it more robust than the 'help'-based methods.

Certainly makes it a lot simpler to write the code!
I do notice, though, that the path that comes back
doesn't have a file separator on the end of the path.
You will have to remember to append this is you are
going to use the path to locate another file, etc.

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.")
Re: path to .sav file [message #50930 is a reply to message #50928] Mon, 23 October 2006 06:06 Go to previous message
greg michael is currently offline  greg michael
Messages: 163
Registered: January 2006
Senior Member
Now I have many to choose from!

Seems Jim's has been updated to use Scope_Traceback(), which probably
makes it more robust than the 'help'-based methods.

many thanks,
Greg
Re: path to .sav file [message #50931 is a reply to message #50930] Mon, 23 October 2006 05:50 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Ben Tupper writes:

> I think you want somethong like Jim Pendleton's SOURCEPATH.pro which you
> can find at http://www.ittvis.com/codebank

Or, PROGRAMROOTDIR, here:

http://www.dfanning.com/programs/programrootdir.pro

It's based on Jim's, but with some tweaks I need for
the way I distribute programs.

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.")
Re: path to .sav file [message #50932 is a reply to message #50931] Mon, 23 October 2006 05:39 Go to previous message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
greg michael wrote:
> I'm sure there must be any easy answer to this, but I can't figure it
> out...
>
> If a VM program is run with something like:
>
> idl -vm=...path.../myprog.sav
>
> how can I get that path from within the program?
>
> Greg
>
Hello,

I think you want somethong like Jim Pendleton's SOURCEPATH.pro which you
can find at http://www.ittvis.com/codebank

Ben
Re: path to .sav file [message #50934 is a reply to message #50932] Mon, 23 October 2006 05:30 Go to previous message
greg michael is currently offline  greg michael
Messages: 163
Registered: January 2006
Senior Member
Thanks very much Allan! That's just what I need. I didn't get the
stregex part to work (wish I could, but it's a magic I can't fathom),
but grabbing it out of the help output is fine. Pretty enough for my
purposes.

main='myprog'
help,/source,output=a
sav_file=strtrim(strmid(a[where(strmid(a,0,strlen(main)+1) eq main+'
')],strlen(main)),2)

(I match an extra space to avoid a routine called 'myprogGUI')

regards,
Greg
Re: path to .sav file [message #50938 is a reply to message #50934] Mon, 23 October 2006 03:55 Go to previous message
Allan Whiteford is currently offline  Allan Whiteford
Messages: 117
Registered: June 2006
Senior Member
greg michael wrote:
> I'm sure there must be any easy answer to this, but I can't figure it
> out...
>
> If a VM program is run with something like:
>
> idl -vm=...path.../myprog.sav
>
> how can I get that path from within the program?
>
> Greg
>

Greg,

It's not pretty but:

help,/source,output=a
idx=where(stregex(a,'myprog +([/,a-z,0-9,_,\.]*)',/fold_case) eq 0)
file=(stregex(a[idx],'myprog +([/,a-z,0-9,_,\.]*)',$
/fold_case,/subexpr,/extract))[1]

I'm sure there is a better way.

Thanks,

Allan
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Retrieving the title of a widget_base after the fact.
Next Topic: sorting string arrays - non alphabetic and user defined order

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

Current Time: Wed Oct 08 11:30:24 PDT 2025

Total time taken to generate the page: 0.00680 seconds