;+ ; NAME: ; hide_env ; PURPOSE: ; Hides explicit directory name ; CATEGORY: ; gen/idl/toolbox/files ; CALLING SEQUENCE: FUNCTION hide_env, file_name, env_var=env_var, exclude=exclude, force=force, silent=silent ; INPUTS: ; file_name ; OPTIONAL INPUT PARAMETERS: ; env_var=env_var array; type: string; default: none ; list of env var definitions in the form name=value ; If not present then the 'set' command is spawned ; to pick up all env vars. ; exclude=exclude list of env vars to be excluded (if they are defined). ; force=force if set then the common block with internally saved ; env vars and values is rewritten. ; OUTPUTS: ; hidden_name ; INCLUDE: @compile_opt.pro ; On error, return to caller ; COMMON BLOCKS: common hide_env_save, nvar, env_vars, env_values ; CALLS: ; InitVar, IsType, destroyvar, boost, CheckDir ; PROCEDURE: ; > The env variables and their values are saved internally in a common block. ; The common block is rewritten each time env_var is specified. ; > If env_var is not defined then the 'set' command is spawned to get ; all env variables. This is done only once (unless /force is set). ; > PWD and OLDPWD are added to the list of env vars to be excluded ; MODIFICATION HISTORY: ; AUG-2003, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- InitVar, force, IsType(env_vars, /undefined) or IsType(env_var, /defined) IF force THEN BEGIN ; First call or env_var given as input. InitVar, silent, 0 IF IsType(env_var, /undefined) THEN spawn, 'set', env_var destroyvar, nvar, env_vars, env_values boost, exclude, ['PWD','OLDPWD'] FOR i=0,n_elements(env_var)-1 DO BEGIN var = env_var[i] pos = strpos(var,'=') value = strmid(var,pos+1) IF strlen(value) GT 0 THEN BEGIN var = strmid(var,0,pos) IF (where(var EQ exclude))[0] EQ -1 THEN BEGIN IF strpos(var,'SMEIDB' ) EQ 0 OR $ strpos(var,'SMEIDC' ) EQ 0 OR $ strpos(var,'SMEISKY') EQ 0 OR $ strpos(var,'FTS' ) EQ 0 OR $ strpos(var,'HAFB' ) EQ 0 OR $ strpos(var,'L1A' ) EQ 0 THEN BEGIN ; This should not be necessary. The SMEIDB and SMEIDC env vars ; point to the SMEI data drives which are crossmounted. If one ; of the crossmounted goes offline then the CheckDir call will ; wait forever until the drive comes online again. boost, env_vars , var boost, env_values, value ENDIF ELSE IF CheckDir(value, /silent) THEN BEGIN boost, env_vars , var boost, env_values, value ENDIF ENDIF ENDIF ENDFOR nvar = n_elements(env_vars) CASE nvar EQ 0 OF 0: BEGIN p = reverse(sort( strlen(env_values) )) ; Longest directories first env_vars = env_vars[p] env_values = env_values[p] IF silent LE 0 THEN FOR i=0,nvar-1 DO message, /info, env_vars[i]+'='+env_values[i] END 1: IF silent LE 0 THEN message, /info, 'no env vars defined' ENDCASE ENDIF FOR i=0,nvar-1 DO BEGIN var = '$'+env_vars[i] env = env_values [i] CASE env EQ file_name OF 0: BEGIN env = filepath(root=env,'') IF strpos(file_name, env) EQ 0 THEN $ RETURN, filepath(root=var, strmid(file_name, strlen(env))) END 1: RETURN, var ENDCASE ENDFOR RETURN, file_name & END