
Delimited Text

Cory K
The data is formatted like this:
a,b,c,d,e
a,b,c,d,e
a,b,c,d,e
a,b,c,d,e,f,g,h,i,j,k,l,m,n
a,b,c,d,e
a,b,c,d,e
Where columns f-n are comments that only appear once in a while.
When I try to load this data using:
Data >> Load Waves >> Load Delimited Text
It does not see columns f-n, since they do not appear in the first row.
Any ideas how to find these columns?
Probably the easiest (though not easy) way to do it is to create a modfied version of the file with commas added so all of the lines have the same number of columns, like this:
a,b,c,d,e,,,,,,,,,
a,b,c,d,e,f,g,h,i,j,k,l,m,n
If you want help with this, send a zipped copy of a sample file as an attachment to support@wavemetrics.com. Mention your Igor version and OS in the body of the email and any other instructions.
July 28, 2009 at 09:15 pm - Permalink
Rather than modifying each file, this type of format might be easier to load ...
a) as a text file into a notebook, with subsequent line-by-line parsing into text waves or
b) as a string, with subsequent string manipulations
You would have to write the functions needed to do either operation. The /r (carriage return) and , (comma) characters would be the key searches for parsing.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
July 29, 2009 at 07:36 am - Permalink
I have another question however.
One of the columns has text before the value:
voltage=6
voltage=7
voltage=4
voltage=3
.....
What is the function in Igor to strip off a certain number of characters?
Or since the text before the value is always a certain length, could I index the string as string[7:end] or something to the effect?
July 29, 2009 at 10:17 am - Permalink
The string looks like this:
APD Voltage= #####
July 29, 2009 at 10:34 am - Permalink
July 29, 2009 at 09:04 pm - Permalink
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
July 30, 2009 at 06:11 am - Permalink
For my initial problem, where Igor wouldnt recognize any columns that werent in row 0, I have a quick question.
Can I write text to the file, then read the new version of the file?
For example:
If the original file was:
a,b,c,d,e
a,b,c,d,e
a,b,c,d,e
a,b,c,d,e,f,g,h,i,j,k,l,m,n
a,b,c,d,e
a,b,c,d,e
Can I write "f,g,h,i,j,k,l,m,n" as text appended to the end of the first row?
Then I think I can get around this issue.
July 30, 2009 at 07:37 am - Permalink
Can I post what I have so far of my code, then it may be easier to see what my main goal is.
What this eventually supposed to do is:
- Load a csv file
- Delete all the columns I dont need
- For the column that only has data every once in a while (wave20), fill in the points that are empty.
To do this, if the space is blank, I just use the most recent non-blank value. When I get to a non-blank index, I use that value until I reach the next non-blank index and so forth
- Lastly I rename all the relevant waves and add them to a table
I will attach a random data file if that will make it easier to see what I am talking about.
(*Note: I cannot attach a .csv file in IgorExchange, so I resaved it as tab delimeted text)
July 30, 2009 at 07:55 am - Permalink
No, that is 1) difficult, and 2) generally not a good idea to go about modifying input data.
There's gotta be a better way.
Software Engineer, WaveMetrics, Inc.
July 30, 2009 at 05:54 pm - Permalink
It seems to me, using LoadWave with the /B flag is the way to go for this convoluted file structure.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
July 30, 2009 at 06:16 pm - Permalink
Thanks for pointing that out. I've added .csv to the list of allowed extensions.
July 31, 2009 at 06:42 am - Permalink
For details, the LoadWave's help explain very well how to use them.
Both of function's work whit .txt file. For .csv file you should modify the LoadWave's /V Flag.
July 31, 2009 at 08:41 am - Permalink
July 31, 2009 at 11:22 am - Permalink
Unfortunately, this does not work as you would expect. A comparison of any number to NaN will always return 0 (false). To test if a number is NaN you must use the numtype function. So your code would be written like this:
August 2, 2009 at 08:15 pm - Permalink
For some reason, Igor is only finding wave0-wave9.
There should be 26 waves, which I then sort through later in the macro.
Can someone please take a look at the attached macro and see if they can spot any errors?
I also attached a random data file you can use to check the macro with.
Thanks again for all your help.
August 3, 2009 at 11:00 am - Permalink
The LoadWave /B format only loads 9 columns, not all 26.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
August 3, 2009 at 11:08 am - Permalink
Correct, I only want to load 9 waves. However, I do not want the FIRST 9 waves,
I am trying to parse only specific columns.
I have found a way around this, but it isnt automated, so its not a great solution.
If I go into the CSV file, and insert 15 commas after the last column heading, everything loads correctly and without issue.
Is there a way to programmatically do this?
August 3, 2009 at 11:18 am - Permalink
Can you specify what row to start loading data from?
If so, I know that by default, row 2 will always have all 26 rows, so everything should go smoothly.
Is there a flag for that?
August 3, 2009 at 11:26 am - Permalink
I answered my own question.
I needed to add:
/L={0,2,0,0,26}
to the LoadWave function.
This did the trick.
Thanks again for your help everyone.
August 3, 2009 at 11:29 am - Permalink