function yo_xda2fitshead, iindex, gen_only=gen_only, history=history, $ sswstruct=sswstruct , allcoms=allcoms, prepend_inst=prepend_inst, $ debug=debug, addorbit=addorbit, addtim2orbit=addtim2orbit ; ;+ ; Name: yo_xda2fitshead ; ; Purpose: map yohkoh index structures to "flattened" ssw-compat. structure ; ; Method: ; flattens out the index substructures, maps comments to tags ; optionally add ssw tags. For SXT which includes the .HIS, ; decode and map history into a more standard form. ; ; Circa 20-May-2003 - S.L.Freeland for Yohkoh Galileo/Legacy program ; 30-Sep-2004 - S.L.Freeland - /ADDTIM2ORBIT keyword&function ; 19-feb-2005 - Aki Takeda - silent version called from yo_xda2legacy.pro ; 19-may-2008 - LWA - Added /quiet to call to rep_tag_name. ; 17-aug-2008 - AkT - Newly define the FITS keywords for which original ; index tags have 2 elements but the second element ; was trancated when flattened and made into FITS. ; e.g., SHAPE_C1 : index.sxt.SHAPE_CMD (1st element) ; SHAPE_C2 : index.sxt.SHAPE_CMD (2nd element) ; CORNE_C1 : index.sxt.CORNER_CMD (1st element) ; CORNE_C2 : index.sxt.CORNER_CMD (2nd element) ; - Delete the incomplete tags, i.e., SHAPE_CM, SHAPE_SA, ; CORNER_C, CORNER_S, FOV_CENT. ; 19-may-2009 - AkT - Define a new FITS keywords to work with gt_res. ; PIX_SIZE : index.his.PIXEL_SIZE ; 23-apr-2010 - S.L.Freeland/G.L.Slater - full WCS compliance ; 25-jun-2010 - AkT - Set 3 vector tags to 0b. ; DP_TIME, FLARE_STATUS, and TEMP_HK. These tags ; yield warning message when read with MREADFITS. ; 18-feb-2013 - AkT - Remove 11 vector or imperfect tags : 'DP_TIME', ; 'FLARE_STATUS','PNTG_ANGLE','SIRIUS','SPARE1', ; 'MLOOP','LOOPS','TEMP_HK','HW_ERROR','SPARE','HSPARE'. ; - Re-define DSUN_OBS as Sun - Earth distance (approx. ; of Sun - S/C dist.) in accordance with JHV project. ; *note* DSUN_OBS is usually filled by SSWSTRUCT_FILL.PRO. ; this mod was prepared just to keep accordance. ;- common yo_xda2fitshead_blk, tim2orb_struct debug=keyword_set(debug) prepend_inst=keyword_set(prepend_inst) if not required_tags(iindex,'gen') then begin box_message,'Expect Yohkoh INDEX structure' return,-1 endif index=iindex sswadd=keyword_set(sswstruct) if required_tags(index,'sxt,his') then begin index=sxt_his2his(index) savhis=index.history index=rem_tag(index,['his','history']) endif case 1 of sswadd and required_tags(index,'xcen,ycen,crpix1,cdelt1'): ; $ ; AkT ; print,'----- Input index already piped through struct2ssw -----' ;AkT ; box_message,'Input index already piped through struct2ssw ;AkT sswadd: begin index=struct2ssw(iindex) index.date_d$obs=index.date_obs index.crota1=0. ;------------------------------------------------------------ 17-feb-2013 ; index.dsun_obs=index.solar_r*2. rsun_meters=6.95508e8 index.dsun_obs=rsun_meters/((!dpi/180.d0) * index.solar_r/3600.d0) ;------------------------------------------------------------ 17-feb-2013 index.hgln_obs=0. index.hglt_obs=index.solar_b0 index.ctype1='Solar-X' index.ctype2='Solar-Y' index.cunit1='arcsec' index.cunit2='arcsec' endcase else: endcase if sswadd then begin sswstruct=index tnames=tag_names(index) nt=n_elements(tnames) tstructs=lonarr(nt) for i=0,nt-1 do tstructs(i)=data_chk(index.(i),/struct) sss=where(tstructs,ssscnt) if ssscnt gt 0 then sswstruct=rem_tag(sswstruct,sss) endif inames='gen,sxt,his,bcs,hxt,wbs,' + (['','his'])(keyword_set(history)) insts=str2arr(inames) ; tags to collapse tind=tag_index(index,insts) tss=where(tind ne -1, tcnt) for i=0,tcnt-1 do begin iix=insts(tss(i)) ; box_message,'Collapsing>> ' + iix ;AkT subs=gt_tagval(index,iix) tnames=tag_names(subs) tcomms=yo_tags2comments(tnames,iix) tcomms=(['',iix+': '])(prepend_inst) + tcomms if i eq 0 then begin ; should have used a WHILE-loop... allcoms=tcomms alltags=tnames retval=subs endif else begin dups=where_arr(alltags,tnames,dcnt) for di=0,dcnt-1 do begin ; map duplicates -> dnam=alltags(dups(di)) unam=strmid(iix,0,1)+dnam ; e.g. INDEX_VER --> SINDEX_VER subs=rep_tag_name(temporary(subs),dnam,unam,/quiet) ; prepend instr abbr. endfor allcoms=[allcoms,tcomms] alltags=[alltags,tnames] retval=join_struct(retval,subs,/duplicate) endelse endfor ;-------- add 4 new tags & remove 5 existing tags (Aug-2008, AkT) -------- ;-------- add one more tag (May-2009, AkT) -------- ; ; his_corner_sav=iindex.his.corner_sav pos=where(alltags eq 'EXPDUR') pos=pos(0) newtags=['SHAPE_C1','SHAPE_C2','CORNE_C1','CORNE_C2','PIX_SIZE'] ; work=add_tag(retval,retval.corner_sav(1),newtags(5),index=pos) ; work=add_tag(work, work.corner_sav(0), newtags(4),index=pos) ; work=add_tag(retval,his_corner_sav(1),newtags(5),index=pos) ; work=add_tag(work, his_corner_sav(0), newtags(4),index=pos) work=add_tag(retval,iindex.his.pixel_size, newtags(4),index=pos) work=add_tag(work,work.corner_cmd(1), newtags(3),index=pos) work=add_tag(work,work.corner_cmd(0), newtags(2),index=pos) work=add_tag(work,work.shape_cmd(1), newtags(1),index=pos) work=add_tag(work,work.shape_cmd(0), newtags(0),index=pos) ; retval=rem_tag(work,['SHAPE_CMD','SHAPE_SAV','CORNER_CMD','CORNER_SAV','FOV_CENTER']) ; ; alltags=[alltags(0:pos+4),alltags(pos+6:*)] ; shrink by 1 tag (not anymore 19-May-2009) ; alltags(pos+1:pos+4)=newtags alltags(pos+1:pos+5)=newtags ; for newly added tag, 'PIX_SIZE' (19-May-2009) ; ; allcoms=[allcoms(0:pos+4),allcoms(pos+6:*)] ; shrink by 1 tag (not anymore 19-May-2009) allcoms(pos+2)=allcoms(pos+1) allcoms(pos+4)=allcoms(pos+3) allcoms(pos+5)='his: pixel size from index.his.pixel_size' ; (19-May-2009) ; ;--- remove 2 problematic tags for JHV and 9 more vector tags (Feb-2013) --- retval=rem_tag(retval,['DP_TIME','FLARE_STATUS','PNTG_ANGLE','SIRIUS', $ 'SPARE1','MLOOP','LOOPS','TEMP_HK','HW_ERROR','SPARE','HSPARE']) ss_kp=where((alltags ne 'DP_TIME') and (alltags ne 'FLARE_STATUS') and $ (alltags ne 'PNTG_ANGLE') and (alltags ne 'SIRIUS') and $ (alltags ne 'SPARE1') and (alltags ne 'MLOOP') and $ (alltags ne 'LOOPS') and (alltags ne 'TEMP_HK') and $ (alltags ne 'HW_ERROR') and (alltags ne 'SPARE') and (alltags ne 'HSPARE')) alltags=alltags(ss_kp) allcoms=allcoms(ss_kp) ; ;-------------------------------------------------------------------------- ; add orb stuff if keyword_set(addorbit) then begin orbinterp=yoh_orb_interp(index) toi=str2arr('lat,long,height,radius,rig') suboi=str_subset(orbinterp,toi) retval=join_struct(retval,suboi) orbcoms= $ ['Spacecraft Lattitude','Spacecraft Longitude',$ 'Spacecrft Altitude (Km)','Radius','Rigidity'] orbcoms=(['','Yoh Orb: '])(prepend_inst) + orbcoms allcoms=[allcoms,orbcoms] endif if keyword_set(addtim2orbit) then begin if n_elements(tim2orbit_struct) eq 0 then $ tim2orbit_struct={tim2fms:0l, tim2nite:0l, in_saa:0b} tim2orbs=replicate(tim2orbit_struct,n_elements(index)) tim2orbit,index,tim2night=t2n, tim2fms=t2fms,saa=saa saa=saa or saa_in(index,/rbm_only) ; ephemeris -or- RBM monitor tim2orbs.tim2fms=round(t2fms*60.) ; -> seconds tim2orbs.tim2nite=round(t2n*60.) ; -> seconds tim2orbs.in_saa=byte(saa) ; SAA? retval=join_struct(retval,tim2orbs) orbcoms=['Seconds Since FMS','Seconds Until LMS','Yohkoh in SAA?'] allcoms=[temporary(allcoms),orbcoms] endif if data_chk(sswstruct,/struct) then begin pressw=tag_names(retval) retval=join_struct(retval,sswstruct) postssw=tag_names(retval) ncoms=n_elements(postssw)-n_elements(pressw) sswcoms=$ replicate('http://www.lmsal.com/solarsoft/ssw_standards.html',ncoms) sswcoms=(['','ssw: '])(prepend_inst) + sswcoms allcoms=[allcoms,sswcoms] ;---- add comment for SOLAR_R and DSUN_OBS (Feb-2013)--- ss1=where(postssw eq 'SOLAR_R') ss2=where(postssw eq 'DSUN_OBS') allcoms(ss1)=(['','ssw: '])(prepend_inst) + $ 'Solar radius in arcsec (geocentric)' allcoms(ss2)=(['','ssw: '])(prepend_inst) + $ 'Sun-Earth distance in meter' endif if n_elements(savhis) gt 0 then begin retval=add_tag(retval,savhis,'HISTORY') allcoms=[allcoms,'HISTORY'] endif ;*** 3 vector tags to 0b (to suppress warning message from mreadfits) *** ; work=[0b,0b,0b,0b] ; retval.DP_TIME = work ; retval.FLARE_STATUS = work ; retval.TEMP_HK =[work,work,work,work,work] ; It turned out STRUCT2FITSHEAD (called in MWRITEFITS) drop these ; tags because of null value. (25-jun-2010, AkT) ;************************************************************************ if debug then stop return,retval end