FUNCTION plot_timetext, Xvar, Yvar, $
TSTART=TSTART,TSTOP=TSTOP,NOTIME=NOTIME, NOSUBTITLE=NOSUBTITLE, $
ONLYLABEL=ONLYLABEL,PLABELOFFSET=PLABELOFFSET, ELEMENTS=ELEMENTS,$
NONOISE=NONOISE, NOVALIDS=NOVALIDS, COMBINE=COMBINE,$
DEBUG=DEBUG,REPORT=REPORT,_EXTRA=EXTRAS, HELP=HELP
status = 0
nogood=0
if keyword_set(help) then begin
print,'Plot_timetext. Example:'
print,'IDL>s=plot_timeseries(xvar,yvar,/onlylabel,panel_height=100,/nosubtitle)'
print,'where xvar and yvar are structures containing the Epoch variable'
print,'as returned by read_myCDF, and the variable to be printed against the'
print,'Epoch variable, respectively.'
print,'IDL>s=plot_timetext(xvar,yvar,/notime, plabellofset=-40)'
status=-1
goto, skipped
endif
if keyword_set(REPORT) then begin & reportflag=1L
a=size(REPORT) & if (a[n_elements(a)-2] eq 7) then $
OPENW,1,REPORT,132,WIDTH=132
endif else reportflag=0L
if (n_params() ne 2) then begin
print,'ERROR=Missing parameter to plot_timetext function' & return,-1
endif
a = size(Xvar)
if (a[n_elements(a)-2] ne 8) then begin
print,'ERROR=1st parameter to plot_timetext not a structure' & return,-1
endif else begin
a = tagindex('DAT',tag_names(Xvar))
if (a[0] ne -1) then times = Xvar.DAT $
else begin
a = tagindex('HANDLE',tag_names(Xvar))
if (a[0] ne -1) then handle_value,Xvar.HANDLE,times $
else begin
print,'ERROR=1st parameter does not have DAT or HANDLE tag' & return,-1
endelse
b = size(times)
if ((b[n_elements(b)-2] ne 5) and (b[n_elements(b)-2] ne 14)) then begin
print,'ERROR=1st parameter datatype not CDF EPOCH' & return,-1
endif
endelse
endelse
szck=size(times)
if(szck[szck[0]+2] ne 1) then $
times = reform(times)
a = size(Yvar)
if (a[n_elements(a)-2] ne 8) then begin
print,'ERROR=2nd parameter to plot_timetext not a structure' & return,-1
endif else begin
YTAGS = tag_names(Yvar)
if keyword_set(COMBINE) then begin
a = tagindex('LOGICAL_SOURCE',YTAGS)
if (a[0] ne -1) then yds = strupcase(Yvar.(a[0]))
endif
a = tagindex('DAT',YTAGS)
if (a[0] ne -1) then THEDATA = Yvar.DAT $
else begin
a = tagindex('HANDLE',YTAGS)
if (a[0] ne -1) then handle_value,Yvar.HANDLE,THEDATA $
else begin
print,'ERROR=2nd parameter does not have DAT or HANDLE tag' & return,-1
endelse
endelse
endelse
szck=size(thedata)
if(szck[szck[0]+2] ne 1) then $
thedata = reform(thedata)
thedata_size = size(thedata)
a = size(thedata) & b = a[n_elements(a)-2] & thedata_size = a
if ((b eq 0) OR (b gt 5)) then begin
print,'STATUS=datatype indicates that data is not plottable' & return,-1
endif else begin
case a[0] of
0 : begin
print,'STATUS=Re-select longer time interval. Single data points are not plottable' & return,-1
end
1 : begin
elist=0
end
2 : begin
elist=indgen(a[1])
if n_elements(ELEMENTS) ne 0 then begin
elist = ELEMENTS
endif else begin
if NOT keyword_set(IGNORE_DISPLAY_TYPE) then begin
b = tagindex('DISPLAY_TYPE',YTAGS)
if (b[0] ne -1) then begin
c = strupcase(Yvar.(b[0])) & c = break_mystring(c,delimiter='>')
if ((c[0] eq 'TIME_TEXT')AND(n_elements(c) gt 1)) then begin
d = break_mystring(c[1],delimiter=',')
elist = long(d) & elist = elist -1
endif
endif
endif
endelse
end
else: begin
print,'ERROR=Cannot plot data with > 2 dimensions' & return,-1
end
endcase
endelse
if (thedata_size[0] eq 1) then mydata = thedata $
else mydata=thedata[elist,*]
mydata=reform(mydata)
tbegin = times[0] & tend = times[n_elements(times)-1]
if keyword_set(TSTART) then begin
tbegin = TSTART & a = size(TSTART)
case a[n_elements(a)-2] of
5: tbegin = tstart
7: tbegin = encode_CDFEPOCH(TSTART)
14:tbegin = tstart
endcase
endif
if keyword_set(TSTOP) then begin
tend = TSTOP & a = size(TSTOP)
case a[n_elements(a)-2] of
5: tend=tstop
7: tend = encode_CDFEPOCH(TSTOP)
14: tend = tstop
endcase
endif
pad_front = 0L & pad_end = 0L
eptt=0
if (size(times[0],/tname) eq 'LONG64')then begin
eptt = 1
endif
if (tbegin lt times[0]) then begin
if keyword_set(DEBUG) then print,'Padding front of times...'
times = [tbegin,times] & pad_front = 1L
endif
if (tend gt times[n_elements(times)-1]) then begin
if keyword_set(DEBUG) then print,'Padding end of times...'
times = [times,tend] & pad_end = 1L
endif
rbegin = 0L & w = where(times ge tbegin,wc)
if (wc gt 0) then rbegin = w[0]
rend = n_elements(times)-1 & w = where(times le tend,wc)
if (wc gt 0) then rend = w[n_elements(w)-1]
rrend=n_elements(mydata)
if ((rbegin ge rend) or (rrend lt rend-2))then begin
print,'STATUS=No data within specified time range.' & return,-1
endif
if not keyword_set(nosubtitle) then begin
CDF_EPOCH,tbegin,year,month,day,hour,minute,second,milli,/BREAK
ical,year,doy,month,day,/idoy
subtitle = 'TIME RANGE='+strtrim(string(fix(year)),2)+'/'+strtrim(string(fix(month)),2)
subtitle = subtitle + '/' + strtrim(string(fix(day)),2)
subtitle = subtitle + ' (' + strtrim(string(fix(doy)),2) + ') to '
CDF_EPOCH,tend,year,month,day,hour,minute,second,milli,/BREAK
ical,year,doy,month,day,/idoy
subtitle = subtitle + strtrim(string(fix(year)),2)+'/'+strtrim(string(fix(month)),2)
subtitle = subtitle + '/' + strtrim(string(fix(day)),2)
subtitle = subtitle + ' (' + strtrim(string(fix(doy)),2) + ')'
endif else subtitle=''
CDF_EPOCH,tbegin,year,month,day,hour,minute,second,milli,/BREAK
CDF_EPOCH,a,year,month,day,0,0,0,0,/COMPUTE_EPOCH
if (eptt) then begin
CDF_EPOCH,tbegin,year,month,day,hour,minute,second,milli,/BREAK,/TOINTEGER
CDF_EPOCH,a,year,month,day,0,0,0,0,/COMPUTE_EPOCH,/TT2000
times = (times - a) / 1000000000.d0
endif else times = (times - a) / 1000
julday = ymd2jd(year,month,day)
xranger = lonarr(2)
if (eptt) then begin
xranger[0] = times[0]
xranger[1] = times[n_elements(times)-1]
endif else begin
xranger[0] = (tbegin-a)/1000
xranger[1] = (tend-a)/1000
endelse
trange = xranger[1] - xranger[0]
if (trange le 60.0) then tform='h$:m$:s$.f$@y$ n$ d$' $
else tform='h$:m$:s$@y$ n$ d$'
a = tagindex('FILLVAL',YTAGS)
if (a[0] ne -1) then Yfillval = round(Yvar.FILLVAL,/L64) else Yfillval = round(1.0e31,/L64)
mydata_size=size(mydata)
if (pad_front) then begin
if (mydata_size[0] eq 1) then begin
mydata = [Yfillval,mydata]
endif else begin
for ii=0,mydata_size[1]-1 do begin
command='mydata'+strtrim(string(ii),2)+ $
'=[Yfillval,reform(mydata('+strtrim(string(ii),2)+',*))]'
status=execute(command)
endfor
mydata=[mydata0]
for ii=1,mydata_size[1]-1 do begin
command='mydata=[[mydata],[mydata'+strtrim(string(ii),2)+']]'
status=execute(command)
endfor
mydata=transpose(mydata)
endelse
endif
if (pad_end) then begin
if (mydata_size[0] eq 1) then begin
mydata = [mydata,Yfillval]
endif else begin
for ii=0,mydata_size[1]-1 do begin
command='mydata'+strtrim(string(ii),2)+ $
'=[reform(mydata('+strtrim(string(ii),2)+',*)),Yfillval]'
status=execute(command)
endfor
mydata=[mydata0]
for ii=1,mydata_size[1]-1 do begin
command='mydata=[[mydata],[mydata'+strtrim(string(ii),2)+']]'
status=execute(command)
endfor
mydata=transpose(mydata)
endelse
endif
rrend=n_elements(mydata)
if(rrend lt rend) then rend = rrend-1
if (mydata_size[0] eq 1) then mydata=mydata[rbegin:rend] else mydata=mydata[*,rbegin:rend]
mytimes = times[rbegin:rend]
addi=[mytimes]
size_mydata=size(mydata)
if size_mydata[0] ne 1 then begin
for ii=0,size_mydata[1]-1 do begin
addi=[[addi],[reform(mydata[ii,*])]]
endfor
endif else begin
addi=[[addi],[mydata]]
endelse
good=where(round(mydata,/L64) ne yfillval, ngood)
if (ngood gt 0) then begin
szaddi=size(addi)
for i=1,szaddi[2]-1 do begin
delta=round(n_elements(addi[*,i])*0.01)
if keyword_set(DEBUG) then print,'DELTA = ',strtrim(delta,2),' 1% of ',strtrim(n_elements(addi[*,i]),2)
q=where(round(addi[*,i],/L64) ne yfillval)
if q[0] ne -1 then begin
j=0
counter=0
value=addi[0,i]
while (round(value,/L64) eq yfillval) do begin
counter=j
j=j+1
value=addi[j,i]
endwhile
if (counter-delta lt 0) then begin
if keyword_set(DEBUG) then print,'Replacing array positions (',$
'0:',strtrim(counter,2),$
',',strtrim(i,2),'), value[s] = ',strtrim(addi[0:counter,i],2),' with ',strtrim(value,2)
addi[0:counter,i]=value
endif else begin
if keyword_set(DEBUG) then print,'Replacing array positions (',$
strtrim(counter-delta,2),':',strtrim(counter,2),$
',',strtrim(i,2),'), value[s] = ',strtrim(addi[counter-delta:counter,i],2),' with ',strtrim(value,2)
addi[counter-delta:counter,i]=value
endelse
j=n_elements(addi[*,i])-1
counter=n_elements(addi[*,i])-1
value=addi[j,i]
while (round(value,/L64) eq yfillval) do begin
counter=j
j=j-1
value=addi[j,i]
endwhile
if (counter+delta gt n_elements(addi[*,i])-1) then begin
if keyword_set(DEBUG) then print,'Replacing array positions (',$
strtrim(counter,2),':',strtrim(n_elements(addi[*,i])-1,2),$
',',strtrim(i,2),'), value[s] = ',strtrim(addi[counter:n_elements(addi[*,i])-1,i],2),' with ',strtrim(value,2)
addi[counter:n_elements(addi[*,i])-1,i]=value
endif else begin
if keyword_set(DEBUG) then print,'Replacing array positions (',$
strtrim(counter,2),':',strtrim(counter+delta,2),$
',',strtrim(i,2),'), value[s] = ',strtrim(addi[counter:counter+delta,i],2),' with ',strtrim(value,2)
addi[counter:counter+delta,i]=value
endelse
for j=1L,n_elements(addi[*,i])-2 do begin
if (round(addi[j,i],/L64) eq yfillval) then begin
prev=addi[j-1,i]
pos_prev=j-1
next=addi[j+1,i]
pos_next=j+1
for k=pos_next,n_elements(addi[*,i])-1 do begin
if (round(addi[k,i],/L64) ne yfillval) then begin
next=addi[k,i]
pos_next=k
goto, fill_gap
endif
endfor
fill_gap:
if (pos_next-pos_prev le delta) then begin
if keyword_set(DEBUG) then print,'Replacing array positions (',$
strtrim(pos_prev+1,2),':', $
strtrim(pos_next-1,2),$
',',strtrim(i,2),'), value[s] = ',strtrim(addi[pos_prev+1:pos_next-1,i],2),' with ',strtrim(prev,2)
addi[pos_prev+1:pos_next-1,i]=prev
endif else begin
if (pos_prev+1 le pos_prev+delta) then $
addi[pos_prev+1:pos_prev+delta,i]=prev
w=where(round(addi[pos_prev+delta:pos_next-1,i],/L64) eq yfillval)
if w[0] ne -1 then begin
if (n_elements(w) gt delta) then begin
if keyword_set(DEBUG) then print,'Replacing array positions (',$
strtrim(pos_next-1-delta,2),':', $
strtrim(pos_next-1,2),$
',',strtrim(i,2),'), value[s] = ',strtrim(addi[pos_next-1-delta:pos_next-1,i],2),' with ',strtrim(next,2)
addi[pos_next-1-delta:pos_next-1,i]=next
endif else begin
if keyword_set(DEBUG) then print,'Replacing array positions (',$
strtrim(w[0],2),':', $
strtrim(w[n_elements(w)-1],2),$
',',strtrim(i,2),'), value[s] = ',strtrim(addi[w,i],2),' with ',strtrim(next,2)
addi[w,i]=next
endelse
endif
endelse
j=k
endif
endfor
endif
qq=where(round(addi[*,i],/L64) eq yfillval)
if qq[0] ne -1 then begin
addi[qq,i] = 0
if keyword_set(debug) then print,'Array position(s) set to 0: ',qq
endif
endfor
if (yvar.lablaxis ne '') then begin
if keyword_set(notime) then addl=[yvar.lablaxis] else addl=['UT','',yvar.lablaxis]
endif else begin
if keyword_set(notime) then addl=[yvar.labl_ptr_1] else addl=['UT','',yvar.labl_ptr_1]
endelse
addf=strarr(szaddi[2])
addf[0]=''
if (yvar.format ne '') then $
addf[1:*]='('+yvar.format+')' else addf[1:*]='('+yvar.form_ptr[elist]+')'
addl=[addl[elist]]
for ii=0,n_elements(addl)-1 do begin
if strlen(addl[ii]) lt 10 then begin
for iii=strlen(addl[ii])+1,10 do addl[ii]=addl[ii]+' '
endif
endfor
add_dataset=''
if (keyword_set(COMBINE) and n_elements(yds) gt 0)then begin
add_dataset = make_array(szaddi[2],/string,value=' ')
add_dataset[0] = yds
endif
timeaxis_text,FORM=tform,JD=julday,title=subtitle,CHARSIZE=0.9, /notime, $
addinfo=addi,addlabel=addl,addformat=addf, add_ds=add_dataset, $
plabeloffset=plabeloffset, onlylabel=onlylabel, _extra=extras
endif else begin
print,'STATUS=Instrumnent may be off - all values are fill values' & return,0
endelse
skipped:
return,status
end