Standard I/O (i.e., Input and Output): {Gumley 4.1 - 4.3} ouptut to screen - see page 141 for formats For example: i7, f7.4, E10.3 or e10.3, a10, 2x, / IDL> x1=1.3e-4 IDL> x2=-5.6973e2 IDL> x3=1.234d39 IDL> x4=-6.1d-150 IDL> PRINT,x1,x2,x3,x4 IDL> PRINT,x1,x2,x3,x4,FORMAT='(e11.3)' or FORMAT='(4(2x,e11.3))' to print all 4 on one line or FORMAT='(2(2x,e11.3))' to print 2 per line but FORMAT='(e10.3)' is not enough for x4 You can also use c-style formatting (as opposed to the default fortran style) if you prefer that. To use c-style formatting, the first thing that appears in your format command is a % sign to indicate c-style. Then you enter your c format string, containing format codes such as %e, %f, %i. Instructions on how to use these format codes can be found in IDL> PRINT,x1,x2,x3,x4,FORMAT='(%"The numbers are %e %e %e and %e.")' IDL> PRINT,x1,x2,x3,x4, $ FORMAT='(%"In another format %15f %15f %15.6e and %15.6e.")' input from keyboard - note, you can't read a sub-array, like only a[1] - it's better to NOT use a format on input; then input values only need to be separated by a space, comma, or carriage return - if you input string variables, they need to be separated by carriage returns IDL> i=0L IDL> a=FLTARR(3) IDL> READ,i,a,PROMPT='enter i and a[0],a[1],a[2]: ' IDL> PRINT,i,a IDL> name='' IDL> READ,name,PROMPT='enter your name: ' IDL> PRINT,name IDL> first_name='' IDL> last_name='' IDL> READ,first_name,last_name, $ IDL> PROMPT='enter your name, separated by a carriage return: ' enter your name, separated by a carriage return: Mark enter your name, separated by a carriage return: Krumholz IDL> PRINT,first_name,' ',last_name Mark Krumholz Reading and writing files: see page 147 for i/o procedures OPENW opens a new file for writing only note: if the specified file already exists it will be over-written OPENR opens an existing file for reading only OPENU opens an existing file for reading before writing note: here "u" stands for "update", not "unformatted" specify an existing file by: myfile='/afs/cats.ucsc.edu/users/m/mkrumhol/mydata' or select an existing file by: myfile=DIALOG_PICKFILE() OPENW,lun,myfile,/GET_LUN ; /GET_LUN is same as GET_LUN=1 . . . CLOSE,lun ; or "FREE_LUN,lun" ; (either one works, with or without /GET_LUN) Formatted (ASCII) files: READF reads data from a formatted file PRINTF writes data to a formatted file note: testfile did not exist before this IDL> OPENW,1,'testfile' IDL> a=1. IDL> b=2. IDL> c=3. IDL> PRINT,a,b,c IDL> PRINTF,1,a,b,c,FORMAT='(3(2x,e10.3))' IDL> CLOSE,1 now open a unix window and do an "ls" to see 'testfile' on your disk. open this file with emacs to see the numbers you placed in it. IDL> OPENR,2,'testfile' IDL> d=0. IDL> e=0. IDL> f=0. IDL> PRINT,d,e,f IDL> READF,2,d,e,f IDL> PRINT,d,e,f IDL> CLOSE,2 you can also update (i.e., add to) the file. IDL> OPENU,3,'testfile' IDL> d=4. IDL> READF,3,a,b,c IDL> PRINT,a,b,c IDL> PRINTF,3,d,FORMAT='(3(2x,e10.3))' IDL> CLOSE,3 open this file again with emacs to see all four numbers. note, the default limit of columns per line is 80. set the WIDTH keyword in OPENW to change this. For example, make the following two procedure files using emacs: ___________________ call this one "test_write.pro" PRO test_write,file COMPILE_OPT IDL2 IF (N_ELEMENTS(file) EQ 0) then MESSAGE,'need to specify a file' nvalues=70 arr=FINDGEN(nvalues) OPENW,6,file PRINTF,6,arr,FORMAT='(7(2x,f6.1))' CLOSE,6 END ___________________ call this one "test_read.pro" PRO test_read,file COMPILE_OPT IDL2 IF (N_ELEMENTS(file) EQ 0) then MESSAGE,'need to specify a file' nmax=500 tmp=FLTARR(7) temp=FLTARR(2,nmax) OPENR,1,file i=-1 WHILE ((EOF(1) ne 1) and (i lt nmax)) DO BEGIN i=i+1 READF,1,tmp temp[0,i]=tmp[0] temp[1,i]=tmp[1] ENDWHILE CLOSE,1 imax=i FOR i=0,imax DO BEGIN PRINT,i,temp[0:1,i] ENDFOR END __________________ Then compile and run these: IDL> .R test_write IDL> .R test_read IDL> test_write,'myfile' IDL> test_read,'myfile'