Sort multiple waves at the same time
mwpro
My codes are
function sortwave(timestamp)
wave timestamp
string listwave
variable i
duplicate/o timestamp timestamp1
listwave =wavelist ("*pptv1",",","")
for (i=0;i<itemsinlist(listwave);i+=1)
string datastring = stringfromlist(i, listwave, ",")
wave compound= $datastring
duplicate/o timestamp timestamp1
sort timestamp1 timestamp1, compound
killwaves timestamp1
endfor
duplicate timestamp timestamp1
sort timestamp1 timestamp1
end
Thank you!
wave timestamp
string listwave
variable i
duplicate/o timestamp timestamp1
listwave =wavelist ("*pptv1",",","")
for (i=0;i<itemsinlist(listwave);i+=1)
string datastring = stringfromlist(i, listwave, ",")
wave compound= $datastring
duplicate/o timestamp timestamp1
sort timestamp1 timestamp1, compound
killwaves timestamp1
endfor
duplicate timestamp timestamp1
sort timestamp1 timestamp1
end
Thank you!
WaveList
:Variable n=CountObjectsDFR(MyFolder, 1)
// Creates a list of all waves in MyFolder
Make/FREE/O/WAVE/N=(n) AllWaves=WaveRefIndexedDFR(MyFolder, p)
But how do you know which wave corresponds to which time stamp? What is the format of the time stamps? date/time, milliseconds? Once that is sorted it's easy:
Wave/WAVE MeasurementWaves
Sort TimeStampWave, TimeStampWave, MeasurementWaves
Your code seems to be sorting the values in each of the measurement waves instead of the waves themselves. Is that what you want to do?
Wave/WAVE MeasurementWaves
Variable n=NumPnts(MeasurementWaves)
for (i=0; i<n; i+=1)
Wave SingleWave=MeasurementWaves[i]
Sort TimeStampWave, SingleWave // This will not change the TimeStampWave
endfor
April 1, 2017 at 02:25 am - Permalink
1) Create a sort command in a string, adding each wave name (possibly with full data folder path) plus a comma to the Sort command. Then use Execute the run the command.
2) If you don't want to sort the key wave, just use Sort on a single value wave at a time in a loop. If you want to sort the key wave as well, you could use MakeIndex to create an index wave and use the index wave with IndexSort in a loop.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
April 3, 2017 at 09:12 am - Permalink
What is the reason for using execute and sort command in string? Is it because the command would be too long? Does it still have to observe the 400-character limit? "Help" for Sort says "The algorithm used does not maintain the relative position of items with the same key value." I don't quite understand what this means.
So it seems to use sort in a loop is a choice for the task. I can get around killing waves in loop by using sort. Are there differences in using Sort or IndexSort in the loop? I know IndexSort uses an extra wave from MakeIndex to sort the sortedwaves. Is one better than the other in loop? It seems I can use both whether I want to sort the sortkeywave or not.
When I try to operate on a wave that is in a different data folder do I switch to the other data folder, reference the wave and then switch back or can I directly reference the wave using a path without changing folders? How to use command to move waves from one datafolder to another?
Thanks!
April 3, 2017 at 02:34 pm - Permalink
It's just that using a string variable that contains a list of wave names simply doesn't work. The parsing for Sort doesn't know how to look inside a string expression. It would be nice, but it doesn't.
if you have a key wave that has more than one instance of a value (say, {1, 3, 2, 3, 5}) there is no guarantee that the value waves will be sorted with point 1 before point 3. Igor is using a fast sort algorithm that doesn't maintain pre-existing ordering in case of ties.
That's all true. The complexity of Sort should be O(n log(n)); the complexity of IndexSort, once the index wave is made, should be O(n). Neglecting constant overhead, that means IndexSort will be faster in the loop. In fact, IndexSort in a loop should be almost as fast as Sort on a list since internally Sort works by making an index, then re-arranging the points in each wave.
Your loop will look something like
WAVE w = $StringFromList(i, listofwaves)
IndexSort indexWave, w
endfor
(I haven't actually compiled or run this "code").
Have you found the command MoveWave?
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
April 3, 2017 at 04:16 pm - Permalink
Thanks again!
April 4, 2017 at 04:46 pm - Permalink
LoadData
. It can load waves, variables, strings, and even data folders from other experiments.HJ
April 5, 2017 at 01:25 am - Permalink
These projects save a snapshot of open graphs, panels, etc. in an experiment as Igor notebooks. To some extent you can browse a saved experiment in as much as waves were displayed in graphs at the time the snapshot was created, but waves cannot be loaded using these snapshots.
http://www.igorexchange.com/project/OSXPreviewGenerator
http://www.igorexchange.com/project/JTG_ExperimentPreview
Maybe this helps?
April 5, 2017 at 05:35 am - Permalink
April 5, 2017 at 05:46 pm - Permalink
Wow! There is some amazing stuff packed in those two experiments. Thanks.
In case you are interested in somewhat the inverse problem, this package will create a stand-alone snapshot experiment of all content from the frontmost graph.
http://www.igorexchange.com/project/SnapIt
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
April 5, 2017 at 07:03 pm - Permalink
April 9, 2017 at 10:48 am - Permalink