Site Map

LITE Level 1 IDL Example Program

Extract the following 2 lines and store them in the file named com_globals.pro
common comconst
common unpackcommon

Directions to execute this example IDL program.

  1. Extract and save the IDL code listed below to a file named idl_example.pro.
  2. Start IDL
  3. At IDL prompt enter: .rnew idl_example
  4. At IDL prompt enter: lite
  5. The IDL program will prompt for the name of the LITE data file.
  6. Upon program completion, the output file idl_example.dat will contain LITE data header information.

Extract the following IDL code (to the end of this file) and save it to a file named: idl_example.pro

;-----------------------------------------------------------------------------------
pro init_p
common comconst, numraw, altitude, nxs, unit_ndx, unit_w
common unpackcommon,andarr,outarr

; Initialize unpacking arrays, used to unpack nxs.outofrange355,
; nxs.outofrange532, and nxs.outofrange064.

initunpack
numraw = 3000     
altitude = fltarr(numraw)

end
;-----------------------------------------------------------------------------------

;-----------------------------------------------------------------------------------
function unpackbytes,thebytearr
@com_globals.pro

;  Unpacking arrays nxs.outofrange355, nxs.outofrange532, and nxs.outofrange064.

;  This function takes an array of 375 bytes and unpacks it to an array of 3000 
;  bytes.

;  thebytearr is the packed byte array that will be unpacked.
;  outarr is the unpacked array.

thesize = size(thebytearr)
if thesize(2) ne 1 then begin
  print,'unpackBytes called with bad parameter'
  stop
endif

; andarr is defined and documented in pro initunpack

unpacksize = thesize(1) * 8

;  rebin will take the 375 element array, thebytearr, and 
;  and create a new 3000 element array by repeating each
;  thebytearr element 8 times.

;  example, want to create a 24 element array from a 3 
;           element array.

;   Let thebytearr be a 3 element array: [228, 0, 126]

;   rebin will create [228,228,228,228,228,228,228,228,           
;                        0,  0,  0,  0,  0,  0,  0,  0,           
;                      126,126,126,126,126,126,126,126]

;  The statement:  

;     (rebin(thebytearr,unpacksize,/sample) and andarr(0:unpacksize-1))

;  will "and" the rebinned array with andarr to determine which
;  bits in each packed word have been set to 1.

;  continue example:
 
;   Let andarr be a 24 element array: 

;     [128 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1]

;   228 in binary is 11100100
;   128 in binary is 10000000
;   228 and 128 =    10000000 = 128

;   228 in binary is 11100100
;    64 in binary is 01000000
;   228 and  64 =    01000000 =  64

;   228 in binary is 11100100
;    32 in binary is 00100000
;   228 and  32 =    00100000 =  32

;   228 in binary is 11100100
;    16 in binary is 00010000
;   228 and  16 =    00000000 =   0

;   228 in binary is 11100100
;     8 in binary is 00001000
;   228 and   8 =    00000000 =   0

;   228 in binary is 11100100
;     4 in binary is 00000100
;   228 and   4 =    00000100 =   4

;   228 in binary is 11100100
;     2 in binary is 00000010
;   228 and   2 =    00000000 =   0

;   228 in binary is 11100100
;     1 in binary is 00000001
;   228 and   1 =    00000000 =   0

;   the "and" operation for the next 8 words will result in 0,

;   126 in binary is 01111110
;   128 in binary is 10000000
;   126 and 128 =    00000000 =   0

;   228 in binary is 01111110
;    64 in binary is 01000000
;   126 and  64 =    01000000 =  64

;   228 in binary is 01111110
;    32 in binary is 00100000
;   126 and  32 =    00100000 =  32

;   228 in binary is 01111110
;    16 in binary is 00010000
;   126 and  16 =    00010000 =  16

;   228 in binary is 01111110
;     8 in binary is 00001000
;   126 and   8 =    00001000 =   8

;   228 in binary is 01111110
;     4 in binary is 00000100
;   126 and   4 =    00000100 =   4

;   228 in binary is 01111110
;     2 in binary is 00000010
;   126 and   2 =    00000010 =   2

;   228 in binary is 01111110
;     1 in binary is 00000001
;   126 and   1 =    00000000 =   0

;   The result of the "and" operation is the array:
;    [128,64,32, 0,0,4,0,0, 
;       0, 0, 0, 0,0,0,0,0, 
;       0,64,32,16,8,4,2,0]

;   The minimum operator (<) returns the smaller value, either 1b or
;   result value.

;   The final unpacked array is defined as follows:
;    unpackedarr = [1,1,1,0,0,1,0,0,
;                   0,0,0,0,0,0,0,0,
;                   0,1,1,1,1,1,1,0]

;   Therefore, out of range occurred at locations that equal 1.

unpackedarr = 1b < $
  (rebin(thebytearr,unpacksize,/sample) and andarr(0:unpacksize-1))

;355, 532, 1064
outarr(*) = unpackedarr(0:2999)

return,outarr
end
;-----------------------------------------------------------------------------------

;-----------------------------------------------------------------------------------
pro lite
;
@com_globals.pro

; Start the procedure here

; Procedure init_p is called to perform initialization.

init_p

; LITE level 1, phase c structure

nxs = {pbstructuretype,  $

  syncvalue:0,               $
  majorversionnumber:0b,     $
  minorversionnumber:0b,     $
  datatakeid:bytarr(7),      $ 
  orbitnumber:0b,            $
  idnumber:0l,               $
  gmtday:0,                  $
  gmthour:0b,                $
  gmtmin:0b,                 $ 
  gmtsec:0b,                 $
  gmthund:0b,                $
  metday:0,                  $
  methour:0b,                $
  metmin:0b,                 $ 
  metsec:0b,                 $
  methund:0b,                $
  latitude:0.0,              $  ;degrees
  longitude:0.0,             $  ;degrees 
  shuttlealtitude:0.0,       $  ;kilometers
  offnadirangle:0.0,         $  ;degrees
  digitizerondelay:0.0,      $  ;useconds
  datatakemode:0b,           $  ;0=daymode 1=nightmode
  specialopsmode:0b,         $  ;0=normal 1=multiscatter 2=gainchange 
  profilevalidstatus:0b,     $  ;0=valid 1=355quest 2=532quest 4=064quest 
                             $  ;     8=355invalid 16=532invalid 32=064invalid
  landwaterflag:0b,          $  ;0=land 1=water
  surfelevfootprint:0.0,     $  ;kilometers
  metdataalts:fltarr(18),    $  ;kilometers
  mettemps:fltarr(18),       $  ;Kelvin
  alttropopause:0.0,         $  ;kilometers
  temptropopause:0.0,        $  ;Kelvin
  laserselected:0b,          $  ;0=a 1=b
  baalignmentstatus:0b,      $  ;0=unaligned 1=aligned
  isdbstatus:0b,             $  ;0=invalid 1=valid
  badatastatus:0b,           $  ;0=invalid 1=valid
  aodatastatus:0b,           $  ;0=invalid 1=valid
  motorinmotion:0b,          $  ;0=stopped 1=inmotion
  aperwheelstatus:0b,        $  ;0=closed 1=large 2=annular 3=small 4=inmotion
  backgroundmongain:0b,      $  ;0=day 1=night
  surfacemode355:0b,         $  ;0=no 1=transition 2=yes
  dbattenuation355:0b,       $  ;db
  numbersatabovesurf355:0,   $  ;num samples 
  highestsatsample355:0.0,   $  ;kilometers
  numberunderflows355:0,     $  ;num samples
  filterstatus355:0b,        $  ;0=out 1=in 2=inmotion
  callibrationstatus355:0b,  $  ;0=estimated 1=calculated 
  calibrationfactor355:0.0,  $  ;unit - see calibration document
  baselinerippleremvd355:0b, $  ;0=no 1=yes
  oscillationremoved355:0b,  $  ;0=no 1=yes 
  backgroundvalue355:0b,     $  ;raw value from instrument
  highvoltage355enabled:0b,  $  ;0=disabled 1=enabled 
  highvoltage355:0.0,        $  ;volts (355 nm measured high voltage)
  energymonitor355:0.0,      $  ;mjoules
  pmtgain355:0.0,            $  ;unit - see gain calculation document
  baselinesubmethod355:0b,   $  ;0=slope 1 = averaged
  subregionunderflow355:0b,  $  ;0=none 1=underflow in baseline subtraction reg.
  anomalousprof355:0b,       $  ;0=normal 1=anomalous
  fillbyte1:0b,              $
  surfacemode532:0b,         $  ;0=no 1=transition 2=yes
  dbattenuation532:0b,       $  ;db
  numbersatabovesurf532:0,   $  ;num samples 
  highestsatsample532:0.0,   $  ;kilometers
  numberunderflows532:0,     $  ;num samples
  filterstatus532:0b,        $  ;0=out 1=in 2=inmotion
  callibrationstatus532:0b,  $  ;0=estimated 1=calculated   
  calibrationfactor532:0.0,  $  ;unit - see calibration document
  baselinerippleremvd532:0b, $  ;0=no 1=yes
  oscillationremoved532:0b,  $  ;0=no 1=yes 
  backgroundvalue532:0b,     $  ;raw value from instrument
  highvoltage532enabled:0b,  $  ;0=disabled 1=enabled 
  highvoltage532:0.0,        $  ;volts (532 nm measured high voltage)
  energymonitor532:0.0,      $  ;mjoules
  pmtgain532:0.0,            $  ;unit - see gain calculation document
  baselinesubmethod532:0b,   $  ;0=slope 1 = averaged
  subregionunderflow532:0b,  $  ;0=none 1=underflow in baseline subtraction reg.
  anomalousprof532:0b,       $  ;0=normal 1=anomalous
  fillbyte2:0b,              $
  surfacemode064:0b,         $  ;0=no 1=transition 2=yes
  dbattenuation064:0b,       $  ;db
  numbersatabovesurf064:0,   $  ;num samples 
  highestsatsample064:0.0,   $  ;kilometers
  numberunderflows064:0,     $  ;num samples
  filterstatus064:0b,        $  ;0=out 1=in 2=inmotion
  callibrationstatus064:0b,  $  ;2=not available
  calibrationfactor064:0.0,  $  ;not defined
  baselinerippleremvd064:0b, $  ;0=no 1=yes
  oscillationremoved064:0b,  $  ;0=no 1=yes 
  backgroundvalue064:0b,     $  ;raw value from instrument
  highvoltage064enabled:0b,  $  ;0=disabled 1=enabled 
  highvoltage064:0.0,        $  ;volts (1064 nm measured high voltage)
  energymonitor064:0.0,      $  ;mjoules
  apdgain064:0.0,            $  ;unit - see gain calculation document
  baselinesubmethod064:0b,   $  ;0=slope 1 = averaged
  subregionunderflow064:0b,  $  ;0=none 1=underflow in baseline subtraction reg.
  anomalousprof064:0b,       $  ;0=normal 1=anomalous
  fillbyte3:0b,              $
  timeedsinthour:0b,         $  ;unadjusted eds time
  timeedsintmin:0b,          $
  timeedsintsec:0b,          $
  timeedsinthund:0b,         $
  level0fileidnumber:0b,     $  ;level 0 directory number
  level0fileidletter:0b,     $  ;level 0 file letter 
  reserved1:bytarr(6),       $
  highvoltage355cmd:0.0,     $  ;volts (355 nm commanded high voltage)
  highvoltage532cmd:0.0,     $  ;volts (532 nm commanded high voltage)
  reserved2:bytarr(4),       $
  b0_355:0.0,                $  ;baseline subtraction value for 355 channel         
  b0_532:0.0,                $  ;baseline subtraction value for 532 channel         
  b0_064:0.0,                $  ;baseline subtraction value for 1064 channel         
  outofrng355abv40:0b,       $  ;0=none,1=underflow,2=overflow,3=underflow and overflow
  outofrng532abv40:0b,       $  ;0=none,1=underflow,2=overflow,3=underflow and overflow
  outofrng064abv40:0b,       $  ;0=none,1=underflow,2=overflow,3=underflow and overflow
  outofrange355:bytarr(375), $  ;bit array, if bit is set then there was underflow or 
  outofrange532:bytarr(375), $  ; overflow for the corresponding count
  outofrange064:bytarr(375), $ 
  top355:0,                  $  ;index of highest valid count
  bottom355:0,               $  ;index of lowest valid count
  top532:0,                  $  ;index of highest valid count
  bottom532:0,               $  ;index of lowest valid count
  top064:0,                  $  ;index of highest valid count
  bottom064:0,               $  ;index of lowest valid count
  profile355:fltarr(3000),   $  ;counts
  profile532:fltarr(3000),   $  ;counts
  profile064:fltarr(3000)    $  ;counts

}
; Print size of structure, size is 37500 bytes.

result = n_tags(nxs,/length)
print,' nxs result ',result

load_nxs

end
;-----------------------------------------------------------------------------------

;-----------------------------------------------------------------------------------
pro load_nxs
@com_globals.pro
 
; Define gridded altitude array. The altitude array has size 3000, the range is
; -4.985 to 40.0 km, and the grid increment is 0.015 km (15 m).

new_alts

; Open optional output file.

out_file = 'idl_example.dat'
openw,unit_w,out_file,/get_lun

lite_file = ' '
print,'Enter the LITE data file name:'
read,lite_file
openr,unit_c,lite_file,/get_lun

on_ioerror,at_eof

icntprof = 0
while (not eof(unit_c)) do begin
  readu, unit_c, nxs

  ; Print profile header information, file unit_w must be open.

  print_readu

  check_ufof = 0
  if (check_ufof gt 0) then begin

  ; Check for underflow and overflow conditions.
  ; Unpacking will occur if check_ufof = a value > 0.
  ; unpacked355, unpacked532, and unpacked064 define underflow and overflow
  ; occurrences in nxs.profile355, nxs.profile532, and nxs.profile064, respectively.

    unpacked355 = unpackbytes(nxs.outofrange355)
    unpacked532 = unpackbytes(nxs.outofrange532)
    unpacked064 = unpackbytes(nxs.outofrange064) 

    indx = where(unpacked355 eq 1,count)
    if (count gt 0) then begin
 
      ; there is underflow or overflow for 355 channel

      ; locate where underflow occurred

      indd = where(nxs.profile355(indx) lt 15.0,cc)
      if (cc gt 0) then begin

        ; ind_355uf is an array of cc values and contains the index locations 
        ; for nxs.profile355 and altitude  where underflow has occurred

        ind_355uf = indx(indd)
        ; print,' 355 underflow ',cc
      end

      ; locate where underflow occurred

      indd = where(nxs.profile355(indx) gt 15.0,cc)
      if (cc gt 0) then begin

        ; ind_355of is an array of cc values and contains the index locations
        ; for nxs.profile355 and altitude  where saturation has occurred

        ind_355of = indx(indd)
        ; print,' 355 overflow ',cc
      end
    end

    indx = where(unpacked532 eq 1,count)
    if (count gt 0) then begin
 
      ; there is underflow or overflow for 532 channel

      ; locate where underflow occurred

      indd = where(nxs.profile532(indx) lt 15.0,cc)
      if (cc gt 0) then begin

        ; ind_532uf is an array of cc values and contains the index locations 
        ; for nxs.profile532 and altitude  where underflow has occurred

        ind_532uf = indx(indd)
        ; print,' 532 underflow ',cc
      end

      ; locate where underflow occurred

      indd = where(nxs.profile532(indx) gt 15.0,cc)
      if (cc gt 0) then begin

        ; ind_532of is an array of cc values and contains the index locations
        ; for nxs.profile532 and altitude  where saturation has occurred

        ind_532of = indx(indd)
        ; print,' 532 overflow ',cc
      end
    end

    indx = where(unpacked064 eq 1,count)
    if (count gt 0) then begin
 
      ; there is underflow or overflow for 1064 channel

      ; locate where underflow occurred

      indd = where(nxs.profile064(indx) lt 15.0,cc)
      if (cc gt 0) then begin

        ; ind_064uf is an array of cc values and contains the index locations 
        ; for nxs.profile064 and altitude  where underflow has occurred

        ind_064uf = indx(indd)
        ; print,' 064 underflow ',cc
      end

      ; locate where underflow occurred

      indd = where(nxs.profile064(indx) gt 15.0,cc)
      if (cc gt 0) then begin

        ; ind_064of is an array of cc values and contains the index locations
        ; for nxs.profile064 and altitude  where saturation has occurred

        ind_064of = indx(indd)
        ; print,' 064 overflow ',cc
      end
    end
  end

  ;the_gmt = double(nxs.gmtday)*86400.d0 + double(nxs.gmthour)*3600.d0 + double(nxs.gmtmin)*60.d0 + $
  ;          double(nxs.gmtsec) + double(nxs.gmthund)/100.d0

  icntprof = icntprof + 1
end
at_eof:
print,' at complete, icntprof = ',icntprof

free_lun, unit_c
free_lun, unit_w

return
end
;-----------------------------------------------------------------------------------

;-----------------------------------------------------------------------------------
pro print_readu
@com_globals.pro

; print profile header information

printf,unit_w,nxs.syncvalue,nxs.majorversionnumber,nxs.minorversionnumber,nxs.datatakeid,nxs.orbitnumber,nxs.idnumber
printf,unit_w,nxs.gmtday,nxs.gmthour,nxs.gmtmin,nxs.gmtsec,nxs.gmthund
printf,unit_w,nxs.metday,nxs.methour,nxs.metmin,nxs.metsec,nxs.methund
printf,unit_w,nxs.latitude,nxs.longitude,nxs.shuttlealtitude,nxs.offnadirangle,nxs.digitizerondelay
printf,unit_w,nxs.datatakemode,nxs.specialopsmode,nxs.profilevalidstatus,nxs.landwaterflag,nxs.surfelevfootprint
printf,unit_w,nxs.alttropopause,nxs.temptropopause
printf,unit_w,nxs.laserselected,nxs.baalignmentstatus,nxs.isdbstatus,nxs.badatastatus
printf,unit_w,nxs.aodatastatus,nxs.motorinmotion,nxs.aperwheelstatus,nxs.backgroundmongain
printf,unit_w,nxs.surfacemode355,nxs.dbattenuation355,nxs.numbersatabovesurf355,nxs.highestsatsample355
printf,unit_w,nxs.numberunderflows355,nxs.filterstatus355,nxs.callibrationstatus355,nxs.calibrationfactor355
printf,unit_w,nxs.baselinerippleremvd355,nxs.oscillationremoved355,nxs.backgroundvalue355
printf,unit_w,nxs.highvoltage355enabled,nxs.highvoltage355,nxs.energymonitor355,nxs.pmtgain355
printf,unit_w,nxs.baselinesubmethod355,nxs.subregionunderflow355,nxs.anomalousprof355

printf,unit_w,nxs.syncvalue,nxs.majorversionnumber,nxs.minorversionnumber,nxs.datatakeid,nxs.orbitnumber,nxs.idnumber
printf,unit_w,nxs.gmtday,nxs.gmthour,nxs.gmtmin,nxs.gmtsec,nxs.gmthund
printf,unit_w,nxs.metday,nxs.methour,nxs.metmin,nxs.metsec,nxs.methund
printf,unit_w,nxs.latitude,nxs.longitude,nxs.shuttlealtitude,nxs.offnadirangle,nxs.digitizerondelay
printf,unit_w,nxs.datatakemode,nxs.specialopsmode,nxs.profilevalidstatus,nxs.landwaterflag,nxs.surfelevfootprint
printf,unit_w,nxs.alttropopause,nxs.temptropopause
printf,unit_w,nxs.laserselected,nxs.baalignmentstatus,nxs.isdbstatus,nxs.badatastatus
printf,unit_w,nxs.aodatastatus,nxs.motorinmotion,nxs.aperwheelstatus,nxs.backgroundmongain
printf,unit_w,nxs.surfacemode532,nxs.dbattenuation532,nxs.numbersatabovesurf532,nxs.highestsatsample532
printf,unit_w,nxs.numberunderflows532,nxs.filterstatus532,nxs.callibrationstatus532,nxs.calibrationfactor532
printf,unit_w,nxs.baselinerippleremvd532,nxs.oscillationremoved532,nxs.backgroundvalue532
printf,unit_w,nxs.highvoltage532enabled,nxs.highvoltage532,nxs.energymonitor532,nxs.pmtgain532
printf,unit_w,nxs.baselinesubmethod532,nxs.subregionunderflow532,nxs.anomalousprof532

printf,unit_w,nxs.syncvalue,nxs.majorversionnumber,nxs.minorversionnumber,nxs.datatakeid,nxs.orbitnumber,nxs.idnumber
printf,unit_w,nxs.gmtday,nxs.gmthour,nxs.gmtmin,nxs.gmtsec,nxs.gmthund
printf,unit_w,nxs.metday,nxs.methour,nxs.metmin,nxs.metsec,nxs.methund
printf,unit_w,nxs.latitude,nxs.longitude,nxs.shuttlealtitude,nxs.offnadirangle,nxs.digitizerondelay
printf,unit_w,nxs.datatakemode,nxs.specialopsmode,nxs.profilevalidstatus,nxs.landwaterflag,nxs.surfelevfootprint
printf,unit_w,nxs.alttropopause,nxs.temptropopause
printf,unit_w,nxs.laserselected,nxs.baalignmentstatus,nxs.isdbstatus,nxs.badatastatus
printf,unit_w,nxs.aodatastatus,nxs.motorinmotion,nxs.aperwheelstatus,nxs.backgroundmongain
printf,unit_w,nxs.surfacemode064,nxs.dbattenuation064,nxs.numbersatabovesurf064,nxs.highestsatsample064
printf,unit_w,nxs.numberunderflows064,nxs.filterstatus064,nxs.callibrationstatus064,nxs.calibrationfactor064
printf,unit_w,nxs.baselinerippleremvd064,nxs.oscillationremoved064,nxs.backgroundvalue064
printf,unit_w,nxs.highvoltage064enabled,nxs.highvoltage064,nxs.energymonitor064,nxs.apdgain064
printf,unit_w,nxs.baselinesubmethod064,nxs.subregionunderflow064,nxs.anomalousprof064

printf,unit_w,nxs.timeedsinthour,nxs.timeedsintmin,nxs.timeedsintsec,nxs.timeedsinthund
printf,unit_w,nxs.highvoltage355cmd,nxs.highvoltage532cmd
printf,unit_w,nxs.b0_355,nxs.b0_532,nxs.b0_064
printf,unit_w,nxs.outofrng355abv40,nxs.outofrng532abv40,nxs.outofrng064abv40
printf,unit_w,nxs.top355,nxs.bottom355,nxs.top532,nxs.bottom532,nxs.top064,nxs.bottom064
end
;-----------------------------------------------------------------------------------

;-----------------------------------------------------------------------------------
pro new_alts
@com_globals.pro

; define altitude array

next = 40.0 * 1000.0
altitude(0) = next
altitude(0) = altitude(0)/1000.0
incre = 15.0
for i=1,2999 do begin
  next = next - incre
  altitude(i) = next
  altitude(i) = altitude(i)/1000.0
end
end
;-----------------------------------------------------------------------------------

;-----------------------------------------------------------------------------------
pro initunpack
@com_globals.pro

; Initialize arrays used in unpacking the out of range packed byte arrays 
; (nxs.outofrange355, nxs.outofrange532, and nxs.outofrange064).

outarr = bytarr(3000)
temparr = reverse(bindgen(3000))

; temparr is an array of 3000 values and is defined as:

;  [183,182,181,180,179,178,177,176,
;   175,174,173,172,171,170,169,168,
;   ...,
;     7,  6,  5,  4,  3,  2,  1,  0,
;   255,254,253,252,251,250,249,248,
;   247,246,245,244,243,242,241,240,
;   ...,
;     7,  6,  5,  4,  3,  2,  1,  0,
;   ...,
;   255,254,253,252,251,250,249,248,
;   247,246,245,244,243,242,241,240,
;   ...,
;     7,  6,  5,  4,  3,  2,  1,  0]

; Each row corresponds to one packed word, there are 375 packed words (8*375=3000).

andarr = byte(2^(temparr mod 8))

; 183 mod 8 = 7, 2^7=128
; 182 mod 8 = 6, 2^6= 64
; 181 mod 8 = 5, 2^5= 32
;     ...
; 176 mod 8 = 0, 2^4=  1

; andarr is an array of 3000 values and is defined as:

;  [128,64,32,16,8,4,2,1,128,64,32,16,8,4,2,1,128,64,32,16,8,4,2,1,...]
end