In most cases you will have far too much data to want to type it in.
E.g. to read data from am ascii file generated by MODTRAN (a radiative transfer code) You have a data file ( lecjm/public_html/Teaching/IDL_course/Data/pldat.dat) containing 14 columns of numbers:
14000. 0.714 7.97E-31 1.56E-26 2.10E-07 4.12E-03 4.11E-08 1.18E-07 2.32E-03 2.94E-08 3.29E-07 6.44E-03 1.64E-05 0.3950 14100. 0.709 4.95E-31 9.84E-27 2.13E-07 4.24E-03 4.15E-08 1.18E-07 2.35E-03 2.90E-08 3.31E-07 6.59E-03 4.96E-05 0.3940 14200. 0.704 3.05E-31 6.15E-27 2.11E-07 4.25E-03 4.17E-08 1.15E-07 2.32E-03 2.81E-08 3.26E-07 6.58E-03 8.22E-05 0.3887 14300. 0.699 1.84E-31 3.77E-27 1.90E-07 3.90E-03 4.06E-08 1.03E-07 2.11E-03 2.56E-08 2.93E-07 6.00E-03 1.12E-04 0.3734 14400. 0.694 1.13E-31 2.35E-27 1.87E-07 3.88E-03 4.05E-08 9.90E-08 2.05E-03 2.46E-08 2.86E-07 5.93E-03 1.40E-04 0.3664 14500. 0.690 6.53E-32 1.37E-27 1.60E-07 3.36E-03 3.74E-08 8.57E-08 1.80E-03 2.17E-08 2.46E-07 5.17E-03 1.65E-04 0.3446 . . . 33800. 0.296 0.00E+00 0.00E+00 2.64E-10 3.01E-05 2.62E-10 2.91E-18 3.33E-13 1.99E-20 2.64E-10 3.01E-05 3.27E-03 0.0001 33900. 0.295 0.00E+00 0.00E+00 1.68E-10 1.93E-05 1.67E-10 1.52E-19 1.75E-14 1.05E-21 1.68E-10 1.93E-05 3.27E-03 0.0000 34000. 0.294 0.00E+00 0.00E+00 1.82E-10 2.10E-05 1.80E-10 1.83E-20 2.11E-15 1.26E-22 1.82E-10 2.10E-05 3.27E-03 0.0000The columns are 201 rows long. We want to read this into a new variable called ``data''. Create a file (modtran.pro) containing the program below and run it in IDL using: modtran, data
pro modtran, data ;+ ;Reads and plots modtran data from a particular file pldat.dat ;Hugh Pumphrey (a long time ago) modified by John Marsham (11/04/2005) ;- ;;;;;; Set up array to contain the data ;;;;;;;;;;;;;;; data=fltarr(14,201) ;;;;;; Open the file, attach it to unit no. 1 ;;;;;;;;; openr,1,'~lecjm/public_html/Teaching/IDL_course/Data/pldat.dat' ;;;;;; read the data from the file attached to unit 1 ;;;;;;; ;;;;;; into the array modtrandata readf,1,data ;;;;IF THE DATA WAS BINARY YOU'D USE READU;;;;; ;;;;;; Close the file ;;;;;; close,1 ;;;;;; Now make the plot ;;;;;; plot,data(1,*),data(11,*), $ xtitle='Wavelength (microns)',$ ytitle='Radiance (Watts/(cm!U2!N Steradian Micron))' ;;;;;; Don't forget the 'end' statement ;;;;;; end
Then type: help,data.
Note that we have to know in advance how many rows and columns there are. We'll look at how to get around this later. Note also that you call this with: ``modtran, newvar'' or ``modtran, blah'', or whatever you like.
For an IDL array with n elements, the individual elements are numbered from 0 to n-1 , just as in C or Java. They are not numbered from 1 to n as in Fortran.
The data has 201 rows and 14 columns and is defined by an array using modtrandata=fltarr(14,201)=fltarr(ncolumns,nrows) .
(0,200) (1,200) (2,200) ... (13,200) . . . . . . . . (0,2) (1,2) (2,2) ... (13,2) (0,1) (1,1) (2,1) ... (13,1) (0,0) (1,0) (2,0) ... (13,0)