pro norh_rd_tsx,arg0,arg1,arg2,arg3,arg4 $ ,status=status,freq=freq,n_files=n_files,n_frames=n_frames $ ,integer=integer,event=event ;+ ; NAME: ; NORH_RD_TSX ; ; PURPOSE: ; This procedure reads the NORH 'tsa' or 'tsz' ; (Time,Status,Intensity,Correlation) file. ; ; CALLING SEQUENCE: ; norh_rd_tsx,infil,index,cor ; norh_rd_tsx,infil,index,cor,flux ; norh_rd_tsx,st_day,ed_day,index,cor,flux ; norh_rd_tsx,date,index,cor,flux ; ; INPUTS: ; infil: list of 'TSX' files to be read ; st_day: start day to be read ; ed_day: end day to be read ; date: day to be read ; ; OPTIONAL INPUT: ; freq: observing frequency ; ; OPTIONAL INPUT KEYWORDS: ; event: if set, read event-mode data ; integer: if set, give the correration in longword integer ; with max. of 2^{15}=32768. ; ; OUTPUTS: ; index: index structure ; cor: Correlation. ; (2-comps. (R and L) for 17GHz or ; 1-comps. (R+L) for 34GHz) ; flux: Flux. ; (2-comps. (R and L) for 17GHz or ; 1-comps. (R+L) for 34GHz) ; ; OPTIONAL OUTPUT: ; status: Observing Status of NORH ; n_files: Number of files to be read ; n_frames: Number of frames to be read ; ; HISTORY: ; Writtern 1998-05-29 JS and TY ; Revised 1998-08-15 TY ; Revised 1998-09-18 TY ; Modified 1999-01-13 TY max. cor becomes unity ; Modified 1999-02-04 TY /event support ; Modified 1999-12-27 TY bug fix for event (JST & UT confuse) ; ;- if (n_elements(freq) eq 0) then freq=17 if (freq eq 34) then freqst='34' else freqst='17' szag1=size(arg1) if (strpos(arg0(0),'ts') ne -1) then begin ; 'arg0' is file list. infil=arg0 endif else begin ; 'arg0' is time. if (szag1(n_elements(szag1)-2) eq 7) then begin ; 'arg1' is time. st_time=arg0 ed_time=arg1 st_daytim=anytim(st_time,/ints) ed_daytim=anytim(ed_time,/ints) endif else begin ; 'arg1' is index. st_time=arg0 st_daytim=anytim(st_time,/ints) ed_daytim=st_daytim ed_daytim.day=st_daytim.day endelse ndayx=ed_daytim.day-st_daytim.day+1 ex=anytim(transpose([[lonarr(ndayx)],[st_daytim.day+lindgen(ndayx)]]),/ex) yyyy=reform(ex(6,*)) mm=reform(ex(5,*)) dd=reform(ex(4,*)) yy=yyyy-yyyy/100*100 yymmdd=$ string(transpose([[yy],[mm],[dd]]),format="(i2.2,i2.2,i2.2)") ; year='19'+string(yy,format="(i2.2)") year=strtrim(string(yyyy),2) mmst=string(mm,format="(i2.2)") dir0=getenv('DIR_NORH_TSX') if not keyword_set(event) then begin if (freq eq 17) then begin files='tsa'+yymmdd+'*' endif else begin files='tsz'+yymmdd+'*' endelse dir=dir0+'/'+year+'/'+mmst if (n_elements(dir) ge 2) then dir=dir(uniq(dir)) infil=file_list(dir,files) infil=infil(where(strpos(infil,'_') eq -1)) endif else begin pr_ex=anytim([0,st_daytim.day-1],/ex) pr_yyyy=reform(pr_ex(6,*)) pr_mm=reform(pr_ex(5,*)) pr_dd=reform(pr_ex(4,*)) pr_yy=pr_yyyy-pr_yyyy/100*100 pr_yymmdd=$ string(pr_yy,pr_mm,pr_dd,format="(i2.2,i2.2,i2.2)") if (freq eq 17) then begin files='tsa'+[pr_yymmdd+'_2*',yymmdd+'_0*'] endif else begin files='tsz'+[pr_yymmdd+'_2*',yymmdd+'_0*'] endelse dir=dir0+'/'+year+'/'+mmst if (n_elements(dir) ge 2) then dir=dir(uniq(dir)) infil=file_list(dir,files) endelse endelse mx=n_elements(infil) n_files=mx if (mx eq 1) then begin if (infil(0) eq '') then message,'No files found' file=norh_dedegen(infil) data=readfits(file,header,/silent) index_el=norh_tsx2idx(data,header) if (strpos(norh_gt_freq(index_el(0)),'17') ne -1) then begin cor_el=reform(data(4:5,*))*0.01 flux_el=reform(data(2:3,*)) endif else begin cor_el=reform(data(3,*))*0.01 flux_el=reform(data(2,*)) endelse status_el=reform(data(1,*)) index=index_el cor=cor_el flux=flux_el status=status_el n_frames=n_elements(index) endif else begin n_frames=lonarr(mx) if (freqst eq '17') then begin m=0 file=infil(m) data=readfits(file,header,/silent) index_el=norh_tsx2idx(data,header) corr_el=reform(data(4,*))*0.01 corl_el=reform(data(5,*))*0.01 fluxr_el=reform(data(2,*)) fluxl_el=reform(data(3,*)) if(keyword_set(status)) then status_el=reform(data(1,*)) index=index_el corr=corr_el corl=corl_el fluxr=fluxr_el fluxl=fluxl_el if(keyword_set(status)) then status=status_el n_frames(m)=n_elements(index_el) for m=1,mx-1 do begin file=infil(m) data=readfits(file,header,/silent) index_el=norh_tsx2idx(data,header) corr_el=reform(data(4,*))*0.01 corl_el=reform(data(5,*))*0.01 fluxr_el=reform(data(2,*)) fluxl_el=reform(data(3,*)) if(keyword_set(status)) then status_el=reform(data(1,*)) n_frames(m)=n_elements(index_el) index=[index,index_el] corr=[corr,corr_el] corl=[corl,corl_el] fluxr=[fluxr,fluxr_el] fluxl=[fluxl,fluxl_el] if(keyword_set(status)) then status=[status,status_el] endfor cor=transpose([[corr],[corl]]) flux=transpose([[fluxr],[fluxl]]) endif else begin m=0 file=infil(m) data=readfits(file,header,/silent) index_el=norh_tsx2idx(data,header) cor_el=reform(data(3,*))*0.01 flux_el=reform(data(2,*)) if(keyword_set(status)) then status_el=reform(data(1,*)) n_frames(m)=n_elements(index_el) index=index_el cor=cor_el flux=flux_el if(keyword_set(status)) then status=status_el for m=1,mx-1 do begin file=infil(m) data=readfits(file,header,/silent) index_el=norh_tsx2idx(data,header) cor_el=reform(data(3,*))*0.01 flux_el=reform(data(2,*)) if(keyword_set(status)) then status_el=reform(data(1,*)) n_frames(m)=n_elements(index_el) index=[index,index_el] cor=[cor,cor_el] flux=[flux,flux_el] if(keyword_set(status)) then status=[status,status_el] endfor endelse endelse if not keyword_set(integer) then cor=cor/32768. if (szag1(n_elements(szag1)-2) eq 7) then begin arg2=index arg3=cor arg4=flux endif else begin arg1=index arg2=cor arg3=flux endelse end