PRO rdkihd,file,header,flag=flag ;+ ; NAME: ; RDKIHD ; ; PURPOSE: ; Read the header of a KI-generated Polar Camera image. ; ; CATEGORY: ; ; CALLING SEQUENCE: ; RDKIHD, FILENAME, HEADER, FLAG=FLAG ; ; INPUTS: ; FILENAME: An unambiguous path to the image file to be read. ; ; KEYWORD PARAMETERS: ; FLAG: If this optional keyword is set, it contains a byte ; indicating the success (0) or failure (1) of the read. ; ; OUTPUTS: ; HEADER: A 512 byte array containing the header information ; from the specified image file. Use function GETHD ; to decode the header into an IDL structure. ; ; COMMON BLOCKS: ; None. ; ; SIDE EFFECTS: ; None. ; ; RESTRICTIONS: ; None. If the file name passed ends in '.z' or '.gz', the ; routine spawns a process to 'gunzip' the file, reads it ; in, and spawns another process to 'gzip' it again. This ; requires that the user be 'cnsr3', as all images now belong ; to that user. ; ; PROCEDURE: ; Straightforward. If the routine is being run on a Unix ; host, the byte order is reversed. ; ; MODIFICATION HISTORY: ; Written July or August 1992 by DPS. ; Modified 93/07/08 by DPS to handle gzipped images. ;- ON_IOERROR,bad_file flag=0B zip=STRPOS(file,'.z') gzip=STRPOS(file,'.gz') IF (zip GT 0) OR (gzip GT 0) THEN BEGIN command='gzcat '+file+' > ! tmp' SPAWN,command sfile='tmp' ENDIF ELSE sfile=STRTRIM(file,2) OPENR,unit,sfile,/GET_LUN filestat=FSTAT(unit) IF filestat.SIZE LT 512 THEN BEGIN CLOSE,unit & FREE_LUN,unit MESSAGE,'Too few bytes found in file '+file+'; aborting',/INFORMATIONAL header=-1 flag=1B RETURN ENDIF header=BYTARR(512) READU,unit,header CLOSE,unit & FREE_LUN,unit IF (zip GT 0) OR (gzip GT 0) THEN SPAWN,'rm tmp' BYTEORDER,header ; reverse byte order RETURN bad_file: MESSAGE,'I/O error reading '+file,/INFORMATIONAL header=-1 flag=1B RETURN END