Lesson 4: Printing a Table with Column Titles
In this lesson you will print a table with column titles. To achieve a presentable format with column titles requires a slightly more complicated approach.
To print a formatted version of the phone_data
table to the screen and place titles above each column, do the following:
1.Restore the phone data from a saved file.
RESTORE, !dir+'/data/phone_example.sav'
RESTORE, !dir+'\data\phone_example.sav'
2. Copy the following FOR loop to print the heading and phone data. The Format keyword in the PRINT statement uses FORTRAN-style format specifiers to format the rows.
FOR i=0, N_ELEMENTS(phone_data) - 1 DO BEGIN $
IF i EQ 0 THEN PRINT,'
DATE TIME DUR INIT'
+ $'
EXT COST AREA NUMBER'
&$
PRINT, Format='
(I6, 1X, I6, 3X, F5.2, 3X,'
+ $'
A3, 3X, I3, 2X, F5.2, 3X, I3, 3X, A10)'
, $
phone_data(i).DATE, phone_data(i).TIME, $
phone_data(i).DUR, phone_data(i).INIT, $
phone_data(i).EXT, phone_data(i).COST, $
phone_data(i).AREA, phone_data(i).NUMBER
This example prints the formatted phone_table
to the screen:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|