
Load waves from my csv file

Hi, I am trying to load the wave header to get the Start and Increment of my csv file.
// Here is the beginning of an example file:
// X, CH2, CH3, Start, Increment
// Sequence, VOLT, VOLT, -6.00E -6,1.00E-8
// 0, -8.00E -2,8.00E-2
// 1, 8.00E-2, 0.00E+0
// 2, -8.00E-2, 0.00E+0
// 3, 8.00E-2, 0.00E+0
// 4, -8.00E-2, 0.00E+0
I am trying to use
LoadWave/D/J/O/L={0,1,0,3,0}/A=dummy /p=my_path fileName
if the number of channels change then my L ={} will change correspondingly
I think but there should be a way for all possible # of channels. So is there a way to load the waves and get the number of columns first, lets call that ncolums, then L will be L={0,1,0,ncolums-2,0}, so that I could always load the wave header of last two columns of my data. Thanks
I have cleaned up (I think) the data you provided. I think "-6,1.00E-8" should be "1.00E-8".
Also "-6.00E" should be "-6.00E+0" and there was an extraneous "2," in the first line of data.
This gives the following:
Given that data, the following code determines the number of data columns to be loaded and loads them:
There are some improvements that I would do:
1. Skip the first column which is of no use assuming that it is always a sequence starting from 0 and stepping by 1.
2. Provide better wave names using the /B flag.
3. Assuming that Start and Increment refer to the starting X value and delta X value, use these to set the X scaling of the loaded waves.
I can help you with those tasks but I'd prefer to work on an actual data file which you can upload as an attachment.
July 26, 2024 at 11:54 am - Permalink
Yes, what I am trying to do is to write a Macro that could load the waves. And the first thing to do is get the starting X value and delta X value, so I could use these to set the X scaling of the loaded waves. But I would like to write a macro that could work for all possible # of channels instead of only two. That is why I am asking how to get the header of last two columns. Thanks
July 26, 2024 at 04:35 pm - Permalink
The code above does load all columns of data regardless of how many there are.
Here is an updated version that:
1. Skips the first column which is of no use assuming that it is always a sequence starting from 0 and stepping by 1.
2. Names the output waves CH0, CH1,...
3. Sets the X scaling of each output wave based on the last two numbers in the "Sequence" line.
This code works assuming that the format of the text in the file matches the format of my cleaned-up text in the post above.
If you attach an actual data file, I will test to make sure this code works with your actual data file.
July 26, 2024 at 08:11 pm - Permalink
Much appreciated!
Here is the Macro that I have so far that only works for two channels, could you try to modify that, so it could work for al possible number of channels? I am hesitating to give you my actual data, since it is important.
July 26, 2024 at 09:39 pm - Permalink
I wonder, did you look at what hrodstein has provided? Did it not work for you? It seems a very neat solution to me... Also, macros are very old tech and should be avoided in favor of functions.
Anyway, here is a code fragment which wraps your manual assignment into a simple loop. Things could be done much more neatly (see Howards solution), but if you just want to quickly modify what you already have...
July 27, 2024 at 09:15 pm - Permalink
In reply to Much appreciated! Here is… by minghaoj
Agree to chozo's take. It really comes down to the /L={0,2,0,0,3}. The 3 dictates how many columns you are loading (in your case the X, CH2, and CH3). You can increase this number accordingly if you have additional channels of data. Since your meta data (Start and Increment) are in the first rows, you won't have issue loading your data.
I am guessing your question is how to have your function be versatile to handle things beyond (the repetitive chunks of code for) w0 to w4??
Personally, for data like this, I prefer to load them into a 2D wave matrix by adding /M to LoadWave and go from there.
Another option would be creating a function that does your post loading processing and then feed the waves generated to that function in a loop. I see you already found the list of names of waves are stored in S_waveNames. You can use ItemsInList to determine the number of channels/waves loaded. Then use a For loop to repeat the process.
Personally, I would change the order of operation as follow and use name the waves differently (you can also use the LoadWave/Name added in Igor Pro 9 or later to handle your wave name changing. Note to myself, start using this).
Unrelated, yet related. I have created loaders for several different types of data files with meta data in it. The solution is similar to what hrodstein provided here. It involves a combination of FReadline and LoadWave (sometimes multiple of each).
Please correct me if I am wrong about this. One pet peeve of mine is that LoadWave/L seems to be limited by the number of columns in the firstLine of data which overrides the numColumns parameter if the later is larger. I am sure there are underlying reason why it does this, but part of me hope we can have an option to override that.
The situation is the worst when multiple chunks of data are stored in the same file with their individual meta data. Doing multiple loops of LoadWave/L can be very slow. FReadline appears to be faster (as the file is only opened once) but requires additional post loading wave handling. Some times I can try loading the entire file into one wave and separate each chunk out. It gets messy if the chunk sizes are dynamic.
July 30, 2024 at 08:37 am - Permalink
That's correct. It is a limitation that I have run into myself on occasion.
The underlying reason is that I didn't think of this situation when I wrote this code (about 35 years ago ;)
I think a flag that says "don't automically determine the number of columns in the file from the first line of data, follow /L instead" is doable.
August 1, 2024 at 10:18 am - Permalink
In reply to One pet peeve of mine is… by hrodstein
That will be cool. I am looking forward to that feature in future updates.
August 6, 2024 at 12:22 pm - Permalink