Can't rename or duplicate the file
jgladh
I have tried to make a script to load ibw files, and that is no bigger problem, but when I try to rename or duplicate the files in the same script something happens and it don't work. I have copied my script below and I really hope that someone can tell me what I have done wrong.
Kindest regards
Jörgen
Function Load_ibw_Wave(start_Num, end_Num)
String start_Num, end_Num
String root:S_waveNames
String fileName, old_fileName, S_stop_Num
String file_List, file_Path, file_Num, new_FileName
Variable i=0, numItems, List_Num, Match_Num, file_Length
Variable single_Num=1, stop_Num=str2num(end_Num)+1, count_up=str2num(start_Num)
start_Num=start_Num+"*"
end_Num=end_Num+"*"
S_stop_Num="0"+num2str(stop_Num)+"*"
NewPath/O/Q my_Path "Macintosh HD:Users:gladh:Documents:Projects:DESY 2018"
file_List = IndexedFile(my_Path, -1, ".ibw")
file_List = SortList(file_List, ";", 16)
numItems = ItemsInList(file_List)
do
fileName = StringFromList(i, file_List)
Match_Num=StringMatch(fileName, start_Num)
if(Match_Num==1)
Match_Num=0
fileName = StringFromList(i, file_List)
file_Length=strlen(fileName)
LoadWave/O/A/P=my_Path/E=0/Q fileName
file_Num=fileName[1,3]
old_fileName=S_waveNames
new_FileName=file_Num+old_fileName
Duplicate/O $old_fileName, $new_FileName; KillWaves root:$old_fileName
count_up+=1
start_Num="0"+num2str(count_up)+"*"
endif
i+=1
if(stringmatch(start_Num,S_stop_Num)==1)
Break
endif
while(i<numItems)
End
String start_Num, end_Num
String root:S_waveNames
String fileName, old_fileName, S_stop_Num
String file_List, file_Path, file_Num, new_FileName
Variable i=0, numItems, List_Num, Match_Num, file_Length
Variable single_Num=1, stop_Num=str2num(end_Num)+1, count_up=str2num(start_Num)
start_Num=start_Num+"*"
end_Num=end_Num+"*"
S_stop_Num="0"+num2str(stop_Num)+"*"
NewPath/O/Q my_Path "Macintosh HD:Users:gladh:Documents:Projects:DESY 2018"
file_List = IndexedFile(my_Path, -1, ".ibw")
file_List = SortList(file_List, ";", 16)
numItems = ItemsInList(file_List)
do
fileName = StringFromList(i, file_List)
Match_Num=StringMatch(fileName, start_Num)
if(Match_Num==1)
Match_Num=0
fileName = StringFromList(i, file_List)
file_Length=strlen(fileName)
LoadWave/O/A/P=my_Path/E=0/Q fileName
file_Num=fileName[1,3]
old_fileName=S_waveNames
new_FileName=file_Num+old_fileName
Duplicate/O $old_fileName, $new_FileName; KillWaves root:$old_fileName
count_up+=1
start_Num="0"+num2str(count_up)+"*"
endif
i+=1
if(stringmatch(start_Num,S_stop_Num)==1)
Break
endif
while(i<numItems)
End
The solution might depend a little on your data structure.
Did you enable the debugger (Right click on the code and select "Enable Debugger" & "Debug on Error")?
Where does the code stop? Is there a more specific error message given?
On a first shot, I'd check the content of S_wavenames (plural! there might be several) and whether "new_FileName" is a valid name in your Igor version.
displayhelptopic "Wave Names"
HJ
May 20, 2018 at 03:15 pm - Permalink
One thing to check is the namespace of the S_wavenames variable. I think I ran into a similar problem assuming that the string in the root folder was the being undated with the load function. It appeared that the loadwave function creates an implicit local variable S_wavenames. By explicitly having the previously created string may not have the updated contents.
I would suggest a simple print statement if you are not comfortable with the debugger.
Andy
May 20, 2018 at 03:44 pm - Permalink
This makes no sense:
For one thing, S_waveNames does not exist until after LoadWave executes.
Your use of root: (KillWaves root:$old_fileName) is also wrong. LoadWave works in the current data folder which may or may not be root.
I suspect there may be other problems.
Instead of this:
new_FileName=file_Num+old_fileName
Duplicate/O $old_fileName, $new_FileName; KillWaves root:$old_fileName
your might try this:
String new_WaveName = file_Num + old_WaveName
Duplicate/O $old_WaveName, $new_WaveName
Wave oldWave = $old_WaveName
KillWaves oldWave
The whole approach of loading the wave, duplicating it with a new name, and killing the loaded wave is unnecessary. You can tell LoadWave to assign the desired final name using the /B flag. Then you don't need any renaming, duplication or killing of waves.
It would make more sense if the start_Num, end_Num parameters were numeric (Variable), not strings.
May 20, 2018 at 07:00 pm - Permalink
Jörgen
May 21, 2018 at 06:35 am - Permalink