; ; Insert blanks at the beginning of the data for plotting ; pro insert_blank_beginning,data,date,missing,base_time,$ time_offset,height ;************************************************************ ; Constants ;************************************************************ ; Seconds in a day sec_per_day=double(24L*60L*60L) ; Get IDL julian day of day 1 day1=julday(1,1,1970,0,0,0); ; find array sizes numtimes=n_elements(time_offset) numheights=n_elements(height) ; Separate out year and month from searchdate year=fix(strmid(date,0,4)) month=fix(strmid(date,4,2)) ;************************************************************ ; Time ;************************************************************ ; Determine if it is a leap year leap_flag=0 check4=(year) mod 4 ;years divisible by 4 are leap years, unless..... check100=(year) mod 100 ;years also divisible by 100 are not leap years, except..... check400=(year) mod 400 ;years divisible by 400 are leap years. if ( (check4 eq 0 and check100 ne 0) or (check400 eq 0) ) then leap_flag=1 ; Determine the last day of the month if month eq 1 then day=31 if month eq 2 and leap_flag eq 0 then day=28 if month eq 2 and leap_flag eq 1 then day=29 if month eq 3 then day=31 if month eq 4 then day=30 if month eq 5 then day=31 if month eq 6 then day=30 if month eq 7 then day=31 if month eq 8 then day=31 if month eq 9 then day=30 if month eq 10 then day=31 if month eq 11 then day=30 if month eq 12 then day=31 ; Calculate the first and last time in the month start_julian_day=julday(month,1,year,0,0,0) end_julian_day=julday(month,day,year,23,59,59) ; Convert to seconds since 1970 start_base_time=long(sec_per_day*(start_julian_day-day1)) end_base_time=long(sec_per_day*(end_julian_day-day1)) ; Print month start and end times in human readable form caldat,start_julian_day,mm,dd,yy,hh,mi,ss print,'start time of the month',yy,mm,dd,hh,mi,ss,format='(A30,1X,I4,1X,5(I2,1X))' caldat,end_julian_day,mm,dd,yy,hh,mi,ss print,'end time of the month',yy,mm,dd,hh,mi,ss,format='(A30,1X,I4,1X,5(I2,1X))' ;******************************************* ; Get the expected time interval (data_int) between shots ;******************************************* delta_time=time_offset delta_time=[delta_time[1:numtimes-1],delta_time[numtimes-1]] delta_time=delta_time-time_offset hist_mode,missing,1,delta_time,data_int ;****************************************** ; Fill any gap that is larger than data_int ;****************************************** gap=data_int ;****************************************** ; Create temporary arrays to hold the filled in data ;****************************************** tempto=make_array(numtimes+10000,/long,value=missing) if size(data,/n_dimensions) eq 2 then begin dim=2 temp_data=fltarr(numtimes+10000,numheights) endif else if size(data,/n_dimensions) eq 1 then begin dim=1 temp_data=fltarr(numtimes+10000) endif else begin print,'can not fill this array' stop endelse ;**************** ; Fill the beginning of the array ;**************** ; If the file start time is after the month start time... if base_time gt start_base_time+gap then begin ; Adjust time_offset to be off new base_time which is the month start time deltas=long(base_time)-long(start_base_time) base_time=long(start_base_time) time_offset=long(time_offset)+long(deltas) ; Initialize the first new time offset to be zero tempto[0]=long(0) ; Initialize the first new data shot to be missing if dim eq 2 then begin temp_data[0,*]=missing endif else if dim eq 1 then begin temp_data[0]=missing endif spacing=time_offset[0] print, 'found a beginning hole',time_offset[0] x=round(spacing/float(data_int)) if x*data_int eq spacing then x=x-1 for k=1.0,x do begin tempto[k]=k*data_int if dim eq 2 then begin temp_data[k,*]=missing endif else if dim eq 1 then begin temp_data[k]=missing endif ;print,k,tempto[k],temp_data[k,0] endfor ;print,k,tempto[k],temp_data[k,0] print, 'filled in hole with ',x,'shots' ; Put the filled data at the front of the old data time_offset=[tempto[0:k-1],time_offset] if dim eq 2 then begin data=[temp_data[0:k-1,*],data] endif else if dim eq 1 then begin data=[temp_data[0:k-1],data] endif endif ;***************************************** ; Fill in the end of the array ;***************************************** ; This is what the last time in the file IS time_end=long(base_time+time_offset[n_elements(time_offset)-1]+gap) ; If the last time in the file is shorter than the last time in the month... if end_base_time ge time_end then begin end_julian_day=double(day1+(time_end/sec_per_day)) caldat,end_julian_day,mm,dd,yy,hh,mi,ss print, 'file_end_time',yy,mm,dd,hh,mi,ss,format='(A20,1X,I4,1X,5(I2,1X))' ; Hole at the end of the file is this many seconds spacing=long(end_base_time)-time_end print, 'found an ending hole of ',spacing,'shots' ; Find how many times intervals are needed to fill the hole x=fix(spacing/float(data_int)) if x*data_int eq spacing then x=x-1 if x gt 1.0 then begin for k=0.0,x do begin tempto[k]=(k+1)*data_int+time_offset[n_elements(time_offset)-1] if dim eq 2 then begin temp_data[k,*]=missing endif else if dim eq 1 then begin temp_data[k]=missing endif endfor print,k,tempto[k],temp_data[k,0] print, 'filled in hole' ; Add the null arrays to the end time_offset=[time_offset,tempto[0:k-1]] if dim eq 2 then begin data=[data,temp_data[0:k-1,*]] endif else if dim eq 1 then begin data=[data,temp_data[0:k-1]] endif endif endif ;there is a hole at the end of the array ;************************************************************** ; Do some time checking with print statements ;************************************************************** do_check='no' if do_check eq 'yes' then begin ; Convert time offset to julian day julian_day=double(day1+((base_time+time_offset)/sec_per_day)) caldat,julian_day,mm,dd,yy,hh,mi,ss for i=0,n_elements(julian_day)-1 do begin print,'filled time',yy[i],mm[i],dd[i],hh[i],mi[i],ss[i],format='(A15,1X,I4,1X,5(I2,1X))' endfor endif return end