-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_batch.pro
More file actions
213 lines (196 loc) · 9.99 KB
/
read_batch.pro
File metadata and controls
213 lines (196 loc) · 9.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
;; Copyright 2018 Euratom/CCFE/TuE
;; Permission is hereby granted, free of charge, to any person obtaining a copy of this
;; software and associated documentation files (the "Software"), to deal in the Software
;; without restriction, including without limitation the rights to use, copy, modify,
;; merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
;; permit persons to whom the Software is furnished to do so, subject to the following
;; conditions:
;; The above copyright notice and this permission notice shall be included in all copies
;; or substantial portions of the Software.
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
;; INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
;; PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
;; CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
;; OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
function read_batch, batchfile
;
; reads the 'batchfile' xml-file in the 'run' directory and returns the command-structure array.
;
; The command-structure array is an array, with as elements a structure.
; This structure has following fields
; - struct.name : string containing the name of the command (i.e. 'calc', 'filter', 'merge', 'plot', 'compare2', 'compareN')
; - struct.setting : string containing the name of the setting file (if any)
; - struct.input : pointer to a string or string array containing the name(s) of the input file(s)
; (because we don't know how many input files there are this has to be a pointer)
; - struct.output : string containing the name of the output file (if any)
; - struct.prefix : string containing the prefix for figure-titles (if any)
; - struct.labels : string-array (size 2) containing the 2 labels used when 2 spectra are compared (if any)
; - struct.param : string containing the parameter file used when N spectra are compared (if any)
;
;
; REMARK: pointers are used. This means one has to be careful to free pointers that are no longer used!
; (otherwise you end up spoiling all your memory!)
; v1.0, mdebock 24/07/2007
;
; open document
;--------------
oDocument = obj_new('IDLffXMLDOMDocument', filename=batchfile)
; get the top node. REMARK: this has to be called 'stark_run'!
;-------------------------------------------------------------
nodelist0 = oDocument->GetElementsByTagName('stark_run')
topnode = nodelist0->Item(0)
; get the 1st level nodes
;------------------------
nodelist = topnode->GetChildNodes()
n_nodes = nodelist->GetLength()
; and loop through them
;----------------------
cmdarr = create_struct('name','','setting','','input',ptr_new(''),$ ; dummy first element of
'output','','prefix','','labels',['',''],'param','') ; the command-structure array
for i=0,n_nodes-1 do begin
; get the node name
node = nodelist->Item(i)
name = node->GetNodeName()
; There are only 6 node names accepted: 'calc', 'filter', 'merge', 'plot', 'compare2' and 'compareN'
name = strlowcase(name)
skip = 0
case name of
'calc' : begin
; get the node's attributes
attributes = node->GetAttributes()
; the get attributes 'settingfile' and 'outputfile'
settingAtt = attributes->getNamedItem('settingfile')
outputAtt = attributes->getNamedItem('outputfile')
; get string values of each these 2 attributes
setting = settingAtt->getNodeValue()
setting = strtrim(setting,2)
output = outputAtt->getNodeValue()
output = strtrim(output,2)
; the other fields in the command-structure are empty for the 'calc'-command
input = ptr_new('')
prefix = ''
labels = ['','']
param = ''
end
'filter' : begin
; get the node's attributes
attributes = node->GetAttributes()
; the get attributes 'settingfile', 'inputfile' and 'outputfile'
settingAtt = attributes->getNamedItem('settingfile')
inputAtt = attributes->getNamedItem('inputfile')
outputAtt = attributes->getNamedItem('outputfile')
; get string values of each these 3 attributes
setting = settingAtt->getNodeValue()
setting = strtrim(setting,2)
output = outputAtt->getNodeValue()
output = strtrim(output,2)
inputstr= inputAtt->getNodeValue()
inputstr= strtrim(inputstr,2)
input = ptr_new(inputstr)
; the other fields in the command-structure are empty for the 'filter'-command
prefix = ''
labels = ['','']
param = ''
end
'merge' : begin
; get the node's attributes
attributes = node->GetAttributes()
; the get attributes 'inputfiles' and 'outputfile'
inputAtt = attributes->getNamedItem('inputfiles')
outputAtt = attributes->getNamedItem('outputfile')
; get string values of each these 2 attributes
output = outputAtt->getNodeValue()
output = strtrim(output,2)
inputstr= inputAtt->getNodeValue()
inputstr= strtrim(strsplit(inputstr,',',/extract),2)
input = ptr_new(inputstr)
; the other fields in the command-structure are empty for the 'filter'-command
setting = ''
prefix = ''
labels = ['','']
param = ''
end
'plot' : begin
; get the node's attributes
attributes = node->GetAttributes()
; the get attributes 'settingfile','inputfile' and 'prefix'
settingAtt = attributes->getNamedItem('settingfile')
inputAtt = attributes->getNamedItem('inputfile')
prefixAtt = attributes->getNamedItem('prefix')
; get string values of each these 2 attributes
setting = settingAtt->getNodeValue()
setting = strtrim(setting,2)
inputstr= inputAtt->getNodeValue()
inputstr= strtrim(inputstr,2)
input = ptr_new(inputstr)
prefix = prefixAtt->getNodeValue()
prefix = strtrim(prefix,2)
; the other fields in the command-structure are empty for the 'filter'-command
output = ''
labels = ['','']
param = ''
end
'compare2': begin
; get the node's attributes
attributes = node->GetAttributes()
; the get attributes 'settingfile','inputfiles', 'labels' and 'prefix'
settingAtt = attributes->getNamedItem('settingfile')
inputAtt = attributes->getNamedItem('inputfiles')
labelsAtt = attributes->getNamedItem('labels')
prefixAtt = attributes->getNamedItem('prefix')
; get string values of each these 2 attributes
setting = settingAtt->getNodeValue()
setting = strtrim(setting,2)
inputstr= inputAtt->getNodeValue()
inputstr= strtrim(strsplit(inputstr,',',/extract),2)
input = ptr_new(inputstr)
labels = labelsAtt->getNodeValue()
labels = strtrim(strsplit(labels,',',/extract),2)
prefix = prefixAtt->getNodeValue()
prefix = strtrim(prefix,2)
; the other fields in the command-structure are empty for the 'filter'-command
output = ''
param = ''
end
'comparen': begin
; get the node's attributes
attributes = node->GetAttributes()
; the get attributes 'settingfile','paramfile', 'inputfiles' and 'prefix'
settingAtt = attributes->getNamedItem('settingfile')
inputAtt = attributes->getNamedItem('inputfiles')
paramAtt = attributes->getNamedItem('paramfile')
prefixAtt = attributes->getNamedItem('prefix')
; get string values of each these 2 attributes
setting = settingAtt->getNodeValue()
setting = strtrim(setting,2)
inputstr= inputAtt->getNodeValue()
inputstr= strtrim(strsplit(inputstr,',',/extract),2)
input = ptr_new(inputstr)
param = paramAtt->getNodeValue()
param = strtrim(param,2)
prefix = prefixAtt->getNodeValue()
prefix = strtrim(prefix,2)
; the other fields in the command-structure are empty for the 'filter'-command
output = ''
labels = ['','']
end
else: skip=1
endcase
; if name is not 'calc', 'filter', etc. then immediately skip to the next node
if skip then continue
; create the command-structure
cmd = create_struct('name',name,'setting',setting,'input',input,$
'output',output,'prefix',prefix,'labels',labels,'param',param)
; add it to the command-structure array
cmdarr = [cmdarr, cmd]
endfor
; remove the first 'dummy' element of the command-structure array
; (DON'T forget to free the pointer first!)
ptr_free, cmdarr[0].input
cmdarr = cmdarr[1:*]
; clean up all xml-objects (i.e. free memory)
obj_destroy, oDocument
; return the setting structure
return, cmdarr
end