function gtt_info_sou_area, dph, mnem ;;sai = strtrim(gtt_info(dph, 'SOU_AREA'), 2) ;;out = gtt_mnem(dph, 'IPBCMP' + sai) ;;^^ doesn't work because GTT_MNEM wants ONE mnemonic, not a different mnemonic per data product header sai = gtt_mnem(dph, 'DPHSAI') out = gtt_mnem(dph, mnem+'0') ;temporary create output array with using area 0 to create the output type ; for isai=1,2 do begin ss = where(sai eq isai, nss) if (nss ne 0) then begin out2 = gtt_mnem(dph, mnem+strtrim(isai,2)) ;just convert all of it to avoid trying to figure out(ss) = out2(ss) ;out what data type and dimensions "in" are end end return, out end ;-------------------------------------------------------------- function gtt_info, in, code, string=string, $ qstop=qstop, qdebug=qdebug, $ lut=lut, ic=ic, oc=oc, q2stop=q2stop, $ force_rd=force_rd, dph=dph, times=times0 ; ;+ ;NAME: ; gtt_info ;PURPOSE: ; To extract information from the TRACE index information. ; The source is either: ; 1) a structure with item as an explict tag ; 2) the integer 505 data product header. ; 3) integer values (input for lookup table access) ;SAMPLE CALLING SEQUENCE: ; out = gtt_info(index, code) ; out = gtt_info(index, 'TAGTIME') ; out = gtt_info(index, 'msfilt1') ; out = gtt_info([0,1,2,3], 'msfilt1') ; print, gtt_info([19,54,91,127], 'mfilt1', /lut) ; print, gtt_info([1,2,3,4], 'mfilt1', /lut, ic=2) ; ; infil = '/td11/log/raw_fits/9712sim/19980218/tri19980218.1500 ; read_trace,infil,-1,index,data,/nodata,/all ; ; tr_rd_index, '18-Feb-98', '18-Feb-98 2:00', index ,/struct ; out = trace_dph2struct(ph,index,dph,/load) ;INPUT: ; in - Input data (structure or integer array) ; code - The item wanted. See the file ; $TR_CAL_INFO/trace_keywords.tdb ; for the decoding information ;OPTIONAL KEYWORD INPUT: ; string ; lut - Perform a lookup table conversion ; ic - Lookup table input column for the conversion ; (default is 0) ; oc - Lookup table output column for the conversion ; (default is 1) ; dph - The binary "505" word header in byte 2-D form ; times - The times to use when doing lookup table call ;METHOD: ; 1. Get the information requested ; A. If the input is a structure ; a. See if the code exists as a tag. If so, extract ; b. See if the dp_header is a tag, If so make the input ; be the dp_header ; B. If the input is an integer, see if it's the header or ; raw values being passed in (generally for lookup table ; conversion) ; 2. To derive or extract the information ; A. See if the definition of the tag is complex and requires ; the full dataproduct header ; B. See if the tag is defined simply in terms of other ; tags ; C. See if the keyword database can extract the information. ; That only works with the raw 505 header ; 3. Optionally convert the results by going through a lookup ; table. ; ; The idea is that most of GTT_INFO should work if a structure ; is passed in with the necessary tags, but with no raw 505 ; data product header. ;HISTORY: ; Written Jan-1998 by M.Morrison ; 29-Jan-98 (MDM) - Expanded to allow various types of input ; 30-Jan-98 (MDM) - Modified to call TRACE_DPH2STRUCT for the ; database reference extraction step ; - Added "dph" keyword input to speed up ; the extraction steps ; 19-Feb-98 (MDM) - Added TIMES keyword ; 24-Feb-98 (MDM) - Corrected GTT_INFO_SOU_AREA function ; 26-Feb-98 (MDM) - Added several of the CCD pixel keywords ; 11-Mar-98 (MDM) - Changed definition of SRI pixels based on ; Tarbell's prediction of the amplifier orientation ; - Corrected(?) 'CRO_LLEX/Y' ; 18-Mar-98 (MDM) - Removed "n1 = n_elements(in(*,0))" code which ; was slowing things considerably (.1 sec/4000 images/call) ; 24-Mar-98 (MDM) - Added "sht_mdur" ; 24-Apr-98 (SLF) - do bytswap for lendian on TIME_TAG (only) ; 5-May-98 (MDM) - Corrected SRI_LLEX/Y -- it was not correcting for ; bin/sum factors ; 12-May-98 (FZ) - Changed loop variable to long ;- ; common gtt_info_blk1a, db_conv, last_code, qrecurse ; if (keyword_set(force_rd)) then delvarx, db_conv ; if (n_elements(in) eq 0) then return, '' ;no input if (n_elements(qrecurse) eq 0) then qrecurse = 0 if (n_elements(last_code) eq 0) then last_code = 'xx' ; if (qrecurse gt 10) and (code eq last_code) then stop, 'Endless recursion for code ' + code + ' ???? last_code = code ; qstruct = data_type(in) eq 8 n1 = data_chk(in, /nx) n2 = data_chk(in, /ny) > 1 qhead = ((n2 gt 1) or (n1 eq 505)) and (1-qstruct) if (qhead) then begin dph = in ;have to make a copy (unfortunately) nin = n_elements(dph(0,*)) end else begin nin = n_elements(in) ;structure or direct end if (keyword_set(qdebug)) then help,n1,n2,qstruct,qhead ; ;=========================== Extract the information ================= ; qin_direct = (1-qstruct) and (1-qhead) ;not structure or header means ;input data is already extacted (passed directly in) qextracted = qin_direct if (qextracted) then out = in if (qstruct) then begin tags = tag_names(in) ss = where(tags eq strupcase(code), nss) if (nss eq 1) then begin out = gt_tagval(in, code) qextracted = 1 end else begin if (not keyword_set(dph)) then begin ss = where(tags eq 'DP_HEADER', nss) if (nss eq 1) then begin print, 'GTT_INFO: Extracting dp_header from the structure dph = make_into_bytarr(in.dp_header) ;make the input be the 505 data product header qhead = 1 qstruct = 0 end end end end qhead = keyword_set(dph) ; ;------- tags which involve detailed extraction from raw header if ((not qextracted) and (qhead)) then begin case strupcase(code) of 'TIME_TAG': begin out = gtt_mnem(dph, 'DPHLOBT') ;TODO - fractional seconds available? if is_lendian() then out=byteswap(out) if (keyword_set(string)) then out = fmt_tim(anytim2ints('24-May-68', off=double(out))) end 'BIN_CCD': begin ;IP binning out = gtt_info_sou_area(dph, 'IPBBM') > 1 ;0=1 end ;-------------- Items coming out of the IPB area blocks 'DL_TYPE': begin out = gtt_info_sou_area(dph, 'IPBCMP') ;TODO - run it through a lookup table end 'COMP_TAB': begin out = gtt_info_sou_area(dph, 'IPBHTLUT') ;JPEG Huffman Table or Lookup Table Number end 'COMP_QT': begin out = gtt_info_sou_area(dph, 'IPBQTPCK') * 16 + $ ;JPEG Quantization Table or Packing Size gtt_info_sou_area(dph, 'IPBQM') ;JPEG Quality Indicator end ;----- Pixel address stuff 'CRO_FPOX': begin out = 0 ;TODO - add offset fractional pixel for summing end 'CRO_FPOY': begin bp_Yoff = gtt_mnem(dph, 'IPBBPYO') ; Bad Pixel Y Offset out = bp_Yoff ;TODO - add offset fractional pixel for summing end 'CRO_LLEX': begin ;1300 = 252 ccd header + 1040 first line + 8 bls ;1292 = 252 ccd header + 1040 first line rowlen = gtt_info_sou_area(dph, 'IPBRL') ;should be 1040,528,272,144 (1024,512,256,128)+8+8 start_addr = gtt_info_sou_area(dph, 'IPBSA') out = (start_addr - 1292) mod rowlen - 8 ;-8 for "bls" ;-- TODO - add offset fractional pixel for binning (and summing) end 'CRO_LLEY': begin rowlen = gtt_info_sou_area(dph, 'IPBRL') start_addr = gtt_info_sou_area(dph, 'IPBSA') out = (start_addr - 1292)/rowlen + gtt_info(in, 'CRO_FPOY', dph=dph) ;-- TODO - add offset for summing end 'CDL_NCOL': begin nrawcol = gtt_info_sou_area(dph, 'IPBNC') bin = gtt_info(in, 'bin_ccd', dph=dph) out = nrawcol/bin end 'CDL_NLIN': begin nrawrow = gtt_info_sou_area(dph, 'IPBNR') bin = gtt_info(in, 'bin_ccd', dph=dph) out = nrawrow/bin end ; ^ AmpA ; ! +---------------+ ! ; ! | N | ! ; ! | | ! ; ! | The Sun | ! ; ! |E W| ! ; ! | | ! ; ! | + | ! ; ! | S | ! ; ! +---------------+ ! ; v ; AmpB 'SRI_LLEX': begin out = intarr(nin)-1 y0 = gtt_info(in, 'CRO_LLEY', dph=dph) amp = gtt_info(in, 'amp', dph=dph) ss = where(amp eq 'A', nss) if (nss ne 0) then begin tbin = gtt_info(in, 'bin_ccd', dph=dph) out0 = 1024 - gtt_info(in, 'cdl_nlin', dph=dph)*tbin - y0 out(ss) = out0(ss) ;TODO - confirm amp a/b orientation end ss = where(amp eq 'B', nss) if (nss ne 0) then begin out0 = y0 out(ss) = out0(ss) end ;TODO - apply another correction for summing and binning? end 'SRI_LLEY': begin out = intarr(nin)-1 x0 = gtt_info(in, 'CRO_LLEX', dph=dph) amp = gtt_info(in, 'amp', dph=dph) ss = where(amp eq 'A', nss) if (nss ne 0) then begin tbin = gtt_info(in, 'bin_ccd', dph=dph) out0 = 1024 - gtt_info(in, 'cdl_ncol', dph=dph)*tbin - x0 out(ss) = out0(ss) ;TODO - confirm amp a/b orientation end ss = where(amp eq 'B', nss) if (nss ne 0) then begin out0 = x0 out(ss) = out0(ss) end ;TODO - apply another correction for summing? end 'SRI_FOVX': begin n = gtt_info(in, 'NX_OUT', dph=dph) tbin = gtt_info(in, 'bin_ccd', dph=dph) x0 = gtt_info(in, 'sri_llex', dph=dph) out = x0 + (n-1)/2. * tbin end 'SRI_FOVY': begin n = gtt_info(in, 'NY_OUT', dph=dph) tbin = gtt_info(in, 'bin_ccd', dph=dph) y0 = gtt_info(in, 'sri_llex', dph=dph) out = y0 + (n-1)/2. * tbin end else: endcase end qextracted = n_elements(out) ne 0 ; ;------- tags which can be derived from other tag values (doesn't require the raw header) ; if (not qextracted) then begin case strupcase(code) of 'IMG_TIME': begin t1 = gtt_info(in, 'time_tag', dph=dph) ;;expdur = gtt_info(in, 'SHUT_NOM')/1000. ;duration in seconds ;;part_readout = ... ? ; may require the full raw header ;;out = t1 - expdur - part_readout * ... out = t1 if (keyword_set(string)) then out = fmt_tim(anytim2ints('24-May-68', off=double(out))) end 'CDELT1': begin out = gtt_info(in, 'tbin_ccd', dph=dph) * .5 ;TODO - what are the arcsec/pixel end 'CDELT2': begin out = gtt_info(in, 'tbin_ccd', dph=dph) * .5 end 'SHT_MDUR': begin out = gtt_shutter_exp(in, dph=dph) end else: ;database needed to convert it? endcase end qextracted = n_elements(out) ne 0 if (qhead) and (not qextracted) then begin ;try the database to get the value ;;;print, 'Calling DPH2STRUCT for ', code qrecurse = qrecurse + 1 out = trace_dph2struct(ph, in, dph, taglist=code, /no_struct, /nonone) qrecurse = 0 ;CAUTION: ^^^ does not protect against endless recursive calling of the routine ; infil = '$TR_CAL_INFO/trace_keywords.tdb' ;TODO - make file name an env var? ; qfound = 0 ; if (n_elements(db_conv) eq 0) then begin ; db_conv = rd_ulin_col(infil, nocomm=';', /nohead) ; db_conv = strupcase(db_conv) ; end ; ss = where(db_conv(0,*) eq strupcase(code), nss) ;is the item in the database ; if (nss eq 1) then begin ; cmd = 'out = ' + db_conv(1,ss(0)) ;command to extract the information ; p1 = strpos(cmd, 'GTT_INFO') ; p2 = strpos(cmd, "'" + strupcase(code) + "'") ; if (p1 ne -1) and (p2 ne -1) then begin ; print, 'GTT_INFO: Item ' + code + ' could result in a recursive endless call. ; print, cmd ; print, 'stopping... ; stop ; end else begin ; ss2 = where(db_conv(0,*) eq '.NONE', nss2) ; for i=0L,nss2-1 do begin ; cmd0 = str_replace(db_conv(1,ss2(i)), '(BE', '(in') ; cmd0 = str_replace(cmd0, 'GTT_INFO(', 'GTT_INFO(dph=dph, ') ; ;;stat = execute(cmd0) ; end ; cmd = str_replace(cmd, '(BE', '(in') ; cmd = str_replace(cmd, 'GTT_INFO(', 'GTT_INFO(dph=dph, ') ; stat = execute(cmd) ; qfound = 1 ; end ; end ; if (not qfound) then print, 'GTT_INFO: Unrecognized key ' + code end qextracted = n_elements(out) ne 0 ; if (not qextracted) then begin print, 'GTT_INFO: Problem figuring out how to extract the info' help, in, code, qstruct, qhead, dph print, 'Stopping...' stop out = -1 end ; ;===================== Lookup table conversion portion ===================================== ; if (keyword_set(lut)) then begin case strupcase(code) of 'WAVE_NUM': lut_fil = 'wave_table' 'MFILT1': lut_fil = 'filt1_pos' 'MFILT2': lut_fil = 'filt2_pos' 'MQUAD': lut_fil = 'quad_pos' else: begin print, 'GTT_INFO: Lookup table requested for item: ' + code print, 'but no lookup table file name information is available tbeep, 3 lut_fil = 'xxx' ;let TR_LUT_CONV format the output end endcase if (not qin_direct) then begin if (keyword_set(times0)) then times = times0 $ else times = gtt_info(in, 'IMG_TIME', dph=dph) end if is_lendian() then out=byteswap(out) out = tr_lut_conv(out, lut_fil, times, ic=ic, oc=oc, qdebug=qdebug, qstop=q2stop) end ; if (keyword_set(qstop)) then stop if is_lendian() then out=byteswap(out) return, out end