load IR data from many text files
Frog
I need to load a large amount of IR data from text files having 2 column, first volume is wavemumber and second is absorbante. I need to extract them, remane them using the file name, scale them and duplicata them twice. I wrote a proc but cannot figure out where it bugged.
could anyone give me an hand with my short macro ? I have attached the .ipf.
thank you,
Sylvie
Load_IR() references the waves Wavenumber and Absorbance in the present data folder. Do they exist before you run the function?
Maybe it's easier if you can post also the raw data.
July 24, 2014 at 12:14 am - Permalink
thank you for spending time on my macro.
sylvie
July 24, 2014 at 12:26 am - Permalink
July 24, 2014 at 12:28 am - Permalink
// Load the actual waves.
String name = ParseFilePath(3, path, ":", 0, 0) // Extract the file name without extension.
name = CleanupName(name, 0)
LoadWave/A=$name/D/J/W/K=0/V={" "," $",0,0}/L={0,0,0,1,1} path
// addiitonal treaments: scalling and duplicate
wave newIR=$name
setscale /I x, 5000, 700, $newIR
duplicate newIR newIR_N
duplicate newIR newIR_F
help anyone ?
July 24, 2014 at 02:19 am - Permalink
You need the same wave three times?
String pathName // Name of an Igor symbolic folder created by Misc->NewPath
String fileName
Variable index=0
if (strlen(pathName) == 0)
String message = "Select a directory containing only Sylvie data files"
NewPath/O/M=message SylvieDataPath // This displays a dialog in which you can select a folder
if (V_flag != 0)
return V_flag // -1 means user canceled
endif
pathName = "SylvieDataPath"
endif
Variable result= 0
do // Loop through each file in folder
fileName = IndexedFile($pathName, index, ".txt") // catch .txt files in folder
if (strlen(fileName) == 0) // No more files ?
break // Break out of loop
endif
result = Load_IR(fileName, pathname)
if( result == -1 )
break // user cancelled or no waves in this file (which we take to be an error)
endif
index += 1
while (1)
if (Exists("SylvieDataPath")) // Kill temp path if it exists
KillPath temporaryPath
endif
return result // 0 Signifies success.
End
Function Load_IR(fileName, pathName)
String fileName// File name to load, not including the path, or "" to get dialog
String pathName // 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, ".txt", inf, 1) - 1]
String Abstr="_A"
String AbstrN="_N"
String AbstrF="_F"
String Wavenumberwave=genericname
String Absorbancewave=genericname+Abstr
String AbsorbancewaveN=genericname+AbstrN
String AbsorbancewaveF=genericname+AbstrF
//NewPath/O path, pathName
LoadWave/A/G/D/O/P=$PathName/B="C=1, N=Wavenumber; C=1, N=Absorbance;" fileName
Wave Wavenumber, Absorbance
SetScale/I x, WaveMax(Wavenumber), WaveMin(Wavenumber), "", Absorbance
Duplicate/O Absorbance $Absorbancewave, $AbsorbancewaveN, $AbsorbancewaveF
KillWaves/Z Wavenumber, Absorbance
return 0 // Signifies success.
End
hm….Sylvie … IR data….is that you??
Cheers
Christian….formerly at BGI ;-)
July 24, 2014 at 02:28 am - Permalink
let me try the new macro. ..coming back soon
July 24, 2014 at 02:32 am - Permalink
nop, the macro does not load the files. Anyway, I have a new version, way shorter, and which load the file succesffully, and rename them, BUT the scaling and duplicata still bugged. do you know why ?
thank again for your time !
in attachment new macro.
// Load the actual waves.
String name = ParseFilePath(3, path, ":", 0, 0) // Extract the file name without extension.
name = CleanupName(name, 0)
LoadWave/A=$name/D/J/W/K=0/V={" "," $",0,0}/L={0,0,0,1,1} path
// additional treaments: scalling and duplicate
String AbstrN="N"
String AbstrF="F"
String newIR=name
String newIRN=name+AbstrN
String newIRF=name+AbstrF
setscale /I x, 5000, 700, "", $newIR
Duplicate/O newIR $newIRN, $newIRF
July 24, 2014 at 03:01 am - Permalink
Print S_waveNames
after the LoadWave command.
Or use the Igor debugger. For details execute:
DisplayHelpTopic "The Debugger"
You will then see that the string variable name does not contain the name of any wave loaded. It is just the base name (e.g., "wave" is the base name of "wave0", "wave1").
After the LoadWave command add this:
String second = StringFromList(0, S_waveNames) // Name of second wave created by LoadWave
Then use either first or second instead of your name variable.
Also, since newIR is t he name of a string variable containing a wave name you must use a $ before newIR in your Duplicate command. For details execute:
DisplayHelpTopic "Converting a String into a Reference Using $"
July 24, 2014 at 05:06 am - Permalink
I post the .ipf file below for other users
I have another question then, when the .txt is load, it add a 0 at the end of the file name ( 'olivine1.txt' becomes 'olivine10' )
I try to use
Print RemoveEnding("second" , "0")
but I could not get the syntaxe right.
any advise?
sylvie
July 24, 2014 at 06:25 am - Permalink
String firstName = name + "First"
String secondName = name + "Second"
String columnInfoStr
sprintf columnInfoStr, "N='%s';N='%s';", firstName, secondName
LoadWave/B=columnInfoStr ...
<pre><code class="language-igor">
July 24, 2014 at 07:50 am - Permalink