RD_TFILE is a generic ASCII (text) file reading routine. It can be used to return the contents of any text file as an IDL array. A fast algorithm is used which makes it more than an order of magnitude faster than reading line by line until the end of the file. It can optionally read and convert string or numeric tables. It is ideally suited for use in reading calibration files - in many cases, existing ASCII calibration files can be read without change. The automatic comment elimination feature makes it simple to internally document calibration files or add to existing documentation without any changes to the IDL access routines.
It is hoped that the use of specialized ASCII read routines can be minimized by use of this routine. Even if a calibration file has a complex internal structure, RD_TFILE can perform the initial read and the user can handle special formatting problems with the IDL intrinsic READS function (read from the string array returned by RD_TFILE). No explicit file open or close commands would be required by those routines which use RD_TFILE. Other typical uses are reading IDL source code (extract documentation), reading in Unix script and VMS command files for parsing, etc.
The following features are available:
IDL> text=rd_tfile(filename) ; orig. file-> string array
IDL> text=rd_tfile(filename,/nocomment) ; same less comment lines
IDL> text=rd_tfile(filename,/compress) ; same less excess blanks
IDL> data=rd_tfile(filename,/hskip,head=head) ; return file header in head
IDL> data=rd_tfile('text.dat',3) ; strarr(3,N) (table data)
IDL> data=rd_tfile('fdata.dat',/auto,/convert) ; auto determine #col/data-type
As a specific example, you can read in a Unix password file as a table with a single command:
PASSWD STRING = Array(7, 39)
Now, search for given user using WC_WHERE and print out relevant fields
IDL> ss=wc_where(passwd(0,*),'free*') ; search on name field
IDL> prstr,passwd(*,ss) ; print users record
freeland YI/g8JD8wqOuo 5498 15 Samuel L. Freeland /sxt1data0/people/freeland /bin/tcsh
Note that PRSTR (stands for PRint STRing) is a general string vector printing routine. See the Reference Guide for more information.