X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 05 Jan 2015 04:25 PM by  anon
Read String and Number on same line
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
05 Jan 2015 04:25 PM
    I want to read a data file of this format: apple 1 2 3 4 5 pear 6 7 8 9 0 I want to be able to read the first column as a string, and the rest of it as numbers. The problem I have is that IDL automatically reads the entire line when you tell it to read a string. So when I try to make it read "apple" it actually reads "apple 1 2 3 4 5". I found a routine called "strmid" which can extract part of a strong. So this will let me extract "apple" from "apple 1 2 3 4 5". But the problem is that I still need to read the numbers after I do that. So in order to read both the numbers and the string, I either need to make the string stop reading before the end of the line, or I need to be able to make it start reading after a certain number of characters so that it can skip the string. It would also be helpful if I could read one character at a time. I haven't figured out how to do either of these things yet. To be honest I am rather annoyed at IDL. I've been using it for months and my opinion of it has not improved at all in that time. IDL does everything with routines, so that I need to google the syntax for every task I need to do, no matter how mundane. In contrast, if I were working in C++, then I would not need to use any routine for "strmid", I would just define a character vector, and then I'd be able to draw the characters I needed out of it directly using the indices. I have never needed to do this task in C before, but I didn't have to google new syntax to figure out how to do it, because C does not rely so heavily on routines like IDL. Fortran would also be a mess to try to read one character at at time, but reading columns in Fortran is trivial, whereas this simple task still gives me headaches in IDL. Also I occasionally run into situations where IDL seems unable to do a trivial task, like reading a string and then a number.

    Deleted User



    New Member


    Posts:
    New Member


    --
    06 Jan 2015 09:31 AM
    I found IDL formatting online. According to the website I found, writing nX into a formatting command will cause it to skip n lines. Also it said that it would ignore quoted strings in the format while reading. So I tried this read statement: readf, 1, FORMAT = '("IDL is great", 23x)', X It told me that my command caused it to enter an infinite loop. Since when has telling a program to skip 23 characters and then to read a string caused anything to enter an infinite loop? Apparently the documentation on this is not very good. Since IDL formatting doesn't work apparently, I just used the strmid function I talked about earlier to extract every single number from the string separately. To do this, I had to find the location of every single column in the document, and then to write a strmid function for each number in the column I wanted to read. My datasheet has 23 columns, so this is probably one of the stupidest solutions to a problem that has ever been used in a program. I had to write 23 strmid functions in order to extract all of it from my strings. This problem is so trivial that I would not even have had to think about how to do it in any other language, but when I use IDL I have to go through all this crap. There is another stupid problem that I have had with IDL that I will share. The example below is a valid IDL statement: for i = 0, N do begin readf, y x(i) = y endfor IDL does not accept this command however: for i = 0, N do begin readf, x(i) endfor I cannot imagine why IDL does this. I've worked briefly with about a dozen programming languages before, and IDL is by far the stupidest language that I have ever worked with. I would never pay to use this product. I am using a student version at my university.
    You are not authorized to post a reply.