In ASCII data, "file_rows" ***is*** "file_lines". A row is demarcated by by a "newline" character(s) and that is exactly what IDL's FILE_LINES function counts. In binary data, however, there are no common formatting rules for a "row" as there are in ASCII data. Each software or programmer has its/his/her own specification for what constitutes a row of data in a binary data file. The reader of the data needs to know this specification before the "rows" can be found. IDL has functions to check what constitutes a "row" in many different kinds of binary files, e.g in all kinds of different image files (e.g. .bmp, .png, .jpg), in all kinds of different scientific data format files (HDF, NITF, DICOM), etc.
The most common kind of binary read request for IDL, though, is to read flat, binary files: Files that have just one datatype of data, and that datatype represents some particular grid of data. To read these, you, the programmer of the reader, need to program into IDL what constitutes a row of data in that file. Thus, if you knew that your binary data files have 200 8-byte double-precision floating point data samples in each row, then you could dynamically determine its number of rows and import it into IDL with the following commands:
nBytes = (file_info('mydata.dat')).size
elementsPerRow = 200
bytesPerRow = elementsPerRow * 8
nRows = nBytes / bytesPerRow
mydata = dblarr(elementsPerRow, nRows) ; Allocate the storage for the file data
openr, lun, 'mydata.dat', /GET_LUN
readu, lun, mydata ; Imports the entire file into the 'mydata' array
free_lun, lun
James Jones
|