Harry,
Extrapolating from the approach taken by the C library you mentioned in your original message thread, I provide below the approximate equivalent of that parser as it could be written in the IDL language. To run this you would use the syntax:
IDL> fdlArray = PARSE_MODIS_FDL(numberOfAerosolTypes, $
IDL> numberOfBands, numberOfSZADegrees)
Each element of the result array would have the following structure:
fdl[opticalDepthIndex, szaDegreeIndex, bandNumberIndex, aerosolTypeIndex]
The function assumes that there is no other header info than what you gave in your abbreviated example data. I.e. this function assumes that the first line in the file is the line demarcating the first Aerosol Type, the second and third lines are the lines demarcating the band number info and the optical info for the first block of FDL values. It is easy to modify, if you know how to use READF at the beginning of a file to move the "file cursor" to the beginning of the first line in the file that IS the first Aerosol Type info line.
Hope that it is not hard to figure out the code steps below.
James Jones
FUNCTION parse_modis_fdl, file, nAerosolTypes, nBands, nSZAs
;nAerosolTypes = 2 ; Values from Harry Kim's User Forum example
;nBands = 2
;nOpticalDepths = 5
;nSZAs = 5
; Parse the first Optical Depth Header Line to dynamically set
; the number of optical depths in the FDL array
nLines = file_lines(file)
textArray = strarr(nLines)
openr, lun, file, /GET_LUN
firstHeaderInfoBlock = strarr(3)
readf, lun, firstHeaderInfoBlock ; Imports first 3 lines of file
opticalDepthHeaderLine0 = firstHeaderInfoBlock[2]
temp = strsplit(opticalDepthHeaderLine0, /EXTRACT)
opticalDepths = float(temp[1:*])
nOpticalDepths = n_elements(opticalDepths)
point_lun, lun, 0 ; Put file pointer at beginning of file again
; initialize the FDL Array
fdlArray = fltarr(nOpticalDepths, nSZAs, nBands, nAerosolTypes)
currentAerosolTypeLine = ''
currentBandInfoLine = ''
currentOpticalDepthInfoLine = ''
currentSZALine=''
for i = 0, nAerosolTypes-1 do begin
readf, lun, currentAerosolTypeLine
for j = 0, nBands-1 do begin
readf, lun, currentBandInfoLine
readf, lun, currentOpticalDepthInfoLine
; Now parse the FDL data from this latest aerosol/band block
for k = 0, nSZAs-1 do begin
readf, lun, currentSZALine
temp = strsplit(currentSZALine, /EXTRACT)
lineFDLValues = temp[1:*]
fdlArray[0,k,j,i] = lineFDLValues
endfor
endfor
endfor
free_lun, lun
return, fdlArray
END
|