;+ ; NAME: ; TMPPRO ; ; PURPOSE: ; Get the filename and path of a temporary .pro file. ; ; CATEGORY: ; IO. ; ; CALLING SEQUENCE: ; ; Result = TMPPRO( [Prefix, Ndigits] ) ; ; OPTIONAL INPUTS: ; ; Prefix: The prefix of the filename, ('tmp'=default). ; ; Ndigits: The number of digits to append to the Prefix, (3=default). ; ; OPTIONAL INPUT KEYWORD PARAMETERS: ; ; SEED: The seed used by the random number generator to determine ; the number to append to the Prefix. ; ; OUTPUTS: ; The file specification returned is: ; ; tmp_dir+Prefix+NNN+Suffix ; ; where NNN is a random LONG integer with number of digits = Ndigits. ; This routine also searches the tmp_dir for this filename. If a ; duplicate filename is found, then another random number is chosen. ; ; tmp_dir is the path to the /tmp directory ; where is the directory containing tmppro ; ; ; EXAMPLE: ; Let's create a temp filename myNNNN.pro: ; ; tmp_file = TMPFILE('my',4) ; ; MODIFICATION HISTORY: ; 30-DEC-2005 Modified from tmpfile by Leslie Young, SwRI ; MODIFICATION HISTORY OF TMPFILE ; Written by: Han Wen, November 1994. ; 08-FEB-1995 Fixed minor bug, random integer -> random LONG integer ; 12-JUN-1995 Check existence of TMP directory and create it if no ; such directory exists. ; 01-JUL-1995 Use DIR_EXIST to check existence of TMP directory. ; 07-AUG-1996 Use TMPPATH (hacked version of FILEPATH) to determine ; TMP directory. ;- function TMPPROPATH, FILENAME, ROOT_DIR=root_dir ON_ERROR,2 ;Return to caller if an error ;occurs ; findpro, 'tmppro', dirlist=dirlist, /noprint ; if n_elements(dirlist) eq 0 then begin ; root_dir = filepath('tmp',/tmp) ; endif else begin ; root_dir = filepath('tmp',root=dirlist[0]) ; endelse res = routine_info('tmppro', /source, /function) ; MUCH faster than findpro tmppro_dir = strmid(res.path,0,strlen(res.path)-strlen(res.name+'.pro')) root_dir = filepath('tmp', root = tmppro_dir) return, filepath(filename, root=root_dir) END function TMPPRO, Prefix, Ndigits, SEED=Seed common TMPCOM, tmpseed NP = N_PARAMS() case NP of 0 : begin name = 'tmp' Ndigits = 3 end 1 : begin name = Prefix Ndigits = 3 end 2 : begin name = Prefix end else : message,'Invalid parameter, Ndigits='+$ string(Ndigits) endcase ext = '.pro' if KEYWORD_SET( SEED ) then tmpseed = SEED VERSION_OS = STRLOWCASE(STRMID(!VERSION.OS,0,3)) NEWRND: numstr = long( 10.^Ndigits * randomu(tmpseed) ) numstr = STRTRIM( numstr,2 ) while (STRLEN(numstr) lt Ndigits) do $ numstr = '0'+numstr ; Make sure Temporary directory EXISTS ; if it does NOT, then create it tmp_path = TMPPROPATH('', ROOT_DIR = tmpdir) iss = DIR_EXIST(tmpdir) if (iss eq 0) then begin message,'Creating a Temp directory...',/INF case VERSION_OS of 'vms' : spawn,'create/dir '+tmpdir 'win' : spawn,'md '+tmpdir 'mac' : print,'Not even! Get a real OS!' else : spawn,'mkdir '+tmpdir endcase endif filename = name+numstr+ext fpath = TMPPROPATH( filename ) existfile = FINDFILE( fpath, COUNT=nexist ) if nexist gt 0 then goto, NEWRND return, fpath end