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

Last change on this file since 982 was 982, checked in by srkline, 7 years ago

more changes and additons to display VSANS data

adding functions for IvsQ plotting

coverted much of VCALC to have similar folder structure as HDF to allow re-use of the Q-binning procedures from VCALC with real data in work files.

re-working the beam center finder to get it to work with work file data rather then only VCALC.

new plotting routines for the panels to rescale to the beam center (still in pixels, though)

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