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