help to import text-format data into igor

I have a text file formatted as
1 //experiment number
1 //pattern number
1 //repeat number

text of condition

44  //this is the real data
155
155
155
...
23
1 //experiment number
1 //pattern number
2 //repeat number
...//repeats


My question is I want to import the data as waves and name the wave as experimentNumber_patternNumber_repeatNumber, but when I try to use "load general text" option, it doesn't work that way. Any suggestion?
Here is one approach that I wrote up. After writing it I decided there is another approach that may be easier. I will post it in a separate post below.

This is quite complicated and is not going to be easy to implement.

You are going to need to read the header data, create your desired wave name, and then in a separate operation load the wave data.

Since you have multiple data sets in a file, each with its own header information, you will need to do this in a loop.

If the header information (experiment number, pattern number, repeat number) is deterministic then you don't have to read it from the file but instead you can generate it using loop variables.

If the header information is not deterministic you will have to read it from the file using either FReadLine or LoadWave.

Here is an example of reading header data and then loading wave data:
http://www.igorexchange.com/node/908

For a more detailed example using FReadLine see
http://www.igorexchange.com/node/880

Instead of using FReadLine to read the header data you could use LoadWave/J/L={0,startLine,3,0,1} which loads the first three lines of the first column only. This will create a numeric wave containing your experiment number, pattern number and repeat number.

You will have to determine startLine yourself either by a-priori knowledge or by counting the lines in each section in a separate step. It is the starting line of a section in the file - the zero-based line on which the experiment number appears.

For loading the actual data you will need to use /L again to tell LoadWave/J to skip the first 6 lines:
LoadWave/J/L={0, startLine,numLinesToLoad,0,1}.


You will have to figure out numLinesToLoad yourself either by a-priori knowledge or by counting the lines in each section in a separate step.

After reading the experiment number, pattern number and repeat number, you will create a string variable containing the desired wave name, something like this:
String name
sprintf name, "E%d_P%d_R%d", experimentNumber, patternNumber, repeatNumber

where you have determined experimentNumber, patternNumber, repeatNumber either by a-priori knowledge or by reading the file.

Once you have the name string variable you can use it with the LoadWave /B flag to set the wave name:
String columnInfoStr = "N=" + name + ";"    // e.g., "N=E1_P1_R1;"
LoadWave/J/L={...}/B=columnInfoStr


This is quite doable if you have reasonably good programming skills. If not I recommend finding someone with good programming skills to help you as it is pretty complicated.
Here is the second approach which should be easier but still requires at least advanced-beginner Igor programming skills.

You load the whole file using
LoadWave/G/O/B="N=RawData;"


This will create a wave named RawData.

Then write a loop that scans through RawData finding the start and number of points in each section.

For each section you read the experiment number, pattern number and repeat number, and determine the starting data line and ending data line. You create a string variable containing the desired wave name and then use the information you have collected in a Duplicate/R command to create the data wave for that section. You then continue with the next section.
Thank you

hrodstein wrote:
Here is the second approach which should be easier but still requires at least advanced-beginner Igor programming skills.

You load the whole file using
LoadWave/G/O/B="N=RawData;"


This will create a wave named RawData.

Then write a loop that scans through RawData finding the start and number of points in each section.

For each section you read the experiment number, pattern number and repeat number, and determine the starting data line and ending data line. You create a string variable containing the desired wave name and then use the information you have collected in a Duplicate/R command to create the data wave for that section. You then continue with the next section.