; Read_Ascii_HPDP ; Procedure to read the ASCII format L01 Pipeline data, as written by WR_ASCII_PPP. ; T W Grundy ; SSTD, RAL, UK ; Original version 7/11/2003 ; Current Version 1.3 28/11/2003 ; ; Change History ; Version 1.0 - Original version. ; Version 1.1 - 10/11/03 - Modified to speed up procedure, to ensure performance is ; maintained for large files. ; Version 1.2 - 12/11/03 - Modified to correct for changes in wr_ascii_ppp. ; Version 1.3 - 28/11/03 - Release version. ; ; USAGE - read_ascii_hpdp, file, data, header ; FILE - String full path to ascii file to be read. ; DATA - Structure output LSAN structure with reduced number of tags compared ; with OLP 10.1 LSAN format. ; HEADER - String array output variable containing primary and secondary headers. ; ; Performance - This procedure can be quite slow for large files. ; ; Limitations - This procedure is designed for use with Unix operating systems. Operation ; has not been tested on Windows, Linux or VMS, and is therefore not guaranteed. PRO READ_ASCII_HPDP, FILE, DATA, HEADER ; try to open file IF (FILE_TEST(file) NE 1) THEN BEGIN PRINT, 'File not found' RETURN ENDIF PRINT, 'Reading headers...' ; read until end of primary header GET_LUN, lun OPENR, lun, file temp1 = '' phend = 0 count = 0 WHILE (phend EQ 0) DO BEGIN READF, lun, temp1, FORMAT='(A80)' IF (count EQ 0) THEN header = temp1 ELSE header = [header, temp1] IF (STRMID(temp1, 0, 3) EQ 'END') THEN phend = 1 count = count + 1 ENDWHILE ; include 1 blank line in header variable to separate primary from secondary gap = 1 WHILE (gap EQ 1) DO BEGIN READF, lun, temp1, FORMAT='(A80)' IF ((BYTE(STRMID(temp1, 0, 1)))[0] NE 32B) THEN gap = 0 ELSE temp2 = temp1 ENDWHILE header = [header, temp2, temp1] ; read secondary header shend = 0 WHILE (shend EQ 0) DO BEGIN READF, lun, temp1, FORMAT='(A80)' header = [header, temp1] IF (STRMID(temp1, 0, 3) EQ 'END') THEN shend = 1 ENDWHILE ; header is now complete, so just need to cross blank space before data gap = 1 WHILE (gap EQ 1) DO BEGIN READF, lun, temp1, FORMAT='(A)' IF ((BYTE(STRMID(temp1, 0, 1)))[0] NE 32B) THEN gap = 0 ENDWHILE READF, lun, temp1, FORMAT='(A)' ; find current file position and compute number of records stat = FSTAT(lun) nrecs = (stat.size-stat.cur_ptr)/49L ; create the output data structure tdata = {lsanrpid: BYTARR(2), lsandet: 0, lsanscnt: 0, lsanwav: 0., lsanflx:0., lsanflxu:0.} data = REPLICATE(tdata, nrecs) ; file pointer is now at the start of the data temp2 = 0 temp3 = 0 temp4 = 0 temp5 = 0 temp6 = 0. temp7 = 0. temp8 = 0. row = 0L PRINT, 'Reading data...' PRINT, 'Records in file: ', nrecs PRINT, 'START: ', SYSTIME() FOR i = 0L, (nrecs-1L) DO BEGIN READF, lun, FORMAT='(I4, I3, I3, I3, F9, E13, E13)', temp2, temp3, temp4, $ temp5, temp6, temp7, temp8 data[i].lsanrpid[0] = temp2 data[i].lsanrpid[1] = temp3 data[i].lsandet = temp4 data[i].lsanscnt = temp5 data[i].lsanwav = temp6 data[i].lsanflx = temp7 data[i].lsanflxu = temp8 IF (row EQ 10000L) THEN BEGIN PRINT, i, ' records read' row = 0L ENDIF row = row + 1L ENDFOR PRINT, nrecs, ' records read' PRINT, 'END: ', SYSTIME() PRINT, 'Finished' CLOSE, lun FREE_LUN, lun END