TXT file problem to load
Frog
- I have a bunch of IR spectra to load in .txt format. in the past I used the little procedure, which works well, but with a new IR software, the file generated look identical but the procedure refuse to load them anymore. See below the procedure and the good and bad spectra. Could any one tell me why the loading as batches of the 'bad' .txt fails compare to the 'good' .txt (see file in attachement).Both are .txt UNICODE UTF-8.
- I also don't understand where comme from the 0 at the end of the new file name.
Thank you for you help and time.
#pragma rtGlobals=1 // Use modern global access method.
Menu "Macros"
Submenu "IR data LMV "
"Load.txt Files", LoadMultipleFiles()
End
End
Function/S LoadMultipleFiles()
Variable refNum
String message = "Select one or more file"
String outputPaths
String fileFilters = "Data Files (*.txt,*.dat):.txt,.dat;"
fileFilters += "All Files:.*;"
Open /D /R /MULT=1 /F=fileFilters /M=message refNum
outputPaths = S_fileName
if (strlen(outputPaths) == 0)
Print "Cancelled"
else
Variable numFilesSelected = ItemsInList(outputPaths, "\r")
Variable i
variable points, newfirstx, newlastx
for(i=0; i String path = StringFromList(i, outputPaths, "\r")
Printf "%d: %s\r", i, path
// Load the actual waves.
String name = ParseFilePath(3, path, ":", 0, 0) // Extract the file name without extension.
name = CleanupName(name, 0)
Print name
LoadWave/A=$name/D/J/W/K=0/V={" ","$",0,0}/L={0,0,0,1,1} path
Print name
Print S_waveNames
String first = StringFromList(0, S_waveNames) // Name of first wave created by LoadWave=first
String second = StringFromList(0, S_waveNames) // Name of second wave created by LoadWave=second
// additional treaments: scalling and duplicate
String AbstrN="N"
String newIR=second
String newIRN=second+AbstrN
SetScale /I x, 5000, 700, " ", $newIR
Duplicate/O $newIR $newIRN
KillWaves/Z first
endfor
endif
return outputPaths // Will be empty if user canceled
End
Could you please re-post your bit of code? It appears to be incomplete (e.g. ending with an incomplete for-statement).
The very first thing I notice between the two text files is that the delimiter has changed from what appears to be a single space to a tab. I would need to see the rest of the code to check for any possible issues.
Best,
Bil
March 19, 2015 at 11:05 am - Permalink
here is the full ipf file. Thank you for having a look.
I have no probleme loading them as delimited text individually, but not as batch.
sylvie
March 19, 2015 at 11:44 am - Permalink
I loaded up your code. Good.txt loaded properly. Bad.txt did not. You should take advantage of the debugger if you aren't familiar with it already (it is fantastically powerful).
I found the issue to be the delimiter ( a space " " ) was hard coded in with the /J and /V flags. You can actually replace the space (" ") with tab ("\t") and get it to load the bad.txt file while failing to load the good.txt file.
LoadWave/A=$name/D/J/W/K=0/V={" ","$",0,0}/L={0,0,0,1,1} path
...
The good.txt file has a space between the numbers. The bad.txt file has a tab between the numbers. The LoadWave will not generate a wavename since it does not see explicitly a space (" ") in the bad.txt file. This issue causes it to error at the duplicate stage of your code since the string $newIR is empty. The simple solution is to replace the /J and /V flags with /G. The /G flag is for general text files and Igor does a good job at deciding what to do with each one. They all get loaded and all get proper names with no errors.
LoadWave/A=$name/D/G/W/K=0/L={0,0,0,1,1} path
...
Let me know if this works.
Cheers,
Bil
March 20, 2015 at 08:09 am - Permalink
Igor automatically names new waves "wave" (or baseName if /N=baseName is used) plus a digit. The digit starts from zero and increments by one for each wave loaded from the file. If the resulting name conflicts with an existing wave, the existing wave is overwritten.
This is so that you can repeatedly load the same filename without having wavename conflicts.
- Bil
March 20, 2015 at 08:15 am - Permalink
Many thank for your help !
yours
sylvie
March 24, 2015 at 04:53 am - Permalink