function readform, file ;+ ; NAME: ; READFORM ; ; PURPOSE: ; Formatted reading of the string-type array from a file ; ; CATEGORY: ; Input/Output ; ; CALLING SEQUENCE: ; Text = READFORM(File) ; ; INPUTS: ; File name. This array must be a scalar string. ; ; OPTIONAL INPUT PARAMETERS: ; None ; ; KEYWORD PARAMETERS: ; None ; ; OUTPUTS: ; String array ; ; COMMON BLOCKS: ; None. ; ; SIDE EFFECTS: ; None. ; ; RESTRICTIONS: ; None. ; ; PROCEDURE: ; The unformatted reading from the file is performed to a byte array. Then the number ; of lines is found (as the number of 0A codes), and the reading is performed again, ; but as a string-type array with explicitly specified number of elements. Finally, ; existence of one possible remainder line in the file is checked, and if it exists, ; then it is read and appended to the array. ; ; MODIFICATION HISTORY: ; ; ISTP SD RAS, Apr, 1998. ; Victor Grechnev (grechnev@iszf.irk.ru): Initially written. ; ; ISTP SD RAS, Jul, 2002. ; Natalia Meshalkina (nata@iszf.irk.ru): Help added. ; ; ISTP SD RAS, Mar, 2003. ; VG : Fixed bug when the file contains only one line. ; ; ;- if file eq '' then begin print, 'No file specified. Returning...' return, '' endif widget_control, /hour openr, lun, file, /get st = fstat(lun) data = bytarr(st.size) readu, lun, data point_lun, lun, 0 iii = where(data eq '0A'xB, N) data = strarr(N > 1) readf, lun, data st = fstat(lun) if (st.cur_ptr + 1) lt st.size then begin tmp = '' readf, lun, tmp data = [data, tmp] endif free_lun, lun return, data end