PRO my_read_ascii, filename, array, ncolumn, nskip=nskip ; PURPOSE: ; read ASCII file data. This version only read numbers. ; It does not work if there are strings in the ASCII file. ; ; INPUT: ; filename - string, the file to read. ; ncolumn - number of columns to read. Could be smaller than ; the real number of columns in the file, but cannot ; be larger. ; ; OUTPUT: ; array - an ncolumn * nrow 2D array. It will always be a ; 2D array, even if ncolumn=1. nrow will be the number ; of rows in the ASCII file. ; ; OPTIONAL INPUT: ; nskip - skip first nskip rows. Default is 0. ; ; EXAMPLE: ; my_read_ascii, 'catalog.cat', cat, 8, nskip=3 ; IF n_elements(nskip) EQ 0 THEN nskip=0 openr, data, filename, /get_lun dummy = '' nrow = long(0) IF nskip NE 0 THEN FOR i=0,nskip-1 DO readf, data, dummy while not eof(data) do begin readf, data, dummy nrow = nrow + 1.0d endwhile point_lun, data, 0 IF nskip NE 0 THEN FOR i=0,nskip-1 DO readf, data, dummy IF nrow EQ 0 THEN print, "MY_READ_ASCII: there seem to be no data. will do nothing." IF nrow EQ 0 THEN goto, skip A=dblarr(ncolumn) array = dblarr(ncolumn, nrow) i = long(0) while not eof(data) do begin readf, data, A array[*,i] = A i=i+1.0d endwhile free_lun, data return skip: end