;+ ; NAME: ; UVIS_PDS_READ_DATA ; ; PURPOSE: ; This procedure will read binary data from a Cassini UVIS PDS data file and also return a subset of the fields in the label file. ; ; CALLING SEQUENCE: ; UVIS_PDS_READ_DATA, Filename, Data, Label ; ; INPUTS: ; Filename: Name of the PDS data file or label file. ; ; KEYWORD PARAMETERS: ; NO_EXTRACT: Default is to extract the data from the valid detector region. ; Set this keyword to 1 to prevent this, maintaining the native format. ; ; OUTPUTS: ; Data: Typically a three-dimensional array of detector readouts. Regardless of the stored data type, the returned values will be floating point. ; Label: Structure containing a subset of the fields available in the PDS label file. ; ; RESTRICTIONS: ; It is required that both the data file and associated label file are present in the same path. ; Requires the routine UVIS_PDS_READ_LABEL.pro. ; ; PROCEDURE: ; First read the field values in the label file. This is necessary to define the dimensions of the ; binary data. Next, read in the binary data. Finally, extract valid region of the detector from the container array. ; ; EXAMPLE: ; Read in the data and label metadata for one UVIS PDS data file. ; ; Filename = 'EUV2008_054_15_36.DAT' ; UVIS_PDS_READ_DATA, Filename, Data, Label ; ; MODIFICATION HISTORY: ; Written by: Greg Holsclaw, University of Colorado/LASP, Aug 2013. ;- pro UVIS_PDS_READ_DATA, Filename, Data, Label, NO_EXTRACT=NO_EXTRACT ; ; The input filename could refer to the data or label file; these differ only by the file extension. ; Create the data and label file names. ; ;filename_dat = filename ;filename_lbl = filename ;strput,filename_lbl,'.LBL',strpos(filename,'.DAT') dir = file_dirname( filename ) fbasename = file_basename(filename) pos = strpos( fbasename, '.', /reverse_search ) fbasename_no_ext = strmid( fbasename, 0, pos ) filename_dat = dir + path_sep() + fbasename_no_ext + '.DAT' filename_lbl = dir + path_sep() + fbasename_no_ext + '.LBL' ; ; check if the files exist ; test1 = file_search( filename_dat, count=nfiles1 ) test2 = file_search( filename_lbl, count=nfiles2 ) if nfiles1 eq 0 then begin print, ' ' print, 'read_uvis_pds_data: required file is not present: ', filename_dat print, ' ' return endif if nfiles2 eq 0 then begin print, ' ' print, 'read_uvis_pds_data: required file is not present: ', filename_lbl print, ' ' return endif ; ; read in the label file ; UVIS_PDS_READ_LABEL,filename_lbl, Label ; ; retrieve the data cube dimensions ; str1 = strmid( Label.core_items, 1, strlen(Label.core_items)-2 ) str2 = strsplit(str1,',',/extract) BAND = fix(str2[0]) LINE = fix(str2[1]) SAMPLE = fix(str2[2]) ; ; see the IDL help for the size() function for data type codes ; case Label.core_item_type of 'IEEE_REAL': begin if Label.core_item_bytes eq 4 then data_type = 4 end 'MSB_UNSIGNED_INTEGER': begin if Label.core_item_bytes eq 2 then data_type = 12 end else: begin print, 'unrecognized data type' stop end endcase ; ; read the data cube ; data = float( read_binary( filename_dat, data_dims=[ BAND, LINE, SAMPLE], data_type=data_type, endian='big' ) ) if keyword_set(NO_EXTRACT) eq 0 then begin ; ; extract the valid data region ; x1 = label.UL_CORNER_BAND x2 = label.UL_CORNER_BAND + (label.LR_CORNER_BAND-label.UL_CORNER_BAND+1) / label.BAND_BIN - 1 y1 = label.UL_CORNER_LINE y2 = label.UL_CORNER_LINE + (label.LR_CORNER_LINE-label.UL_CORNER_LINE+1) / label.LINE_BIN - 1 data = data[x1:x2,y1:y2,*] ; endif return end