PEARL Procedures rev-distro-1.6.0-0-gcf1399e-dirty Igor procedures for the analysis of PEARL data

- Main Page
- Related Pages
- Packages
- Namespaces
- Files

- File List
- Globals

pearl-tools.ipf
Go to the documentation of this file.
1 #pragma rtGlobals=3// Use modern global access method and strict wave access.
2 #pragma version = 1.00
3 #pragma IgorVersion = 6.2
4 #pragma ModuleName = PearlTools
5 #include "pearl-gui-tools"
6
7 // general programming tools for Igor
8
9 // $Id$
10 // author: matthias.muntwiler@psi.ch
11 // Copyright (c) 2009-14 Paul Scherrer Institut
12
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 // http://www.apache.org/licenses/LICENSE-2.0
17
18 variable DefaultWaveIterator(wave w, string* sdata){
19 // function prototype for IterateWaves
20 wave w// wave which the iterator is supposed to work on
21 string &sdata// string with additional data, shared between calls
22 // this is a pass-by-reference argument,
23 // the function may modify the string
24 };
25
26 variable AppendToGraphIterator(wave w, string* sdata){
27 // append iterated waves to the current graph
28 wave w// wave to be displayed
29 string &sdata// not used
30
31 appendtograph w
32 };
33
34 variable SumWavesIterator(wave w, string* sdata){
35 // sum waves into one result wave
36 wave w// wave which the iterator is supposed to work on
37 string &sdata// name of the result wave, can include absolute path
38 // the wave must exist and compatible with the summands
39 // the caller is responsible for initialization of the wave
40
41 wave result = $sdata
42 result += w
43 };
44
45 string IterateWaves(string matchStr, funcref iterator, string sdata){
46 // iterate over all waves matching a specified pattern (see built-in WaveList function),
47 // passing each wave to a user-defined iterator function
48 string matchStr// matchStr as for WaveList
49 funcref DefaultWaveIterator iterator// iterator function
50 // use the DefaultWaveIterator function as a template
51 string sdata// data string passed to iterator function
52 // the iterator may modify the string
53 // the function returns the string at the end
54
55 string wlist = WaveList(matchStr, ";", "")
56 variable n = ItemsInList(wlist, ";")
57 variable i
58 for (i = 0; i < n; i += 1)
59 wave w = $(StringFromList(i, wlist, ";"))
60 iterator(w, sdata)
61 endfor
62 return sdata
63 };
64
65 variable DefaultFolderIterator(dfref df, string* sdata){
66 // function prototype for IterateWaves
67 dfref df// data folder reference which the iterator is supposed to work on
68 string &sdata// string with additional data, shared between calls
69 // this is a pass-by-reference argument,
70 // the function may modify the string
71
72 // switch to requested data folder
73 setdatafolder df
74 // for testing
75 print getdatafolder(1)
76 // no need to switch back to original folder
77 };
78
79 string IterateDataFolders(string matchStr, funcref iterator, string sdata, string progress_title = defaultValue){
80 // iterate over all data folders matching a specified pattern in the current data folder,
81 // passing each folder to a user-defined iterator function
82 string matchStr// matchStr as for the built-in stringmatch function
83 funcref DefaultFolderIterator iterator// iterator function
84 // use the DefaultFolderIterator function as a template
85 string sdata// data string passed to iterator function
86 // the iterator may modify the string
87 // the function returns the string at the end
88 string progress_title// title of the progress window (optional)
89 // if not specified or empty, the progress window will not be shown.
90 // if the progress window is show, the user can abort the iteration.
91 // the function result does not indicate whether the iteration was completed or aborted.
92 // the iterator and caller must take care of leaving the data in a consistent state.
93
94 if (ParamIsDefault(progress_title))
95 progress_title = ""
96 endif
97 variable show_progress = strlen(progress_title) > 0
98
99 dfref origdf = GetDataFolderDFR()
100 dfref curdf
101 variable index = 0
102 variable abort_req = 0
103 string objName
104
105 variable ndf = CountObjectsDFR(origdf, 4)
106 if (show_progress)
107 display_progress_panel(progress_title, "", ndf)
108 endif
109
110 do
111 objName = GetIndexedObjNameDFR(origdf, 4, index)
112 if (strlen(objName) == 0)
113 break
114 endif
115 if (stringmatch(objname, matchstr))
116 if (show_progress)
117 abort_req = update_progress_panel(index, message=objName)
118 if (abort_req)
119 break
120 endif
121 endif
122 setdatafolder origdf
123 curdf = $(":" + objname)
124 iterator(curdf, sdata)
125 endif
126 index += 1
127 while(1)
128
129 if (show_progress)
130 kill_progress_panel()
131 endif
132
133 setdatafolder origdf
134 return sdata
135 };
136
kill_progress_panel
variable kill_progress_panel()
Definition: pearl-gui-tools.ipf:50
IterateDataFolders
string IterateDataFolders(string matchStr, funcref iterator, string sdata, string progress_title=defaultValue)
Definition: pearl-tools.ipf:79
display_progress_panel
variable display_progress_panel(string title, string message, variable progress_max)
Definition: pearl-gui-tools.ipf:18
AppendToGraphIterator
variable AppendToGraphIterator(wave w, string *sdata)
Definition: pearl-tools.ipf:26
IterateWaves
string IterateWaves(string matchStr, funcref iterator, string sdata)
Definition: pearl-tools.ipf:45
DefaultWaveIterator
variable DefaultWaveIterator(wave w, string *sdata)
Definition: pearl-tools.ipf:18
update_progress_panel
variable update_progress_panel(variable progress, string message=defaultValue, variable progress_max=defaultValue)
Definition: pearl-gui-tools.ipf:32
SumWavesIterator
variable SumWavesIterator(wave w, string *sdata)
Definition: pearl-tools.ipf:34
DefaultFolderIterator
variable DefaultFolderIterator(dfref df, string *sdata)
Definition: pearl-tools.ipf:65