Subchapters:
|
Reading and writing dataThere is a lot of ways to read and write data in different formats, from gif, mpeg to fits and others that I even don't know <;-). Have a look at the help... I will here deal with ascii and fits files. To save a sequence of commands, use the journal command. For ASCII data like, for example, a catalog of stars like used in the above structure example. You have to know the format of your data and you have to initialize the array of structures. Give a name for each tag corresponding to the different columns of the data file and give an initial value that describe their type. For example, to read a 10000-lines file of the form: [...] IDL>newcat = replicate({etoile, name: 'etoile', ra: 0.0, dec: 0.0, mag : 0.0},10000) Now, open the file. You have to specify a logical unit number. This number will be associated with the file (you can open many files at the same time, each of them with a different logical unit number). You will have to specify this number each time you will access the file. For example: IDL>openr,122,'stars.cat' You can put this number in a variable, let's say lun1. IDL>lun1
= 122 If you don't want to risk a collision with an already open file with the same logical unit number, ask IDL to give you this number, by the /get_lun keyword. IDL knows what numbers are not used at the time you opened the file: IDL>openr,lun1,'stars.cat',/get_lun then you can read the whole catalog in one time: IDL>readf,lun1,newcat,format='(a10,f7.3,f7.3,f7.3)' If you have only numerical data, you can read them without format. The format is similar to the Fortran one. Now, don't forget to close the file and to free the logical unit number: IDL>close,lun1 You can now play with the newcat array of structures. If you don't know the number of data nor the format, the READ_ASCII procedure will help you. Or you can do a loop with a while not eof(lun). Writing data follow the same principle, except the opening is: IDL>openw,lun,'test.tmp',/get_lun You can write gif and jpeg images. Quick access to ASCII filesUsing my lect_ascii() function, it's easy to read an ascii file and have the data in one array of structure. IDL> lect_ascii() ; will let
you choose the file to read The lect_ascii() function is not very well written, it use twice the memory needed for the input file, so don't use it with very very big files. Better in this case to use readu. Save and Restore
IDL>save,filename='minha_sessao.sav' When coming back from the beach, just restore the session with: IDL>restore,'minha_sessao.sav' You can also specify one or more variables that you just want to save: IDL>save,filename='minhas_images.sav',image1,image2 Fits files
IDL>add_path,/as,/es You have all the information about the image in the string array head. |
IDL courses C. Morisset © 2004 IA/UNAM V 2.2 |