;+ ; :Description: ; Fits writer for Cube Generator, for Cassini UVIS data. ; ; :Params: ; filename [in, required, String] : Filename ; datastruct [in, required, struct] : data structure ; datastruct_initial [in, required, struct] : data structure ; datastruct_final [in, required, struct] : data structure ; ; :Requires: ; Written with IDL 8.6.1, but should run with anything > 8.3 ; IDLAstro : https://github.com/wlandsman/IDLAstro ; ; :Author: ; Josh Elliott : joshua.elliott@lasp.colorado.edu ; ; :History: ; Created 1 November 2017 ; ;- pro uvis_fits_writer, filename, datastruct, datastruct_initial, datastruct_final, $ calibration_matrix, calibration_error_matrix, HEADER=_hdr compile_opt idl2 ; TODO: Do we need a more comprehensive header for each of the data fields? For now this ; is a sample from the PDS UVIS datasets. st = '' hdr = list() openr, lun, file_dirname(routine_filepath()) + path_sep() + 'uvis_cube_header.txt', /GET_LUN while ~eof(lun) do begin readf, lun, st hdr.add, st endwhile hdr = 'COMMENT ' + hdr.toarray() if isa(_hdr, 'string', /array) then begin hdr = [hdr, 'COMMENT ' + _hdr] endif hdr = [hdr, 'COMMENT '] ; An empty line is needed at the end. ; Write the header to a new fits file: mwrfits, !null, filename, hdr, /CREATE, /SILENT ; Write the calibration matrices, if present if isa(calibration_matrix) then begin mwrfits, {dataset_name:'calibration_matrix', data:calibration_matrix}, filename, /SILENT endif if isa(calibration_error_matrix) then begin mwrfits, {dataset_name:'calibration_error_matrix', data:calibration_error_matrix}, filename, /SILENT endif ; Loop over the input datasets and add to the fits file datasets = orderedhash('datastruct', datastruct, 'datastruct_initial', datastruct_initial, 'datastruct_final', datastruct_final) i = 0 foreach dataset, datasets, key do begin if (isa(dataset, 'struct')) then begin d = orderedhash(dataset) d['dataset_name'] = key d = d.tostruct() mwrfits, d, filename, /SILENT endif endforeach end