1 | #pragma rtGlobals=3 // Use modern global access method. |
---|
2 | #pragma version=5.0 |
---|
3 | #pragma IgorVersion=6.1 |
---|
4 | |
---|
5 | #include <HDF5 Browser> |
---|
6 | |
---|
7 | //************************ |
---|
8 | // Vers 1.15 20171003 |
---|
9 | // |
---|
10 | //************************ |
---|
11 | |
---|
12 | |
---|
13 | /////////////////////////////////////////////////////////////////////////// |
---|
14 | // |
---|
15 | // Basic file open/create and file initialization routines |
---|
16 | |
---|
17 | // Generic open or create file |
---|
18 | Function NXcanSAS_OpenOrCreate(dialog,fullpath,base) |
---|
19 | Variable dialog |
---|
20 | String fullpath,base |
---|
21 | Variable fileID |
---|
22 | if(dialog || stringmatch(fullpath, "")) |
---|
23 | fileID = NxCansas_DoSaveFileDialog(base) |
---|
24 | else |
---|
25 | fileID = NxCansas_CreateFile(fullpath,base) |
---|
26 | Endif |
---|
27 | if(!fileID) |
---|
28 | abort "Unable to create file at " + fullpath + "." |
---|
29 | EndIf |
---|
30 | return fileID |
---|
31 | End |
---|
32 | |
---|
33 | // Select/create file through prompt |
---|
34 | Function NxCansas_DoSaveFileDialog(base) |
---|
35 | String base |
---|
36 | Variable refNum, fileID |
---|
37 | String message = "Save a file" |
---|
38 | String outputPath |
---|
39 | String fileFilters = "Data Files (*.h5):.h5;" |
---|
40 | fileFilters += "All Files:.*;" |
---|
41 | Open /D /F=fileFilters /M=message refNum |
---|
42 | outputPath = S_fileName |
---|
43 | fileID = NxCansas_CreateFile(outputPath,base) |
---|
44 | return fileID |
---|
45 | End |
---|
46 | |
---|
47 | // Create file with a known path |
---|
48 | Function NxCansas_CreateFile(fullpath, base) |
---|
49 | String fullpath,base |
---|
50 | Variable fileID |
---|
51 | Make/T/O/N=1 $("root:NXfile_name") = fullpath |
---|
52 | fullpath = ReplaceString(":\\", fullpath, ":") |
---|
53 | fullpath = ReplaceString("\\", fullpath, ":") |
---|
54 | HDF5CreateFile /O/Z fileID as fullpath |
---|
55 | NXCansas_InitializeFile(fileID, base) |
---|
56 | return fileID |
---|
57 | End |
---|
58 | |
---|
59 | // Open\ file with a known path |
---|
60 | Function NxCansas_OpenFile(fullpath) |
---|
61 | String fullpath |
---|
62 | String fileName |
---|
63 | Variable fileID |
---|
64 | fileName = ParseFilePath(3,fullpath,":",0,0) |
---|
65 | Make/T/O/N=1 $("root:NXfile_name") = fileName |
---|
66 | fullpath = ReplaceString(":\\", fullpath, ":") |
---|
67 | fullpath = ReplaceString("\\", fullpath, ":") |
---|
68 | HDF5OpenFile /Z fileID as fullpath |
---|
69 | return fileID |
---|
70 | End |
---|
71 | |
---|
72 | // Select/create file through prompt |
---|
73 | Function NxCansas_DoOpenFileDialog() |
---|
74 | Variable refNum,fileID |
---|
75 | String message = "Select a file" |
---|
76 | String inputPath,fileName |
---|
77 | String fileFilters = "Data Files (*.h5):.h5;" |
---|
78 | STRUCT HDF5BrowserData bd |
---|
79 | fileFilters += "All Files:.*;" |
---|
80 | Open /D /F=fileFilters /M=message refNum as fileName |
---|
81 | inputPath = S_fileName |
---|
82 | fileID = NxCansas_OpenFile(inputPath) |
---|
83 | return fileID |
---|
84 | End |
---|
85 | |
---|
86 | // Initialize the file to a base state |
---|
87 | Function NxCansas_InitializeFile(fileID, base) |
---|
88 | Variable fileID |
---|
89 | String base |
---|
90 | String location,nxParent |
---|
91 | Variable sasentry = NumVarOrDefault("root:Packages:NIST:gSASEntryNumber", 1) |
---|
92 | sPrintf location,"%s:sasentry%d",base,sasentry // Igor memory base path for all |
---|
93 | sPrintf nxParent,"/sasentry%d/",sasentry // HDF5 base path for all |
---|
94 | NewDataFolder/O/S $(location) |
---|
95 | Make/O/T/N=1 $(location + ":vals") = {""} |
---|
96 | Make/O/T/N=3 $(location + ":attr") = {"NX_class", "canSAS_class", "version"} |
---|
97 | Make/O/T/N=3 $(location + ":attrVals") = {"NXentry", "SASentry", "1.0"} |
---|
98 | CreateStrNxCansas(fileID,nxParent,"","",$(location + ":vals"),$(location + ":attr"),$(location + ":attrVals")) |
---|
99 | Make/O/T/N=1 $(location + ":entryAttr") = {""} |
---|
100 | Make/O/T/N=1 $(location + ":entryAttrVals") = {""} |
---|
101 | CreateStrNxCansas(fileID,nxParent,"","definition",{"NXcanSAS"},$(location + ":entryAttr"),$(location + ":entryAttrVals")) |
---|
102 | End |
---|
103 | |
---|
104 | // |
---|
105 | /////////////////////////////////////////////////////////////////////////// |
---|
106 | |
---|
107 | /////////////////////////////////////////////////////////////////////////// |
---|
108 | // Functions used to save data to file |
---|
109 | |
---|
110 | // Intermediate error handler for saving variable waves - this function should be called instead of saveNxCansas |
---|
111 | Function CreateVarNxCansas(fileID,parent,group,var,valueWave,attr,attrValues) |
---|
112 | Variable fileID |
---|
113 | String parent,group,var |
---|
114 | Wave valueWave |
---|
115 | Wave /T attr,attrValues |
---|
116 | Variable err |
---|
117 | err = saveNxCansasVars(fileID,parent,group,var,valueWave,attr,attrValues) |
---|
118 | if(err) |
---|
119 | Print "NxCansas write err = ",err |
---|
120 | endif |
---|
121 | End |
---|
122 | // Intermediate error handler for saving string waves - this function should be called instead of saveNxCansas |
---|
123 | Function CreateStrNxCansas(fileID,parent,group,var,valueWave,attr,attrValues) |
---|
124 | Variable fileID |
---|
125 | String parent,group,var |
---|
126 | Wave /T valueWave,attr,attrValues |
---|
127 | Variable err |
---|
128 | err = saveNxCansasStrs(fileID,parent,group,var,valueWave,attr,attrValues) |
---|
129 | if(err) |
---|
130 | Print "NxCansas write err = ",err |
---|
131 | endif |
---|
132 | End |
---|
133 | |
---|
134 | Function NxCansas_writeAttributes(fileID,path,attrNames,attrVals) |
---|
135 | Variable fileID |
---|
136 | String path |
---|
137 | Wave/T attrNames, attrVals |
---|
138 | int numAttrs,i |
---|
139 | numAttrs = numpnts(attrNames) |
---|
140 | Duplicate/O/T attrNames, names |
---|
141 | Duplicate/O/T attrVals, vals |
---|
142 | |
---|
143 | for(i=0; i < numAttrs; i += 1) |
---|
144 | String name_i = names[i] |
---|
145 | String vals_i = vals[i] |
---|
146 | Make/O/T/N=1 vals_i_wave |
---|
147 | vals_i_wave[0] = vals_i |
---|
148 | if(!CmpStr(name_i,"") == 0) |
---|
149 | HDF5SaveData /A=name_i vals_i_wave, fileID, path |
---|
150 | endif |
---|
151 | endfor |
---|
152 | |
---|
153 | End |
---|
154 | |
---|
155 | Function NxCansas_CreateGroup(fileID,parent) |
---|
156 | Variable fileID |
---|
157 | String parent |
---|
158 | Variable groupID |
---|
159 | try |
---|
160 | if(!fileID) |
---|
161 | abort "HDF5 file does not exist" |
---|
162 | endif |
---|
163 | |
---|
164 | // Create the group if it doesn't already exist |
---|
165 | HDF5CreateGroup /Z fileID, parent, groupID |
---|
166 | |
---|
167 | catch |
---|
168 | // DO something if error is thrown |
---|
169 | Print "NxCansas write err in saveNxCansas = ",V_AbortCode |
---|
170 | endtry |
---|
171 | return groupID |
---|
172 | End |
---|
173 | |
---|
174 | // Write in a single NxCansas element (from the STRUCTURE) |
---|
175 | // This method should only be called by CreateVarNxCansas |
---|
176 | Function saveNxCansasVars(fileID,parent,group,var,valueWave,attr,attrValues) |
---|
177 | |
---|
178 | Variable fileID |
---|
179 | String parent,group,var |
---|
180 | Wave valueWave |
---|
181 | Wave /T attr,attrValues |
---|
182 | int i, numAttrs |
---|
183 | |
---|
184 | variable err=0, groupID |
---|
185 | String NXentry_name |
---|
186 | |
---|
187 | groupID = NxCansas_CreateGroup(fileID,parent) |
---|
188 | |
---|
189 | // Save data to disk |
---|
190 | if(!stringmatch(var,"")) |
---|
191 | HDF5SaveData /O /Z /IGOR=0 valueWave, groupID, var |
---|
192 | if (V_flag != 0) |
---|
193 | err = 1 |
---|
194 | abort "Cannot save wave to HDF5 dataset " + var + " with V_flag of " + num2str(V_flag) |
---|
195 | endif |
---|
196 | endif |
---|
197 | |
---|
198 | NxCansas_writeAttributes(fileID,parent+var,attr,attrValues) |
---|
199 | |
---|
200 | // Close group and file to release resources |
---|
201 | if(groupID) |
---|
202 | HDF5CloseGroup /Z groupID |
---|
203 | endif |
---|
204 | |
---|
205 | return err |
---|
206 | end |
---|
207 | |
---|
208 | // Write in a single NxCansas element |
---|
209 | // This method should only be called by CreateStrNxCansas |
---|
210 | Function saveNxCansasStrs(fileID,parent,group,var,valueWave,attr,attrValues) |
---|
211 | Variable fileID |
---|
212 | String parent,group,var |
---|
213 | Wave /T attr,attrValues, valueWave |
---|
214 | int i, numAttrs |
---|
215 | |
---|
216 | variable err=0, groupID |
---|
217 | String NXentry_name |
---|
218 | |
---|
219 | groupID = NxCansas_CreateGroup(fileID,parent) |
---|
220 | |
---|
221 | // Save data to disk |
---|
222 | if(!stringmatch(var,"")) |
---|
223 | HDF5SaveData /O /Z /IGOR=0 valueWave, groupID, var |
---|
224 | if (V_flag != 0) |
---|
225 | err = 1 |
---|
226 | abort "Cannot save wave to HDF5 dataset " + var + " with V_flag of " + num2str(V_flag) |
---|
227 | endif |
---|
228 | endif |
---|
229 | |
---|
230 | NxCansas_writeAttributes(fileID,parent+var,attr,attrValues) |
---|
231 | |
---|
232 | // Close group and file to release resources |
---|
233 | if(groupID) |
---|
234 | HDF5CloseGroup /Z groupID |
---|
235 | endif |
---|
236 | |
---|
237 | return err |
---|
238 | end |
---|
239 | |
---|
240 | // |
---|
241 | /////////////////////////////////////////////////////////////////////////// |
---|
242 | |
---|
243 | /////////////////////////////////////////////////////////////////////////// |
---|
244 | // |
---|
245 | // NXcanSAS Reader and Utilities |
---|
246 | |
---|
247 | Function LoadNXcanSASData(fileStr,outstr,doPlot,forceOverwrite) |
---|
248 | String fileStr, outstr |
---|
249 | Variable doPlot,forceOverwrite |
---|
250 | |
---|
251 | Variable refnum,fileID |
---|
252 | Variable rr,gg,bb,xdim,ydim |
---|
253 | SetDataFolder root: //build sub-folders for each data set under root |
---|
254 | |
---|
255 | String filename |
---|
256 | String I_dataS,Q_dataS,dQ_dataS,dQl_dataS,dQw_dataS,dI_dataS |
---|
257 | String angst = StrVarOrDefault("root:Packages:NIST:gAngstStr", "A") |
---|
258 | String/G loadDir = "root:" |
---|
259 | |
---|
260 | // Check fullpath and dialog |
---|
261 | if(stringmatch(fileStr, "")) |
---|
262 | fileID = NxCansas_DoOpenFileDialog() |
---|
263 | else |
---|
264 | fileID = NxCansas_OpenFile(fileStr) |
---|
265 | Endif |
---|
266 | |
---|
267 | filename = ParseFilePath(3,fileStr,":",0,0) |
---|
268 | String basestr |
---|
269 | if (!cmpstr(outstr, "")) //Outstr = "", cmpstr returns 0 |
---|
270 | baseStr = ShortFileNameString(CleanupName(filename,0)) |
---|
271 | baseStr = CleanupName(baseStr,0) //in case the user added odd characters |
---|
272 | else |
---|
273 | baseStr = outstr //for output, hopefully correct length as passed in |
---|
274 | endif |
---|
275 | String baseFormat = baseStr + "_%d" |
---|
276 | |
---|
277 | if(fileID) |
---|
278 | HDF5ListGroup /F/R/Type=1/Z fileID,"/" |
---|
279 | String groupList = S_HDF5ListGroup |
---|
280 | Variable groupID |
---|
281 | Variable inc=1,ii=0,isMultiData=0,i=0,j=0 |
---|
282 | String entryUnformatted = "/sasentry%d/" |
---|
283 | String dataUnformatted = "sasdata%d/" |
---|
284 | String addDigit = "%d" |
---|
285 | String entryBase |
---|
286 | String dataBase = "sasdata/" |
---|
287 | sPrintf entryBase,entryUnformatted,inc |
---|
288 | // Open first group |
---|
289 | HDF5OpenGroup /Z fileID, entryBase + dataBase, groupID |
---|
290 | If (groupID == 0) |
---|
291 | sPrintF dataBase,dataUnformatted,0 |
---|
292 | HDF5OpenGroup /z fileID, entryBase + dataBase, groupID |
---|
293 | isMultiData = 1 |
---|
294 | sPrintF baseStr,baseformat,0 |
---|
295 | EndIf |
---|
296 | |
---|
297 | // Multiple SASentry groups |
---|
298 | do |
---|
299 | //go back to the root folder and clean up before leaving |
---|
300 | // Multiple SASdata groups |
---|
301 | do |
---|
302 | if (isMultiData == 1) |
---|
303 | sPrintF baseStr,baseformat,ii |
---|
304 | EndIf |
---|
305 | loadDir = "root:" + baseStr |
---|
306 | NewDataFolder/O/S $(loadDir) |
---|
307 | // Load in data |
---|
308 | HDF5LoadData /O/Z/N=$(baseStr + "_i") fileID, entryBase + dataBase + "I" |
---|
309 | HDF5LoadData /O/Z/N=$(baseStr + "_q") fileID, entryBase + dataBase + "Q" |
---|
310 | HDF5LoadData /O/Z/N=$(baseStr + "_dq") fileID, entryBase + dataBase + "dQ" |
---|
311 | HDF5LoadData /O/Z/N=$(baseStr + "_dql") fileID, entryBase + dataBase + "dQl" |
---|
312 | HDF5LoadData /O/Z/N=$(baseStr + "_dqw") fileID, entryBase + dataBase + "dQw" |
---|
313 | HDF5LoadData /O/Z/N=$(baseStr + "_s") fileID, entryBase + dataBase + "Idev" |
---|
314 | if (DimSize($(baseStr + "_i"), 1) > 1) |
---|
315 | // Do not auto-plot 2D data |
---|
316 | doPlot = 0 |
---|
317 | xdim = DimSize($(baseStr + "_i"), 0) |
---|
318 | ydim = DimSize($(baseStr + "_i"), 1) |
---|
319 | Wave q = $(baseStr + "_q") |
---|
320 | Wave dq = $(baseStr + "_dq") |
---|
321 | Make/O/N=(xdim,ydim) $(baseStr + "_qx") |
---|
322 | Wave qx = $(baseStr + "_qx") |
---|
323 | Make/O/N=(xdim,ydim) $(baseStr + "_qy") |
---|
324 | Wave qy = $(baseStr + "_qy") |
---|
325 | if (numpnts(dq)>0) |
---|
326 | Make/O/N=(xdim,ydim) $(baseStr + "_dqx") |
---|
327 | Wave dqx = $(baseStr + "_dqx") |
---|
328 | Make/O/N=(xdim,ydim) $(baseStr + "_dqy") |
---|
329 | Wave dqy = $(baseStr + "_dqy") |
---|
330 | EndIf |
---|
331 | for(i=0; i < xdim; i += 1) |
---|
332 | for(j=0; j < ydim; j +=1) |
---|
333 | qx[i][j] = q[0][i][j] |
---|
334 | qy[i][j] = q[1][i][j] |
---|
335 | if (numpnts(dq)>0) |
---|
336 | dqx[i][j] = dq[0][i][j] |
---|
337 | dqy[i][j] = dq[1][i][j] |
---|
338 | EndIf |
---|
339 | endFor |
---|
340 | endFor |
---|
341 | KillWaves $(baseStr + "_q"),$(baseStr + "_dq"),$(baseStr + "_qx"),$(baseStr + "_qy") |
---|
342 | EndIf |
---|
343 | if (isMultiData) |
---|
344 | sprintf dataBase,dataUnformatted,ii |
---|
345 | // Open next group to see if it exists |
---|
346 | HDF5OpenGroup /Z fileID, entryBase + dataBase, groupID |
---|
347 | else |
---|
348 | groupID = 0 |
---|
349 | endIf |
---|
350 | ii += 1 |
---|
351 | // Load in Meta Data |
---|
352 | LoadMetaData(fileID,loadDir,entryBase) |
---|
353 | while (groupID != 0) |
---|
354 | inc += 1 |
---|
355 | If (isMultiData) |
---|
356 | sprintf dataBase,dataUnformatted,ii |
---|
357 | endIf |
---|
358 | // Open next group to see if it exists |
---|
359 | sPrintf entryBase,entryUnformatted,inc |
---|
360 | HDF5OpenGroup /Z fileID, entryBase + dataBase, groupID |
---|
361 | while(groupID != 0) |
---|
362 | |
---|
363 | //plot if desired |
---|
364 | if(doPlot) |
---|
365 | Print GetDataFolder(1) |
---|
366 | |
---|
367 | String w0 = (baseStr + "_q") |
---|
368 | String w1 = (baseStr + "_i") |
---|
369 | String w2 = (baseStr + "_s") |
---|
370 | |
---|
371 | // assign colors randomly |
---|
372 | rr = abs(trunc(enoise(65535))) |
---|
373 | gg = abs(trunc(enoise(65535))) |
---|
374 | bb = abs(trunc(enoise(65535))) |
---|
375 | |
---|
376 | // if target window is a graph, and user wants to append, do so |
---|
377 | DoWindow/B Plot_Manager |
---|
378 | if(WinType("") == 1) |
---|
379 | DoAlert 1,"Do you want to append this data to the current graph?" |
---|
380 | |
---|
381 | if(V_Flag == 1) |
---|
382 | AppendToGraph $w1 vs $w0 |
---|
383 | ModifyGraph mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1 |
---|
384 | ErrorBars/T=0 $w1 Y,wave=($w2,$w2) |
---|
385 | ModifyGraph tickUnit(left)=1 |
---|
386 | else |
---|
387 | //new graph |
---|
388 | Display $w1 vs $w0 |
---|
389 | ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1 |
---|
390 | ModifyGraph grid=1,mirror=2,standoff=0 |
---|
391 | ErrorBars/T=0 $w1 Y,wave=($w2,$w2) |
---|
392 | ModifyGraph tickUnit(left)=1 |
---|
393 | Label left "I(q)" |
---|
394 | Label bottom "q ("+angst+"\\S-1\\M)" |
---|
395 | Legend |
---|
396 | endif |
---|
397 | else |
---|
398 | // graph window was not target, make new one |
---|
399 | Display $w1 vs $w0 |
---|
400 | ModifyGraph log=1,mode($w1)=3,marker($w1)=19,msize($w1)=2,rgb($w1)=(rr,gg,bb),tickUnit=1 |
---|
401 | ModifyGraph grid=1,mirror=2,standoff=0 |
---|
402 | ErrorBars/T=0 $w1 Y,wave=($w2,$w2) |
---|
403 | ModifyGraph tickUnit(left)=1 |
---|
404 | Label left "I(q)" |
---|
405 | Label bottom "q ("+angst+"\\S-1\\M)" |
---|
406 | Legend |
---|
407 | endif |
---|
408 | endif |
---|
409 | endif |
---|
410 | |
---|
411 | // Close the file |
---|
412 | if(fileID) |
---|
413 | HDF5CloseFile /Z fileID |
---|
414 | endif |
---|
415 | |
---|
416 | end |
---|
417 | |
---|
418 | Function LoadMetaData(fileID,loadDir,parentBase) |
---|
419 | String parentBase,loadDir |
---|
420 | Variable fileID |
---|
421 | Variable groupID |
---|
422 | SetDataFolder $(loadDir) |
---|
423 | Make/O/N=52 $(loadDir + ":realsRead") |
---|
424 | Make/O/T/N=11 $(loadDir + ":textRead") |
---|
425 | Wave rw = $(loadDir + ":realsRead") |
---|
426 | Wave/T textw = $(loadDir + ":textRead") |
---|
427 | int isMultiDetector = 0, ii = 0 |
---|
428 | |
---|
429 | // Title |
---|
430 | HDF5OpenGroup /Z fileID, parentBase, groupID |
---|
431 | HDF5LoadData /O/Z/N=title fileID, parentBase + "title" |
---|
432 | Wave/T title = $(loadDir + ":title") |
---|
433 | |
---|
434 | // SASinstrument |
---|
435 | String instrParent = parentBase + "sasinstrument/" |
---|
436 | |
---|
437 | // SASaperture |
---|
438 | String apertureParent = instrParent + "sasaperture/" |
---|
439 | HDF5OpenGroup /Z fileID, apertureParent, groupID |
---|
440 | HDF5LoadData /O/Z/N=xg fileID, apertureParent + "x_gap" |
---|
441 | Wave/Z xg = $(loadDir + ":xg") |
---|
442 | |
---|
443 | // SAScollimation |
---|
444 | String collimationParent = instrParent + "sascollimation/" |
---|
445 | HDF5OpenGroup /Z fileID, collimationParent, groupID |
---|
446 | HDF5LoadData /O/Z/N=cdis fileID, collimationParent + "distance" |
---|
447 | Wave/Z cdis = $(loadDir + ":cdis") |
---|
448 | |
---|
449 | // SASdetector |
---|
450 | String detectorParent = instrParent + "sasdetector/" |
---|
451 | HDF5OpenGroup /Z fileID, detectorParent, groupID |
---|
452 | If (groupID == 0) |
---|
453 | isMultiDetector = 1 |
---|
454 | ii = 1 |
---|
455 | String detectorUnformatted = "sasdetector%d/" |
---|
456 | sprintf detectorParent,instrParent + detectorUnformatted,ii |
---|
457 | HDF5OpenGroup /Z fileID, detectorParent, groupID |
---|
458 | EndIf |
---|
459 | do |
---|
460 | HDF5LoadData /O/Z/N=detname fileID, detectorParent + "name" |
---|
461 | HDF5LoadData /O/Z/N=sdd fileID, detectorParent + "SDD" |
---|
462 | HDF5LoadData /O/Z/N=bcx fileID, detectorParent + "beam_center_x" |
---|
463 | HDF5LoadData /O/Z/N=bcy fileID, detectorParent + "beam_center_y" |
---|
464 | HDF5LoadData /O/Z/N=xps fileID, detectorParent + "x_pixel_size" |
---|
465 | HDF5LoadData /O/Z/N=xpy fileID, detectorParent + "y_pixel_size" |
---|
466 | Wave/Z/T detname = $(loadDir + ":detname") |
---|
467 | Wave/Z sdd = $(loadDir + ":sdd") |
---|
468 | Wave/Z bcx = $(loadDir + ":bcx") |
---|
469 | Wave/Z bcy = $(loadDir + ":bcy") |
---|
470 | Wave/Z xps = $(loadDir + ":xps") |
---|
471 | Wave/Z xpy = $(loadDir + ":xpy") |
---|
472 | If (isMultiDetector) |
---|
473 | ii += 1 |
---|
474 | sprintf detectorParent,instrParent + detectorUnformatted,ii |
---|
475 | HDF5OpenGroup /Z fileID, detectorParent, groupID |
---|
476 | Else |
---|
477 | groupID = 0 |
---|
478 | EndIf |
---|
479 | while (groupID != 0) |
---|
480 | |
---|
481 | // SASsource |
---|
482 | String sourceParent = instrParent + "sassource/" |
---|
483 | HDF5OpenGroup /Z fileID, sourceParent, groupID |
---|
484 | HDF5LoadData /O/Z/N=wvel fileID, sourceParent + "incident_wavelength" |
---|
485 | HDF5LoadData /O/Z/N=wvels fileID, sourceParent + "incident_wavelength_spread" |
---|
486 | Wave/Z wvel = $(loadDir + ":wvel") |
---|
487 | Wave/Z wvels = $(loadDir + ":wvels") |
---|
488 | |
---|
489 | // SASsample |
---|
490 | String sampleParent = parentBase + "sassample/" |
---|
491 | HDF5OpenGroup /Z fileID, sampleParent, groupID |
---|
492 | HDF5LoadData /O/Z/N=smplname fileID, sampleParent + "name" |
---|
493 | HDF5LoadData /O/Z/N=smplthick fileID, sampleParent + "thickness" |
---|
494 | HDF5LoadData /O/Z/N=smpltrans fileID, sampleParent + "transmission" |
---|
495 | Wave/T/Z smplname = $(loadDir + ":smplname") |
---|
496 | Wave/Z smplthick = $(loadDir + ":smplthick") |
---|
497 | Wave/Z smpltrans = $(loadDir + ":smpltrans") |
---|
498 | |
---|
499 | // error if any of these waves are not loaded from the metadata. Most of these are NOT present |
---|
500 | // in data that has been passed through NSORT. |
---|
501 | // -- need to check each one. there must be a better way to do this... |
---|
502 | if(WaveExists(title)) |
---|
503 | textw[0] = title[0] |
---|
504 | else |
---|
505 | textw[0] = "" |
---|
506 | endif |
---|
507 | if(WaveExists(smplname)) |
---|
508 | textw[6] = smplname[0] |
---|
509 | else |
---|
510 | textw[6] = "" |
---|
511 | endif |
---|
512 | if(WaveExists(detname)) |
---|
513 | textw[9] = detname[0] |
---|
514 | else |
---|
515 | textw[9] = "" |
---|
516 | endif |
---|
517 | if(WaveExists(smplthick)) |
---|
518 | rw[4] = smplthick[0] |
---|
519 | else |
---|
520 | rw[4] = 0 |
---|
521 | endif |
---|
522 | if(WaveExists(smpltrans)) |
---|
523 | rw[5] = smpltrans[0] |
---|
524 | else |
---|
525 | rw[5] = 0 |
---|
526 | endif |
---|
527 | if(WaveExists(xps)) |
---|
528 | rw[10] = xps[0] |
---|
529 | else |
---|
530 | rw[10] = 0 |
---|
531 | endif |
---|
532 | if(WaveExists(xpy)) |
---|
533 | rw[13] = xpy[0] |
---|
534 | else |
---|
535 | rw[13] = 0 |
---|
536 | endif |
---|
537 | if(WaveExists(bcx)) |
---|
538 | rw[16] = bcx[0] |
---|
539 | else |
---|
540 | rw[16] = 0 |
---|
541 | endif |
---|
542 | if(WaveExists(bcy)) |
---|
543 | rw[17] = bcy[0] |
---|
544 | else |
---|
545 | rw[17] = 0 |
---|
546 | endif |
---|
547 | if(WaveExists(sdd)) |
---|
548 | rw[18] = sdd[0] |
---|
549 | else |
---|
550 | rw[18] = 0 |
---|
551 | endif |
---|
552 | if(WaveExists(xg)) |
---|
553 | rw[24] = xg[0] |
---|
554 | else |
---|
555 | rw[24] = 0 |
---|
556 | endif |
---|
557 | if(WaveExists(cdis)) |
---|
558 | rw[25] = cdis[0] |
---|
559 | else |
---|
560 | rw[25] = 0 |
---|
561 | endif |
---|
562 | if(WaveExists(wvel)) |
---|
563 | rw[26] = wvel[0] |
---|
564 | else |
---|
565 | rw[26] = 0 |
---|
566 | endif |
---|
567 | if(WaveExists(wvels)) |
---|
568 | rw[27] = wvels[0] |
---|
569 | else |
---|
570 | rw[27] = 0 |
---|
571 | endif |
---|
572 | |
---|
573 | |
---|
574 | KillWaves title,smplname,detname,smplthick,smpltrans,xps,xpy,bcx,bcy,sdd,xg,cdis,wvel,wvels |
---|
575 | |
---|
576 | End |
---|
577 | |
---|
578 | // |
---|
579 | /////////////////////////////////////////////////////////////////////////// |
---|
580 | |
---|
581 | |
---|
582 | /////////////////////////////////////////////////////////////////////////// |
---|
583 | // |
---|
584 | // Generic Read/Write operations. |
---|
585 | |
---|
586 | //Needed to test whether file is NXcanSAS. The load routine will then either give an error if HDF5 XOP is not present or load the file if it is. |
---|
587 | Function isNXcanSAS(filestr) |
---|
588 | String filestr |
---|
589 | |
---|
590 | Variable fileID=0,groupID=0 |
---|
591 | Int isHDF5File = 0 |
---|
592 | |
---|
593 | fileID = NxCansas_OpenFile(filestr) |
---|
594 | HDF5ListGroup /F/R/Type=1/Z fileID,"/" |
---|
595 | Variable length = strlen(S_HDF5ListGroup) |
---|
596 | |
---|
597 | if (numtype(length) != 2) |
---|
598 | isHDF5File = 1 |
---|
599 | endif |
---|
600 | |
---|
601 | if (fileID != 0) |
---|
602 | // Close the file |
---|
603 | HDF5CloseFile /Z fileID |
---|
604 | endif |
---|
605 | |
---|
606 | return isHDF5File |
---|
607 | |
---|
608 | end |
---|
609 | |
---|
610 | // |
---|
611 | /////////////////////////////////////////////////////////////////////////// |
---|
612 | |
---|
613 | |
---|
614 | /////////////////////////////////////////////////////////////////////////// |
---|