function create_new_label, raw_label, raw_filename, cal_filename, cfg_content, logname, comments = comments ;+ ;$Log: ; ; NAME: ; create_new_label ; ; PURPOSE: ; Creates a new AMIE label for the calibrated image ; ; CATEGORY: ; AMIE Calibration - part of the project 'amie_pipeline' ; ; CALLING SEQUENCE: ; new_label = create_new_label(raw_label, cal_file_name, master_flat_name, master_dark_name) ; ; INPUTS: ; raw_label: raw label extracted from the raw data file ; cal_file_name: file name of the new calibrated image ; master_flat_name: file name of the master flat used in the calibration to be inserted in the label ; master_dark_name: file name of the master dark used in the calibration to be inserted in the label ; ; OPTIONAL INPUT PARAMETERS: ; None. ; ; OUTPUTS: ; new label for the calibrated images ; ; COMMON BLOCKS: ; None. ; ; SIDE EFFECTS: ; Hopefully none. ; ; RESTRICTIONS: ; None. ; ; MODIFICATION HISTORY: ; 2004 Feb 18, MA: First version ; 2008-Feb-14, SM: Transfer comment lines of the style /*** COMMENT ***/ ; 2008-Feb-14, SM: Adaptions to keyword values in the calibrated header ; ; (c) 2004, Miguel Almeida, ESA/RSSD ;- create_log_entry, logname, 'Entering New Label Creator Module' ;------------------------------------------------------------------------------------------------------------------------- ; ;Initialize the new label with the raw data values ; ;------------------------------------------------------------------------------------------------------------------------- calibrated_label = raw_label ;------------------------------------------------------------------------------------------------------------------------- ; ;Add comments from original label before applying new values to the label (2008-Feb-14, SM) ; ;------------------------------------------------------------------------------------------------------------------------- if (keyword_set(comments)) then begin ;; Open the raw image file (path + filename) openr,unit,raw_filename,/get_lun lineNo = 0 ln = '' while (~EOF(unit)) do begin ;; Read raw image label readf,unit,ln if (strpos(ln,'END ',0) eq 0) then break ;; Insert comments in the empty lines read by the headpds function if ((strpos(ln,'/***') ne -1) and (strpos(ln,'***/') ne -1)) then begin calibrated_label[lineNo] = ln endif lineNo++ endwhile close,unit free_lun,unit endif ;------------------------------------------------------------------------------------------------------------------------- ; ;Edit each of the label entries that are modified when an image is calibrated ; ;------------------------------------------------------------------------------------------------------------------------- ;FILE_NAME calibrated_label = pdsupdatekeyword(calibrated_label, 'FILE_NAME', '"' + cal_filename(0) + '"') ;DATA_SET_ID ; calibrated_label = replace_string(calibrated_label, 'DATA_SET_ID', '2-EDR-RAW', '3-RDR-CAL') calibrated_label = replace_string(calibrated_label, 'DATA_SET_ID', '2-EDR', '3-RDR') ; Had to be changed for version 0.4 and up, as we do not use any ; more RAW and CAL in the ID, 2010-Mar-30, BG ;DATA_SET_NAME ;calibrated_label = replace_string(calibrated_label, 'DATA_SET_NAME', '2 EDR RAW', '3 RDR CAL') line = where(strpos(calibrated_label,'2 EDR RAW') ne -1) temp = calibrated_label[line] strput, temp, '3 RDR CAL', strpos(calibrated_label[line],'2 EDR RAW',0) calibrated_label[line] = temp ;PRODUCT ID calibrated_label = pdsupdatekeyword(calibrated_label, 'PRODUCT_ID', strmid(cal_filename(0),0,strlen(cal_filename(0))-4)) ;PROCESSING_LEVEL_ID calibrated_label = pdsupdatekeyword(calibrated_label, 'PROCESSING_LEVEL_ID', '3') ;PROCESSING_LEVEL_DESC ;; 2008-Feb-14, SM: Changed processing level description calibrated_label = pdsupdatekeyword(calibrated_label, 'PROCESSING_LEVEL_DESC', '"CALIBRATED DATA.') line = where(strpos(calibrated_label,'SOMETIMES CALLED EXPERIMENTAL') ne -1) calibrated_label = [calibrated_label(0:line-1),$ ' SOMETIMES CALLED REDUCED DATA RECORD (RDR)"',$ calibrated_label(line+1:*)] ;PRODUCT_CREATION_TIME product_creation_time = string(FORMAT='(C(CYI,"-",CMOI2.2,"-",CDI2.2,"T",CHI2.2, ":", CMI2.2, ":", CSI2.2))',SYSTIME(/julian,/utc)) calibrated_label = pdsupdatekeyword(calibrated_label, 'PRODUCT_CREATION_TIME', product_creation_time) ;PRODUCT_TYPE calibrated_label = pdsupdatekeyword(calibrated_label, 'PRODUCT_TYPE', 'RDR') ;DARK_CURRENT_CORRECTION_FLAG ;; 2008-Feb-14, SM: "TRUE" instead of '1' calibrated_label = pdsupdatekeyword(calibrated_label, 'DARK_CURRENT_CORRECTION_FLAG', '"TRUE"') ;DARK_CURRENT_FILE_NAME ;; 2008-Feb-14, SM: Dark Current file names in PDS format. ;; 2008-Feb-18, SM: Delete one empty line before the END keyword. ;; 2008-Feb-21, BG: Changed string to sequence. calibrated_label = pdsupdatekeyword(calibrated_label, 'DARK_CURRENT_FILE_NAME', '(AMI_CMA_071101_00001_00000.IMG,') line = where(strpos(calibrated_label,'DARK_CURRENT_FILE_NAME') ne -1) calibrated_label = [calibrated_label(0:line),$ ' AMI_CMA_071101_00002_00001.IMG)',$ calibrated_label(line+1:*)] line = where(strpos(calibrated_label,'END ') ne -1) calibrated_label = [calibrated_label(0:line-2),calibrated_label(line:*)] ;FLAT_FIELD_CORRECTION_FLAG ;; 2008-Feb-14, SM: "TRUE" instead of '1' calibrated_label = pdsupdatekeyword(calibrated_label, 'FLAT_FIELD_CORRECTION_FLAG', '"TRUE"') ;FLAT_FIELD_FILE_NAME ;; 2008-Feb-14, SM: File name without slash ;;strmid(cfg_content(5),30,/reverse_offset)) calibrated_label = pdsupdatekeyword(calibrated_label, 'FLAT_FIELD_FILE_NAME', $ '"' + strmid(cfg_content(5),strlen(cfg_content(5))-strpos(cfg_content(5), $ path_sep(),/reverse_search)-2,/reverse_offset) + '"') create_log_entry, logname, '[New Label Creator Module] label entries updated' ;------------------------------------------------------------------------------------------------------------------------- ; ;Return new label ; ;------------------------------------------------------------------------------------------------------------------------- return, calibrated_label end