function READPDS, filename, label, NOSCALE = noscale, SILENT = silent ;+ ; NAME: ; READPDS ; PURPOSE: ; Read a PDS file into IDL data and label variables. ; ; CALLING SEQUENCE: ; Result=READPDS (Filename,[ Label,/NOSCALE,/SILENT] ) ; ; INPUTS: ; FILENAME = Scalar string containing the name of the PDS file ; to be read. ; ; OUTPUTS: ; Result = PDS data array constructed from designated record. ; ; OPTIONAL OUTPUT: ; Label = String array containing the "header" from the PDS file. ; ; OPTIONAL INPUT KEYWORDS: ; NOSCALE - If present and non-zero, then the ouput data will not be ; scaled using the optional SCALING_FACTOR and OFFSETkeywords ; in the PDS header. Default is to scale. ; ; SILENT - Normally, READPDS will display the size of the array at ; the terminal. The SILENT keyword will suppress this ; ; EXAMPLE: ; Read a PDS file TEST.PDS into an IDL image array, IM and PDS ; header array, lbl. Do not scale the data with BSCALE and BZERO. ; ; IDL> im = READPDS( 'TEST.PDS', lbl, /NOSCALE) ; WARNINGS: ; This version of READPDS only returns IMAGE data files, TABLES, ; SERIES, PALETTE, and SPECTRUM; other file types have yet to ; be dealt with. READPDS will eventually work on all forms of ; PDS data files, as it is modified to be more 'universal'. ; ; It is also intended to be used only on MSB architectures ('big- ; endian')if the file being read was written on an MSB architecture; ; it has no conversion from MSB to other architectures, yet. ; ; PROCEDURES USED: ; Functions: HEADPDS, PDSPAR, IMAGEPDS, TASCPDS ; ; MODIFICATION HISTORY: ; Adapted by John D. Koch from READFITS by Wayne Landsman,August,1994 ;- On_error,2 ;Return to user ; Check for filename input if N_params() LT 1 then begin print,'Syntax - result = READPDS( filename,[ label, /NOSCALE, /SILENT])' return, -1 endif silent = keyword_set( SILENT ) fname = filename ; Use HEADPDS to extract the PDS label label = headpds(filename) ; Read object to determine type of data in file object = pdspar(label,'OBJECT',COUNT=objects,INDEX=obindex) if !ERR EQ -1 then message, $ 'ERROR - '+filename+' missing required OBJECT keyword' ; Set a test varible to determine format of following function calls st = 0 if keyword_set(NOSCALE) then st = st + 1 if keyword_set(SILENT) then st = st + 2 i = fix(0) while i LT objects(0) do begin if strpos(object(i),'IMAGE') GT -1 then begin CASE st(0) of 0: data = imagepds(fname,label) ;neither option 1: data = imagepds(fname,label,/NOSCALE) ;/NOSCALE only 2: data = imagepds(fname,label,/SILENT) ;/SILENT only 3: data = imagepds(fname,label,/NOSCALE,/SILENT) ;both options else: message, 'ERROR - too many inputs in call to IMAGEPDS' ENDCASE i = objects(0)+10 ; if viable object found, increment i to escape loop endif else if strpos(object(i),'TABLE') GT -1 then begin inform = pdspar( label, 'INTERCHANGE_FORMAT',INDEX = index ) if !ERR EQ -1 then message, $ 'ERROR - '+fname+' missing required INTERCHANGE_FORMAT keyword' w = where(index GT obindex(i)) if strpos(inform(w(0)),'ASCII') GT -1 then begin if st(0) GT 1 then data = tascpds(fname,label,/SILENT) else $ data = tascpds(fname,label) endif else if strpos(inform(w(0)),'BINARY') GT -1 then begin if st(0) GT 1 then data = tbinpds(fname,label,/SILENT) else $ data = tbinpds(fname,label) endif else message,$ 'ERROR - Invalid PDS table interchange format '+inform(0) i = objects(0)+10 ; if viable object found, increment i to escape loop endif else if strpos(object(i),'SERIES') GT -1 then begin inform = pdspar( label, 'INTERCHANGE_FORMAT',INDEX = index ) if !ERR EQ -1 then message, $ 'ERROR - '+fname+' missing required INTERCHANGE_FORMAT keyword' w = where(index GT obindex(i)) if strpos(inform(w(0)),'ASCII') GT -1 then begin if st(0) GT 1 then data = tascpds(fname,label,/SILENT) else $ data = tascpds(fname,label) endif else if strpos(inform(w(0)),'BINARY') GT -1 then begin if st(0) GT 1 then data = tbinpds(fname,label,/SILENT) else $ data = tbinpds(fname,label) endif else message,$ 'ERROR - Invalid PDS table interchange format '+inform(0) i = objects(0)+10 ; if viable object found, increment i to escape loop endif else if strpos(object(i),'PALETTE') GT -1 then begin inform = pdspar( label, 'INTERCHANGE_FORMAT',INDEX = index ) if !ERR EQ -1 then message, $ 'ERROR - '+fname+' missing required INTERCHANGE_FORMAT keyword' w = where(index GT obindex(i)) if strpos(inform(w(0)),'ASCII') GT -1 then begin if st(0) GT 1 then data = tascpds(fname,label,/SILENT) else $ data = tascpds(fname,label) endif else if strpos(inform(w(0)),'BINARY') GT -1 then begin if st(0) GT 1 then data = tbinpds(fname,label,/SILENT) else $ data = tbinpds(fname,label) endif else message,$ 'ERROR - Invalid PDS table interchange format '+inform(0) i = objects(0)+10 ; if viable object found, increment i to escape loop endif else if strpos(object(i),'SPECTRUM') GT -1 then begin inform = pdspar( label, 'INTERCHANGE_FORMAT',INDEX = index ) if !ERR EQ -1 then message, $ 'ERROR - '+fname+' missing required INTERCHANGE_FORMAT keyword' w = where(index GT obindex(i)) if strpos(inform(w(0)),'ASCII') GT -1 then begin if st(0) GT 1 then data = tascpds(fname,label,/SILENT) else $ data = tascpds(fname,label) endif else if strpos(inform(w(0)),'BINARY') GT -1 then begin if st(0) GT 1 then data = tbinpds(fname,label,/SILENT) else $ data = tbinpds(fname,label) endif else message,$ 'ERROR - Invalid PDS table interchange format '+inform(0) i = objects(0)+10 ; if viable object found, increment i to escape loop endif i = i + 1 endwhile if i LT objects(0)+10 then message,$ 'No valid data type (image,table,series,palette,spectrum) found in '+fname ; Return file data and exit program return, data end