procedure to load the txt data

Hi everyone,

I'd like to load the attached file (1.txt), and combine h,k,l (first three columns) to one column and set it to TEXT string with the format: [h<space>k<space>l]. For example, in the attached file, the 1st row has h=1,k=1 and l=0, I'd like to set the loaded data to [1 1 0]. Moreover, I'd like to name the waves with each column title, provided that all the characters are allowed in igor language.

In the attached 1.txt, each row has the same number of columns. But this is not always the case, as can be seen in 2.txt. When I use cmd+L to load the data, igor automatically separates to two sub-loading process. 1st block with 7 columns (7 waves) and 2nd block with 7+5 columns (additional 7+5 waves). This is not what I want. As you see in the data, it's just some rows missing the last 5 columns. All I need is the 12 waves named after the column title. If some columns are missing, I'd like to pad with something like "Null" that doesn't effect the future plotting.

Could anyone help me to write a procedure to automatically load in the file? I'm pretty new to igor programming, and don't know where to start. 

Thanks a lot!

 

1.txt (627 bytes) 2.txt (3 KB)

Quote:
When I use cmd+L to load the data, igor automatically separates to two sub-loading process

This is a feature of /L. For details, execute:

DisplayHelpTopic "Loading General Text Files"

This is an awkward file format to load. However, I think I have come up with something that works for both of the files you posted. It uses "Load Delimited Text".

Function Demo()
    String columnInfoStr = ""
    columnInfoStr += "N='_skip_';"          // Skip leading spaces
    columnInfoStr += "N=hWave;"
    columnInfoStr += "N=kWave;"
    columnInfoStr += "N=lWave;"
    columnInfoStr += "N=dWave;"
    columnInfoStr += "N=fRealWave;"
    columnInfoStr += "N=fImagWave;"
    columnInfoStr += "N=absFWave;"
    columnInfoStr += "N=twoIWave;"
    columnInfoStr += "N=iWave;"
    columnInfoStr += "N=mWave;"
    columnInfoStr += "N=IDWave;"
    columnInfoStr += "N=PhaseWave;"
    LoadWave/J/D/E=1/K=0/V={" "," $",0,0}/L={0,1,0,0,0}/W/B=columnInfoStr
End

This uses "Load Delimited Text" (/J) with space as the delimiter. For background information:

DisplayHelpTopic "Loading Delimited Text Files"

/W makes Igor determine the number of columns to load from the provided column names. Without it, LoadWave would determine the number of columns from the first row to be loaded, but this is inconsistent between the two files.

I use /B to generate meaningful wave names. You can change these to your taste. I did not use and "h", "k", "l" because they are vague.

 

 

In reply to by hrodstein

I'll use your codes as the starting point to build my own more sophisticated ones. Previously, I use bash shell script to pre-treat the data before loading into Igor. After studying several posts in the forum, I just realized that I can do everything with Igor. Thank you very much! 

 

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More