Missing wave, skip it with AbortOnRTE and try-catch
chrisNell
I need to load a lots of waves from several experiments but unfortunately some of them are missing. Usually, when I load the wave, I manually click on "skip this wave" when the Missing wave File window appears, but I want to have a function that do it automatically without modifying my loadwave function.
Execute "LoadAllWave.upx"
// And in LoadAllWave.upx I have the following code:
LoadWave/C /P=home "DA121_TestRheo_ch2_4008.ibw"
LoadWave/C /P=home "DA121_TestRheo_ch3_4008.ibw"
LoadWave/C /P=home "DA121_TestRheo_ch2_4009.ibw"
LoadWave/C /P=home "DA121_TestRheo_ch3_4009.ibw"
LoadWave/C /P=home "DA121_TestRheo_ch2_4010.ibw"
LoadWave/C /P=home "DA121_TestRheo_ch3_4010.ibw"
LoadWave/C /P=home "DA121_SponHold30_ch2_4011.ibw"
LoadWave/C /P=home "DA121_SponHold30_ch3_4011.ibw"
LoadWave/C /P=home "DA121_IV_ch2_4012.ibw"
LoadWave/C /P=home "DA121_IV_ch3_4012.ibw"
LoadWave/C /P=home "DA121_IV_ch2_4013.ibw"
LoadWave/C /P=home "DA121_IV_ch3_4013.ibw"
LoadWave/C /P=home "DA121_IV_ch2_4014.ibw"
LoadWave/C /P=home "DA121_IV_ch3_4014.ibw"
LoadWave/C /P=home "DA121_IV_ch2_4015.ibw"
LoadWave/C /P=home "DA121_IV_ch3_4015.ibw"
LoadWave/C /P=home "DA121_IV_ch2_4016.ibw"
LoadWave/C /P=home "DA121_IV_ch3_4016.ibw"
LoadWave/C /P=home "DA121_IV_ch2_4017.ibw"
LoadWave/C /P=home "DA121_IV_ch3_4017.ibw"
end
// I was thinking about something like:
Function CN_trycatchwithExp()
string pathforExp = "D:\002_DACoding\LoadAllWave.upx", cmd
sprintf cmd "Execute/P \"LOADFILE %s\"", pathforExp
try
Execute cmd; AbortOnRTE
catch
if (V_AbortCode == -4)
Print "Error"
Variable CFerror = GetRTError(1) // 1 to clear the error
Print GetErrMessage(CFerror)
endif
endtry
End
//But of course it doesn't change anything...
//Thank a lot if you know how to do it or if you have a clue
//Chris
// And in LoadAllWave.upx I have the following code:
LoadWave/C /P=home "DA121_TestRheo_ch2_4008.ibw"
LoadWave/C /P=home "DA121_TestRheo_ch3_4008.ibw"
LoadWave/C /P=home "DA121_TestRheo_ch2_4009.ibw"
LoadWave/C /P=home "DA121_TestRheo_ch3_4009.ibw"
LoadWave/C /P=home "DA121_TestRheo_ch2_4010.ibw"
LoadWave/C /P=home "DA121_TestRheo_ch3_4010.ibw"
LoadWave/C /P=home "DA121_SponHold30_ch2_4011.ibw"
LoadWave/C /P=home "DA121_SponHold30_ch3_4011.ibw"
LoadWave/C /P=home "DA121_IV_ch2_4012.ibw"
LoadWave/C /P=home "DA121_IV_ch3_4012.ibw"
LoadWave/C /P=home "DA121_IV_ch2_4013.ibw"
LoadWave/C /P=home "DA121_IV_ch3_4013.ibw"
LoadWave/C /P=home "DA121_IV_ch2_4014.ibw"
LoadWave/C /P=home "DA121_IV_ch3_4014.ibw"
LoadWave/C /P=home "DA121_IV_ch2_4015.ibw"
LoadWave/C /P=home "DA121_IV_ch3_4015.ibw"
LoadWave/C /P=home "DA121_IV_ch2_4016.ibw"
LoadWave/C /P=home "DA121_IV_ch3_4016.ibw"
LoadWave/C /P=home "DA121_IV_ch2_4017.ibw"
LoadWave/C /P=home "DA121_IV_ch3_4017.ibw"
end
// I was thinking about something like:
Function CN_trycatchwithExp()
string pathforExp = "D:\002_DACoding\LoadAllWave.upx", cmd
sprintf cmd "Execute/P \"LOADFILE %s\"", pathforExp
try
Execute cmd; AbortOnRTE
catch
if (V_AbortCode == -4)
Print "Error"
Variable CFerror = GetRTError(1) // 1 to clear the error
Print GetErrMessage(CFerror)
endif
endtry
End
//But of course it doesn't change anything...
//Thank a lot if you know how to do it or if you have a clue
//Chris
There may be other commands to do this more efficiently, but this is a start.
August 19, 2015 at 08:31 am - Permalink
IndexedFile(pathName, -1, "*.ibw")
to return a list of all .ibw files. Then just loop through each filename in the list and load it in.August 19, 2015 at 11:10 pm - Permalink
Hello,
Thank you for the replies. I tried with sprintf cmd "Execute/P/Z \"LOADFILE %s\"", fullFilePath but the result is the same. I know that it should be linked to Loadwave/Z but I can't really access this command. Can I set the V_flag in order that it says the same during all the process?
The problem is that my file "LoadAllWave.upx" is a bit more complicated than what I put on my previous post.
All the wave are in different folders and need to be organized in the same way within the experiment. This is why I directly use the unpacked experiment file. So I don't want to change it but I want to do it before/during the execution of my .upx file.
It is more like:
NewPath/Z p "C:"
NewPath/Z Stimuli "C:PulseQ:config:Olivier:Stimuli:"
NewPath/Z DataSet_OSRMReCode "::::"
NewPath/Z ASSProject "C:PulseQ:config:ASSProject:"
NewPath/Z PQStimulus "C:Program Files (x86):WaveMetrics:Igor Pro Folder:"
NewPath/Z X001_150410A02_OH "::"
NewPath/Z DefaultOpenProtStim "::::"
NewPath pathLoad "D:002_DACoding:001_150410A02_OH:001_150410A2MMP16SNcDA_OH:"
ReadVariables
LoadWave/C /P=home "DA117_APWaveform_ch2_1053.ibw"
LoadWave/C /P=home "DA117_APWaveform_ch2_1054.ibw"
LoadWave/C /P=home "DA117_APWaveform_ch2_1055.ibw"
LoadWave/C /P=home "DA117_APWaveform_ch2_1056.ibw"
LoadWave/C /P=home "DA117_APWaveform_ch2_1057.ibw"
LoadWave/C /P=home "DA117_APWaveform_ch2_1058.ibw"
LoadWave/C /P=home "DA117_APWaveform_ch2_2028.ibw"
...
C /P=home "DA117_TestSpikeRec_ch3_4132.ibw"
LoadWave/C /P=home "DA117_WhiteNoise_ch2_4173.ibw"
LoadWave/C /P=home "DA117_WhiteNoise_ch3_4173.ibw"
NewDataFolder/S Packages
NewPath home ":001_150410A2MMP16SNcDA_OH:Packages:"
NewDataFolder/S Control
NewPath home ":001_150410A2MMP16SNcDA_OH:Packages:Control:"
ReadVariables
LoadWave/C /P=home "gbox.ibw"
LoadWave/C /P=home "gpos.ibw"
LoadWave/C /P=home "prop.ibw"
LoadWave/C /P=home "fonts.ibw"
NewDataFolder/S ListBox
NewPath home ":001_150410A2MMP16SNcDA_OH:Packages:Control:ListBox:"
ReadVariables
SetDataFolder ::
SetDataFolder ::
NewDataFolder/S PulseQ
NewPath home ":001_150410A2MMP16SNcDA_OH:Packages:PulseQ:"
ReadVariables
NewDataFolder/S Protocol
NewPath home ":001_150410A2MMP16SNcDA_OH:Packages:PulseQ:Protocol:"
ReadVariables
LoadWave/C /P=home "type.ibw"
LoadWave/C /P=home "chan.ibw"
LoadWave/C /P=home "gain.ibw"
LoadWave/C /P=home "offset.ibw"
LoadWave/C /P=home "col.ibw"
LoadWave/C /P=home "ptr.ibw"
...
<pre><code class="language-igor">
August 20, 2015 at 12:49 am - Permalink
August 20, 2015 at 01:49 am - Permalink
//Call this function before the loadwave operation to determine if the file exists
//returns 0 for file not found and 1 for file found
String sPath //name of symbolic path
String sFileName //file to open, for example: "junk.ibw"
Variable n_refnum
Variable RtnVal = 0 //default for file not opened
Open/R/Z/P=$sPath n_refnum as sFileName
if( V_flag == 0 ) //file opened
Close n_refnum
RtnVal = 1 //success
endif
return RtnVal
End
The Open operation can be used to determine if a file exists at the specified path location. Your code indicates that you know the location and names of files you want to open. Just feed those values to this function to determine if they exist.
I did test this function and it did work in my limited testing.
There may be far better ways to accomplish your goal. This is the first that came to my mind. You could take KurtB's advice and get a list of all ".ibw" files in the directory of interest. If this list might contain some files you're not interested in loading, then you could compare the list of files you want to load against the indexedfile list before attempting to load them.
August 20, 2015 at 05:50 am - Permalink
1) You are using Execute to run a command containing Execute/P. I don't think you need Execute at all, much less two layers of Execute. Just put the file name into a string variable and pass that to LoadWave instead of the quoted string. As a really simple example that doesn't involve computation of the file name:
LoadWave/C/P=home fname
That is equivalent to your first LoadWave command above.
2) I don't know off the top of my head if try-catch works with Execute. I suppose it would. But what I can definitely tell you is that Execute/P will make the try-catch not work at all. Execute/P means "Execute later when my function isn't running", and that means that the error occurs at a time when the try-catch has been done and is no longer running. All the try-catch tells you is that the Execute command that invokes Execute/P worked- it put the Execute/P command into the operation queue for later execution.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
August 20, 2015 at 11:31 am - Permalink
Thank you for your comments, the fact I want to run multiple experiment this is why I put them in a operation queue, with that I can start my code with hundred experiments, let it run overnight at see the result the next day.
I use two layers of Execute simply because the code of my batch function comes from the code provided in Igor:
Choose: File->Example Experiments->Programming->Multi-Experiment Process.
However, I don't really see the advantage of such construction but it doesn't come from me. But I will try to put in the queue a complete function that do execute within a try-catch function, maybe I will be able to catch the error like this.
@jtigor:
This example code is probably a nice solution to avoid the mistake, so thank you very much for it. My first idea was to ignore the missing waves and still execute my experiment but maybe the best solution is to check within the .uxp file what he will load before running it. With that I can skip the whole experiment for my batch script and then delete the line that want to load missing waves by hand. I notice that if I load the experiment and skip the missing wave, then save the experiment, the command line that want to load them disappears, so it is a waist of time but maybe the best solution to debug my experiment before running my batch script on them.
August 21, 2015 at 01:59 am - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
August 21, 2015 at 02:48 pm - Permalink
Ok, thanks a lot for the reply, I guess that it will be better to do it by hand and save the uxp file when it's done with the correction.
Best
Christophe
August 25, 2015 at 12:23 am - Permalink