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

Home » Public Forums » archive » Path info in *.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
Path info in *.sav file [message #12563] Tue, 18 August 1998 00:00 Go to next message
htsang is currently offline  htsang
Messages: 14
Registered: September 1997
Junior Member
In my program, I have to load a couple gif images, however, I would like
the path to these images be more flexible so that I don't need to define the
absolute path in compile time.

Is it possible to:
1) incoporate the gif file in the sav file?
2) setup relative path for everytime when I need to load the image?

-- Herbert (htsang@mda.ca)
Re: Path info in *.sav file [message #12610 is a reply to message #12563] Mon, 24 August 1998 00:00 Go to previous message
David Foster is currently offline  David Foster
Messages: 341
Registered: January 1996
Senior Member
Herbert Tsang wrote:
>
> In my program, I have to load a couple gif images, however, I would like
> the path to these images be more flexible so that I don't need to define the
> absolute path in compile time.
>
> Is it possible to:
> 1) incoporate the gif file in the sav file?
> 2) setup relative path for everytime when I need to load the image?

Could you set an environment variable and use GETENV()?

Dave
--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2240
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
Re: Path info in *.sav file [message #12616 is a reply to message #12563] Mon, 24 August 1998 00:00 Go to previous message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
Herbert Tsang wrote:
>
> In my program, I have to load a couple gif images, however, I would like
> the path to these images be more flexible so that I don't need to define the
> absolute path in compile time.

Hi Herbert,

I've had to deal with this issue, I think I can lend a hand.

> Is it possible to:
> 1) incoporate the gif file in the sav file?

You could, of course, read the gif file into an array, but one sav file
can contain only routines _or_ variables, not both. Saving a second sav
file doesn't get you any closer to your goal, so this doesn't look good.

> 2) setup relative path for everytime when I need to load the image?

Unfortunately, a routine in a sav file seems to have no way of knowing
what file it came from. To get around this, I suggest using two names, a
'SavName' and a 'ProName' as follows:

- savname.pro - the main program file
- savname.sav - saved from savname.pro
- proname.pro - what you will call from IDL, and which _can_ find its
own location

;===== proname.pro =====

PRO ProName

COMMON DirCommon, dir

;; Find out the directory that this file is in
Help, Calls = c
l = c(0) ; c(0) describes THIS routine
;; e.g.: PRONAME </home/djackson/idl/lib/proname.pro( 5)>
;; Note: the use of '/' here is Unix-specific

;; Extract dir from the string
IF StrPos(l, '/') EQ -1 THEN dir = './' ELSE $
dir = StrMid(l, StrPos(l, '<')+1, RStrPos(l, '/')-StrPos(l, '<'))

Print, 'Using directory: ' + dir

;; Restore the .sav file and call the main routine
;; (if savname.pro and savname.sav exist, savname.pro would be used)
Restore, dir + 'savname.sav'
SavName

END

;===== savname.pro =====

PRO SavName

COMMON DirCommon, dir

;; Show it works by printing contents of this directory.
Print, FindFile(dir)

END

;===== then, in IDL: =====
IDL> .run savname
% Compiled module: SAVNAME.
IDL> save,/routines,filename='savname.sav'

;===== then, in a new IDL session: =====
IDL> proname
% Compiled module: PRONAME.
proname.pro proname.pro~ savname.pro savname.pro~ savname.sav

Your aim in doing this may be to distribute a .sav file without the .pro
source, so in this case you would send savname.sav and proname.pro (with
your .gif files!) that simply need to stay in the same directory,
somewhere on the IDL !PATH.

While you are debugging the code in savname.pro, you may want to call it
directly, without going through 'proname'. If so, then you would need to
find the directory in the savname routine in savname.pro, by adding
something like this after the COMMON statement:

IF N_Elements(dir) EQ 0 THEN BEGIN ; If dir is undefined
;; same code to find out the directory that this file is in
Help, Calls = c
;; [...]
END

This may look a bit messy, but this is the best way I've found to handle
it.

Best regards,
--
-Dick

Dick Jackson Fanning Software Consulting, Canadian Office
djackson "at" dfanning "dot" com Winnipeg, Manitoba (204) 885-0331
Coyote's Guide to IDL Programming: http://www.dfanning.com/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Call_External and Re-Compiling C programs
Next Topic: Re: minor bug in IDL 5 poisson random numbers?

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

Current Time: Wed Oct 08 13:38:43 PDT 2025

Total time taken to generate the page: 0.00830 seconds