source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/HDF5_ConvertVAX_to_HDF5.ipf @ 947

Last change on this file since 947 was 946, checked in by srkline, 9 years ago

Adding procedures that will allow read/write of raw data in HDF5 format. No Nexus file definition has been settled upon yet, so I made up my own for testing, simply converting what was present in the VAX file header. Simple read/write operations are functional, but no full scale testing.

Transmission calculation is partially broken as there are no file suffixes anymore.

Otherwise, a good starting point for the HDF5/Nexus of the future.

File size: 22.9 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2
3
4// crudely converts the VAX format as read into RAW into an HDF5 file
5//
6// Not any thought was given to HDF5 structure
7//
8// the simple read/write works...
9// linear_data does not seem to need to be transposed at all
10//
11//  -- this seems too easy. what am I doing wrong? Is something getting garbled when I
12// write back any single values back to the file
13//
14// -- try a string value next
15//
16
17
18// lays out the tree
19
20Function SetupStructure()
21
22        SetDataFolder root:
23       
24        NewDataFolder/O root:entry1
25        NewDataFolder/O root:entry1:Run1
26        NewDataFolder/O root:entry1:Run1:Sample
27        NewDataFolder/O root:entry1:Run1:Run
28        NewDataFolder/O root:entry1:Run1:Detector
29        NewDataFolder/O root:entry1:Run1:Instrument
30        NewDataFolder/O root:entry1:Run1:Analysis
31
32
33        SetDataFolder root:entry1
34    Make/O/T/N=1 filename
35   
36        SetDataFolder root:entry1:Run1
37        Make/O/T/N=1 runLabel
38
39        SetDataFolder root:entry1:Run1:Sample
40// SAMPLE     
41        Make/O/D/N=1 TRNS
42        Make/O/D/N=1 THK
43        Make/O/D/N=1 POSITION
44        Make/O/D/N=1 ROTANG
45        Make/O/I/N=1 TABLE
46        Make/O/I/N=1 HOLDER
47        Make/O/I/N=1 BLANK
48        Make/O/D/N=1 TEMP
49        Make/O/D/N=1 FIELD
50        Make/O/I/N=1 TCTRLR
51        Make/O/D/N=1 MAGNET
52        Make/O/T/N=1 TUNITS
53        Make/O/T/N=1 FUNITS
54
55        SetDataFolder root:entry1:Run1:Run
56// RUN
57        Make/O/I/N=1 NPRE
58        Make/O/I/N=1 CTIME
59        Make/O/I/N=1 RTIME
60        Make/O/I/N=1 NUMRUNS
61        Make/O/D/N=1 MONCNT
62        Make/O/D/N=1 SAVMON
63        Make/O/D/N=1 DETCNT
64        Make/O/D/N=1 ATTEN
65        Make/O/T/N=1 TIMDAT
66        Make/O/T/N=1 TYPE
67        Make/O/T/N=1 DEFDIR
68        Make/O/T/N=1 MODE
69        Make/O/T/N=1 RESERVE
70//        Make/O/T/N=1 LOGDATIM
71       
72       
73        SetDataFolder root:entry1:Run1:Detector
74// DET
75        Make/O/T/N=1 TYP
76        Make/O/D/N=3 CALX
77        Make/O/D/N=3 CALY
78        Make/O/I/N=1 NUM
79        Make/O/I/N=1 DetSPACER
80        Make/O/D/N=1 BEAMX
81        Make/O/D/N=1 BEAMY
82        Make/O/D/N=1 DIS
83        Make/O/D/N=1 ANG
84        Make/O/D/N=1 SIZ
85        Make/O/D/N=1 BSTOP
86        Make/O/D/N=1 DetBLANK
87
88                Make/O/D/N=(128,128) data
89
90        SetDataFolder root:entry1:Run1:Instrument
91// RESOLUTION
92        Make/O/D/N=1 AP1
93        Make/O/D/N=1 AP2
94        Make/O/D/N=1 AP12DIS
95        Make/O/D/N=1 LMDA
96        Make/O/D/N=1 DLMDA
97        Make/O/D/N=1 SAVEFlag
98// BMSTP
99        Make/O/D/N=1 XPOS
100        Make/O/D/N=1 YPOS       
101// TIMESLICING
102        Make/O/T/N=1 SLICING
103        Make/O/I/N=1 MULTFACT
104        Make/O/I/N=1 LTSLICE
105
106// POLARIZATION
107        Make/O/T/N=1 PRINTPOL
108        Make/O/T/N=1 FLIPPER
109        Make/O/D/N=1 HORIZ
110        Make/O/D/N=1 VERT       
111// TEMP
112        Make/O/T/N=1 PRINTEMP
113        Make/O/D/N=1 HOLD
114//        Make/O/D/N=1 ERR
115        Make/O/D/N=1 ERR_TEMP
116        Make/O/D/N=1 TempBLANK
117        Make/O/T/N=1 EXTEMP
118        Make/O/T/N=1 EXTCNTL
119        Make/O/T/N=1 TempEXTRA2
120        Make/O/I/N=1 TempRESERVE
121// MAGNET
122        Make/O/T/N=1 PRINTMAG
123        Make/O/T/N=1 SENSOR
124        Make/O/D/N=1 CURRENT
125        Make/O/D/N=1 CONV
126        Make/O/D/N=1 FIELDLAST
127        Make/O/D/N=1 MagnetBLANK
128        Make/O/D/N=1 MagnetSPACER
129// VOLTAGE
130        Make/O/T/N=1 PRINTVOLT
131        Make/O/D/N=1 VOLTS
132        Make/O/D/N=1 VoltBLANK
133        Make/O/I/N=1 VoltSPACER
134     
135        SetDataFolder root:entry1:Run1:Analysis
136// ANALYSIS
137        Make/O/I/N=2 ROWS
138        Make/O/I/N=2 COLS
139        Make/O/D/N=1 FACTOR
140        Make/O/D/N=1 AnalysisQMIN
141        Make/O/D/N=1 AnalysisQMAX
142        Make/O/D/N=1 IMIN
143        Make/O/D/N=1 IMAX
144
145// PARAMS
146        Make/O/I/N=1 BLANK1
147        Make/O/I/N=1 BLANK2
148        Make/O/I/N=1 BLANK3
149        Make/O/D/N=1 TRNSCNT
150        Make/O/D/N=1 ParamEXTRA1
151        Make/O/D/N=1 ParamEXTRA2
152        Make/O/D/N=1 ParamEXTRA3
153        Make/O/T/N=1 ParamRESERVE
154
155        SetDataFolder root:
156       
157End
158
159
160// fills the tree structure based on the RTI from RAW
161// logicals are skipped
162Function FillStructureFromRTI()
163
164        WAVE rw = root:Packages:NIST:RAW:RealsRead
165        WAVE iw = root:Packages:NIST:RAW:IntegersRead
166        WAVE/T tw = root:Packages:NIST:RAW:TextRead
167
168       
169        SetDataFolder root:entry1
170    Wave/T filename
171
172        String newFileName= GetNameFromHeader(tw[0])            //02JUL13
173
174        //TODO - not the best choice of file name, (maybe not unique) but this is only a test...     
175    filename[0] = newfilename[0,7]+".h5"                //make sure the file name in the header matches that on disk!
176   
177        SetDataFolder root:entry1:Run1
178    Wave/T runLabel
179
180        runLabel[0] = tw[6]
181
182        SetDataFolder root:entry1:Run1:Sample
183// SAMPLE     
184        Wave TRNS
185        Wave THK
186        Wave POSITION
187        Wave ROTANG
188        Wave TABLE
189        Wave HOLDER
190        Wave BLANK
191        Wave TEMP
192        Wave FIELD
193        Wave TCTRLR
194        Wave MAGNET
195        Wave/T TUNITS
196        Wave/T FUNITS
197
198        TRNS[0] = rw[4]
199        THK[0] = rw[5]
200        POSITION[0] = rw[6]
201        ROTANG[0] = rw[7]
202        TABLE[0] = iw[4]
203        HOLDER[0] = iw[5]
204        BLANK[0] = iw[6]
205        TEMP[0] = rw[8]
206        FIELD[0] = rw[9]
207        TCTRLR[0] = iw[7]
208        MAGNET[0] = iw[8]
209        TUNITS[0] = tw[7]
210        FUNITS[0] = tw[8]
211
212
213        SetDataFolder root:entry1:Run1:Run
214// RUN
215        Wave NPRE
216        Wave CTIME
217        Wave RTIME
218        Wave NUMRUNS
219        Wave MONCNT
220        Wave SAVMON
221        Wave DETCNT
222        Wave ATTEN
223        Wave/T TIMDAT
224        Wave/T TYPE
225        Wave/T DEFDIR
226        Wave/T MODE
227        Wave/T RESERVE
228//        Wave/T LOGDATIM
229       
230       
231        NPRE[0] = iw[0]
232        CTIME[0] = iw[1]
233        RTIME[0] = iw[2]
234        NUMRUNS[0] = iw[3]
235        MONCNT[0] = rw[0]
236        SAVMON[0] = rw[1]
237        DETCNT[0] = rw[2]
238        ATTEN[0] = rw[3]
239        TIMDAT[0] = tw[1]
240        TYPE[0] = tw[2]
241        DEFDIR[0] = tw[3]
242        MODE[0] = tw[4]
243        RESERVE[0] = tw[5]
244//        LOGDATIM
245       
246       
247        SetDataFolder root:entry1:Run1:Detector
248// DET
249        Wave/T TYP
250        Wave CALX
251        Wave CALY
252        Wave NUM
253        Wave DetSPACER
254        Wave BEAMX
255        Wave BEAMY
256        Wave DIS
257        Wave ANG
258        Wave SIZ
259        Wave BSTOP
260        Wave DetBLANK
261       
262                 Wave data
263
264                //CALX is 3 pts
265                //CALY is 3 pts
266                //data is 128,128
267               
268       TYP[0] = tw[9]
269        CALX[0] = rw[10]
270        CALX[1] = rw[11]
271        CALX[2] = rw[12]
272        CALY[0] = rw[13]
273        CALY[1] = rw[14]
274        CALY[2] = rw[15]
275        NUM[0] = iw[9]
276        DetSPACER[0] = iw[10]
277        BEAMX[0] = rw[16]
278        BEAMY[0] = rw[17]
279        DIS[0] = rw[18]
280        ANG[0] = rw[19]
281        SIZ[0] = rw[20]
282        BSTOP[0] = rw[21]
283        DetBLANK[0] = rw[22]
284
285                 Wave linear_data = root:Packages:NIST:RAW:linear_data
286                 data = linear_data
287               
288               
289        SetDataFolder root:entry1:Run1:Instrument
290// RESOLUTION
291        Wave AP1
292        Wave AP2
293        Wave AP12DIS
294        Wave LMDA
295        Wave DLMDA
296        Wave SAVEFlag
297// BMSTP
298        Wave XPOS
299        Wave YPOS       
300// TIMESLICING
301        Wave/T SLICING          //logical
302        Wave MULTFACT
303        Wave LTSLICE
304
305// POLARIZATION
306        Wave/T PRINTPOL                 //logical
307        Wave/T FLIPPER                  //logical
308        Wave HORIZ
309        Wave VERT       
310// TEMP
311        Wave/T PRINTEMP                 //logical
312        Wave HOLD
313        Wave ERR_TEMP
314        Wave TempBLANK
315        Wave/T EXTEMP                   //logical
316        Wave/T EXTCNTL                  //logical
317        Wave/T TempEXTRA2               //logical
318        Wave TempRESERVE
319// MAGNET
320        Wave/T PRINTMAG                 //logical
321        Wave/T SENSOR                   //logical
322        Wave CURRENT
323        Wave CONV
324        Wave FIELDLAST
325        Wave MagnetBLANK
326        Wave MagnetSPACER
327// VOLTAGE
328        Wave/T PRINTVOLT                //logical
329        Wave VOLTS
330        Wave VoltBLANK
331        Wave VoltSPACER
332 
333 
334        AP1[0] = rw[23]
335        AP2[0] = rw[24]
336        AP12DIS[0] = rw[25]
337        LMDA[0] = rw[26]
338        DLMDA[0] = rw[27]
339        SAVEFlag[0] = rw[28]
340 
341        XPOS[0] = rw[37]
342        YPOS[0] = rw[38]
343     
344        MULTFACT[0] = iw[11]
345        LTSLICE[0] = iw[12]
346     
347        HORIZ[0] = rw[45]
348        VERT[0] = rw[46]
349// TEMP
350        HOLD[0] = rw[29]
351        ERR_TEMP[0] = rw[30]
352        TempBLANK[0] = rw[31]
353        TempRESERVE[0] = iw[14]
354// MAGNET
355        CURRENT[0] = rw[32]
356        CONV[0] = rw[33]
357        FIELDLAST[0] = rw[34]
358        MagnetBLANK[0] = rw[35]
359        MagnetSPACER[0] = rw[36]
360// VOLTAGE
361        VOLTS[0] = rw[43]
362        VoltBLANK[0] = rw[44]
363        VoltSPACER[0] = iw[18]
364     
365        SetDataFolder root:entry1:Run1:Analysis
366// ANALYSIS
367        Wave ROWS
368        Wave COLS
369        Wave FACTOR
370        Wave AnalysisQMIN
371        Wave AnalysisQMAX
372        Wave IMIN
373        Wave IMAX
374
375// PARAMS
376        Wave BLANK1
377        Wave BLANK2
378        Wave BLANK3
379        Wave TRNSCNT
380        Wave ParamEXTRA1
381        Wave ParamEXTRA2
382        Wave ParamEXTRA3
383        Wave/T ParamRESERVE     
384       
385                        // ROWS is 2 pts
386                        // COLS is 2 pts
387                       
388// ANALYSIS
389        ROWS[0] = iw[19]
390        ROWS[1] = iw[20]
391        COLS[0] = iw[21]
392        COLS[1] = iw[22]
393
394        FACTOR[0] = rw[47]
395        AnalysisQMIN[0] = rw[48]
396        AnalysisQMAX[0] = rw[49]
397        IMIN[0] = rw[50]
398        IMAX[0] = rw[51]
399
400// PARAMS
401        BLANK1[0] = iw[15]
402        BLANK2[0] = iw[16]
403        BLANK3[0] = iw[17]
404        TRNSCNT[0] = rw[39]
405        ParamEXTRA1[0] = rw[40]
406        ParamEXTRA2[0] = rw[41]
407        ParamEXTRA3[0] = rw[42]
408        ParamRESERVE[0] = tw[10]
409                       
410                       
411        SetDataFolder root:
412               
413        return(0)
414End
415
416
417
418Function Test_HDFWriteTrans(fname,val)
419        String fname
420        Variable val
421       
422       
423        String str
424        PathInfo home
425        str = S_path
426       
427        WriteTransmissionToHeader(str+fname,val)
428       
429        return(0)
430End
431
432//Function WriteTransmissionToHeader(fname,trans)
433//      String fname
434//      Variable trans
435//     
436//      Make/O/D/N=1 wTmpWrite
437//      String groupName = "/Sample"    //      /Run1/Sample becomes groupName /Run1/Run1/Sample
438//      String varName = "TRNS"
439//      wTmpWrite[0] = trans //
440//
441//      variable err
442//      err = HDFWrite_Wave(fname, groupName, varName, wTmpWrite)
443//      KillWaves wTmpWrite
444//     
445//      //err not handled here
446//             
447//      return(0)
448//End
449
450
451
452Function Test_ListAttributes(fname,groupName)
453        String fname,groupName
454        Variable trans
455       
456//      Make/O/D/N=1 wTmpWrite
457//      String groupName = "/Sample"    //      /Run1/Sample becomes groupName /Run1/Run1/Sample
458//      String varName = "TRNS"
459//      wTmpWrite[0] = trans //
460        String str
461        PathInfo home
462        str = S_path
463       
464        variable err
465        err = HDF_ListAttributes(str+fname, groupName)
466       
467        //err not handled here
468               
469        return(0)
470End
471
472Function HDF_ListAttributes(fname, groupName)
473        String fname, groupName
474       
475        variable err=0, fileID,groupID
476        String cDF = getDataFolder(1), temp
477        String NXentry_name, attrValue=""
478       
479        STRUCT HDF5DataInfo di  // Defined in HDF5 Browser.ipf.
480        InitHDF5DataInfo(di)    // Initialize structure.
481       
482        try     
483                HDF5OpenFile /Z fileID  as fname  //open file read-write
484                if(!fileID)
485                        err = 1
486                        abort "HDF5 file does not exist"
487                endif
488               
489                HDF5OpenGroup /Z fileID , groupName, groupID
490
491        //      !! At the moment, there is no entry for sample thickness in our data file
492        //      therefore create new HDF5 group to enable write / patch command
493        //      comment out the following group creation once thickness appears in revised file
494       
495                if(!groupID)
496                        HDF5CreateGroup /Z fileID, groupName, groupID
497                        //err = 1
498                        //abort "HDF5 group does not exist"
499                else
500
501//                      HDF5AttributeInfo(fileID, "/", 1, "file_name", 0, di)
502                        HDF5AttributeInfo(fileID, "/", 1, "NeXus_version", 0, di)
503                        Print di
504
505//                      see the HDF5 Browser  for how to get the actual <value> of the attribute. See GetPreviewString in
506//        or in FillGroupAttributesList or in FillDatasetAttributesList (from FillLists)
507//                      it seems to be ridiculously complex to get such a simple bit of information - the HDF5BrowserData STRUCT
508//                      needs to be filled first. Ugh.
509                        attrValue = GetPreviewString(fileID, 1, di, "/entry", "cucumber")
510                        Print "attrValue = ",attrValue
511                       
512                       
513                        //get attributes and save them
514                        HDF5ListAttributes/TYPE=1 /Z fileID, groupName          //TYPE=1 means that we're referencing a group, not a dataset
515                        Print "S_HDF5ListAttributes = ", S_HDF5ListAttributes
516                       
517                        // passing the groupID works too, then the group name is not needed                     
518                        HDF5ListAttributes/TYPE=1 /Z groupID, "."               //TYPE=1 means that we're referencing a group, not a dataset
519                        Print "S_HDF5ListAttributes = ", S_HDF5ListAttributes
520                endif
521        catch
522
523                // catch any aborts here
524               
525        endtry
526       
527        if(groupID)
528                HDF5CloseGroup /Z groupID
529        endif
530       
531        if(fileID)
532                HDF5CloseFile /Z fileID
533        endif
534
535        setDataFolder $cDF
536        return err
537end
538
539// this is my procedure to save VAX to HDF5, once I've filled the folder tree
540//
541Function VAXSaveGroupAsHDF5(dfPath, filename)
542        String dfPath   // e.g., "root:FolderA" or ":"
543        String filename
544
545        Variable result = 0     // 0 means no error
546       
547        Variable fileID
548        HDF5CreateFile/P=home /O /Z fileID as filename
549        if (V_flag != 0)
550                Print "HDF5CreateFile failed"
551                return -1
552        endif
553
554        HDF5SaveGroup /IGOR=0 /O /R /Z $dfPath, fileID, "."
555//      HDF5SaveGroup /O /R /Z $dfPath, fileID, "."
556        if (V_flag != 0)
557                Print "HDF5SaveGroup failed"
558                result = -1
559        endif
560       
561        HDF5CloseFile fileID
562
563        return result
564End
565
566
567
568//////// Two procedures that test out Pete Jemain's HDF5Gateway
569//
570// This works fine, but it may not be terribly compatible with the way NICE will eventually
571// write out the data files. I'll have very little control over that and I'll need to cobble together
572// a bunch of fixes to cover up their mistakes.
573//
574// Using Nick Hauser's code as a starting point may be a lot more painful, but more flexible in the end.
575//
576// I'm completely baffled about what to do with attributes. Are they needed, is this the best way to deal
577// with them, do I care about reading them in, and if I do, why?
578//
579Proc HDF5Gate_WriteTest()
580
581        // create the folder structure
582        NewDataFolder/O/S root:mydata
583        NewDataFolder/O sasentry
584        NewDataFolder/O :sasentry:sasdata
585
586        // create the waves
587        Make/O :sasentry:sasdata:I0
588        Make/O :sasentry:sasdata:Q0
589
590        Make/O/N=0 Igor___folder_attributes
591        Make/O/N=0 :sasentry:Igor___folder_attributes
592        Make/O/N=0 :sasentry:sasdata:Igor___folder_attributes
593
594        // create the attributes
595        Note/K Igor___folder_attributes, "producer=IgorPro\rNX_class=NXroot"
596        Note/K :sasentry:Igor___folder_attributes, "NX_class=NXentry"
597        Note/K :sasentry:sasdata:Igor___folder_attributes, "NX_class=NXdata"
598        Note/K :sasentry:sasdata:I0, "units=1/cm\rsignal=1\rtitle=reduced intensity"
599        Note/K :sasentry:sasdata:Q0, "units=1/A\rtitle=|scattering vector|"
600
601        // create the cross-reference mapping
602        Make/O/T/N=(5,2) HDF5___xref
603        Edit/K=0 'HDF5___xref';DelayUpdate
604        HDF5___xref[0][1] = ":"
605        HDF5___xref[1][1] = ":sasentry"
606        HDF5___xref[2][1] = ":sasentry:sasdata"
607        HDF5___xref[3][1] = ":sasentry:sasdata:I0"
608        HDF5___xref[4][1] = ":sasentry:sasdata:Q0"
609        HDF5___xref[0][0] = "/"
610        HDF5___xref[1][0] = "/sasentry"
611        HDF5___xref[2][0] = "/sasentry/sasdata"
612        HDF5___xref[3][0] = "/sasentry/sasdata/I"
613        HDF5___xref[4][0] = "/sasentry/sasdata/Q"
614
615        // Check our work so far.
616        // If something prints, there was an error above.
617        print H5GW_ValidateFolder("root:mydata")
618
619        // set I0 and Q0 to your data
620
621        print H5GW_WriteHDF5("root:mydata", "mydata.h5")
622       
623        SetDataFolder root:
624End
625
626Proc HDF5Gate_ReadTest(file)
627        String file
628//      NewDataFolder/O/S root:newdata
629        Print H5GW_ReadHDF5("", file)   // reads into current folder
630        SetDataFolder root:
631End
632
633
634
635//// after reading in an HDF file, convert it into something I can use with data reduction
636//
637// This is to be an integral part of the file loader
638//
639// I guess I need to load the file into a temporary location, and then copy what I need to the local RTI
640// and then get rid of the temp dump. ANSTO keeps all of the loads around, but this may get too large
641// especially if NICE dumps all of the logs into the data file.
642//
643// -- and I may need to have a couple of these, at least for testing to be able to convert the
644// minimal VAX file to HDF, and also to write out/ have a container/ for what NICE calls a data file.
645//
646//
647
648// From the HDF5 tree as read in from a (converted) raw VAX file,
649// put everything back into its proper place in the RTI waves
650// (and the data!)
651//
652Function FillRTIFromHDFTree(folderStr)
653        String folderStr
654
655        WAVE rw = root:Packages:NIST:RAW:RealsRead
656        WAVE iw = root:Packages:NIST:RAW:IntegersRead
657        WAVE/T tw = root:Packages:NIST:RAW:TextRead
658
659        rw = -999
660        iw = 11111
661        tw = "jibberish"
662       
663        folderStr = RemoveDotExtension(folderStr)               // to make sure that the ".h5" or any other extension is removed
664//      folderStr = RemoveEnding(folderStr,".h5")               // to make sure that the ".h5" or any other extension is removed
665       
666        String base="root:"+folderStr+":"
667        SetDataFolder $base
668    Wave/T filename
669   
670    tw[0] = filename[0]
671   
672        SetDataFolder $(base+"Run1")
673    Wave/T runLabel
674
675        tw[6] = runLabel[0]
676
677        SetDataFolder $(base+"Run1:Sample")
678// SAMPLE     
679        Wave TRNS
680        Wave THK
681        Wave POSITION
682        Wave ROTANG
683        Wave TABLE
684        Wave HOLDER
685        Wave BLANK
686        Wave TEMP
687        Wave FIELD
688        Wave TCTRLR
689        Wave MAGNET
690        Wave/T TUNITS
691        Wave/T FUNITS
692
693        rw[4] = TRNS[0]
694        rw[5] = THK[0]
695        rw[6] = POSITION[0]
696        rw[7] = ROTANG[0]
697        iw[4] = TABLE[0]
698        iw[5] = HOLDER[0]
699        iw[6] = BLANK[0]
700        rw[8] = TEMP[0]
701        rw[9] = FIELD[0]
702        iw[7] = TCTRLR[0]
703        iw[8] = MAGNET[0]
704        tw[7] = TUNITS[0]
705        tw[8] = FUNITS[0]
706
707
708        SetDataFolder $(base+"Run1:Run")
709// RUN
710        Wave NPRE
711        Wave CTIME
712        Wave RTIME
713        Wave NUMRUNS
714        Wave MONCNT
715        Wave SAVMON
716        Wave DETCNT
717        Wave ATTEN
718        Wave/T TIMDAT
719        Wave/T TYPE
720        Wave/T DEFDIR
721        Wave/T MODE
722        Wave/T RESERVE
723//        Wave/T LOGDATIM
724       
725       
726        iw[0] = NPRE[0]
727        iw[1] = CTIME[0]
728        iw[2] = RTIME[0]
729        iw[3] = NUMRUNS[0]
730        rw[0] = MONCNT[0]
731        rw[1] = SAVMON[0]
732        rw[2] = DETCNT[0]
733        rw[3] = ATTEN[0]
734        tw[1] = TIMDAT[0]
735        tw[2] = TYPE[0]
736        tw[3] = DEFDIR[0]
737        tw[4] = MODE[0]
738        tw[5] = RESERVE[0]
739//        LOGDATIM
740       
741       
742        SetDataFolder $(base+"Run1:Detector")
743// DET
744        Wave/T TYP
745        Wave CALX
746        Wave CALY
747        Wave NUM
748        Wave DetSPACER
749        Wave BEAMX
750        Wave BEAMY
751        Wave DIS
752        Wave ANG
753        Wave SIZ
754        Wave BSTOP
755        Wave DetBLANK
756       
757                 Wave data
758
759                //CALX is 3 pts
760                //CALY is 3 pts
761                //data is 128,128
762               
763        tw[9] = TYP[0]
764        rw[10] = CALX[0]
765        rw[11] = CALX[1]
766        rw[12] = CALX[2]
767        rw[13] = CALY[0]
768        rw[14] = CALY[1]
769        rw[15] = CALY[2]
770        iw[9] = NUM[0]
771        iw[10] = DetSPACER[0]
772        rw[16] = BEAMX[0]
773        rw[17] = BEAMY[0]
774        rw[18] = DIS[0]
775        rw[19] = ANG[0]
776        rw[20] = SIZ[0]
777        rw[21] = BSTOP[0]
778        rw[22] = DetBLANK[0]
779
780//               Wave linear_data = root:Packages:NIST:RAW:linear_data
781//               Wave raw_data = root:Packages:NIST:RAW:data
782//               linear_data = data
783//               raw_data = data
784               
785                /// **** what about the error wave?
786               
787               
788               
789        SetDataFolder $(base+"Run1:Instrument")
790// RESOLUTION
791        Wave AP1
792        Wave AP2
793        Wave AP12DIS
794        Wave LMDA
795        Wave DLMDA
796        Wave SAVEFlag
797// BMSTP
798        Wave XPOS
799        Wave YPOS       
800// TIMESLICING
801        Wave/T SLICING          //logical
802        Wave MULTFACT
803        Wave LTSLICE
804
805// POLARIZATION
806        Wave/T PRINTPOL                 //logical
807        Wave/T FLIPPER                  //logical
808        Wave HORIZ
809        Wave VERT       
810// TEMP
811        Wave/T PRINTEMP                 //logical
812        Wave HOLD
813        Wave ERR_TEMP
814//        Wave ERR0
815        Wave TempBLANK
816        Wave/T EXTEMP                   //logical
817        Wave/T EXTCNTL                  //logical
818        Wave/T TempEXTRA2               //logical
819        Wave TempRESERVE
820// MAGNET
821        Wave/T PRINTMAG                 //logical
822        Wave/T SENSOR                   //logical
823        Wave CURRENT
824        Wave CONV
825        Wave FIELDLAST
826        Wave MagnetBLANK
827        Wave MagnetSPACER
828// VOLTAGE
829        Wave/T PRINTVOLT                //logical
830        Wave VOLTS
831        Wave VoltBLANK
832        Wave VoltSPACER
833 
834 
835        rw[23] = AP1[0]
836        rw[24] = AP2[0]
837        rw[25] = AP12DIS[0]
838        rw[26] = LMDA[0]
839        rw[27] = DLMDA[0]
840        rw[28] = SAVEFlag[0]
841 
842        rw[37] = XPOS[0]
843        rw[38] = YPOS[0]
844     
845        iw[11] = MULTFACT[0]
846        iw[12] = LTSLICE[0]
847     
848        rw[45] = HORIZ[0]
849        rw[46] = VERT[0]
850// TEMP
851        rw[29] = HOLD[0]
852        rw[30] = ERR_TEMP[0]
853//        rw[30] = ERR0[0]
854        rw[31] = TempBLANK[0]
855        iw[14] = TempRESERVE[0]
856// MAGNET
857        rw[32] = CURRENT[0]
858        rw[33] = CONV[0]
859        rw[34] = FIELDLAST[0]
860        rw[35] = MagnetBLANK[0]
861        rw[36] = MagnetSPACER[0]
862// VOLTAGE
863        rw[43] = VOLTS[0]
864        rw[44] = VoltBLANK[0]
865        iw[18] = VoltSPACER[0]
866     
867        SetDataFolder $(base+"Run1:Analysis")
868// ANALYSIS
869        Wave ROWS
870        Wave COLS
871        Wave FACTOR
872        Wave AnalysisQMIN
873        Wave AnalysisQMAX
874        Wave IMIN
875        Wave IMAX
876
877// PARAMS
878        Wave BLANK1
879        Wave BLANK2
880        Wave BLANK3
881        Wave TRNSCNT
882        Wave ParamEXTRA1
883        Wave ParamEXTRA2
884        Wave ParamEXTRA3
885        Wave/T ParamRESERVE     
886       
887                        // ROWS is 2 pts
888                        // COLS is 2 pts
889                       
890// ANALYSIS
891        iw[19] = ROWS[0]
892        iw[20] = ROWS[1]
893        iw[21] = COLS[0]
894        iw[22] = COLS[1]
895
896        rw[47] = FACTOR[0]
897        rw[48] = AnalysisQMIN[0]
898        rw[49] = AnalysisQMAX[0]
899        rw[50] = IMIN[0]
900        rw[51] = IMAX[0]
901
902// PARAMS
903        iw[15] = BLANK1[0]
904        iw[16] = BLANK2[0]
905        iw[17] = BLANK3[0]
906        rw[39] = TRNSCNT[0]
907        rw[40] = ParamEXTRA1[0]
908        rw[41] = ParamEXTRA2[0]
909        rw[42] = ParamEXTRA3[0]
910        tw[10] = ParamRESERVE[0]
911                       
912                       
913        SetDataFolder root:
914               
915        return(0)
916End
917
918
919//given a filename of a SANS data filename of the form
920// name.anything
921//returns the name as a string without the ".fbdfasga" extension
922//
923// returns the input string if a"." can't be found (maybe it wasn't there"
924Function/S RemoveDotExtension(item)
925        String item
926        String invalid = item   //
927        Variable num=-1
928       
929        //find the "dot"
930        String runStr=""
931        Variable pos = strsearch(item,".",0)
932        if(pos == -1)
933                //"dot" not found
934                return (invalid)
935        else
936                //found, get all of the characters preceeding it
937                runStr = item[0,pos-1]
938                return (runStr)
939        Endif
940End
941
942
943
944
945//////////////////////////////////////////////////
946
947
948
949Macro BatchConvertToHDF5(firstFile,lastFile)
950        Variable firstFile=1,lastFile=100
951
952        SetupStructure()
953        fBatchConvertToHDF5(firstFile,lastFile)
954
955End
956
957// lo is the first file number
958// hi is the last file number (inclusive)
959//
960Function fBatchConvertToHDF5(lo,hi)
961        Variable lo,hi
962       
963        Variable ii
964        String file
965       
966        String fname="",pathStr="",fullPath="",newFileName=""
967
968        PathInfo catPathName                    //this is where the files are
969        pathStr=S_path
970       
971        //loop over all files
972        for(ii=lo;ii<=hi;ii+=1)
973                file = FindFileFromRunNumber(ii)
974                if(strlen(file) != 0)
975                        // load the data
976                        ReadHeaderAndData(file)         //file is the full path
977                        String/G root:myGlobals:gDataDisplayType="RAW" 
978                        fRawWindowHook()
979                        WAVE/T/Z tw = $"root:Packages:NIST:RAW:textRead"        //to be sure that wave exists if no data was ever displayed
980                        newFileName= GetNameFromHeader(tw[0])           //02JUL13
981                       
982                        // convert it
983                        FillStructureFromRTI()
984                       
985                        // save it
986                        VAXSaveGroupAsHDF5("root:entry1", newfilename[0,7]+".h5")
987
988                else
989                        printf "run number %d not found\r",ii
990                endif
991        endfor
992       
993        return(0)
994End
995
Note: See TracBrowser for help on using the repository browser.