pro spaconvert_mwc, date ;Modified: ;Mar. 29, 2018 MWC replaced fix(second*10)/10.0, which causes problems ;when there are "extra" points between expected interval year = strmid(date, 0, 4) month = strmid(date, 4, 2) day = strmid(date, 6, 2) spa_date = year + '-' + month + '-' + day idatfil = findfile('/media/mirl-ulf/4TB_HDD2/mirl/ULF/incoming/database/SPA/*' + spa_date + '*.txt') ; for il=0, endi(3)-1 do begin for il = 0, 0 do begin filein = idatfil[0] ;;Find the file openr, idatunit, filein,/get_lun nlines = file_lines(filein) text=' ' dataout = fltarr(5,nlines) readf, idatunit, format='(a8)', text for i = 0, nlines-2 do begin ;READF,IDATUNIT,format='(i4,1x,i2,1x,i2,1x,i2,1x,i2,1x,f6.6,3f8.8)',yr,mo,dy,hour,minute,second, xval, yval, zval readf, idatunit, $ format='(i4,1x,i2,1x,i2,1x,i2,1x,i2,1x,f6.6,a32)', $ yr,mo,dy,hour,minute,second, text temp = strsplit(text,/EXTRACT) ;Print, temp months = [0,0,31,28,31,30,31,30,31,31,30,31,30,31] if yr mod 400 eq 0 or (yr mod 4 eq 0 and yr mod 100 ne 0) then $ months[3:3] = months[3:3]+1 yrday = long(1000*(yr mod 100) + total(months(0:mo))+dy) dataout[0,i] = yrday ; dataout(1,i) = hour*3600.0+ minute*60.0+fix(second*10)/10.0 ; replaced by MWC dataout[1,i] = hour * 3600.0 + minute * 60.0 + second dataout[2,i] = float(temp[0]) * .365 dataout[3,i] = float(temp[1]) * .365 dataout[4,i] = float(temp[2]) * .365 last = i endfor close, /all yrday = dataout[0, 0] dayout = dataout[1:4, where(fix(dataout[0,*]) eq yrday)] temp = size(dayout) firsttime = dayout[0,0] lasttime = dayout(0, temp[2]-1) lasttime_long = long(dayout[0, last]*10.)-1L ; % of points interpolated missing = 100.0 - ((temp[2]/((lasttime-firsttime) * 10L)) * 100) print, yrday, temp(2), (lasttime-firsttime) * 10L, missing delta_t = dataout[1,1:last-1] - dataout[1,0:last-2] w_gap = where(delta_t gt 1., gap_count) print, date, max(delta_t[w_gap]) LAST_MAX = 864000L ;this is because a rare day with extra data, e.g. 20180124 if last gt 863999L then LAST_MAX = last + 1 dayoutfix = fltarr(4, LAST_MAX) new_time = dindgen(LAST_MAX)/10.;Mark changed this to double precision dayoutfix[0, *] = new_time if gap_count eq 0 then begin dayoutfix[1, 0:lasttime_long] = $ spline(dayout[0, 0:last-1], $ dayout[1, 0:last-1], $ new_time[0:lasttime_long]) dayoutfix[2, 0:lasttime_long] = $ spline(dayout[0, 0:last-1], $ dayout[2, 0:last-1], $ new_time[0:lasttime_long]) dayoutfix[3, 0:lasttime_long] = $ spline(dayout[0, 0:last-1], $ dayout[3, 0:last-1], $ new_time[0:lasttime_long]) endif else begin i_gap = 0 gap_stop_t = long(dayout[0, w_gap[i_gap]]) gap_hour = gap_stop_t / 3600L gap_min = (gap_stop_t - gap_hour * 3600L) / 60L gap_sec = (gap_stop_t - gap_hour * 3600L - gap_min * 60L) gap_start = 0 gap_stop = (gap_hour * 3600L + gap_min * 60L + gap_sec) * 10 if (w_gap[i_gap]) gt 9 then begin dayoutfix[1, 0:gap_stop] = $ spline(dayout[0, 0:w_gap[i_gap]-1], $ dayout[1, 0:w_gap[i_gap]-1], $ new_time[gap_start:gap_stop]) dayoutfix[2, 0:gap_stop] = $ spline(dayout[0, 0:w_gap[i_gap]-1], $ dayout[2, 0:w_gap[i_gap]-1], $ new_time[gap_start:gap_stop]) dayoutfix[3, 0:gap_stop] = $ spline(dayout[0, 0:w_gap[i_gap]-1], $ dayout[3, 0:w_gap[i_gap]-1], $ new_time[gap_start:gap_stop]) endif ;print, gap_hour, gap_min, gap_sec for i_gap = 1, gap_count-1 do begin gap_start_t = long(dayout[0, w_gap[i_gap-1]+1]) gap_hour = gap_start_t / 3600L gap_min = (gap_start_t - gap_hour * 3600L) / 60L gap_sec = (gap_start_t - gap_hour * 3600L - gap_min * 60L) gap_start = (gap_hour * 3600L + gap_min * 60L + gap_sec) * 10 ;print, gap_hour, gap_min, gap_sec gap_stop_t = long(dayout[0, w_gap[i_gap]]) gap_hour = gap_stop_t / 3600L gap_min = (gap_stop_t - gap_hour * 3600L) / 60L gap_sec = (gap_stop_t - gap_hour * 3600L - gap_min * 60L) gap_stop = (gap_hour * 3600L + gap_min * 60L + gap_sec) * 10 ;print, gap_hour, gap_min, gap_sec ;print, gap_start, gap_stop if (w_gap[i_gap] - w_gap[i_gap-1]) gt 9 then begin dayoutfix[1, [gap_start:gap_stop]] = $ spline(dayout[0, w_gap[i_gap-1]+1:w_gap[i_gap]], $ dayout[1, w_gap[i_gap-1]+1:w_gap[i_gap]], $ new_time[gap_start:gap_stop]) dayoutfix[2, [gap_start:gap_stop]] = $ spline(dayout[0, w_gap[i_gap-1]+1:w_gap[i_gap]], $ dayout[2, w_gap[i_gap-1]+1:w_gap[i_gap]], $ new_time[gap_start:gap_stop]) dayoutfix[3, [gap_start:gap_stop]] = $ spline(dayout[0, w_gap[i_gap-1]+1:w_gap[i_gap]], $ dayout[3, w_gap[i_gap-1]+1:w_gap[i_gap]], $ new_time[gap_start:gap_stop]) endif endfor ;last gap to end of file gap_start_t = long(dayout[0, w_gap[i_gap-1]+1]) gap_hour = gap_start_t / 3600L gap_min = (gap_start_t - gap_hour * 3600L) / 60L gap_sec = (gap_start_t - gap_hour * 3600L - gap_min * 60L) gap_start = (gap_hour * 3600L + gap_min * 60L + gap_sec) * 10 ;print, gap_hour, gap_min, gap_sec gap_stop = long(dayout[0, last]*10.)-1L if (last - w_gap[i_gap-1]) gt 9 then begin dayoutfix[1, [gap_start:gap_stop]] = $ spline(dayout[0, w_gap[i_gap-1]:last-1], $ dayout[1, w_gap[i_gap-1]:last-1], $ new_time[gap_start:gap_stop]) dayoutfix[2, [gap_start:gap_stop]] = $ spline(dayout[0, w_gap[i_gap-1]+1:last-1], $ dayout[2, w_gap[i_gap-1]+1:last-1], $ new_time[gap_start:gap_stop]) dayoutfix[3, [gap_start:gap_stop]] = $ spline(dayout[0, w_gap[i_gap-1]+1:last-1], $ dayout[3, w_gap[i_gap-1]+1:last-1], $ new_time[gap_start:gap_stop]) endif endelse if firsttime gt 10.0 then begin dayoutfix[1:3,0:firsttime*10.0] = $ (finite(dayoutfix[1:3,0:firsttime*10.0]))*0.00 endif if lasttime lt 86390 then begin dayoutfix[1:3,lasttime*10.0:863999] = $ (finite(dayoutfix[1:3,lasttime*10.0:863999]))*0.00 endif idoc = lonarr(24) sta = 'SPA' missing_str = $ strcompress('South Pole'+string(missing)+'% of points missing') IDOC[3] = 16 idoc[0] = 1 idoc[2] = 864000 idoc[4] = yrday yrday = string(yrday,format='(i5.5)') out_name_short = year + '_' + month + '_' + day + '_' + sta + $ '_dbdt_v2.txt' out_name = '/media/mirl-ulf/4TB_HDD2/mirl/ULF/incoming/database/SPA_converted/' + out_name_short openw, asciiunit, out_name, /GET_LUN printf, asciiunit, format = '(4(i8),3x,i5.5,7(i8),/,12(i8))', IDOC[*] printf, asciiunit, missing_str printf, asciiunit, format = '(f15.1,3f18.8)', dayoutfix close,/all endfor END