; ; BITVERT ; ; Automatically translate a bit-packed ATDF binary file into ASCII ; text. ; ; Three outputs are produced: ; * "raw" ASCII containing exactly the same info as the binary ; ATDF file, except represented as ASCII integer ; values. (suffix ".dat") ; ; * "processed" ASCII file containing some relevant quantities. ; The processing involves merging two-field values, and ; scaling the values to physical units. The TRK-2-25 format ; document is used to specify this. (suffix ".sum") ; ; NOTE: the "processed" ASCII file does not contain all of the ; fields, so it may need to be modified for general usage. ; Also, it assumes S-band uplink and downlink when computing ; FSKY. ; ; * an IDL SAVE file of the processed data. (suffix ".sav") ; ; INFILE - name of binary ATDF input file ; ; OUTROOT - root name of output files, to which above suffixes are ; appended. ; ; KEYWORD TAI - set if you desire output times to be in TAI rather ; than UTC. Note that you need the Markwardt program ; TAI_UTC to compute leap seconds ; ; $Id: bitvert.pro,v 1.6 2002/07/04 14:40:15 craigm Exp $ ; ; C. Markwardt 03 Feb 2002 ; pro bitvert, infile, outroot, tai=tai, $ ground_modes=ground_modes, data_types=data_types ;; Read TRK-2-25 format @trk225fmt.pro ;; Open file and compute size openr, unit, infile, /get_lun fsize = (fstat(unit)).size strip = 0 if (fsize MOD 8065L) EQ 0 then begin recsize = 8065L strip = 1 endif else if (fsize MOD 8064L) EQ 0 then begin recsize = 8064L strip = 0 endif else begin message, 'ERROR: Input file is not a multiple of 8064 or 8065 bytes' endelse nrec = fsize / recsize ;; Make output files outfile1 = outroot+'_raw.dat' outfile2 = outroot+'_dcnt.dat' outfile3 = outroot+'_ramp.dat' outfile4 = outroot+'_dcnt.sav' outfile5 = outroot+'_ramp.sav' openw, outunit1, outfile1, /get_lun openw, outunit2, outfile2, /get_lun openw, outunit3, outfile3, /get_lun ndone = 0L first = 1 ;; Process the file in chunks while ndone LT nrec AND NOT EOF(unit) do begin nbuf = (nrec-ndone) < 120 ;; Read byte data and strip out record marker bb = bytarr(recsize, nbuf) readu, unit, bb if strip then bb = bb(0:8063,*) ndone = ndone + nbuf ;; Reform into logical records nlog = n_elements(bb)/288L bb = reform(bb, 288L, nlog, /overwrite) ;; First time through print the header of the ASCII files if ndone EQ nbuf then begin printf, outunit1, $ '; ----------------------------------------------------- ' printf, outunit2, $ '; ----------------------------------------------------- ' printf, outunit3, $ '; ----------------------------------------------------- ' bitvread, bb(*,0), idform, idform.item, hrec1 str = '' for i = 8, n_tags(hrec1)-1 $ do str = str + string(hrec1.(i)) outstr = string(str, hrec1.spacecraft, $ hrec1.year_num+1900, hrec1.day_num, $ hrec1.hour, hrec1.minute, hrec1.second, $ format=('("; ",A0," : SPACECRAFT ",I0," File written ",' + $ 'I4.4,":",I3.3,":",I2.2,":",I2.2,":",I2.2)')) printf, outunit1, outstr printf, outunit2, outstr printf, outunit3, outstr printf, outunit1, $ '; ----------------------------------------------------- ' printf, outunit2, $ '; ----------------------------------------------------- ' printf, outunit3, $ '; ----------------------------------------------------- ' bitvread, bb(*,1), xpform, xpform.item, hrec2 outstr = string(hrec2.spacecraft, $ hrec2.sc_xpon_hp*10000d +hrec2.sc_xpon_lp/1000,$ format=('("; SPACECRAFT ",I0," : '+ $ 'TRANSPONDER ",D15.3," Hz")')) printf, outunit1, outstr printf, outunit2, outstr printf, outunit3, outstr outstr = string(hrec2.year_on+1900, hrec2.day_on, $ hrec2.hour_on, hrec2.minute_on, hrec2.second_on, $ hrec2.year_off+1900, hrec2.day_off, $ hrec2.hour_off, hrec2.minute_off, hrec2.second_off, $ format=('("; Transponder times : ",' + $ 'I4.4,":",I3.3,":",I2.2,":",I2.2,":",I2.2," - ",' + $ 'I4.4,":",I3.3,":",I2.2,":",I2.2,":",I2.2)')) printf, outunit1, outstr printf, outunit2, outstr printf, outunit3, outstr printf, outunit1, $ '; ----------------------------------------------------- ' printf, outunit2, $ '; ----------------------------------------------------- ' printf, outunit3, $ '; ----------------------------------------------------- ' offset = 2L endif else begin offset = 0L endelse ;; Read the tracking records into IDL format bitvread, bb, tkform, tkform.item, recs, offset=offset ;; Print header and then data if first then begin bitvhead, tkform, tkform.item, outunit1 endif bitvwrite, tkform, tkform.item, recs, outunit1 bitvconv, recs, conv, outunit2, first=first, tai=tai, $ rampconv=rampconv, rampunit=outunit3, ngood=ngood, $ ground_modes=ground_modes, data_types=data_types if ngood EQ 0 then goto, NEXT_BATCH ;; Append converted data to existing data if n_elements(totconv) EQ 0 then begin totconv = temporary(conv) endif else begin totconv = [temporary(totconv), temporary(conv)] endelse if n_elements(rampconv) GT 0 then begin if n_elements(totrampconv) GT 0 then begin totrampconv = [temporary(totrampconv), temporary(rampconv)] endif else begin totrampconv = [temporary(rampconv)] endelse endif first = 0 NEXT_BATCH: endwhile free_lun, unit free_lun, outunit1 free_lun, outunit2 free_lun, outunit3 ;; Save the IDL-format data for later use if n_elements(totconv) GT 0 then begin conv = temporary(totconv) save, hrec1, hrec2, conv, file=outfile4 endif if n_elements(totrampconv) GT 0 then begin rampconv = temporary(totrampconv) save, hrec1, hrec2, rampconv, file=outfile5 endif return end