comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: PROCEDURE: Read arbitrary table of data

PROCEDURE: Read arbitrary table of data
type: item
description: IDL has a handy ability to read a table of numbers of n columns by m rows, simply by defining IDL> a = fltarr(n,m) IDL> readf,1,a However, one doesn't always know m and n. I wrote this piece of code to solve the problem of reading a table of data (floats or ints) with a fixed (but unknown) number of rows and columns, separated by whitespace and returns. I'm releasing it into the public domain; if you find any bugs or make any improvements, please send them to me and I'll fix or incorporate them. Randy Smith rsmith@wisp5.physics.wisc.edu -------------------cut here------------------------------------ PRO read_array,filename,array,SKIP=skip,INTEGER=integer ;+ ; NAME: ; READ_ARRAY ; ; PURPOSE: ; Reads a file into an array variable. The file is assumed to ; consist of lines of numbers, separated by tabs or spaces, ; with the same number of values on each line. The file length ; is arbitrary. ; ; CATEGORY: ; PROG ; ; CALLING SEQUENCE: ; READ_ARRAY, filename, array ; ; INPUTS: ; filename: The name of the file to be read. ; array: The variable to hold the data. ; ; KEYWORD PARAMETERS: ; SKIP: The number of lines of "header" information in the ; file to skip. ; ; INTEGER: If the data in the file is integer. The default is ; floating point. ; ; OUTPUTS: ; Returns a two-dimensional array whose first index is the ; number of elements per line, and second index is the number of ; lines in the file. Also outputs these numbers to the screen. ; ; RESTRICTIONS: ; Not tested all that much. Does not read double precision data. ; ; EXAMPLE: ; READ_ARRAY, 'spectra.dat', spectrum, SKIP=3 ; Reads the file spectra.dat, skipping the first 3 lines, creating ; the array variable spectrum. ; ; MODIFICATION HISTORY: ; Written by: Randall Smith, 6/19/95 ;- if (N_params() lt 2) then begin print,'Call with' print,'''Read_Array,''filename'',array,[skip=n],[/integer]' print,'where ''filename'' is the file to be read' print,' ''array'' is the variable to put the data into and' print,' /skip=n where …
creator: rsmith
date: 1995-07-14T07:00:00-00:00