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

Last change on this file since 1070 was 954, checked in by srkline, 8 years ago

converted and renamed VSANS files. "VC_" prefix for VCALC related files (that's all of them right now), and moved and renamed parts of files so that the ipf names are more logical now with the contents. Deleted the "V_" prefix files. Added a lengthy routine to be able to write out a VSANS file in HDF format. This is NOT the final and approved data format, only a working version so that I can test things out...

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