1 | #pragma rtGlobals=3 // Use modern global access method and strict wave access. |
---|
2 | |
---|
3 | // |
---|
4 | // The base functions for R/W from HDF5 files. |
---|
5 | // All of the specific "get" and "write" functions call these base functions which are responsible |
---|
6 | // for all of the open/close mechanics. |
---|
7 | // |
---|
8 | // These VSANS file-specific functions are in: |
---|
9 | // V_HDF5_Read.ipf |
---|
10 | // and |
---|
11 | // V_HDF5_Write.ipf |
---|
12 | // |
---|
13 | |
---|
14 | // data is read into: |
---|
15 | // NewDataFolder/O/S root:Packages:NIST:VSANS:RawVSANS |
---|
16 | // so that the data folders of the raw data won't be lying around on the top level, looking like |
---|
17 | // 1D data sets and interfering. |
---|
18 | |
---|
19 | |
---|
20 | // the base data folder path where the raw data is loaded |
---|
21 | Strconstant ksBaseDFPath = "root:Packages:NIST:VSANS:RawVSANS:" |
---|
22 | |
---|
23 | // the list of WORK Folders |
---|
24 | Strconstant ksWorkFolderList = "RAW;SAM;EMP;BGD;COR;DIV;ABS;MSK;CAL;STO;SUB;DRK;ADJ;VCALC;RawVSANS;" |
---|
25 | Strconstant ksWorkFolderListShort = "RAW;SAM;EMP;BGD;COR;DIV;ABS;MSK;CAL;STO;SUB;DRK;ADJ;" |
---|
26 | |
---|
27 | |
---|
28 | // passing null file string presents a dialog |
---|
29 | Proc LoadFakeDIVData() |
---|
30 | V_LoadHDF5Data("","DIV") |
---|
31 | End |
---|
32 | |
---|
33 | // passing null file string presents a dialog |
---|
34 | Proc LoadFakeMASKData() |
---|
35 | V_LoadHDF5Data("","MSK") |
---|
36 | End |
---|
37 | |
---|
38 | // passing null file string presents a dialog |
---|
39 | Proc Read_HDF5_Raw_No_Attributes() |
---|
40 | V_LoadHDF5Data("","RAW") |
---|
41 | End |
---|
42 | |
---|
43 | |
---|
44 | // TODO: |
---|
45 | // x- move the initialization of the raw data folder to be in the as-yet unwritten initialization routine for |
---|
46 | // reduction. be sure that it's duplicated in the VCALC initialization too. |
---|
47 | // -- as needed, get rid of the FAKE redimension of the data from 3D->2D and from 128x128 to something else for VSANS |
---|
48 | // This is a fake since I don't have anything close to correct fake data yet. (1/29/16) |
---|
49 | // |
---|
50 | // DONE: x- is there an extra "entry" heading? Am I adding this by mistake by setting base_name="entry" for RAW data? |
---|
51 | // x- as dumb as it is -- do I just leave it now, or break everything. On the plus side, removing the extra "entry" |
---|
52 | // layer may catch a lot of the hard-wired junk that is present... |
---|
53 | // extra entry layer is no longer generated for any WORK folders |
---|
54 | // |
---|
55 | Function V_LoadHDF5Data(file,folder) |
---|
56 | String file,folder |
---|
57 | |
---|
58 | String base_name,detStr |
---|
59 | String destPath |
---|
60 | Variable ii |
---|
61 | |
---|
62 | SetDataFolder $("root:Packages:NIST:VSANS:"+folder) |
---|
63 | destPath = "root:Packages:NIST:VSANS:"+folder |
---|
64 | |
---|
65 | Variable err= V_LoadHDF5_NoAtt(file,folder) // reads into current folder |
---|
66 | |
---|
67 | // if RAW data, then generate the errors and linear data copy |
---|
68 | // do this 9x |
---|
69 | // then do any "massaging" needed to redimension, fake values, etc. |
---|
70 | // |
---|
71 | string tmpStr = "root:Packages:NIST:VSANS:RAW:entry:instrument:" |
---|
72 | |
---|
73 | if(cmpstr(folder,"RAW")==0) |
---|
74 | |
---|
75 | // TODO -- once I get "real" data, get rid of this call to force the data to be proper dimensions. |
---|
76 | // V_RedimFakeData() |
---|
77 | |
---|
78 | V_MakeDataWaves_DP(folder) |
---|
79 | // V_FakeBeamCenters() |
---|
80 | // V_FakeScaleToCenter() |
---|
81 | |
---|
82 | |
---|
83 | // makes data error and linear copy -- DP waves if V_MakeDataWaves_DP() called above |
---|
84 | for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1) |
---|
85 | detStr = StringFromList(ii, ksDetectorListAll, ";") |
---|
86 | V_MakeDataError(tmpStr+"detector_"+detStr) |
---|
87 | endfor |
---|
88 | |
---|
89 | // TODO |
---|
90 | // -- get rid of these fake calibration waves as "real" ones are filled in by NICE |
---|
91 | // (currently does nothing) |
---|
92 | // Execute "MakeFakeCalibrationWaves()" |
---|
93 | |
---|
94 | // fMakeFakeCalibrationWaves() //skips the alert |
---|
95 | |
---|
96 | |
---|
97 | // TODO -- do I want to calculate the nonlinear x/y arrays and the q-values here? |
---|
98 | // -- otherwise the mouse-over doesn't calculate the correct Q_values |
---|
99 | // the display currently is not shifted or altered at all to account for the non-linearity |
---|
100 | // or for display in q-values -- so why bother with this? |
---|
101 | NVAR gDoNonLinearCor = root:Packages:NIST:VSANS:Globals:gDoNonLinearCor |
---|
102 | // generate a distance matrix for each of the detectors |
---|
103 | if (gDoNonLinearCor == 1) |
---|
104 | Print "Calculating Non-linear correction at RAW load time"// for "+ detStr |
---|
105 | for(ii=0;ii<ItemsInList(ksDetectorListNoB);ii+=1) |
---|
106 | detStr = StringFromList(ii, ksDetectorListNoB, ";") |
---|
107 | Wave w = V_getDetectorDataW(folder,detStr) |
---|
108 | // Wave w_err = V_getDetectorDataErrW(fname,detStr) |
---|
109 | Wave w_calib = V_getDetTube_spatialCalib(folder,detStr) |
---|
110 | Variable tube_width = V_getDet_tubeWidth(folder,detStr) |
---|
111 | NonLinearCorrection(w,w_calib,tube_width,detStr,destPath) |
---|
112 | |
---|
113 | |
---|
114 | //(2.4) Convert the beam center values from pixels to mm |
---|
115 | // TODO -- there needs to be a permanent location for these values?? |
---|
116 | // |
---|
117 | ConvertBeamCtr_to_mm(folder,detStr,destPath) |
---|
118 | |
---|
119 | // (2.5) Calculate the q-values |
---|
120 | // calculating q-values can't be done unless the non-linear corrections are calculated |
---|
121 | // so go ahead and put it in this loop. |
---|
122 | // TODO : |
---|
123 | // -- make sure that everything is present before the calculation |
---|
124 | // -- beam center must be properly defined in terms of real distance |
---|
125 | // -- distances/zero location/ etc. must be clearly documented for each detector |
---|
126 | // ** this assumes that NonLinearCorrection() has been run to generate data_RealDistX and Y |
---|
127 | // ** this routine Makes the waves QTot, qx, qy, qz in each detector folder. |
---|
128 | // |
---|
129 | V_Detector_CalcQVals(folder,detStr,destPath) |
---|
130 | |
---|
131 | endfor |
---|
132 | |
---|
133 | //"B" is separate |
---|
134 | NonLinearCorrection_B(folder,"B",destPath) |
---|
135 | ConvertBeamCtr_to_mmB(folder,"B",destPath) |
---|
136 | V_Detector_CalcQVals(folder,"B",destPath) |
---|
137 | |
---|
138 | else |
---|
139 | Print "Non-linear correction not done" |
---|
140 | endif |
---|
141 | |
---|
142 | |
---|
143 | /// END FAKE DATA CORRECTIONS |
---|
144 | |
---|
145 | endif |
---|
146 | |
---|
147 | SetDataFolder root: |
---|
148 | return(err) |
---|
149 | End |
---|
150 | |
---|
151 | // fname is the folder = "RAW" |
---|
152 | Function V_MakeDataWaves_DP(fname) |
---|
153 | String fname |
---|
154 | |
---|
155 | Variable ii |
---|
156 | String detStr |
---|
157 | |
---|
158 | for(ii=0;ii<ItemsInList(ksDetectorListAll);ii+=1) |
---|
159 | detStr = StringFromList(ii, ksDetectorListAll, ";") |
---|
160 | Wave w = V_getDetectorDataW(fname,detStr) |
---|
161 | // Wave w_err = V_getDetectorDataErrW(fname,detStr) |
---|
162 | Redimension/D w |
---|
163 | // Redimension/D w_err |
---|
164 | endfor |
---|
165 | |
---|
166 | return(0) |
---|
167 | End |
---|
168 | |
---|
169 | |
---|
170 | |
---|
171 | // |
---|
172 | // TODO -- this is all FAKED since all the data arrays are written to hdf as (1,128,128) |
---|
173 | // -- try to fill in the bits from VCALC, if it exists (or force it) |
---|
174 | // |
---|
175 | // the SetScale parts may be useful later. |
---|
176 | // |
---|
177 | // This is NOT CALLED anymore. |
---|
178 | // the rescaling (SetScale) of the data sets is still done separately to a "fake" beam center |
---|
179 | Function V_RedimFakeData() |
---|
180 | |
---|
181 | // check for fake data in VCALC folder... |
---|
182 | wave/Z tmpw=$"root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_B:det_B" |
---|
183 | if(WaveExists(tmpw) == 0) |
---|
184 | Execute "VCALC_Panel()" |
---|
185 | endif |
---|
186 | |
---|
187 | SetDataFolder root:Packages:NIST:VSANS:RAW:entry:instrument:detector_B |
---|
188 | Wave det_B=data |
---|
189 | // Redimension/N=(150,150)/E=1 det_B |
---|
190 | Redimension/D det_B |
---|
191 | wave tmpw=$"root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_B:det_B" |
---|
192 | // det_B=tmpw |
---|
193 | // det_B += 2 |
---|
194 | Wave distance=distance |
---|
195 | distance = VCALC_getSDD("B")*100 // to convert m to cm |
---|
196 | |
---|
197 | |
---|
198 | Variable ctr=20,npix=128 |
---|
199 | SetDataFolder root:Packages:NIST:VSANS:RAW:entry:instrument:detector_MT |
---|
200 | Wave det_MT=data |
---|
201 | // Redimension/N=(npix,48)/E=1 det_MT |
---|
202 | Redimension/D det_MT |
---|
203 | SetScale/I x -npix/2,npix/2,"",det_MT |
---|
204 | SetScale/I y ctr,ctr+48,"",det_MT |
---|
205 | // det_MT *= 10 |
---|
206 | // det_MT += 2 |
---|
207 | wave tmpw=$"root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_MT:det_MT" |
---|
208 | // det_MT=tmpw |
---|
209 | // det_MT += 2 |
---|
210 | Wave distance=distance |
---|
211 | distance = VCALC_getSDD("MT")*100 // to convert m to cm |
---|
212 | |
---|
213 | |
---|
214 | SetDataFolder root:Packages:NIST:VSANS:RAW:entry:instrument:detector_MB |
---|
215 | Wave det_MB=data |
---|
216 | // Redimension/N=(npix,48)/E=1 det_MB |
---|
217 | Redimension/D det_MB |
---|
218 | SetScale/I x -npix/2,npix/2,"",det_MB |
---|
219 | SetScale/I y -ctr-48,-ctr,"",det_MB |
---|
220 | // det_MB *= 5 |
---|
221 | // det_MB += 2 |
---|
222 | wave tmpw=$"root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_MB:det_MB" |
---|
223 | // det_MB=tmpw |
---|
224 | // det_MB += 2 |
---|
225 | Wave distance=distance |
---|
226 | distance = VCALC_getSDD("MB")*100 // to convert m to cm |
---|
227 | |
---|
228 | |
---|
229 | ctr=30 |
---|
230 | SetDataFolder root:Packages:NIST:VSANS:RAW:entry:instrument:detector_ML |
---|
231 | Wave det_ML=data |
---|
232 | // Redimension/N=(48,npix)/E=1 det_ML |
---|
233 | Redimension/D det_ML |
---|
234 | SetScale/I x -ctr-48,-ctr,"",det_ML |
---|
235 | SetScale/I y -npix/2,npix/2,"",det_ML |
---|
236 | // det_ML *= 2 |
---|
237 | // det_ML += 2 |
---|
238 | wave tmpw=$"root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_ML:det_ML" |
---|
239 | // det_ML=tmpw |
---|
240 | // det_ML += 2 |
---|
241 | Wave distance=distance |
---|
242 | distance = VCALC_getSDD("ML")*100 // to convert m to cm |
---|
243 | |
---|
244 | |
---|
245 | SetDataFolder root:Packages:NIST:VSANS:RAW:entry:instrument:detector_MR |
---|
246 | Wave det_MR=data |
---|
247 | // Redimension/N=(48,npix)/E=1 det_MR |
---|
248 | Redimension/D det_MR |
---|
249 | SetScale/I x ctr,ctr+48,"",det_MR |
---|
250 | SetScale/I y -npix/2,npix/2,"",det_MR |
---|
251 | // det_MR +=2 |
---|
252 | wave tmpw=$"root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_MR:det_MR" |
---|
253 | // det_MR=tmpw |
---|
254 | // det_MR += 2 |
---|
255 | Wave distance=distance |
---|
256 | distance = VCALC_getSDD("MR")*100 // to convert m to cm |
---|
257 | |
---|
258 | |
---|
259 | ctr=30 |
---|
260 | SetDataFolder root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FT |
---|
261 | Wave det_FT=data |
---|
262 | // Redimension/N=(npix,48)/E=1 det_FT |
---|
263 | Redimension/D det_FT |
---|
264 | SetScale/I x -npix/2,npix/2,"",det_FT |
---|
265 | SetScale/I y ctr,ctr+48,"",det_FT |
---|
266 | wave tmpw=$"root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_FT:det_FT" |
---|
267 | // det_FT=tmpw |
---|
268 | Wave distance=distance |
---|
269 | distance = VCALC_getSDD("FT")*100 // to convert m to cm |
---|
270 | |
---|
271 | |
---|
272 | SetDataFolder root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FB |
---|
273 | Wave det_FB=data |
---|
274 | // Redimension/N=(npix,48)/E=1 det_FB |
---|
275 | Redimension/D det_FB |
---|
276 | SetScale/I x -npix/2,npix/2,"",det_FB |
---|
277 | SetScale/I y -ctr-48,-ctr,"",det_FB |
---|
278 | wave tmpw=$"root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_FB:det_FB" |
---|
279 | // det_FB=tmpw |
---|
280 | Wave distance=distance |
---|
281 | distance = VCALC_getSDD("FB")*100 // to convert m to cm |
---|
282 | |
---|
283 | |
---|
284 | SetDataFolder root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FL |
---|
285 | Wave det_FL=data |
---|
286 | // Redimension/N=(48,npix)/E=1 det_FL |
---|
287 | Redimension/D det_FL |
---|
288 | SetScale/I x -ctr-48,-ctr,"",det_FL |
---|
289 | SetScale/I y -npix/2,npix/2,"",det_FL |
---|
290 | wave tmpw=$"root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_FL:det_FL" |
---|
291 | // det_FL=tmpw |
---|
292 | Wave distance=distance |
---|
293 | distance = VCALC_getSDD("FL")*100 // to convert m to cm |
---|
294 | |
---|
295 | |
---|
296 | SetDataFolder root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FR |
---|
297 | Wave det_FR=data |
---|
298 | // Redimension/N=(48,npix)/E=1 det_FR |
---|
299 | Redimension/D det_FR |
---|
300 | SetScale/I x ctr,ctr+48,"",det_FR |
---|
301 | SetScale/I y -npix/2,npix/2,"",det_FR |
---|
302 | wave tmpw=$"root:Packages:NIST:VSANS:VCALC:entry:instrument:detector_FR:det_FR" |
---|
303 | // det_FR=tmpw |
---|
304 | Wave distance=distance |
---|
305 | distance = VCALC_getSDD("FR")*100 // to convert m to cm |
---|
306 | |
---|
307 | |
---|
308 | // get rid of zeros |
---|
309 | // det_FL += 2 |
---|
310 | // det_FR += 2 |
---|
311 | // det_FT += 2 |
---|
312 | // det_FB += 2 |
---|
313 | |
---|
314 | |
---|
315 | // fake beam center values |
---|
316 | V_putDet_beam_center_x("RAW","B",75) |
---|
317 | V_putDet_beam_center_y("RAW","B",75) |
---|
318 | |
---|
319 | V_putDet_beam_center_x("RAW","MB",64) |
---|
320 | V_putDet_beam_center_y("RAW","MB",55) |
---|
321 | V_putDet_beam_center_x("RAW","MT",64) |
---|
322 | V_putDet_beam_center_y("RAW","MT",-8.7) |
---|
323 | V_putDet_beam_center_x("RAW","MR",-8.1) |
---|
324 | V_putDet_beam_center_y("RAW","MR",64) |
---|
325 | V_putDet_beam_center_x("RAW","ML",55) |
---|
326 | V_putDet_beam_center_y("RAW","ML",64) |
---|
327 | |
---|
328 | V_putDet_beam_center_x("RAW","FB",64) |
---|
329 | V_putDet_beam_center_y("RAW","FB",55) |
---|
330 | V_putDet_beam_center_x("RAW","FT",64) |
---|
331 | V_putDet_beam_center_y("RAW","FT",-8.7) |
---|
332 | V_putDet_beam_center_x("RAW","FR",-8.1) |
---|
333 | V_putDet_beam_center_y("RAW","FR",64) |
---|
334 | V_putDet_beam_center_x("RAW","FL",55) |
---|
335 | V_putDet_beam_center_y("RAW","FL",64) |
---|
336 | |
---|
337 | |
---|
338 | V_RescaleToBeamCenter("RAW","MB",64,55) |
---|
339 | V_RescaleToBeamCenter("RAW","MT",64,-8.7) |
---|
340 | V_RescaleToBeamCenter("RAW","MR",-8.1,64) |
---|
341 | V_RescaleToBeamCenter("RAW","ML",55,64) |
---|
342 | V_RescaleToBeamCenter("RAW","FL",55,64) |
---|
343 | V_RescaleToBeamCenter("RAW","FR",-8.1,64) |
---|
344 | V_RescaleToBeamCenter("RAW","FT",64,-8.7) |
---|
345 | V_RescaleToBeamCenter("RAW","FB",64,55) |
---|
346 | |
---|
347 | |
---|
348 | |
---|
349 | return(0) |
---|
350 | End |
---|
351 | |
---|
352 | |
---|
353 | // This loads for speed, since loading the attributes takes a LOT of time. |
---|
354 | // |
---|
355 | // this will load in the whole HDF file all at once. |
---|
356 | // Attributes are NOT loaded at all. |
---|
357 | // |
---|
358 | // -- the Gateway function H5GW_ReadHDF5(parentFolder, fileName, [hdf5Path]) |
---|
359 | // reads in the attributes too, but is very slow |
---|
360 | // -- the H5GW function is called by: H_HDF5Gate_Read_Raw(file) |
---|
361 | // |
---|
362 | // TODO: |
---|
363 | // -x remove the P=home restriction top make this more generic (replaced with catPathName from PickPath) |
---|
364 | // -- get rid of bits leftover here that I don't need |
---|
365 | // -- be sure I'm using all of the correct flags in the HDF5LoadGroup operation |
---|
366 | // -- settle on how the base_name is to be used. "entry" for the RAW, fileName for the "rawVSANS"? |
---|
367 | // x- error check for path existence |
---|
368 | // |
---|
369 | // passing in "" for base_name will take the name from the file name as selected |
---|
370 | // |
---|
371 | Function V_LoadHDF5_NoAtt(fileName,base_name) |
---|
372 | String fileName, base_name |
---|
373 | |
---|
374 | // if ( ParamIsDefault(hdf5Path) ) |
---|
375 | // hdf5Path = "/" |
---|
376 | // endif |
---|
377 | |
---|
378 | PathInfo/S catPathName |
---|
379 | if(V_flag == 0) |
---|
380 | V_PickPath() |
---|
381 | endif |
---|
382 | |
---|
383 | String hdf5path = "/" //always read from the top |
---|
384 | String status = "" |
---|
385 | |
---|
386 | Variable fileID = 0 |
---|
387 | // HDF5OpenFile/R/P=home/Z fileID as fileName //read file from home directory? |
---|
388 | HDF5OpenFile/R/P=catPathName/Z fileID as fileName |
---|
389 | if (V_Flag != 0) |
---|
390 | return 0 |
---|
391 | endif |
---|
392 | |
---|
393 | String/G root:file_path = S_path |
---|
394 | String/G root:file_name = S_FileName |
---|
395 | |
---|
396 | if ( fileID == 0 ) |
---|
397 | Print fileName + ": could not open as HDF5 file" |
---|
398 | return (0) |
---|
399 | endif |
---|
400 | |
---|
401 | //s_tic() //fast |
---|
402 | |
---|
403 | SVAR tmpStr=root:file_name |
---|
404 | fileName=tmpStr //SRK - in case the file was chosen from a dialog, I'll need access to the name later |
---|
405 | |
---|
406 | // read the data (too bad that HDF5LoadGroup does not read the attributes) |
---|
407 | // if(cmpstr(base_name,"") == 0) |
---|
408 | // base_name = StringFromList(0,FileName,".") |
---|
409 | // endif |
---|
410 | |
---|
411 | // if base_name is from my list of WORK folders, then base_name = "" |
---|
412 | // use a stringSwitch? WhichListItem? |
---|
413 | Variable isFolder = WhichListItem(base_name,ksWorkFolderList) |
---|
414 | if(isFolder != -1) |
---|
415 | base_name = "" |
---|
416 | else |
---|
417 | base_name = StringFromList(0,FileName,".") |
---|
418 | endif |
---|
419 | |
---|
420 | HDF5LoadGroup/Z/L=7/O/R/T=$base_name :, fileID, hdf5Path // recursive |
---|
421 | if ( V_Flag != 0 ) |
---|
422 | Print fileName + ": could not open as HDF5 file" |
---|
423 | setdatafolder root: |
---|
424 | return (0) |
---|
425 | endif |
---|
426 | |
---|
427 | HDF5CloseFile fileID |
---|
428 | |
---|
429 | //s_toc() |
---|
430 | return(0) |
---|
431 | end |
---|
432 | |
---|
433 | |
---|
434 | // read a single real value |
---|
435 | // - fname passed in is the full path to the file on disk |
---|
436 | // - path is the path to the value in the HDF tree |
---|
437 | // |
---|
438 | // check to see if the value exists (It will be a wave) |
---|
439 | // -- if it does, return the value from the local folder |
---|
440 | // -- if not, read the file in, then return the value |
---|
441 | // |
---|
442 | // TODO: |
---|
443 | // currently, the work folders have the following path - so passing in "RAW" as fname |
---|
444 | // will take some re-configuring. |
---|
445 | // root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FL:distance |
---|
446 | // -- be sure this read from work folders is not broken in the future, and is passed to ALL of the |
---|
447 | // top-level R/W routines. (Write is necessary ONLY for SIM data files. Patch is direct to disk.) |
---|
448 | Function V_getRealValueFromHDF5(fname,path) |
---|
449 | String fname,path |
---|
450 | |
---|
451 | String folderStr="" |
---|
452 | Variable valExists=0 |
---|
453 | |
---|
454 | folderStr = V_RemoveDotExtension(V_GetFileNameFromPathNoSemi(fname)) |
---|
455 | |
---|
456 | // check for a work folder first (note that "entry" is now NOT doubled) |
---|
457 | if(Exists("root:Packages:NIST:VSANS:"+folderStr+":"+path)) |
---|
458 | Wave/Z w = $("root:Packages:NIST:VSANS:"+folderStr+":"+path) |
---|
459 | return(w[0]) |
---|
460 | endif |
---|
461 | |
---|
462 | if(Exists(ksBaseDFPath+folderStr+":"+path)) |
---|
463 | valExists=1 |
---|
464 | endif |
---|
465 | |
---|
466 | if(!valExists) |
---|
467 | //then read in the file, putting the data in RawVSANS |
---|
468 | SetDataFolder ksBaseDFPath |
---|
469 | V_LoadHDF5_NoAtt(fname,"") |
---|
470 | SetDataFolder root: |
---|
471 | endif |
---|
472 | |
---|
473 | // this should exist now - if not, I need to see the error |
---|
474 | Wave/Z w = $(ksBaseDFPath+folderStr+":"+path) |
---|
475 | |
---|
476 | if(WaveExists(w)) |
---|
477 | return(w[0]) |
---|
478 | else |
---|
479 | return(-999999) |
---|
480 | endif |
---|
481 | End |
---|
482 | |
---|
483 | // Returns a wave reference, not just a single value |
---|
484 | // ---then you pick what you need from the wave |
---|
485 | // |
---|
486 | // - fname passed in is the full path to the file on disk |
---|
487 | // - path is the path to the value in the HDF tree |
---|
488 | // |
---|
489 | // check to see if the value exists (It will be a wave) |
---|
490 | // -- if it does, return the value from the local folder |
---|
491 | // -- if not, read the file in, then return the value |
---|
492 | // |
---|
493 | Function/WAVE V_getRealWaveFromHDF5(fname,path) |
---|
494 | String fname,path |
---|
495 | |
---|
496 | String folderStr="" |
---|
497 | Variable valExists=0 |
---|
498 | |
---|
499 | folderStr = V_RemoveDotExtension(V_GetFileNameFromPathNoSemi(fname)) |
---|
500 | |
---|
501 | // check for a work folder first (note that "entry" is NOT doubled) |
---|
502 | if(Exists("root:Packages:NIST:VSANS:"+folderStr+":"+path)) |
---|
503 | Wave wOut = $("root:Packages:NIST:VSANS:"+folderStr+":"+path) |
---|
504 | return wOut |
---|
505 | endif |
---|
506 | |
---|
507 | if(Exists(ksBaseDFPath+folderStr+":"+path)) |
---|
508 | valExists=1 |
---|
509 | endif |
---|
510 | |
---|
511 | if(!valExists) |
---|
512 | //then read in the file, putting the data in RawVSANS |
---|
513 | SetDataFolder ksBaseDFPath |
---|
514 | V_LoadHDF5_NoAtt(fname,"") |
---|
515 | SetDataFolder root: |
---|
516 | endif |
---|
517 | |
---|
518 | // this should exist now - if not, I need to see the error |
---|
519 | Wave wOut = $(ksBaseDFPath+folderStr+":"+path) |
---|
520 | |
---|
521 | return wOut |
---|
522 | |
---|
523 | End |
---|
524 | |
---|
525 | // Returns a wave reference, not just a single value |
---|
526 | // ---then you pick what you need from the wave |
---|
527 | // |
---|
528 | // - fname passed in is the full path to the file on disk |
---|
529 | // - path is the path to the value in the HDF tree |
---|
530 | // |
---|
531 | // check to see if the value exists (It will be a wave) |
---|
532 | // -- if it does, return the value from the local folder |
---|
533 | // -- if not, read the file in, then return the value |
---|
534 | // |
---|
535 | Function/WAVE V_getTextWaveFromHDF5(fname,path) |
---|
536 | String fname,path |
---|
537 | |
---|
538 | String folderStr="" |
---|
539 | Variable valExists=0 |
---|
540 | |
---|
541 | folderStr = V_RemoveDotExtension(V_GetFileNameFromPathNoSemi(fname)) |
---|
542 | |
---|
543 | // check for a work folder first (note that "entry" is NOT doubled) |
---|
544 | if(Exists("root:Packages:NIST:VSANS:"+folderStr+":"+path)) |
---|
545 | Wave/T wOut = $("root:Packages:NIST:VSANS:"+folderStr+":"+path) |
---|
546 | return wOut |
---|
547 | endif |
---|
548 | |
---|
549 | if(Exists(ksBaseDFPath+folderStr+":"+path)) |
---|
550 | valExists=1 |
---|
551 | endif |
---|
552 | |
---|
553 | if(!valExists) |
---|
554 | //then read in the file, putting the data in RawVSANS |
---|
555 | SetDataFolder ksBaseDFPath |
---|
556 | V_LoadHDF5_NoAtt(fname,"") |
---|
557 | SetDataFolder root: |
---|
558 | endif |
---|
559 | |
---|
560 | // this should exist now - if not, I need to see the error |
---|
561 | Wave/T wOut = $(ksBaseDFPath+folderStr+":"+path) |
---|
562 | |
---|
563 | return wOut |
---|
564 | |
---|
565 | End |
---|
566 | |
---|
567 | |
---|
568 | // |
---|
569 | // TODO |
---|
570 | // depricated? in HDF5 - store all of the values as real? |
---|
571 | // Igor sees no difference in real and integer variables (waves are different) |
---|
572 | // BUT-- Igor 7 will have integer variables |
---|
573 | // |
---|
574 | // truncate to integer before returning?? |
---|
575 | // |
---|
576 | // TODO |
---|
577 | // write a "getIntegerWave" function?? |
---|
578 | // |
---|
579 | ////// integer values |
---|
580 | // reads 32 bit integer |
---|
581 | Function V_getIntegerFromHDF5(fname,path) |
---|
582 | String fname //full path+name |
---|
583 | String path //path to the hdf5 location |
---|
584 | |
---|
585 | Variable val = V_getRealValueFromHDF5(fname,path) |
---|
586 | |
---|
587 | val = round(val) |
---|
588 | return(val) |
---|
589 | End |
---|
590 | |
---|
591 | |
---|
592 | // read a single string |
---|
593 | // - fname passed in is the full path to the file on disk |
---|
594 | // - path is the path to the value in the HDF tree |
---|
595 | // - num is the number of characters in the VAX string |
---|
596 | // check to see if the value exists (It will be a wave) |
---|
597 | // -- if it does, return the value from the local folder |
---|
598 | // -- if not, read the file in, then return the value |
---|
599 | // |
---|
600 | // TODO -- string could be checked for length, but returned right or wrong |
---|
601 | // |
---|
602 | // -- currently num is completely ignored |
---|
603 | // |
---|
604 | Function/S V_getStringFromHDF5(fname,path,num) |
---|
605 | String fname,path |
---|
606 | Variable num |
---|
607 | |
---|
608 | String folderStr="" |
---|
609 | Variable valExists=0 |
---|
610 | |
---|
611 | folderStr = V_RemoveDotExtension(V_GetFileNameFromPathNoSemi(fname)) |
---|
612 | |
---|
613 | // check for a work folder first (note that "entry" is NOT doubled) |
---|
614 | if(Exists("root:Packages:NIST:VSANS:"+folderStr+":"+path)) |
---|
615 | Wave/Z/T tw = $("root:Packages:NIST:VSANS:"+folderStr+":"+path) |
---|
616 | return(tw[0]) |
---|
617 | endif |
---|
618 | |
---|
619 | if(Exists(ksBaseDFPath+folderStr+":"+path)) |
---|
620 | valExists=1 |
---|
621 | endif |
---|
622 | |
---|
623 | if(!valExists) |
---|
624 | //then read in the file, putting the data in RawVSANS |
---|
625 | SetDataFolder ksBaseDFPath |
---|
626 | V_LoadHDF5_NoAtt(fname,"") |
---|
627 | SetDataFolder root: |
---|
628 | endif |
---|
629 | |
---|
630 | // this should exist now - if not, I need to see the error |
---|
631 | Wave/T/Z tw = $(ksBaseDFPath+folderStr+":"+path) |
---|
632 | |
---|
633 | if(WaveExists(tw)) |
---|
634 | |
---|
635 | // if(strlen(tw[0]) != num) |
---|
636 | // Print "string is not the specified length" |
---|
637 | // endif |
---|
638 | |
---|
639 | return(tw[0]) |
---|
640 | else |
---|
641 | return("The specified wave does not exist: " + path) |
---|
642 | endif |
---|
643 | End |
---|
644 | |
---|
645 | |
---|
646 | |
---|
647 | /////////////////////////////// |
---|
648 | |
---|
649 | // |
---|
650 | //Write Wave 'wav' to hdf5 file 'fname' |
---|
651 | //Based on code from ANSTO (N. Hauser. nha 8/1/09) |
---|
652 | // |
---|
653 | // TODO: |
---|
654 | // -- figure out if this will write in the native format of the |
---|
655 | // wave as passed in, or if it will only write as DP. |
---|
656 | // -- do I need to write separate functions for real, integer, etc.? |
---|
657 | // -- the lines to create a missing group have been commented out to avoid filling |
---|
658 | // in missing fields that should have been generated by the data writer. Need to make |
---|
659 | // a separate function that will write and generate if needed, and use this in specific cases |
---|
660 | // only if I really have to force it. |
---|
661 | // |
---|
662 | // --Attributes are not currently saved. Fix this, maybe make it optional? See the help file for |
---|
663 | // DemoAttributes(w) example under the HDF5SaveData operation |
---|
664 | // |
---|
665 | // -x change the /P=home to the user-defined data path (catPathName) |
---|
666 | // |
---|
667 | Function V_WriteWaveToHDF(fname, groupName, varName, wav) |
---|
668 | String fname, groupName, varName |
---|
669 | Wave wav |
---|
670 | |
---|
671 | |
---|
672 | // try a local folder first, then try to save to disk |
---|
673 | // |
---|
674 | String folderStr = V_RemoveDotExtension(V_GetFileNameFromPathNoSemi(fname)) |
---|
675 | |
---|
676 | String localPath = "root:Packages:NIST:VSANS:"+folderStr//+":entry" |
---|
677 | localPath += groupName + "/" + varName |
---|
678 | // make everything colons for local data folders |
---|
679 | localPath = ReplaceString("/", localPath, ":") |
---|
680 | |
---|
681 | Wave/Z w = $localPath |
---|
682 | if(waveExists(w) == 1) |
---|
683 | w = wav |
---|
684 | Print "write to local folder done" |
---|
685 | return(0) //we're done, get out |
---|
686 | endif |
---|
687 | |
---|
688 | |
---|
689 | // if the local wave did not exist, then we proceed to write to disk |
---|
690 | |
---|
691 | |
---|
692 | variable err=0, fileID,groupID |
---|
693 | String cDF = getDataFolder(1), temp |
---|
694 | String NXentry_name |
---|
695 | |
---|
696 | try |
---|
697 | HDF5OpenFile/P=catPathName /Z fileID as fname //open file read-write |
---|
698 | if(!fileID) |
---|
699 | err = 1 |
---|
700 | abort "HDF5 file does not exist" |
---|
701 | endif |
---|
702 | |
---|
703 | //get the NXentry node name |
---|
704 | HDF5ListGroup /TYPE=1 fileID, "/" |
---|
705 | //remove trailing ; from S_HDF5ListGroup |
---|
706 | |
---|
707 | Print "S_HDF5ListGroup = ",S_HDF5ListGroup |
---|
708 | |
---|
709 | NXentry_name = S_HDF5ListGroup |
---|
710 | NXentry_name = ReplaceString(";",NXentry_name,"") |
---|
711 | if(strsearch(NXentry_name,":",0)!=-1) //more than one entry under the root node |
---|
712 | err = 1 |
---|
713 | abort "More than one entry under the root node. Ambiguous" |
---|
714 | endif |
---|
715 | //concatenate NXentry node name and groupName |
---|
716 | // SRK - NOV2015 - dropped this and require the full group name passed in |
---|
717 | // groupName = "/" + NXentry_name + groupName |
---|
718 | Print "groupName = ",groupName |
---|
719 | HDF5OpenGroup /Z fileID , groupName, groupID |
---|
720 | |
---|
721 | if(!groupID) |
---|
722 | // don't create the group if the name isn't right -- throw up an error |
---|
723 | //HDF5CreateGroup /Z fileID, groupName, groupID |
---|
724 | err = 1 |
---|
725 | HDF5CloseFile /Z fileID |
---|
726 | DoAlert 0, "HDF5 group does not exist "+groupName+varname |
---|
727 | return(err) |
---|
728 | else |
---|
729 | // get attributes and save them |
---|
730 | //HDF5ListAttributes /Z fileID, groupName this is returning null. expect it to return semicolon delimited list of attributes |
---|
731 | //Wave attributes = S_HDF5ListAttributes |
---|
732 | endif |
---|
733 | |
---|
734 | HDF5SaveData /O /Z /IGOR=0 wav, groupID, varName |
---|
735 | if (V_flag != 0) |
---|
736 | err = 1 |
---|
737 | abort "Cannot save wave to HDF5 dataset " + varName |
---|
738 | endif |
---|
739 | |
---|
740 | |
---|
741 | //attributes - something could be added here as optional parameters and flagged |
---|
742 | // String attributes = "units" |
---|
743 | // Make/O/T/N=1 tmp |
---|
744 | // tmp[0] = "dimensionless" |
---|
745 | // HDF5SaveData /O /Z /IGOR=0 /A=attributes tmp, groupID, varName |
---|
746 | // if (V_flag != 0) |
---|
747 | // err = 1 |
---|
748 | // abort "Cannot save attributes to HDF5 dataset" |
---|
749 | // endif |
---|
750 | catch |
---|
751 | |
---|
752 | endtry |
---|
753 | |
---|
754 | // it is not necessary to close the group here. HDF5CloseFile will close the group as well |
---|
755 | if(groupID) |
---|
756 | HDF5CloseGroup /Z groupID |
---|
757 | endif |
---|
758 | |
---|
759 | if(fileID) |
---|
760 | HDF5CloseFile /Z fileID |
---|
761 | endif |
---|
762 | |
---|
763 | setDataFolder $cDF |
---|
764 | return err |
---|
765 | end |
---|
766 | |
---|
767 | //Write Wave 'wav' to hdf5 file 'fname' |
---|
768 | //Based on code from ANSTO (N. Hauser. nha 8/1/09) |
---|
769 | // |
---|
770 | // TODO |
---|
771 | // |
---|
772 | // -x change the /P=home to the user-defined data path (catPathName) |
---|
773 | // |
---|
774 | Function V_WriteTextWaveToHDF(fname, groupName, varName, wav) |
---|
775 | String fname, groupName, varName |
---|
776 | Wave/T wav |
---|
777 | |
---|
778 | // try a local folder first, then try to save to disk |
---|
779 | // |
---|
780 | String folderStr = V_RemoveDotExtension(V_GetFileNameFromPathNoSemi(fname)) |
---|
781 | |
---|
782 | String localPath = "root:Packages:NIST:VSANS:"+folderStr//+":entry" |
---|
783 | localPath += groupName + "/" + varName |
---|
784 | // make everything colons for local data folders |
---|
785 | localPath = ReplaceString("/", localPath, ":") |
---|
786 | |
---|
787 | Wave/Z/T w = $localPath |
---|
788 | if(waveExists(w) == 1) |
---|
789 | w = wav |
---|
790 | Print "write to local folder done" |
---|
791 | return(0) //we're done, get out |
---|
792 | endif |
---|
793 | |
---|
794 | |
---|
795 | // if the local wave did not exist, then we proceed to write to disk |
---|
796 | |
---|
797 | |
---|
798 | |
---|
799 | variable err=0, fileID,groupID |
---|
800 | String cDF = getDataFolder(1), temp |
---|
801 | String NXentry_name |
---|
802 | |
---|
803 | try |
---|
804 | HDF5OpenFile/P=catPathName /Z fileID as fname //open file read-write |
---|
805 | if(!fileID) |
---|
806 | err = 1 |
---|
807 | abort "HDF5 file does not exist" |
---|
808 | endif |
---|
809 | |
---|
810 | //get the NXentry node name |
---|
811 | HDF5ListGroup /TYPE=1 fileID, "/" |
---|
812 | //remove trailing ; from S_HDF5ListGroup |
---|
813 | |
---|
814 | Print "S_HDF5ListGroup = ",S_HDF5ListGroup |
---|
815 | |
---|
816 | NXentry_name = S_HDF5ListGroup |
---|
817 | NXentry_name = ReplaceString(";",NXentry_name,"") |
---|
818 | if(strsearch(NXentry_name,":",0)!=-1) //more than one entry under the root node |
---|
819 | err = 1 |
---|
820 | abort "More than one entry under the root node. Ambiguous" |
---|
821 | endif |
---|
822 | |
---|
823 | //concatenate NXentry node name and groupName |
---|
824 | // SRK - NOV2015 - dropped this and require the full group name passed in |
---|
825 | // groupName = "/" + NXentry_name + groupName |
---|
826 | Print "groupName = ",groupName |
---|
827 | |
---|
828 | HDF5OpenGroup /Z fileID , groupName, groupID |
---|
829 | |
---|
830 | if(!groupID) |
---|
831 | // don't create the group it the name isn't right -- throw up an error |
---|
832 | //HDF5CreateGroup /Z fileID, groupName, groupID |
---|
833 | err = 1 |
---|
834 | HDF5CloseFile /Z fileID |
---|
835 | DoAlert 0, "HDF5 group does not exist "+groupName+varname |
---|
836 | return(err) |
---|
837 | else |
---|
838 | // get attributes and save them |
---|
839 | //HDF5ListAttributes /Z fileID, groupName this is returning null. expect it to return semicolon delimited list of attributes |
---|
840 | //Wave attributes = S_HDF5ListAttributes |
---|
841 | endif |
---|
842 | |
---|
843 | HDF5SaveData /O /Z /IGOR=0 wav, groupID, varName |
---|
844 | if (V_flag != 0) |
---|
845 | err = 1 |
---|
846 | abort "Cannot save wave to HDF5 dataset " + varName |
---|
847 | endif |
---|
848 | |
---|
849 | |
---|
850 | //attributes - something could be added here as optional parameters and flagged |
---|
851 | // String attributes = "units" |
---|
852 | // Make/O/T/N=1 tmp |
---|
853 | // tmp[0] = "dimensionless" |
---|
854 | // HDF5SaveData /O /Z /IGOR=0 /A=attributes tmp, groupID, varName |
---|
855 | // if (V_flag != 0) |
---|
856 | // err = 1 |
---|
857 | // abort "Cannot save attributes to HDF5 dataset" |
---|
858 | // endif |
---|
859 | catch |
---|
860 | |
---|
861 | endtry |
---|
862 | |
---|
863 | if(groupID) |
---|
864 | HDF5CloseGroup /Z groupID |
---|
865 | endif |
---|
866 | |
---|
867 | if(fileID) |
---|
868 | HDF5CloseFile /Z fileID |
---|
869 | endif |
---|
870 | |
---|
871 | setDataFolder $cDF |
---|
872 | return err |
---|
873 | end |
---|
874 | |
---|
875 | ////////////////////////////// |
---|
876 | ////////////////////////////// |
---|
877 | ////////////////////////////// |
---|
878 | |
---|
879 | |
---|