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

Home » Public Forums » archive » Re: tilde file names in FINDFILE
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: tilde file names in FINDFILE [message #9983] Wed, 01 October 1997 00:00
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
Martin Schultz <mgs@io.harvard.edu> writes:

> Hi everyone,

> I am still using IDL 4 and AIX 3.2.5, but that shouldn't really matter
> for the following question, I suppose:

> When I am opening a file with
> OPENR,unit,'~/IDL/DATA/test.dat',/get_lun
> it works fine. But if I try to find that file via
> PRINT,FINDFILE('~/IDL/DATA/test.dat')
> I get an empty string indicating that IDL did not find it.

> Does anyone know how to teach IDL to accept the '~' in FINDFILE ?
> One option might be to use SPAWN,'echo $HOME',result but
> (a) is this highly OS dependent
> (b) does it not work for something like ~user/file.dat
> Any ideas appreciated !

This routine should do the trick, thanks to my colleague Dominic Zarro.

============================================================ ===================
;+
; Project : SOHO - CDS
;
; Name : EXPAND_TILDE
;
; Purpose : expand tilde in UNIX directory names
;
; Category : system
;
; Explanation :
;
; Syntax : IDL> output=expand_tilde(input)
;
; Examples : output=expand_tilde('~zarro/test.doc')
; ---> output='/usr/users/zarro'
;
; Inputs : INPUT = input file or directory name
;
; Opt. Inputs :
;
; Outputs : OUTPUT = expanded filename
;
; Opt. Outputs: None
;
; Keywords : None
;
; Common : None
;
; Restrictions: None
;
; Side effects: None.
;
; History : Version 1, 17-Feb-1997, D M Zarro. Written
; Version 2, 15-Sep-1997, W. T. Thompson
; Brought into line with Astrolib version
;
; Contact : DZARRO@SOLAR.STANFORD.EDU
;-

function expand_tilde,name
if N_elements(name) EQ 0 then return,''
if datatype(name) ne 'STR' then return,name
tpos=strpos(name,'~')
if tpos eq -1 then return,name
spos=strpos(name,'/')
if spos eq -1 then begin
dir=name
rest=''
endif else begin
dir=strmid(name,0,spos)
rest=strmid(name,spos+1,strlen(name))
endelse
cd,dir,curr=curr
cd,curr,curr=dcurr
if rest ne '' then tname=dcurr+'/'+rest else tname=dcurr
return,tname & end
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: creating a special kind of array
Next Topic: Re: label_date precision problem

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

Current Time: Wed Oct 08 15:06:50 PDT 2025

Total time taken to generate the page: 0.01185 seconds