source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_HDF5_RW_Utils.ipf @ 1002

Last change on this file since 1002 was 1002, checked in by srkline, 6 years ago

main changes here are the addition of a first pass at the file catalog, and patch panel. each of these is based on the old SANS file (for now) and has been updated to at least compile.

Much more work needs to be done to get the functionality to be what VSANS needs, both in what is important to report in the file catalog, and how to best present the patch GUI for different situations

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