pro example02,filename,record_number,header,data ;================================================ ; This program reads one record of a BSCAN ; file and returns the header and data. ; ; INPUT: filename .... string containing name of BSCAN file ; record_number ... integer record number to be read ; ; OUTPUT: header..... array of 30 floats the header ; data ...... array of data values ; ;================================================ ; First, check to see if the filename exists. err = findfile(filename,count=count) if (count eq 0) then begin print,'Data file: '+filename+' cannot be found.' return endif ; Second, read the first 30-words of the first record ; to see how long the data profile is. openr,lun,filename,/get_lun stats = fstat(lun) record = assoc(lun,fltarr(30)) first_header = record(0) close,lun free_lun,lun prof_len = first_header(28) ; Third, compute the record length and number of records in the file. rec_len = prof_len + 30 recs_in_file = long(stats.size/(rec_len*4)) ; Return if user specifies a record number too high or low. if ((record_number gt recs_in_file-1) OR (record_number lt 0)) then begin print,'Sorry, valid record numbers are 0 to '+strtrim(recs_in_file-1,2) print,'and you asked to read number '+strtrim(record_number,2) return endif data = fltarr(prof_len) header = fltarr(30) openr,lun,filename,/get_lun record = assoc(lun,fltarr(rec_len)) z=record(record_number) header(*) = z(0:29) data(*) = z(30:rec_len-1) close,lun free_lun,lun return end