How to load a datafile containing a space letter
pingerhitachi
Dear Sir/Madam,
I have to load the datafile containing a space letter in the filename, but I did not success.
It seems that Igor does not allow me to load a file with a space letter in the filename.
Here is my program in Igor. Any comments are highly appreciated.
#pragma rtGlobals=1 // Use modern global access method.
////////////////////////////////////////
macro semi_auto_dataformat(RunNo_1st,RunNo_last)
Variable RunNo_1st=0,RunNo_last=0
Prompt RunNo_1st, "Enter the first of RunNo.: "
Prompt RunNo_last, "Enter the last of RunNo.: "
Fun_load_wave(RunNo_1st,RunNo_last,i)
endmacro
Function Fun_load_wave(RunNo_1st,RunNo_last,i)
Variable i
Variable RunNo_1st,RunNo_last
string RunNo
Variable fileNo
string fpath
Open/D/R/T="????"/M="Please select an arbitrary file in the target folder. " fileNo
Variable ftmp
ftmp=strsearch(S_filename, ".CSV", 0)
fpath=S_filename[0,ftmp-3]
print fpath
for (i=RunNo_1st; i<=RunNo_last ; i+=1)
if (i>=100)
RunNo=num2str(i)
elseif (i>=10)
RunNo="0"+num2str(i)
else
RunNo="00"+num2str(i)
endif
// LoadWave/G/D/A=wave "E509AA (1).CSV"
LoadWave/G/D/A=wave fpath+num2str(i)+").CSV"
fpath=S_filename[0,5]+"R"
Save/J/M="\r\n"/W wave0,wave1 as fpath+RunNo+".txt"
killwaves wave0,wave1
endfor
end
////////////////////////////////////////
macro semi_auto_dataformat(RunNo_1st,RunNo_last)
Variable RunNo_1st=0,RunNo_last=0
Prompt RunNo_1st, "Enter the first of RunNo.: "
Prompt RunNo_last, "Enter the last of RunNo.: "
Fun_load_wave(RunNo_1st,RunNo_last,i)
endmacro
Function Fun_load_wave(RunNo_1st,RunNo_last,i)
Variable i
Variable RunNo_1st,RunNo_last
string RunNo
Variable fileNo
string fpath
Open/D/R/T="????"/M="Please select an arbitrary file in the target folder. " fileNo
Variable ftmp
ftmp=strsearch(S_filename, ".CSV", 0)
fpath=S_filename[0,ftmp-3]
print fpath
for (i=RunNo_1st; i<=RunNo_last ; i+=1)
if (i>=100)
RunNo=num2str(i)
elseif (i>=10)
RunNo="0"+num2str(i)
else
RunNo="00"+num2str(i)
endif
// LoadWave/G/D/A=wave "E509AA (1).CSV"
LoadWave/G/D/A=wave fpath+num2str(i)+").CSV"
fpath=S_filename[0,5]+"R"
Save/J/M="\r\n"/W wave0,wave1 as fpath+RunNo+".txt"
killwaves wave0,wave1
endfor
end
What version of Igor are you using? rtGlobals=1 suggests an older version perhaps?
You code works for me in the newest versions never the less.
Alternatively, it could be there is some other non-printable or escape character elsewhere in your file path.
Just FYI you can set the format of your code block to "Igor" in your post and it will appear correctly and be easier to read .e.g
////////////////////////////////////////
macro semi_auto_dataformat(RunNo_1st,RunNo_last)
Variable RunNo_1st=0,RunNo_last=0
Prompt RunNo_1st, "Enter the first of RunNo.: "
Prompt RunNo_last, "Enter the last of RunNo.: "
Fun_load_wave(RunNo_1st,RunNo_last,i)
endmacro
Function Fun_load_wave(RunNo_1st,RunNo_last,i)
Variable i
Variable RunNo_1st,RunNo_last
string RunNo
Variable fileNo
string fpath
Open/D/R/T="????"/M="Please select an arbitrary file in the target folder. " fileNo
Variable ftmp
ftmp=strsearch(S_filename, ".CSV", 0)
fpath=S_filename[0,ftmp-3]
print fpath
for (i=RunNo_1st; i<=RunNo_last ; i+=1)
if (i>=100)
RunNo=num2str(i)
elseif (i>=10)
RunNo="0"+num2str(i)
else
RunNo="00"+num2str(i)
endif
// LoadWave/G/D/A=wave "E509AA (1).CSV"
LoadWave/G/D/A=wave fpath+num2str(i)+").CSV"
fpath=S_filename[0,5]+"R"
Save/J/M="\r\n"/W wave0,wave1 as fpath+RunNo+".txt"
killwaves wave0,wave1
endfor
end
September 4, 2021 at 02:53 am - Permalink
It is not completely clear to me what you are trying to achieve. I 'guess' you want to write a function which loads the CSV files and saves them back as text. The following modified code will do this:
Variable RunNo_1st, RunNo_last
Variable fileNo, i
Open/D/R/F="Data Files (*.csv):.csv;"/M="Please select an arbitrary file in the target folder." fileNo
if (!strlen(S_filename))
return -1
endif
Variable ftmp=strsearch(S_filename, "(", 0)
String fpath=S_filename[0,ftmp-2]
for (i = RunNo_1st; i <= RunNo_last ; i+=1)
String RunNo
sprintf RunNo, "%03d", i
LoadWave/Q/G/D/A/ENCG=4 fpath+" ("+num2str(i)+").CSV"
Save/O/J/M="\r\n"/W wave0,wave1 as fpath+"R"+RunNo+".txt"
KillWaves wave0,wave1
endfor
End
Just run:
Fun_load_wave(1,2)
to convert your two test CSV files.
September 4, 2021 at 03:11 am - Permalink
This should not be a problem.
Please describe what version of Igor you are using and exactly what the symptom (error message or other unwanted behavior) is.
If you are running Igor Pro 6, paths containing characters that are not part of "Language for non-Unicode Programs" will not work. Move the input file to some simple path that uses only ASCII characters, like "C:\Users\<user>\MyIgorData".
September 4, 2021 at 03:48 am - Permalink