These three vectors can be turned into row vectors by using the REFORM command to dimension them into a rows-by-1 array. The preferred way to read this data is like this: For example, if you want to print out all the dates in the file, you would do this.
Our first task is to create a structure to represent each row of data. First, you must attach the file to a logical unit number, since all file input and output occurs over logical unit numbers in IDL. The logical unit number will be assigned to the variable lun in the command below. Thus, these arrays become normal one-dimensional row vectors.
Next, we have to create an array of these structures, one for each row of data.
The first few lines of the data file look like this: I want each column to be a separate IDL vector. How can I read this kind of data file in IDL? IDL was designed as an array processing language and it excells at handling data arrays all at once rather than in loops.
There are any number of ways to read this type of data file in IDL, but here is one way. When reading a string variable, IDL reads until the end of the current line in the file. Normally, when you think of a vector in IDL you think of a row vector. Or the number of rows will be variable.
Your code might look like this: What do you do then? With the number of rows known, it might occur to you especially if you are a FORTRAN programmer that you can initialize the three vectors you are after and read them directly, like this: You could read values into temporary variables, and store them in your loop if you like.
I might have set my code up like this: You would set your structure up as appropriate for your data file. The number of rows in the data file is variable, but the number is written in the second line of the header.
The code looks like this: PRINT, header The next step is to read the number of rows in the data file from the second line of the header. Just read the data. Or, you can read a longer answer here.
We can use the Replicate command to do this. Now you are ready to read the data itself. It would be better to read the data all at once and use array processing techniques to pull the vectors out of the larger array.The READ_ASCII function reads data from an ASCII file into an IDL structure variable.
READ_ASCII may be used with templates created by the ASCII_TEMPLATE function.
This routine handles ASCII files consisting of an optional header of a fixed number of lines, followed by columnar data. IDL provides great flexibility in writing data to files by use of the FORMAT keyword in the PRINTF procedure. Over time you should learn about the many options and use them to your advantage.
I never > could write an ascii file with columns of no.s from IDL. > I have two specific qs. regarding this: > > 1.
When I use printf (and even writeu), it gives me > non-sensible results. Reading and Writing Ascii Files The fastest and easiest way to read in an ascii table is if that table is already in a column format. Writing Ascii Files. Analogous to how we write files, we first need to open a file.
openw,lun2, 'filename', /get_lun. Reading ASCII Data Files. QUESTION: I have an ASCII data file named ultimedescente.com with a three line header and three columns of data. I want each column to be a separate IDL vector. The number of rows in the data file is variable, but the number is written in the second line of the header.
3. Input/Output Save/Restore. In astronomy there is a very popular way for reading free-format ASCII files by making use of the READCOL facility provided by the free-software IDL Astronomy Library FITS format reading/writing routines.
IDL does not provide any routine for reading/writing .Download