;+ ; NAME: ; gunzip_file ; PURPOSE: ; Unzip .gz. file ; CATEGORY: ; gen/idl/util ; CALLING SEQUENCE: FUNCTION gunzip_file, zipfile, rawfile, check=check, isgz=isgz, ramdisk=ramdisk ; INPUTS: ; zipfile scalar; type: string ; file to be unzipped ; OPTIONAL INPUT PARAMETERS: ; /check if set then check whether the file exists ; /ramdisk by default the unzipped file is written to $TUB ; if /ramdisk is set the environment variable $ramdisk ; is tried first. ; OUTPUTS: ; status 0: unzip not successfull ; 1: file succesfully unzipped into file 'rawfile' ; rawfile scalar; type: string ; name of unzipped file (if status=1) or the blank ; string (if status=0) ; OPTIONAL OUTPUTS: ; isgz=isgz 1 if input file was .gz file; 0 if not. ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, SetFileSpec, GetFileSpec ; PROCEDURE: ; If the input file 'zipfile' does not exist or is not a .gz file then ; status = 0 is returned. ; ; The unzipped output file has the same name as the input file with ; the prefix _tmp_ added and the .gz stripped. ; By default the file is written to $TUB. If /ramdisk is set then ; $ramdisk is used (if the env var exists). Usually $ramdisk will point ; to a ramdisk. Note that the user should set up the ramdisk and make ; sure it is big enough to hold the unzipped file. ; MODIFICATION HISTORY: ; APR-2003, Paul Hick (UCSD/CASS) ; JUL-2004, Paul Hick (UCSD/CASS) ; Added /ramdisk keyword. ; DEC-2007, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Change name of temp file from _tmp_* to _tmp##_*, where ## is ; a number less than 10. The number is the lowest number that ; make a file name for a non-existent files. This was added to ; avoid conflicts with other program trying the same file ; (the conflicting program might delete the temp file before it ; is read). ;- InitVar, check , /key InitVar, ramdisk, /key rawfile = '' SetFileSpec, zipfile isgz = strlowcase(GetFileSpec(part='type')) EQ '.gz' IF check THEN BEGIN status = (file_search(zipfile))[0] IF status EQ '' THEN RETURN, 0 ENDIF status = isgz IF status THEN BEGIN CASE ramdisk OF 0: rawdir = getenv('TUB') 1: BEGIN rawdir = getenv('ramdisk') IF rawdir EQ '' THEN rawdir = getenv('TUB') END ENDCASE i = 0 REPEAT BEGIN i += 1 IF i GT 10 THEN message, 'unable to name temporary file' raw = filepath(root=rawdir,'_tmp'+string(i,format='(I2.2)')+'_'+GetFileSpec(part='name')) ENDREP UNTIL (file_search(raw))[0] EQ '' CASE !version.os_family OF 'unix': gzip = 'gzip' ; Should be in the PATH 'win ': gzip = filepath(root=getenv('SSW_SMEI_UCSD'), subdir= $ ['gen','exe','win'], 'gzip.exe') ELSE : message, 'not implemented on '+!version.os_family ENDCASE gzip = gzip+' --decompress --stdout '+zipfile+' > '+raw CASE !version.os_family OF 'unix':spawn, gzip 'win': spawn, /hide, gzip ENDCASE status = (file_search(raw))[0] NE '' CASE status OF 0: message, /info, 'unzipped file not found: '+raw 1: rawfile = raw ENDCASE ENDIF RETURN, status & END