Importing xy waves stored in a lot of files

warakurna
Posts: 23
Joined: 2008-07-23
Location: Germany

Hej,

I'm a freshman to Igor and currently I'm working on a procedure to import IR data (wavenumber vs. absorbance) from simple delimited text files. The files include one spectra with two columns (wavenumber and absorbance). The file ending is ".dpt". Setting up a method to load spectra out of one file succeeded:

// ------ IR spectra XY data loader for one spec -----
 
Function Load_IR(genericname, path)
String genericname // Name of file to load or "" to get dialog
String path // Name of path or "" to get dialog
 
String file=genericname+".dpt"
 
Wave Wavenumber, Absorbance
String wnstr="_cm-1"
String Wavenumberwave=genericname+wnstr
String Abstr="_A"
String Absorbancewave=genericname+Abstr
 
// Load the waves and set the globals
LoadWave/J/D/O/P=$path/B="C=1, N=Wavenumber; C=1, N=Absorbance;" file
  duplicate/o Wavenumber $Wavenumberwave
  duplicate/o Absorbance $Absorbancewave
 
End

I even got a method which plots the imported data:

// ------ IR spectra XY data loader & grapher for one spec -----
 
Function LoadAndGraph_IR(genericname, path)
String genericname // Name of file to load or "" to get dialog
String path // Name of path or "" to get dialog
 
String file=genericname+".dpt"
 
Wave Wavenumber, Absorbance
String wnstr="_cm-1"
String Wavenumberwave=genericname+wnstr
String Abstr="_A"
String Absorbancewave=genericname+Abstr
 
// Load the waves and set the globals
LoadWave/J/D/O/P=$path/B="C=1, N=Wavenumber; C=1, N=Absorbance;" file
  duplicate/o Wavenumber $Wavenumberwave
  duplicate/o Absorbance $Absorbancewave
 
// Begin Graphing
Display/k=1/w=(50,20,450,420) $Absorbancewave vs $wavenumberwave;
// SetAxis for MIR
SetAxis left -0.2,3;DelayUpdate
SetAxis bottom 4000,1000
// SetAxisLabels
Label left "Absorbance";DelayUpdate
Label bottom "Wavernumber (cm\\S-1\\M)";DelayUpdate
// Annotate graph
Legend/C/N=text0/A=MC
Textbox/A=LT "Loaded from " + S_fileName
return 0 // Signifies success.
End

But I fail to set it up for all files (with this ending) in one folder. I already tried to adopt code snippets but without success.
Does somebody know how to solve this problem...

Thanks for comments...


Posts: 404
Joined: 2007-03-01
Location: United States

warakurna wrote:
Hej,
But I fail to set it up for all files (with this ending) in one folder. I already tried to adopt code snippets but without success.
Does somebody know how to solve this problem...
Thanks for comments...

Can you clarify what you mean when you say you "fail to set it up for all files"? What goes wrong? Which of your two functions doesn't provide the correct results? Also it would be helpful if you provided a small file that contains data in the format you are loading so that others can use your code directly to test it.

By the way, when you are typing in Igor Pro code on this web site, it's best to enclose the code in <igor></igor> tags, so that it will be colored correctly for Igor. You used <ccode></ccode> tags, which color keywords and functions common to Igor and C, but miss a lot of Igor specific keywords, etc.


jjweimer
jjweimer's picture
Posts: 573
Joined: 2007-08-14
Location: United States

warakurna wrote:
I'm a freshman to Igor and currently I'm working on a procedure to import IR data (wavenumber vs. absorbance) from simple delimited text files.

FWIW, the packages SpXZeigR and/or LinkVS and/or Scroll Traces may be of interest to you. They have been designed from a basis of using Igor to work on data from chemical spectroscopies.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH


warakurna
Posts: 23
Joined: 2008-07-23
Location: Germany

aclight wrote:

Can you clarify what you mean when you say you "fail to set it up for all files"? What goes wrong? Which of your two functions doesn't provide the correct results? Also it would be helpful if you provided a small file that contains data in the format you are loading so that others can use your code directly to test it.

By the way, when you are typing in Igor Pro code on this web site, it's best to enclose the code in <igor></igor> tags, so that it will be colored correctly for Igor. You used <ccode></ccode> tags, which color keywords and functions common to Igor and C, but miss a lot of Igor specific keywords, etc.

Sorry, I did not see the igor tag.
The two functions I posted work good. But I'm not able to figure out how to design a function which loads all the files in one folder or path.
A file with the data is attached.

AttachmentSize
G1.0.txt120.86 KB

Posts: 404
Joined: 2007-03-01
Location: United States

If I understand you correctly, the two functions you posted above work fine, you just want to programatically run those two functions on all files of a certain type in a directory on your disk. If that's correct, I think you can start off with the code snippet at http://www.igorexchange.com/node/1078. But instead of printing the folder/file name, you want to run your functions.

From that code snippet, you want to replace

Printf "%s\t%s%s\r", prefix, path, fileName

with a call to your two functions. Also, you can probably comment out the following line if you don't need the directory name printed to the command line:
Printf "%s%s\r", prefix, path

I would suggest that you change your two functions to take a fileName parameter, instead of genericname. Then to get everything started you would execute something like the following at the Igor command line:

PrintFoldersAndFiles(pathName, ".dpt", 0, 0)

This assumes that you do not want to recurse into subdirectories. You may want to change the name of the function as well and if you do so then obviously you need to change what you type into the command line.

Let me know if I've misunderstood the problem you're having.


warakurna
Posts: 23
Joined: 2008-07-23
Location: Germany

Hej,

You didn't misunderstand! That's exactly what I want to do. The Snippet you linked is a good start. I just inserted it in my procedure file as is and the "PrintFoldersAndFiles" function works good. I get a list of all dpt type files in my history.

But, how to replace the printf term you mentioned. It does not work with simply replacing this line

Printf "%s\t%s%s\r", prefix, path, fileName

with
Load_IR(genericname, path)

from the function in the first post.
It seems to be a bit more complex. Do you have a hint or an explanation.

By now, my knowledge on writing and/or modidying procedures is very limited! Sorry for that...


Posts: 404
Joined: 2007-03-01
Location: United States

Well, you need to alter your function a little if you're passing the full file name. So your function would look something like this:

Function Load_IR(fileName, path)
	String fileName// File name to load, not including the path, or "" to get dialog
	String path // Name of path or "" to get dialog
 
	// Strip the extension from the file name to get the generic name.
	String genericname = fileName[0, strsearch(fileName, ".", inf, 1) - 1]
 
	Wave Wavenumber, Absorbance
	String wnstr="_cm-1"
	String Wavenumberwave=genericname+wnstr
	String Abstr="_A"
	String Absorbancewave=genericname+Abstr
 
	// Load the waves and set the globals
	LoadWave/J/D/O/P=$path/B="C=1, N=Wavenumber; C=1, N=Absorbance;" fileName
	duplicate/o Wavenumber $Wavenumberwave
	duplicate/o Absorbance $Absorbancewave
 
End


Back to top