Have you contacted AGRC to find out why there are LFs strewn throughout their products?
From my past experiences with dealing with USGS DEMs, WINZIP would add LF/CR during decompression. WinZip has this feature “Smart CR/LF Conversion” where it would add CR/LF during decompression. I’m wondering if AGRC had this turned on when they created these self-extracting DEM files and LFs were added during compression.
The way I see it, you have three choices. Choice 1: External from IDL, you can use sed or awk to remove the LF, Choice 2: Internal to IDL, read the DEM file one byte at a time and remove the LF (ASCII 10B), then follow the USGS format description to extract the DEM information, Choice 3: Use ENVI to read the DEM and use IDL to read the hdr and img files that ENVI creates.
From my brief review of the data, I see LF at various spots – every 439, 893, and 1021 bytes.
For (choice 2) example,
file = ‘36109h1.dem’
b = 0B
oldpos = 0L
cnt = 0L
info = FILE_INFO( file )
HELP, info, /STRUCT
barr = BYTarr( info.size )
OPENR, lun, file, /GET_LUN
WHILE ( NOT EOF(lun) ) DO BEGIN
READU, lun, b
IF ( b EQ 10B ) THEN BEGIN
POINT_LUN, -lun, pos
PRINT, ' #### ', pos, ( pos - oldpos )
oldpos = pos
ENDIF ELSE BEGIN
barr[cnt] = b
cnt = cnt + 1
ENDELSE
ENDWHILE
CLOSE, lun
FREE_LUN, lun
Then to get Record A, which according to the USGS documentation is 144 bytes,
is = 0L
ie = 143L
PRINT, STRING( [ barr[is:ie] ] )
I’ll leave the rest of your imagination to extract Record B and Record C.
Kelly Dean
|