source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_HDF5_Write.ipf @ 1109

Last change on this file since 1109 was 1109, checked in by srkline, 4 years ago

Many changes:

Made the VCALC panel aware of all of the binning options
Corrected the behavior of the VCALC preset conditions
Adjusted how the Slit data is binned so that there are not duplicated q-values in the output

Made Absolute scaling aware of the back detector. Now the ABS String in the protocol has a second
set of scaling constants tagged with "_B" for the back detector. There is an added button
on the protocol panel to set the second set of constants. For the back detector, the read noise
is subtracted by reading it from the empty beam file (shifting over to the right by one box width)
All of the associated abs procedures are now aware of this.
More error checking needs to be added.

Back detector image is now shifted upon loading of the data. the default mask takes this into account
and masks out the padded (zero) regions.

in the protocol, DIV and MSK do not use grep any longer. it was just way too slow. Now it depends on

the file name having DIV or MASK respectively.



Raw data files can now be added together, in the usual way from the protocol panel.



File size: 191.4 KB
Line 
1#pragma rtGlobals=3             // Use modern global access method and strict wave access.
2
3
4// Start to build up and test the r/w accessors for VSANS
5// (SANS has a template, VSANS does not, so just start from scratch here, since the
6// file structure will be different)
7//
8//
9
10//////////// WRITE FUNCTIONS ////////////////////
11//
12// Each of the individual write functions have both the "write" and "kill" function
13// calls explicitly in each named function to allow flexibility during real implementation.
14// The calls could be streamlined, but writing this way allows for individualized kill/nokill, depending
15// on the details of what is actually being written out, and the possibility of changing the
16// particular "Write" routine, if specific changes need to be made to match the data type (int, fp, etc).
17// Currently, I don't know all of the data types, or what is important in the HDF structure.
18// NOV 2015
19//
20
21
22//////////////////////////////////////////////
23//////////////////////////////////
24// for TESTING of the get functions - to quickly access and see if there are errors
25//
26// -- not sure how to test the string functions -- can't seem to get a FUNCREF to a string function
27// to work -- maybe it's not alllowed?
28//
29// -- also, now I have get_functions that take a detStr input with the detector information, so that the
30//    functions didn't need to be repeated
31//
32//      -- Not sure how to test the "write" functions. writing the wrong data type to the wrong data field will be a disaster
33//    Writing odd, dummy values will also be a mess - no way to know if I'm doing anything correctly
34//
35Function proto_V_write_FP(str)
36        String str
37        return(0)
38end
39Function proto_V_write_FP2(str,str2)
40        String str,str2
41        return(0)
42end
43//Function proto_V_write_STR(str)
44//      String str
45//      return("")
46//end
47
48Function Test_V_write_FP(str,fname)
49        String str,fname
50       
51        Variable ii,num
52        String list,item
53       
54       
55        list=FunctionList(str,";","NPARAMS:1,VALTYPE:1") //,VALTYPE:1 gives real return values, not strings
56//      Print list
57        num = ItemsInlist(list)
58       
59       
60        for(ii=0;ii<num;ii+=1)
61                item = StringFromList(ii, list , ";")
62                FUNCREF proto_V_write_FP f = $item
63                Print item ," = ", f(fname)
64        endfor
65       
66        return(0)
67end
68
69Function Test_V_write_FP2(str,fname,detStr)
70        String str,fname,detStr
71       
72        Variable ii,num
73        String list,item
74       
75       
76        list=FunctionList(str,";","NPARAMS:2,VALTYPE:1") //,VALTYPE:1 gives real return values, not strings
77//      Print list
78        num = ItemsInlist(list)
79       
80       
81        for(ii=0;ii<num;ii+=1)
82                item = StringFromList(ii, list , ";")
83                FUNCREF proto_V_write_FP2 f = $item
84                Print item ," = ", f(fname,detStr)
85        endfor
86       
87        return(0)
88end
89
90Function Test_V_write_STR(str,fname)
91        String str,fname
92       
93        Variable ii,num
94        String list,item,strToEx
95       
96       
97        list=FunctionList(str,";","NPARAMS:1,VALTYPE:4")
98//      Print list
99        num = ItemsInlist(list)
100       
101       
102        for(ii=0;ii<num;ii+=1)
103                item = StringFromList(ii, list , ";")
104        //      FUNCREF proto_V_write_STR f = $item
105                printf "%s = ",item
106                sprintf strToEx,"Print %s(\"%s\")",item,fname
107                Execute strToEx
108//              print strToEx
109//              Print item ," = ", f(fname)
110        endfor
111       
112        return(0)
113end
114
115Function Test_V_write_STR2(str,fname,detStr)
116        String str,fname,detStr
117       
118        Variable ii,num
119        String list,item,strToEx
120       
121       
122        list=FunctionList(str,";","NPARAMS:2,VALTYPE:4")
123//      Print list
124        num = ItemsInlist(list)
125       
126       
127        for(ii=0;ii<num;ii+=1)
128                item = StringFromList(ii, list , ";")
129        //      FUNCREF proto_V_write_STR f = $item
130                printf "%s = ",item
131                sprintf strToEx,"Print %s(\"%s\",\"%s\")",item,fname,detStr
132                Execute strToEx
133//              print strToEx
134//              Print item ," = ", f(fname)
135        endfor
136       
137        return(0)
138end
139///////////////////////////////////////
140
141
142//////////////////////////////////////////////
143
144
145///////////////////////
146//
147// *These are the specific bits of information to retrieve (or write) to the data file
148// *These functions use the path to the file as input, and each has the specific
149//   path to the variable srting, or wave hard-coded into the access function
150// *They call the generic worker functions to get the values, either from the local copy if present,
151//   or the full file is loaded.
152//
153// *Since the path is the important bit, these are written as get/write pairs to make it easier to
154//   keep up with any changes in path
155//
156//
157// TODO -- verify the paths, and add more as needed
158// TODO -- for all of the String functions -- "num" does nothing right now -
159//         -- if it ever does, or needs to, a lot of locations will need to be corrected
160//
161
162
163//////// TOP LEVEL
164//////// TOP LEVEL
165//////// TOP LEVEL
166
167//// nexus version used for definitions
168//Function V_writeNeXus_version(fname,str)
169//      String fname,str
170//     
171////    String path = "entry:NeXus_version"     
172//     
173//      Make/O/T/N=1 tmpTW
174//      String groupName = "/entry"     //     
175//      String varName = "NeXus_version"
176//      tmpTW[0] = str //
177//
178//      variable err
179//      err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
180//      if(err)
181//              Print "HDF write err = ",err
182//      endif
183//     
184//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
185////    err = V_KillNamedDataFolder(fname)
186////    if(err)
187////            Print "DataFolder kill err = ",err
188////    endif
189//             
190//      return(err)
191//End
192
193// TODO -- not mine, added somewhere by Nexus writer?
194// data collection time (! this is the true counting time??)
195Function V_writeCollectionTime(fname,val)
196        String fname
197        Variable val
198       
199//      String path = "entry:collection_time"   
200       
201        Make/O/D/N=1 wTmpWrite
202//      Make/O/R/N=1 wTmpWrite
203        String groupName = "/entry"     
204        String varName = "collection_time"
205        wTmpWrite[0] = val
206
207        variable err
208        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
209        if(err)
210                Print "HDF write err = ",err
211        endif
212        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
213//      err = V_KillNamedDataFolder(fname)
214//      if(err)
215//              Print "DataFolder kill err = ",err
216//      endif
217        return(err)
218End
219
220// fname is a local WORK folder
221Function V_putCollectionTime(fname,val)
222        String fname
223        Variable val
224
225//root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FB:beam_center_x
226        String path = "root:Packages:NIST:VSANS:"+fname+":"
227        path += "entry:collection_time"
228       
229        Wave/Z w = $path
230        if(waveExists(w) == 0)
231                return(1)
232        else
233        w[0] = val
234                return(0)
235        endif
236
237End
238
239// data directory where data files are stored (for user access, not archive)
240Function V_writeData_directory(fname,str)
241        String fname,str
242       
243//      String path = "entry:data_directory"   
244
245        Make/O/T/N=1 tmpTW
246        String groupName = "/entry"     //     
247        String varName = "data_directory"
248        tmpTW[0] = str //
249
250        variable err
251        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
252        if(err)
253                Print "HDF write err = ",err
254        endif
255       
256        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
257//      err = V_KillNamedDataFolder(fname)
258//      if(err)
259//              Print "DataFolder kill err = ",err
260//      endif
261               
262        return(err)
263End
264
265// Base class of Nexus definition (=NXsas)
266Function V_writeNexusDefinition(fname,str)
267        String fname,str
268       
269//      String path = "entry:definition"       
270
271        Make/O/T/N=1 tmpTW
272        String groupName = "/entry"     //     
273        String varName = "definition"
274        tmpTW[0] = str //
275
276        variable err
277        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
278        if(err)
279                Print "HDF write err = ",err
280        endif
281       
282        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
283//      err = V_KillNamedDataFolder(fname)
284//      if(err)
285//              Print "DataFolder kill err = ",err
286//      endif
287               
288        return(err)
289End
290
291// TODO -- not mine, added somewhere by Nexus writer?
292// data collection duration (may include pauses, other "dead" time)
293Function V_writeDataDuration(fname,val)
294        String fname
295        Variable val
296       
297        String path = "entry:duration" 
298       
299        Make/O/D/N=1 wTmpWrite
300//      Make/O/R/N=1 wTmpWrite
301        String groupName = "/entry"     
302        String varName = "duration"
303        wTmpWrite[0] = val
304
305        variable err
306        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
307        if(err)
308                Print "HDF write err = ",err
309        endif
310        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
311//      err = V_KillNamedDataFolder(fname)
312//      if(err)
313//              Print "DataFolder kill err = ",err
314//      endif
315        return(err)
316End
317
318// TODO -- not mine, added somewhere by Nexus writer?
319// data collection end time
320Function V_writeDataEndTime(fname,str)
321        String fname,str
322       
323//      String path = "entry:end_time" 
324
325        Make/O/T/N=1 tmpTW
326        String groupName = "/entry"     //     
327        String varName = "end_time"
328        tmpTW[0] = str //
329
330        variable err
331        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
332        if(err)
333                Print "HDF write err = ",err
334        endif
335       
336        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
337//      err = V_KillNamedDataFolder(fname)
338//      if(err)
339//              Print "DataFolder kill err = ",err
340//      endif
341               
342        return(err)
343End
344
345// experiment description
346Function V_writeExperiment_description(fname,str)
347        String fname,str
348       
349//      String path = "entry:experiment_description"   
350
351        Make/O/T/N=1 tmpTW
352        String groupName = "/entry"     //     
353        String varName = "experiment_description"
354        tmpTW[0] = str //
355
356        variable err
357        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
358        if(err)
359                Print "HDF write err = ",err
360        endif
361       
362        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
363//      err = V_KillNamedDataFolder(fname)
364//      if(err)
365//              Print "DataFolder kill err = ",err
366//      endif
367               
368        return(err)
369End
370
371// experiment identifier? used only by NICE?
372Function V_writeExperiment_identifier(fname,str)
373        String fname,str
374       
375//      String path = "entry:experiment_identifier"     
376
377        Make/O/T/N=1 tmpTW
378        String groupName = "/entry"     //     
379        String varName = "experiment_identifier"
380        tmpTW[0] = str //
381
382        variable err
383        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
384        if(err)
385                Print "HDF write err = ",err
386        endif
387       
388        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
389//      err = V_KillNamedDataFolder(fname)
390//      if(err)
391//              Print "DataFolder kill err = ",err
392//      endif
393               
394        return(err)
395End
396
397// name of facility = NCNR
398Function V_writeFacility(fname,str)
399        String fname,str
400       
401//      String path = "entry:facility" 
402
403        Make/O/T/N=1 tmpTW
404        String groupName = "/entry"     //     
405        String varName = "facility"
406        tmpTW[0] = str //
407
408        variable err
409        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
410        if(err)
411                Print "HDF write err = ",err
412        endif
413       
414        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
415//      err = V_KillNamedDataFolder(fname)
416//      if(err)
417//              Print "DataFolder kill err = ",err
418//      endif
419               
420        return(err)
421End
422
423
424// file name
425Function V_writeFile_name(fname,str)
426        String fname,str
427       
428//      String path = "entry:file_name"
429
430        Make/O/T/N=1 tmpTW
431        String groupName = "/entry"     //     
432        String varName = "file_name"
433        tmpTW[0] = str //
434
435        variable err
436        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
437        if(err)
438                Print "HDF write err = ",err
439        endif
440       
441        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
442//      err = V_KillNamedDataFolder(fname)
443//      if(err)
444//              Print "DataFolder kill err = ",err
445//      endif
446               
447        return(err)
448End
449
450       
451//// file write time (what is this??)
452//// TODO - figure out if this is supposed to be an integer or text (ISO)
453//Function V_writeFileWriteTime(fname,val)
454//      String fname
455//      Variable val
456//     
457//      String path = "entry:file_time"
458//     
459//      Make/O/D/N=1 wTmpWrite
460////    Make/O/R/N=1 wTmpWrite
461//      String groupName = "/entry"     
462//      String varName = "file_time"
463//      wTmpWrite[0] = val
464//
465//      variable err
466//      err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
467//      if(err)
468//              Print "HDF write err = ",err
469//      endif
470//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
471////    err = V_KillNamedDataFolder(fname)
472////    if(err)
473////            Print "DataFolder kill err = ",err
474////    endif
475//      return(err)
476//End
477               
478//
479Function V_writeHDF_version(fname,str)
480        String fname,str
481       
482//      String path = "entry:hdf_version"       
483
484        Make/O/T/N=1 tmpTW
485        String groupName = "/entry"     //     
486        String varName = "hdf_version"
487        tmpTW[0] = str //
488
489        variable err
490        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
491        if(err)
492                Print "HDF write err = ",err
493        endif
494       
495        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
496//      err = V_KillNamedDataFolder(fname)
497//      if(err)
498//              Print "DataFolder kill err = ",err
499//      endif
500               
501        return(err)
502End
503
504// TODO -- not mine, added somewhere by Nexus writer?
505Function V_writeProgram_name(fname,str)
506        String fname,str
507       
508//      String path = "entry:program_name"     
509
510        Make/O/T/N=1 tmpTW
511        String groupName = "/entry"     //     
512        String varName = "program_name"
513        tmpTW[0] = str //
514
515        variable err
516        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
517        if(err)
518                Print "HDF write err = ",err
519        endif
520       
521        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
522//      err = V_KillNamedDataFolder(fname)
523//      if(err)
524//              Print "DataFolder kill err = ",err
525//      endif
526               
527        return(err)
528End
529
530// TODO -- not mine, added somewhere by Nexus writer?
531// data collection start time
532Function V_writeDataStartTime(fname,str)
533        String fname,str
534       
535//      String path = "entry:start_time"       
536
537        Make/O/T/N=1 tmpTW
538        String groupName = "/entry"     //     
539        String varName = "start_time"
540        tmpTW[0] = str //
541
542        variable err
543        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
544        if(err)
545                Print "HDF write err = ",err
546        endif
547       
548        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
549//      err = V_KillNamedDataFolder(fname)
550//      if(err)
551//              Print "DataFolder kill err = ",err
552//      endif
553               
554        return(err)
555End
556               
557// title of experiment
558Function V_writeTitle(fname,str)
559        String fname,str
560       
561//      String path = "entry:title"     
562
563        Make/O/T/N=1 tmpTW
564        String groupName = "/entry"     //     
565        String varName = "title"
566        tmpTW[0] = str //
567
568        variable err
569        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
570        if(err)
571                Print "HDF write err = ",err
572        endif
573       
574        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
575//      err = V_KillNamedDataFolder(fname)
576//      if(err)
577//              Print "DataFolder kill err = ",err
578//      endif
579               
580        return(err)
581end
582       
583       
584               
585////////// USER
586////////// USER
587////////// USER
588
589// list of user names
590// DONE -- currently not written out to data file??
591Function V_writeUserNames(fname,str)
592        String fname,str
593       
594//      String path = "entry:user:name"
595
596        Make/O/T/N=1 tmpTW
597        String groupName = "/entry/user"        //     
598        String varName = "name"
599        tmpTW[0] = str //
600
601        variable err
602        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
603        if(err)
604                Print "HDF write err = ",err
605        endif
606       
607        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
608//      err = V_KillNamedDataFolder(fname)
609//      if(err)
610//              Print "DataFolder kill err = ",err
611//      endif
612               
613        return(err)
614end
615
616
617//////// CONTROL
618//////// CONTROL
619//////// CONTROL
620
621// TODO -- for the control section, document each of the fields
622//
623Function V_writeCount_end(fname,str)
624        String fname,str
625       
626//      String path = "entry:control:count_end"
627
628        Make/O/T/N=1 tmpTW
629        String groupName = "/entry/control"     //     
630        String varName = "count_end"
631        tmpTW[0] = str //
632
633        variable err
634        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
635        if(err)
636                Print "HDF write err = ",err
637        endif
638       
639        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
640//      err = V_KillNamedDataFolder(fname)
641//      if(err)
642//              Print "DataFolder kill err = ",err
643//      endif
644               
645        return(err)
646end
647
648Function V_writeCount_start(fname,str)
649        String fname,str
650       
651//      String path = "entry:control:count_start"       
652
653        Make/O/T/N=1 tmpTW
654        String groupName = "/entry/control"     //     
655        String varName = "count_start"
656        tmpTW[0] = str //
657
658        variable err
659        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
660        if(err)
661                Print "HDF write err = ",err
662        endif
663       
664        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
665//      err = V_KillNamedDataFolder(fname)
666//      if(err)
667//              Print "DataFolder kill err = ",err
668//      endif
669               
670        return(err)
671end
672
673
674Function V_writeCount_time(fname,val)
675        String fname
676        Variable val
677       
678//      String path = "entry:control:count_time"       
679       
680        Make/O/D/N=1 wTmpWrite
681//      Make/O/R/N=1 wTmpWrite
682        String groupName = "/entry/control"     
683        String varName = "count_time"
684        wTmpWrite[0] = val
685
686        variable err
687        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
688        if(err)
689                Print "HDF write err = ",err
690        endif
691        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
692//      err = V_KillNamedDataFolder(fname)
693//      if(err)
694//              Print "DataFolder kill err = ",err
695//      endif
696        return(err)
697end
698
699// fname is a local WORK folder
700Function V_putCount_time(fname,val)
701        String fname
702        Variable val
703
704//root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FB:beam_center_x
705        String path = "root:Packages:NIST:VSANS:"+fname+":"
706        path += "entry:control:count_time"
707       
708        Wave/Z w = $path
709        if(waveExists(w) == 0)
710                return(1)
711        else
712        w[0] = val
713                return(0)
714        endif
715
716End
717
718Function V_writeCount_time_preset(fname,val)
719        String fname
720        Variable val
721       
722//      String path = "entry:control:count_time_preset"
723       
724        Make/O/D/N=1 wTmpWrite
725//      Make/O/R/N=1 wTmpWrite
726        String groupName = "/entry/control"     
727        String varName = "count_time_preset"
728        wTmpWrite[0] = val
729
730        variable err
731        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
732        if(err)
733                Print "HDF write err = ",err
734        endif
735        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
736//      err = V_KillNamedDataFolder(fname)
737//      if(err)
738//              Print "DataFolder kill err = ",err
739//      endif
740        return(err)
741end
742
743
744Function V_writeDetector_counts(fname,val)
745        String fname
746        Variable val
747       
748//      String path = "entry:control:detector_counts"
749       
750        Make/O/D/N=1 wTmpWrite
751//      Make/O/R/N=1 wTmpWrite
752        String groupName = "/entry/control"     
753        String varName = "detector_counts"
754        wTmpWrite[0] = val
755
756        variable err
757        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
758        if(err)
759                Print "HDF write err = ",err
760        endif
761        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
762//      err = V_KillNamedDataFolder(fname)
763//      if(err)
764//              Print "DataFolder kill err = ",err
765//      endif
766        return(err)
767end
768
769// fname is a local WORK folder
770Function V_putDetector_counts(fname,val)
771        String fname
772        Variable val
773
774//root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FB:beam_center_x
775        String path = "root:Packages:NIST:VSANS:"+fname+":"
776        path += "entry:control:detector_counts"
777       
778        Wave/Z w = $path
779        if(waveExists(w) == 0)
780                return(1)
781        else
782        w[0] = val
783                return(0)
784        endif
785
786End
787
788Function V_writeDetector_preset(fname,val)
789        String fname
790        Variable val
791       
792//      String path = "entry:control:detector_preset"   
793       
794        Make/O/D/N=1 wTmpWrite
795//      Make/O/R/N=1 wTmpWrite
796        String groupName = "/entry/control"     
797        String varName = "detector_preset"
798        wTmpWrite[0] = val
799
800        variable err
801        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
802        if(err)
803                Print "HDF write err = ",err
804        endif
805        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
806//      err = V_KillNamedDataFolder(fname)
807//      if(err)
808//              Print "DataFolder kill err = ",err
809//      endif
810        return(err)
811end
812
813// integer value
814Function V_writeIntegral(fname,val)
815        String fname
816        Variable val
817       
818//      String path = "entry:control:integral"
819       
820        Make/O/I/N=1 wTmpWrite
821//      Make/O/R/N=1 wTmpWrite
822        String groupName = "/entry/control"     
823        String varName = "integral"
824        wTmpWrite[0] = val
825
826        variable err
827        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
828        if(err)
829                Print "HDF write err = ",err
830        endif
831        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
832//      err = V_KillNamedDataFolder(fname)
833//      if(err)
834//              Print "DataFolder kill err = ",err
835//      endif
836        return(err)
837end
838
839// control mode for data acquisition, "timer"
840Function V_writeControlMode(fname,str)
841        String fname,str
842       
843//      String path = "entry:control:mode"     
844
845        Make/O/T/N=1 tmpTW
846        String groupName = "/entry/control"     //     
847        String varName = "mode"
848        tmpTW[0] = str //
849
850        variable err
851        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
852        if(err)
853                Print "HDF write err = ",err
854        endif
855       
856        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
857//      err = V_KillNamedDataFolder(fname)
858//      if(err)
859//              Print "DataFolder kill err = ",err
860//      endif
861               
862        return(err)
863End
864
865//monitor count
866// integer value
867Function V_writeControlMonitorCount(fname,val)
868        String fname
869        Variable val
870       
871//      String path = "entry:control:monitor_counts"   
872       
873        Make/O/I/N=1 wTmpWrite
874//      Make/O/R/N=1 wTmpWrite
875        String groupName = "/entry/control"     
876        String varName = "monitor_counts"
877        wTmpWrite[0] = val
878
879        variable err
880        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
881        if(err)
882                Print "HDF write err = ",err
883        endif
884        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
885//      err = V_KillNamedDataFolder(fname)
886//      if(err)
887//              Print "DataFolder kill err = ",err
888//      endif
889        return(err)
890end
891
892// fname is a local WORK folder
893Function V_putControlMonitorCount(fname,val)
894        String fname
895        Variable val
896
897//root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FB:beam_center_x
898        String path = "root:Packages:NIST:VSANS:"+fname+":"
899        path += "entry:control:monitor_counts"
900       
901        Wave/Z w = $path
902        if(waveExists(w) == 0)
903                return(1)
904        else
905        w[0] = val
906                return(0)
907        endif
908
909End
910
911//integer value
912Function V_writeControlMonitor_preset(fname,val)
913        String fname
914        Variable val
915       
916//      String path = "entry:control:monitor_preset"
917       
918        Make/O/I/N=1 wTmpWrite
919//      Make/O/R/N=1 wTmpWrite
920        String groupName = "/entry/control"     
921        String varName = "monitor_preset"
922        wTmpWrite[0] = val
923
924        variable err
925        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
926        if(err)
927                Print "HDF write err = ",err
928        endif
929        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
930//      err = V_KillNamedDataFolder(fname)
931//      if(err)
932//              Print "DataFolder kill err = ",err
933//      endif
934        return(err)
935end
936
937Function V_writeControlPreset(fname,str)
938        String fname,str
939       
940//      String path = "entry:control:preset"
941               
942        Make/O/T/N=1 tmpTW
943        String groupName = "/entry/control"     
944        String varName = "preset"
945        tmpTW[0] = str //
946
947        variable err
948        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
949        if(err)
950                Print "HDF write err = ",err
951        endif
952        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
953//      err = V_KillNamedDataFolder(fname)
954//      if(err)
955//              Print "DataFolder kill err = ",err
956//      endif
957        return(err)
958end
959
960
961
962
963
964//////// INSTRUMENT
965//////// INSTRUMENT
966//////// INSTRUMENT
967
968Function V_writeLocalContact(fname,str)
969        String fname,str
970
971//      String path = "entry:instrument:local_contact"
972
973        Make/O/T/N=1 tmpTW
974        String groupName = "/entry/instrument"  //     
975        String varName = "local_contact"
976        tmpTW[0] = str //
977
978        variable err
979        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
980        if(err)
981                Print "HDF write err = ",err
982        endif
983       
984        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
985//      err = V_KillNamedDataFolder(fname)
986//      if(err)
987//              Print "DataFolder kill err = ",err
988//      endif
989               
990        return(err)
991End
992
993Function V_writeInstrumentName(fname,str)
994        String fname,str
995
996//      String path = "entry:instrument:name"
997
998        Make/O/T/N=1 tmpTW
999        String groupName = "/entry/instrument"  //     
1000        String varName = "name"
1001        tmpTW[0] = str //
1002
1003        variable err
1004        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1005        if(err)
1006                Print "HDF write err = ",err
1007        endif
1008       
1009        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1010//      err = V_KillNamedDataFolder(fname)
1011//      if(err)
1012//              Print "DataFolder kill err = ",err
1013//      endif
1014               
1015        return(err)
1016End
1017
1018Function V_writeInstrumentType(fname,str)
1019        String fname,str
1020
1021//      String path = "entry:instrument:type"
1022
1023        Make/O/T/N=1 tmpTW
1024        String groupName = "/entry/instrument"  //     
1025        String varName = "type"
1026        tmpTW[0] = str //
1027
1028        variable err
1029        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1030        if(err)
1031                Print "HDF write err = ",err
1032        endif
1033       
1034        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1035//      err = V_KillNamedDataFolder(fname)
1036//      if(err)
1037//              Print "DataFolder kill err = ",err
1038//      endif
1039               
1040        return(err)
1041End
1042
1043////// INSTRUMENT/ATTENUATOR
1044// TODO - verify the format of how these are written out to the file
1045//
1046
1047// transmission value for the attenuator in the beam
1048// use this, but if something wrong, the tables are present
1049Function V_writeAttenuator_transmission(fname,val)
1050        String fname
1051        Variable val
1052       
1053//      String path = "entry:instrument:attenuator:attenuator_transmission"     
1054       
1055        Make/O/D/N=1 wTmpWrite
1056//      Make/O/R/N=1 wTmpWrite
1057        String groupName = "/entry/instrument/attenuator"       
1058        String varName = "attenuator_transmission"
1059        wTmpWrite[0] = val
1060
1061        variable err
1062        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1063        if(err)
1064                Print "HDF write err = ",err
1065        endif
1066        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1067//      err = V_KillNamedDataFolder(fname)
1068//      if(err)
1069//              Print "DataFolder kill err = ",err
1070//      endif
1071        return(err)
1072end
1073
1074// transmission value (error) for the attenuator in the beam
1075// use this, but if something wrong, the tables are present
1076Function V_writeAttenuator_trans_err(fname,val)
1077        String fname
1078        Variable val
1079       
1080//      String path = "entry:instrument:attenuator:attenuator_transmission_error"       
1081       
1082        Make/O/D/N=1 wTmpWrite
1083//      Make/O/R/N=1 wTmpWrite
1084        String groupName = "/entry/instrument/attenuator"       
1085        String varName = "attenuator_transmission_error"
1086        wTmpWrite[0] = val
1087
1088        variable err
1089        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1090        if(err)
1091                Print "HDF write err = ",err
1092        endif
1093        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1094//      err = V_KillNamedDataFolder(fname)
1095//      if(err)
1096//              Print "DataFolder kill err = ",err
1097//      endif
1098        return(err)
1099end
1100
1101// desired thickness of attenuation
1102Function V_writeAttenuator_desiredThick(fname,val)
1103        String fname
1104        Variable val
1105       
1106//      String path = "entry:instrument:attenuator:attenuator_transmission_error"       
1107       
1108        Make/O/D/N=1 wTmpWrite
1109//      Make/O/R/N=1 wTmpWrite
1110        String groupName = "/entry/instrument/attenuator"       
1111        String varName = "desired_thickness"
1112        wTmpWrite[0] = val
1113
1114        variable err
1115        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1116        if(err)
1117                Print "HDF write err = ",err
1118        endif
1119        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1120//      err = V_KillNamedDataFolder(fname)
1121//      if(err)
1122//              Print "DataFolder kill err = ",err
1123//      endif
1124        return(err)
1125end
1126
1127
1128// distance from the attenuator to the sample (units??)
1129Function V_writeAttenDistance(fname,val)
1130        String fname
1131        Variable val
1132       
1133//      String path = "entry:instrument:attenuator:distance"   
1134       
1135        Make/O/D/N=1 wTmpWrite
1136//      Make/O/R/N=1 wTmpWrite
1137        String groupName = "/entry/instrument/attenuator"       
1138        String varName = "distance"
1139        wTmpWrite[0] = val
1140
1141        variable err
1142        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1143        if(err)
1144                Print "HDF write err = ",err
1145        endif
1146        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1147//      err = V_KillNamedDataFolder(fname)
1148//      if(err)
1149//              Print "DataFolder kill err = ",err
1150//      endif
1151        return(err)
1152end
1153
1154
1155// table of the attenuation factor error
1156Function V_writeAttenIndex_table_err(fname,inW)
1157        String fname
1158        Wave inW
1159       
1160//      String path = "entry:instrument:attenuator:index_table"
1161       
1162        Duplicate/O inW wTmpWrite       
1163// then use redimension as needed to cast the wave to write to the specified type
1164// see WaveType for the proper codes
1165//      Redimension/T=() wTmpWrite
1166// -- May also need to check the dimension(s) before writing (don't trust the input)
1167        String groupName = "/entry/instrument/attenuator"       
1168        String varName = "index_error_table"
1169
1170        variable err
1171        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1172        if(err)
1173                Print "HDF write err = ",err
1174        endif
1175        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1176//      err = V_KillNamedDataFolder(fname)
1177//      if(err)
1178//              Print "DataFolder kill err = ",err
1179//      endif
1180        return(err)
1181end
1182
1183// table of the attenuation factor
1184Function V_writeAttenIndex_table(fname,inW)
1185        String fname
1186        Wave inW
1187       
1188//      String path = "entry:instrument:attenuator:index_table"
1189       
1190        Duplicate/O inW wTmpWrite       
1191// then use redimension as needed to cast the wave to write to the specified type
1192// see WaveType for the proper codes
1193//      Redimension/T=() wTmpWrite
1194// -- May also need to check the dimension(s) before writing (don't trust the input)
1195        String groupName = "/entry/instrument/attenuator"       
1196        String varName = "index_table"
1197
1198        variable err
1199        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1200        if(err)
1201                Print "HDF write err = ",err
1202        endif
1203        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1204//      err = V_KillNamedDataFolder(fname)
1205//      if(err)
1206//              Print "DataFolder kill err = ",err
1207//      endif
1208        return(err)
1209end
1210
1211
1212//// status "in or out"
1213//Function V_writeAttenStatus(fname,str)
1214//      String fname,str
1215//
1216////    String path = "entry:instrument:attenuator:status"
1217//
1218//      Make/O/T/N=1 tmpTW
1219//      String groupName = "/entry/instrument/attenuator"       //     
1220//      String varName = "status"
1221//      tmpTW[0] = str //
1222//
1223//      variable err
1224//      err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1225//      if(err)
1226//              Print "HDF write err = ",err
1227//      endif
1228//     
1229//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1230////    err = V_KillNamedDataFolder(fname)
1231////    if(err)
1232////            Print "DataFolder kill err = ",err
1233////    endif
1234//             
1235//      return(err)
1236//End
1237
1238//// number of attenuators actually dropped in
1239//// an integer value
1240Function V_writeAtten_num_dropped(fname,val)
1241        String fname
1242        Variable val
1243       
1244//      String path = "entry:instrument:attenuator:thickness"   
1245       
1246        Make/O/I/N=1 wTmpWrite
1247//      Make/O/R/N=1 wTmpWrite
1248        String groupName = "/entry/instrument/attenuator"       
1249        String varName = "num_atten_dropped"
1250        wTmpWrite[0] = val
1251
1252        variable err
1253        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1254        if(err)
1255                Print "HDF write err = ",err
1256        endif
1257        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1258//      err = V_KillNamedDataFolder(fname)
1259//      if(err)
1260//              Print "DataFolder kill err = ",err
1261//      endif
1262        return(err)
1263end
1264
1265// thickness of the attenuator (PMMA) - units??
1266Function V_writeAttenThickness(fname,val)
1267        String fname
1268        Variable val
1269       
1270//      String path = "entry:instrument:attenuator:thickness"   
1271       
1272        Make/O/D/N=1 wTmpWrite
1273//      Make/O/R/N=1 wTmpWrite
1274        String groupName = "/entry/instrument/attenuator"       
1275        String varName = "thickness"
1276        wTmpWrite[0] = val
1277
1278        variable err
1279        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1280        if(err)
1281                Print "HDF write err = ",err
1282        endif
1283        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1284//      err = V_KillNamedDataFolder(fname)
1285//      if(err)
1286//              Print "DataFolder kill err = ",err
1287//      endif
1288        return(err)
1289end
1290
1291
1292// type of material for the atteunator
1293Function V_writeAttenType(fname,str)
1294        String fname,str
1295
1296//      String path = "entry:instrument:attenuator:type"
1297
1298        Make/O/T/N=1 tmpTW
1299        String groupName = "/entry/instrument/attenuator"       //     
1300        String varName = "type"
1301        tmpTW[0] = str //
1302
1303        variable err
1304        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1305        if(err)
1306                Print "HDF write err = ",err
1307        endif
1308       
1309        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1310//      err = V_KillNamedDataFolder(fname)
1311//      if(err)
1312//              Print "DataFolder kill err = ",err
1313//      endif
1314               
1315        return(err)
1316End
1317
1318
1319
1320
1321////// INSTRUMENT/BEAM
1322//
1323Function V_writeAnalyzer_depth(fname,val)
1324        String fname
1325        Variable val
1326       
1327//      String path = "entry:instrument:beam:analyzer:depth"
1328
1329        Make/O/D/N=1 wTmpWrite
1330//      Make/O/R/N=1 wTmpWrite
1331        String groupName = "/entry/instrument/beam/analyzer"   
1332        String varName = "depth"
1333        wTmpWrite[0] = val
1334
1335        variable err
1336        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1337        if(err)
1338                Print "HDF write err = ",err
1339        endif
1340        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1341//      err = V_KillNamedDataFolder(fname)
1342//      if(err)
1343//              Print "DataFolder kill err = ",err
1344//      endif
1345        return(err)
1346end
1347
1348Function V_writeAnalyzer_direction(fname,str)
1349        String fname,str
1350
1351//      String path = "entry:instrument:beam:analyzer:direction"
1352
1353        Make/O/T/N=1 tmpTW
1354        String groupName = "/entry/instrument/beam/analyzer"    //     
1355        String varName = "direction"
1356        tmpTW[0] = str //
1357
1358        variable err
1359        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1360        if(err)
1361                Print "HDF write err = ",err
1362        endif
1363       
1364        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1365//      err = V_KillNamedDataFolder(fname)
1366//      if(err)
1367//              Print "DataFolder kill err = ",err
1368//      endif
1369               
1370        return(err)
1371End
1372
1373Function V_writeAnalyzer_height(fname,val)
1374        String fname
1375        Variable val
1376       
1377//      String path = "entry:instrument:beam:analyzer:height"   
1378
1379        Make/O/D/N=1 wTmpWrite
1380//      Make/O/R/N=1 wTmpWrite
1381        String groupName = "/entry/instrument/beam/analyzer"   
1382        String varName = "height"
1383        wTmpWrite[0] = val
1384
1385        variable err
1386        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1387        if(err)
1388                Print "HDF write err = ",err
1389        endif
1390        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1391//      err = V_KillNamedDataFolder(fname)
1392//      if(err)
1393//              Print "DataFolder kill err = ",err
1394//      endif
1395        return(err)
1396end
1397
1398// ?? TODO is this equivalent to "status" -- is this 0|1 ??
1399Function V_writeAnalyzer_inBeam(fname,val)
1400        String fname
1401        Variable val
1402       
1403//      String path = "entry:instrument:beam:analyzer:inBeam"   
1404
1405        Make/O/D/N=1 wTmpWrite
1406//      Make/O/R/N=1 wTmpWrite
1407        String groupName = "/entry/instrument/beam/analyzer"   
1408        String varName = "inBeam"
1409        wTmpWrite[0] = val
1410
1411        variable err
1412        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1413        if(err)
1414                Print "HDF write err = ",err
1415        endif
1416        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1417//      err = V_KillNamedDataFolder(fname)
1418//      if(err)
1419//              Print "DataFolder kill err = ",err
1420//      endif
1421        return(err)
1422end
1423
1424Function V_writeAnalyzer_innerDiameter(fname,val)
1425        String fname
1426        Variable val
1427       
1428//      String path = "entry:instrument:beam:analyzer:innerDiameter"   
1429
1430        Make/O/D/N=1 wTmpWrite
1431//      Make/O/R/N=1 wTmpWrite
1432        String groupName = "/entry/instrument/beam/analyzer"   
1433        String varName = "innerDiameter"
1434        wTmpWrite[0] = val
1435
1436        variable err
1437        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1438        if(err)
1439                Print "HDF write err = ",err
1440        endif
1441        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1442//      err = V_KillNamedDataFolder(fname)
1443//      if(err)
1444//              Print "DataFolder kill err = ",err
1445//      endif
1446        return(err)
1447end
1448
1449// one of the most important
1450Function V_writeAnalyzer_name(fname,str)
1451        String fname,str
1452
1453//      String path = "entry:instrument:beam:analyzer:name"
1454
1455        Make/O/T/N=1 tmpTW
1456        String groupName = "/entry/instrument/beam/analyzer"    //     
1457        String varName = "name"
1458        tmpTW[0] = str //
1459
1460        variable err
1461        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1462        if(err)
1463                Print "HDF write err = ",err
1464        endif
1465       
1466        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1467//      err = V_KillNamedDataFolder(fname)
1468//      if(err)
1469//              Print "DataFolder kill err = ",err
1470//      endif
1471               
1472        return(err)
1473End
1474
1475Function V_writeAnalyzer_opacityAt1Ang(fname,val)
1476        String fname
1477        Variable val
1478       
1479//      String path = "entry:instrument:beam:analyzer:opacityAt1Ang"   
1480
1481        Make/O/D/N=1 wTmpWrite
1482//      Make/O/R/N=1 wTmpWrite
1483        String groupName = "/entry/instrument/beam/analyzer"   
1484        String varName = "opacityAt1Ang"
1485        wTmpWrite[0] = val
1486
1487        variable err
1488        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1489        if(err)
1490                Print "HDF write err = ",err
1491        endif
1492        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1493//      err = V_KillNamedDataFolder(fname)
1494//      if(err)
1495//              Print "DataFolder kill err = ",err
1496//      endif
1497        return(err)
1498end
1499
1500Function V_writeAna_opacityAt1Ang_err(fname,val)
1501        String fname
1502        Variable val
1503       
1504//      String path = "entry:instrument:beam:analyzer:opacityAt1AngStd"
1505
1506        Make/O/D/N=1 wTmpWrite
1507//      Make/O/R/N=1 wTmpWrite
1508        String groupName = "/entry/instrument/beam/analyzer"   
1509        String varName = "opacityAt1AngStd"
1510        wTmpWrite[0] = val
1511
1512        variable err
1513        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1514        if(err)
1515                Print "HDF write err = ",err
1516        endif
1517        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1518//      err = V_KillNamedDataFolder(fname)
1519//      if(err)
1520//              Print "DataFolder kill err = ",err
1521//      endif
1522        return(err)
1523end
1524
1525Function V_writeAnalyzer_outerDiameter(fname,val)
1526        String fname
1527        Variable val
1528       
1529//      String path = "entry:instrument:beam:analyzer:outerDiameter"   
1530
1531        Make/O/D/N=1 wTmpWrite
1532//      Make/O/R/N=1 wTmpWrite
1533        String groupName = "/entry/instrument/beam/analyzer"   
1534        String varName = "outerDiameter"
1535        wTmpWrite[0] = val
1536
1537        variable err
1538        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1539        if(err)
1540                Print "HDF write err = ",err
1541        endif
1542        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1543//      err = V_KillNamedDataFolder(fname)
1544//      if(err)
1545//              Print "DataFolder kill err = ",err
1546//      endif
1547        return(err)
1548end
1549
1550Function V_writeAnalyzer_shape(fname,str)
1551        String fname,str
1552
1553//      String path = "entry:instrument:beam:analyzer:shape"
1554
1555        Make/O/T/N=1 tmpTW
1556        String groupName = "/entry/instrument/beam/analyzer"    //     
1557        String varName = "shape"
1558        tmpTW[0] = str //
1559
1560        variable err
1561        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1562        if(err)
1563                Print "HDF write err = ",err
1564        endif
1565       
1566        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1567//      err = V_KillNamedDataFolder(fname)
1568//      if(err)
1569//              Print "DataFolder kill err = ",err
1570//      endif
1571               
1572        return(err)
1573End
1574
1575Function V_writeAnalyzer_tE(fname,val)
1576        String fname
1577        Variable val
1578               
1579//      String path = "entry:instrument:beam:analyzer:tE"       
1580
1581        Make/O/D/N=1 wTmpWrite
1582//      Make/O/R/N=1 wTmpWrite
1583        String groupName = "/entry/instrument/beam/analyzer"   
1584        String varName = "tE"
1585        wTmpWrite[0] = val
1586
1587        variable err
1588        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1589        if(err)
1590                Print "HDF write err = ",err
1591        endif
1592        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1593//      err = V_KillNamedDataFolder(fname)
1594//      if(err)
1595//              Print "DataFolder kill err = ",err
1596//      endif
1597        return(err)
1598end
1599
1600Function V_writeAnalyzer_tE_err(fname,val)
1601        String fname
1602        Variable val
1603       
1604//      String path = "entry:instrument:beam:analyzer:tEStd"   
1605
1606        Make/O/D/N=1 wTmpWrite
1607//      Make/O/R/N=1 wTmpWrite
1608        String groupName = "/entry/instrument/beam/analyzer"   
1609        String varName = "tEStd"
1610        wTmpWrite[0] = val
1611
1612        variable err
1613        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1614        if(err)
1615                Print "HDF write err = ",err
1616        endif
1617        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1618//      err = V_KillNamedDataFolder(fname)
1619//      if(err)
1620//              Print "DataFolder kill err = ",err
1621//      endif
1622        return(err)
1623end
1624
1625Function V_writeAnalyzer_type(fname,str)
1626        String fname,str
1627
1628//      String path = "entry:instrument:beam:analyzer:type"
1629
1630        Make/O/T/N=1 tmpTW
1631        String groupName = "/entry/instrument/beam/analyzer"    //     
1632        String varName = "type"
1633        tmpTW[0] = str //
1634
1635        variable err
1636        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1637        if(err)
1638                Print "HDF write err = ",err
1639        endif
1640       
1641        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1642//      err = V_KillNamedDataFolder(fname)
1643//      if(err)
1644//              Print "DataFolder kill err = ",err
1645//      endif
1646               
1647        return(err)
1648End
1649
1650
1651Function V_writeAnalyzer_width(fname,val)
1652        String fname
1653        Variable val
1654       
1655//      String path = "entry:instrument:beam:analyzer:width"   
1656
1657        Make/O/D/N=1 wTmpWrite
1658//      Make/O/R/N=1 wTmpWrite
1659        String groupName = "/entry/instrument/beam/analyzer"   
1660        String varName = "width"
1661        wTmpWrite[0] = val
1662
1663        variable err
1664        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1665        if(err)
1666                Print "HDF write err = ",err
1667        endif
1668        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1669//      err = V_KillNamedDataFolder(fname)
1670//      if(err)
1671//              Print "DataFolder kill err = ",err
1672//      endif
1673        return(err)
1674end
1675
1676
1677
1678
1679
1680// instrument/beam/chopper (data folder)
1681Function V_writeChopperAngular_opening(fname,val)
1682        String fname
1683        Variable val
1684       
1685//      String path = "entry:instrument:beam:chopper:angular_opening"
1686       
1687        Make/O/D/N=1 wTmpWrite
1688//      Make/O/R/N=1 wTmpWrite
1689        String groupName = "/entry/instrument/beam/chopper"     
1690        String varName = "angular_opening"
1691        wTmpWrite[0] = val
1692
1693        variable err
1694        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1695        if(err)
1696                Print "HDF write err = ",err
1697        endif
1698        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1699//      err = V_KillNamedDataFolder(fname)
1700//      if(err)
1701//              Print "DataFolder kill err = ",err
1702//      endif
1703        return(err)
1704end
1705
1706Function V_writeChopDistance_from_sample(fname,val)
1707        String fname
1708        Variable val
1709       
1710//      String path = "entry:instrument:beam:chopper:distance_from_sample"
1711       
1712        Make/O/D/N=1 wTmpWrite
1713//      Make/O/R/N=1 wTmpWrite
1714        String groupName = "/entry/instrument/beam/chopper"     
1715        String varName = "distance_from_sample"
1716        wTmpWrite[0] = val
1717
1718        variable err
1719        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1720        if(err)
1721                Print "HDF write err = ",err
1722        endif
1723        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1724//      err = V_KillNamedDataFolder(fname)
1725//      if(err)
1726//              Print "DataFolder kill err = ",err
1727//      endif
1728        return(err)
1729end
1730
1731Function V_writeChopDistance_from_source(fname,val)
1732        String fname
1733        Variable val
1734       
1735//      String path = "entry:instrument:beam:chopper:distance_from_source"     
1736       
1737        Make/O/D/N=1 wTmpWrite
1738//      Make/O/R/N=1 wTmpWrite
1739        String groupName = "/entry/instrument/beam/chopper"     
1740        String varName = "distance_from_source"
1741        wTmpWrite[0] = val
1742
1743        variable err
1744        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1745        if(err)
1746                Print "HDF write err = ",err
1747        endif
1748        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1749//      err = V_KillNamedDataFolder(fname)
1750//      if(err)
1751//              Print "DataFolder kill err = ",err
1752//      endif
1753        return(err)
1754end
1755
1756Function V_writeChopperDuty_cycle(fname,val)
1757        String fname
1758        Variable val
1759       
1760//      String path = "entry:instrument:beam:chopper:duty_cycle"       
1761       
1762        Make/O/D/N=1 wTmpWrite
1763//      Make/O/R/N=1 wTmpWrite
1764        String groupName = "/entry/instrument/beam/chopper"     
1765        String varName = "duty_cycle"
1766        wTmpWrite[0] = val
1767
1768        variable err
1769        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1770        if(err)
1771                Print "HDF write err = ",err
1772        endif
1773        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1774//      err = V_KillNamedDataFolder(fname)
1775//      if(err)
1776//              Print "DataFolder kill err = ",err
1777//      endif
1778        return(err)
1779end
1780
1781Function V_writeChopperRotation_speed(fname,val)
1782        String fname
1783        Variable val
1784       
1785//      String path = "entry:instrument:beam:chopper:rotation_speed"   
1786       
1787        Make/O/D/N=1 wTmpWrite
1788//      Make/O/R/N=1 wTmpWrite
1789        String groupName = "/entry/instrument/beam/chopper"     
1790        String varName = "rotation_speed"
1791        wTmpWrite[0] = val
1792
1793        variable err
1794        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1795        if(err)
1796                Print "HDF write err = ",err
1797        endif
1798        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1799//      err = V_KillNamedDataFolder(fname)
1800//      if(err)
1801//              Print "DataFolder kill err = ",err
1802//      endif
1803        return(err)
1804end
1805
1806// integer value
1807Function V_writeChopperSlits(fname,val)
1808        String fname
1809        Variable val
1810       
1811//      String path = "entry:instrument:beam:chopper:slits"     
1812       
1813        Make/O/I/N=1 wTmpWrite
1814//      Make/O/R/N=1 wTmpWrite
1815        String groupName = "/entry/instrument/beam/chopper"     
1816        String varName = "slits"
1817        wTmpWrite[0] = val
1818
1819        variable err
1820        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1821        if(err)
1822                Print "HDF write err = ",err
1823        endif
1824        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1825//      err = V_KillNamedDataFolder(fname)
1826//      if(err)
1827//              Print "DataFolder kill err = ",err
1828//      endif
1829        return(err)
1830end
1831
1832Function V_writeChopperstatus(fname,str)
1833        String fname,str
1834
1835//      String path = "entry:instrument:beam:chopper:status"
1836
1837        Make/O/T/N=1 tmpTW
1838        String groupName = "/entry/instrument/beam/chopper"     //     
1839        String varName = "status"
1840        tmpTW[0] = str //
1841
1842        variable err
1843        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1844        if(err)
1845                Print "HDF write err = ",err
1846        endif
1847       
1848        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1849//      err = V_KillNamedDataFolder(fname)
1850//      if(err)
1851//              Print "DataFolder kill err = ",err
1852//      endif
1853               
1854        return(err)
1855End
1856
1857Function V_writeChoppertype(fname,str)
1858        String fname,str
1859
1860//      String path = "entry:instrument:beam:chopper:type"
1861
1862        Make/O/T/N=1 tmpTW
1863        String groupName = "/entry/instrument/beam/chopper"     //     
1864        String varName = "type"
1865        tmpTW[0] = str //
1866
1867        variable err
1868        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1869        if(err)
1870                Print "HDF write err = ",err
1871        endif
1872       
1873        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1874//      err = V_KillNamedDataFolder(fname)
1875//      if(err)
1876//              Print "DataFolder kill err = ",err
1877//      endif
1878               
1879        return(err)
1880End
1881
1882
1883///////////////
1884// instrument/beam/flipperPolarizer (data folder)
1885// this is upstream, after the supermirror but before the sample
1886//
1887Function V_writeflipperPol_Direction(fname,str)
1888        String fname,str
1889
1890//      String path = "entry:instrument:beam:flipperPolarizer:direction"
1891
1892        Make/O/T/N=1 tmpTW
1893        String groupName = "/entry/instrument/beam/flipperPolarizer"    //     
1894        String varName = "direction"
1895        tmpTW[0] = str //
1896
1897        variable err
1898        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1899        if(err)
1900                Print "HDF write err = ",err
1901        endif
1902       
1903        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1904//      err = V_KillNamedDataFolder(fname)
1905//      if(err)
1906//              Print "DataFolder kill err = ",err
1907//      endif
1908               
1909        return(err)
1910End
1911
1912Function V_writeflipperPolarizer_inBeam(fname,val)
1913        String fname
1914        Variable val
1915       
1916//      String path = "entry:instrument:beam:flipperPolarizer:inBeam"   
1917
1918        Make/O/D/N=1 wTmpWrite
1919//      Make/O/R/N=1 wTmpWrite
1920        String groupName = "/entry/instrument/beam/flipperPolarizer"   
1921        String varName = "inBeam"
1922        wTmpWrite[0] = val
1923
1924        variable err
1925        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1926        if(err)
1927                Print "HDF write err = ",err
1928        endif
1929        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1930//      err = V_KillNamedDataFolder(fname)
1931//      if(err)
1932//              Print "DataFolder kill err = ",err
1933//      endif
1934        return(err)
1935end
1936
1937Function V_writeflipperPolarizer_Type(fname,str)
1938        String fname,str
1939
1940//      String path = "entry:instrument:beam:flipperPolarizer:type"
1941        Make/O/T/N=1 tmpTW
1942        String groupName = "/entry/instrument/beam/flipperPolarizer"    //     
1943        String varName = "type"
1944        tmpTW[0] = str //
1945
1946        variable err
1947        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1948        if(err)
1949                Print "HDF write err = ",err
1950        endif
1951       
1952        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1953//      err = V_KillNamedDataFolder(fname)
1954//      if(err)
1955//              Print "DataFolder kill err = ",err
1956//      endif
1957               
1958        return(err)
1959End
1960
1961
1962
1963
1964//////////
1965//// instrument/beam/flipper (data folder)
1966//Function V_writeFlipperDriving_current(fname,val)
1967//      String fname
1968//      Variable val
1969//     
1970////    String path = "entry:instrument:beam:flipper:driving_current"   
1971//     
1972//      Make/O/D/N=1 wTmpWrite
1973////    Make/O/R/N=1 wTmpWrite
1974//      String groupName = "/entry/instrument/beam/flipper"     
1975//      String varName = "driving_current"
1976//      wTmpWrite[0] = val
1977//
1978//      variable err
1979//      err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1980//      if(err)
1981//              Print "HDF write err = ",err
1982//      endif
1983//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1984////    err = V_KillNamedDataFolder(fname)
1985////    if(err)
1986////            Print "DataFolder kill err = ",err
1987////    endif
1988//      return(err)
1989//end
1990//
1991//Function V_writeFlipperFrequency(fname,val)
1992//      String fname
1993//      Variable val
1994//     
1995////    String path = "entry:instrument:beam:flipper:frequency"
1996//     
1997//      Make/O/D/N=1 wTmpWrite
1998////    Make/O/R/N=1 wTmpWrite
1999//      String groupName = "/entry/instrument/beam/flipper"     
2000//      String varName = "frequency"
2001//      wTmpWrite[0] = val
2002//
2003//      variable err
2004//      err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2005//      if(err)
2006//              Print "HDF write err = ",err
2007//      endif
2008//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2009////    err = V_KillNamedDataFolder(fname)
2010////    if(err)
2011////            Print "DataFolder kill err = ",err
2012////    endif
2013//      return(err)
2014//end
2015//
2016//Function V_writeFlipperstatus(fname,str)
2017//      String fname,str
2018//
2019////    String path = "entry:instrument:beam:flipper:status"
2020//
2021//      Make/O/T/N=1 tmpTW
2022//      String groupName = "/entry/instrument/beam/flipper"     //     
2023//      String varName = "status"
2024//      tmpTW[0] = str //
2025//
2026//      variable err
2027//      err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2028//      if(err)
2029//              Print "HDF write err = ",err
2030//      endif
2031//     
2032//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2033////    err = V_KillNamedDataFolder(fname)
2034////    if(err)
2035////            Print "DataFolder kill err = ",err
2036////    endif
2037//             
2038//      return(err)
2039//End
2040//
2041//Function V_writeFlipperTransmitted_power(fname,val)
2042//      String fname
2043//      Variable val
2044//     
2045////    String path = "entry:instrument:beam:flipper:transmitted_power"
2046//
2047//      Make/O/D/N=1 wTmpWrite
2048////    Make/O/R/N=1 wTmpWrite
2049//      String groupName = "/entry/instrument/beam/flipper"     
2050//      String varName = "transmitted_power"
2051//      wTmpWrite[0] = val
2052//
2053//      variable err
2054//      err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2055//      if(err)
2056//              Print "HDF write err = ",err
2057//      endif
2058//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2059////    err = V_KillNamedDataFolder(fname)
2060////    if(err)
2061////            Print "DataFolder kill err = ",err
2062////    endif
2063//      return(err)
2064//end
2065//
2066//Function V_writeFlipperWaveform(fname,str)
2067//      String fname,str
2068//
2069////    String path = "entry:instrument:beam:flipper:waveform"
2070//
2071//      Make/O/T/N=1 tmpTW
2072//      String groupName = "/entry/instrument/beam/flipper"     //     
2073//      String varName = "waveform"
2074//      tmpTW[0] = str //
2075//
2076//      variable err
2077//      err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2078//      if(err)
2079//              Print "HDF write err = ",err
2080//      endif
2081//     
2082//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2083////    err = V_KillNamedDataFolder(fname)
2084////    if(err)
2085////            Print "DataFolder kill err = ",err
2086////    endif
2087//             
2088//      return(err)
2089//End
2090
2091
2092
2093// instrument/beam/monochromator (data folder)
2094Function V_writeMonochromatorType(fname,str)
2095        String fname,str
2096
2097//      String path = "entry:instrument:beam:monochromator:type"
2098
2099        Make/O/T/N=1 tmpTW
2100        String groupName = "/entry/instrument/beam/monochromator"       //     
2101        String varName = "type"
2102        tmpTW[0] = str //
2103
2104        variable err
2105        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2106        if(err)
2107                Print "HDF write err = ",err
2108        endif
2109       
2110        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2111//      err = V_KillNamedDataFolder(fname)
2112//      if(err)
2113//              Print "DataFolder kill err = ",err
2114//      endif
2115               
2116        return(err)
2117End
2118
2119Function V_writeWavelength(fname,val)
2120        String fname
2121        Variable val
2122       
2123//      String path = "entry:instrument:beam:monochromator:wavelength" 
2124       
2125        Make/O/D/N=1 wTmpWrite
2126//      Make/O/R/N=1 wTmpWrite
2127        String groupName = "/entry/instrument/beam/monochromator"       
2128        String varName = "wavelength"
2129        wTmpWrite[0] = val
2130
2131        variable err
2132        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2133        if(err)
2134                Print "HDF write err = ",err
2135        endif
2136        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2137//      err = V_KillNamedDataFolder(fname)
2138//      if(err)
2139//              Print "DataFolder kill err = ",err
2140//      endif
2141        return(err)
2142end
2143
2144Function V_writeWavelength_spread(fname,val)
2145        String fname
2146        Variable val
2147       
2148//      String path = "entry:instrument:beam:monochromator:wavelength_spread"   
2149       
2150        Make/O/D/N=1 wTmpWrite
2151//      Make/O/R/N=1 wTmpWrite
2152        String groupName = "/entry/instrument/beam/monochromator"       
2153        String varName = "wavelength_spread"
2154        wTmpWrite[0] = val
2155
2156        variable err
2157        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2158        if(err)
2159                Print "HDF write err = ",err
2160        endif
2161        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2162//      err = V_KillNamedDataFolder(fname)
2163//      if(err)
2164//              Print "DataFolder kill err = ",err
2165//      endif
2166        return(err)
2167end
2168
2169
2170
2171
2172
2173
2174// instrument/beam/monochromator/crystal (data folder)
2175//
2176Function V_writeCrystalDistance(fname,val)
2177        String fname
2178        Variable val
2179       
2180//      String path = "entry:instrument:beam:monochromator:crystal:distance"   
2181       
2182        Make/O/D/N=1 wTmpWrite
2183//      Make/O/R/N=1 wTmpWrite
2184        String groupName = "/entry/instrument/beam/monochromator/crystal"       
2185        String varName = "distance"
2186        wTmpWrite[0] = val
2187
2188        variable err
2189        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2190        if(err)
2191                Print "HDF write err = ",err
2192        endif
2193        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2194//      err = V_KillNamedDataFolder(fname)
2195//      if(err)
2196//              Print "DataFolder kill err = ",err
2197//      endif
2198        return(err)
2199end
2200
2201Function V_writeCrystalEnergy(fname,val)
2202        String fname
2203        Variable val
2204       
2205//      String path = "entry:instrument:beam:monochromator:crystal:energy"     
2206       
2207        Make/O/D/N=1 wTmpWrite
2208//      Make/O/R/N=1 wTmpWrite
2209        String groupName = "/entry/instrument/beam/monochromator/crystal"       
2210        String varName = "energy"
2211        wTmpWrite[0] = val
2212
2213        variable err
2214        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2215        if(err)
2216                Print "HDF write err = ",err
2217        endif
2218        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2219//      err = V_KillNamedDataFolder(fname)
2220//      if(err)
2221//              Print "DataFolder kill err = ",err
2222//      endif
2223        return(err)
2224end
2225
2226Function V_writeCrystalHoriz_apert(fname,val)
2227        String fname
2228        Variable val
2229       
2230//      String path = "entry:instrument:beam:monochromator:crystal:horizontal_aperture"
2231       
2232        Make/O/D/N=1 wTmpWrite
2233//      Make/O/R/N=1 wTmpWrite
2234        String groupName = "/entry/instrument/beam/monochromator/crystal"       
2235        String varName = "horizontal_aperture"
2236        wTmpWrite[0] = val
2237
2238        variable err
2239        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2240        if(err)
2241                Print "HDF write err = ",err
2242        endif
2243        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2244//      err = V_KillNamedDataFolder(fname)
2245//      if(err)
2246//              Print "DataFolder kill err = ",err
2247//      endif
2248        return(err)
2249end
2250
2251Function V_writeCrystalHoriz_curvature(fname,val)
2252        String fname
2253        Variable val
2254       
2255//      String path = "entry:instrument:beam:monochromator:crystal:horizontal_curvature"       
2256       
2257        Make/O/D/N=1 wTmpWrite
2258//      Make/O/R/N=1 wTmpWrite
2259        String groupName = "/entry/instrument/beam/monochromator/crystal"       
2260        String varName = "horizontal_curvature"
2261        wTmpWrite[0] = val
2262
2263        variable err
2264        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2265        if(err)
2266                Print "HDF write err = ",err
2267        endif
2268        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2269//      err = V_KillNamedDataFolder(fname)
2270//      if(err)
2271//              Print "DataFolder kill err = ",err
2272//      endif
2273        return(err)
2274end
2275
2276Function V_writeCrystalLattice_parameter(fname,val)
2277        String fname
2278        Variable val
2279       
2280//      String path = "entry:instrument:beam:monochromator:crystal:lattice_parameter"   
2281       
2282        Make/O/D/N=1 wTmpWrite
2283//      Make/O/R/N=1 wTmpWrite
2284        String groupName = "/entry/instrument/beam/monochromator/crystal"       
2285        String varName = "lattice_parameter"
2286        wTmpWrite[0] = val
2287
2288        variable err
2289        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2290        if(err)
2291                Print "HDF write err = ",err
2292        endif
2293        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2294//      err = V_KillNamedDataFolder(fname)
2295//      if(err)
2296//              Print "DataFolder kill err = ",err
2297//      endif
2298        return(err)
2299end
2300
2301
2302Function V_writeCrystalReflection(fname,val)
2303        String fname
2304        Variable val
2305       
2306//      String path = "entry:instrument:beam:monochromator:crystal:reflection" 
2307       
2308        Make/O/D/N=1 wTmpWrite
2309//      Make/O/R/N=1 wTmpWrite
2310        String groupName = "/entry/instrument/beam/monochromator/crystal"       
2311        String varName = "reflection"
2312        wTmpWrite[0] = val
2313
2314        variable err
2315        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2316        if(err)
2317                Print "HDF write err = ",err
2318        endif
2319        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2320//      err = V_KillNamedDataFolder(fname)
2321//      if(err)
2322//              Print "DataFolder kill err = ",err
2323//      endif
2324        return(err)
2325end
2326
2327Function V_writeCrystalRotation(fname,val)
2328        String fname
2329        Variable val
2330       
2331//      String path = "entry:instrument:beam:monochromator:crystal:rotation"   
2332       
2333        Make/O/D/N=1 wTmpWrite
2334//      Make/O/R/N=1 wTmpWrite
2335        String groupName = "/entry/instrument/beam/monochromator/crystal"       
2336        String varName = "rotation"
2337        wTmpWrite[0] = val
2338
2339        variable err
2340        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2341        if(err)
2342                Print "HDF write err = ",err
2343        endif
2344        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2345//      err = V_KillNamedDataFolder(fname)
2346//      if(err)
2347//              Print "DataFolder kill err = ",err
2348//      endif
2349        return(err)
2350end
2351
2352Function V_writeCrystalStatus(fname,str)
2353        String fname,str
2354
2355//      String path = "entry:instrument:beam:monochromator:crystal:status"
2356
2357        Make/O/T/N=1 tmpTW
2358        String groupName = "/entry/instrument/beam/monochromator/crystal"       //     
2359        String varName = "status"
2360        tmpTW[0] = str //
2361
2362        variable err
2363        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2364        if(err)
2365                Print "HDF write err = ",err
2366        endif
2367       
2368        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2369//      err = V_KillNamedDataFolder(fname)
2370//      if(err)
2371//              Print "DataFolder kill err = ",err
2372//      endif
2373               
2374        return(err)
2375End
2376
2377Function V_writeCrystalVertical_aperture(fname,val)
2378        String fname
2379        Variable val
2380       
2381//      String path = "entry:instrument:beam:monochromator:crystal:vertical_aperture"   
2382       
2383        Make/O/D/N=1 wTmpWrite
2384//      Make/O/R/N=1 wTmpWrite
2385        String groupName = "/entry/instrument/beam/monochromator/crystal"       
2386        String varName = "vertical_aperture"
2387        wTmpWrite[0] = val
2388
2389        variable err
2390        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2391        if(err)
2392                Print "HDF write err = ",err
2393        endif
2394        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2395//      err = V_KillNamedDataFolder(fname)
2396//      if(err)
2397//              Print "DataFolder kill err = ",err
2398//      endif
2399        return(err)
2400end
2401
2402Function V_writeCrystalVertical_curv(fname,val)
2403        String fname
2404        Variable val
2405       
2406//      String path = "entry:instrument:beam:monochromator:crystal:vertical_curvature" 
2407       
2408        Make/O/D/N=1 wTmpWrite
2409//      Make/O/R/N=1 wTmpWrite
2410        String groupName = "/entry/instrument/beam/monochromator/crystal"       
2411        String varName = "vertical_curvature"
2412        wTmpWrite[0] = val
2413
2414        variable err
2415        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2416        if(err)
2417                Print "HDF write err = ",err
2418        endif
2419        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2420//      err = V_KillNamedDataFolder(fname)
2421//      if(err)
2422//              Print "DataFolder kill err = ",err
2423//      endif
2424        return(err)
2425end
2426
2427Function V_writeCrystalWavelength(fname,val)
2428        String fname
2429        Variable val
2430       
2431//      String path = "entry:instrument:beam:monochromator:crystal:wavelength" 
2432       
2433        Make/O/D/N=1 wTmpWrite
2434//      Make/O/R/N=1 wTmpWrite
2435        String groupName = "/entry/instrument/beam/monochromator/crystal"       
2436        String varName = "wavelength"
2437        wTmpWrite[0] = val
2438
2439        variable err
2440        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2441        if(err)
2442                Print "HDF write err = ",err
2443        endif
2444        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2445//      err = V_KillNamedDataFolder(fname)
2446//      if(err)
2447//              Print "DataFolder kill err = ",err
2448//      endif
2449        return(err)
2450end
2451
2452Function V_writeCrystalWavelength_spread(fname,val)
2453        String fname
2454        Variable val
2455       
2456//      String path = "entry:instrument:beam:monochromator:crystal:wavelength_spread"   
2457       
2458        Make/O/D/N=1 wTmpWrite
2459//      Make/O/R/N=1 wTmpWrite
2460        String groupName = "/entry/instrument/beam/monochromator/crystal"       
2461        String varName = "wavelength_spread"
2462        wTmpWrite[0] = val
2463
2464        variable err
2465        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2466        if(err)
2467                Print "HDF write err = ",err
2468        endif
2469        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2470//      err = V_KillNamedDataFolder(fname)
2471//      if(err)
2472//              Print "DataFolder kill err = ",err
2473//      endif
2474        return(err)
2475end
2476
2477Function V_writeCrystalWavevector(fname,val)
2478        String fname
2479        Variable val
2480       
2481//      String path = "entry:instrument:beam:monochromator:crystal:wavevector" 
2482       
2483        Make/O/D/N=1 wTmpWrite
2484//      Make/O/R/N=1 wTmpWrite
2485        String groupName = "/entry/instrument/beam/monochromator/crystal"       
2486        String varName = "wavevector"
2487        wTmpWrite[0] = val
2488
2489        variable err
2490        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2491        if(err)
2492                Print "HDF write err = ",err
2493        endif
2494        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2495//      err = V_KillNamedDataFolder(fname)
2496//      if(err)
2497//              Print "DataFolder kill err = ",err
2498//      endif
2499        return(err)
2500end
2501
2502////////////
2503// instrument/beam/monochromator/velocity_selector (data folder)
2504Function V_writeVSDistance(fname,val)
2505        String fname
2506        Variable val
2507       
2508//      String path = "entry:instrument:beam:monochromator:velocity_selector:distance" 
2509       
2510        Make/O/D/N=1 wTmpWrite
2511//      Make/O/R/N=1 wTmpWrite
2512        String groupName = "/entry/instrument/beam/monochromator/velocity_selector"     
2513        String varName = "distance"
2514        wTmpWrite[0] = val
2515
2516        variable err
2517        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2518        if(err)
2519                Print "HDF write err = ",err
2520        endif
2521        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2522//      err = V_KillNamedDataFolder(fname)
2523//      if(err)
2524//              Print "DataFolder kill err = ",err
2525//      endif
2526        return(err)
2527end
2528
2529Function V_writeVSRotation_speed(fname,val)
2530        String fname
2531        Variable val
2532       
2533//      String path = "entry:instrument:beam:monochromator:velocity_selector:rotation_speed"   
2534       
2535        Make/O/D/N=1 wTmpWrite
2536//      Make/O/R/N=1 wTmpWrite
2537        String groupName = "/entry/instrument/beam/monochromator/velocity_selector"     
2538        String varName = "rotation_speed"
2539        wTmpWrite[0] = val
2540
2541        variable err
2542        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2543        if(err)
2544                Print "HDF write err = ",err
2545        endif
2546        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2547//      err = V_KillNamedDataFolder(fname)
2548//      if(err)
2549//              Print "DataFolder kill err = ",err
2550//      endif
2551        return(err)
2552end
2553
2554Function V_writeVelSelStatus(fname,str)
2555        String fname,str
2556
2557//      String path = "entry:instrument:beam:monochromator:velocity_selector:status"
2558
2559        Make/O/T/N=1 tmpTW
2560        String groupName = "/entry/instrument/beam/monochromator/velocity_selector"     //     
2561        String varName = "status"
2562        tmpTW[0] = str //
2563
2564        variable err
2565        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2566        if(err)
2567                Print "HDF write err = ",err
2568        endif
2569       
2570        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2571//      err = V_KillNamedDataFolder(fname)
2572//      if(err)
2573//              Print "DataFolder kill err = ",err
2574//      endif
2575               
2576        return(err)
2577End
2578
2579Function V_writeVSTable_parameters(fname,inW)
2580        String fname
2581        Wave inW
2582       
2583//      String path = "entry:instrument:beam:monochromator:velocity_selector:table"     
2584
2585        Duplicate/O inW wTmpWrite       
2586// then use redimension as needed to cast the wave to write to the specified type
2587// see WaveType for the proper codes
2588//      Redimension/T=() wTmpWrite
2589// -- May also need to check the dimension(s) before writing (don't trust the input)
2590        String groupName = "/entry/instrument/beam/monochromator/velocity_selector"     
2591        String varName = "table_parameters"
2592
2593        variable err
2594        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2595        if(err)
2596                Print "HDF write err = ",err
2597        endif
2598        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2599//      err = V_KillNamedDataFolder(fname)
2600//      if(err)
2601//              Print "DataFolder kill err = ",err
2602//      endif
2603        return(err)
2604end
2605
2606//// DONE - this does not exist for VSANS - per JGB 4/2016
2607//Function V_writeVS_tilt(fname,val)
2608//      String fname
2609//      Variable val
2610//     
2611////    String path = "entry:instrument:beam:monochromator:velocity_selector:vs_tilt"   
2612//     
2613//      Make/O/D/N=1 wTmpWrite
2614////    Make/O/R/N=1 wTmpWrite
2615//      String groupName = "/entry/instrument/beam/monochromator/velocity_selector"     
2616//      String varName = "vs_tilt"
2617//      wTmpWrite[0] = val
2618//
2619//      variable err
2620//      err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2621//      if(err)
2622//              Print "HDF write err = ",err
2623//      endif
2624//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2625////    err = V_KillNamedDataFolder(fname)
2626////    if(err)
2627////            Print "DataFolder kill err = ",err
2628////    endif
2629//      return(err)
2630//end
2631
2632Function V_writeVSWavelength(fname,val)
2633        String fname
2634        Variable val
2635       
2636//      String path = "entry:instrument:beam:monochromator:velocity_selector:wavelength"       
2637       
2638        Make/O/D/N=1 wTmpWrite
2639//      Make/O/R/N=1 wTmpWrite
2640        String groupName = "/entry/instrument/beam/monochromator/velocity_selector"     
2641        String varName = "wavelength"
2642        wTmpWrite[0] = val
2643
2644        variable err
2645        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2646        if(err)
2647                Print "HDF write err = ",err
2648        endif
2649        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2650//      err = V_KillNamedDataFolder(fname)
2651//      if(err)
2652//              Print "DataFolder kill err = ",err
2653//      endif
2654        return(err)
2655end
2656
2657Function V_writeVSWavelength_spread(fname,val)
2658        String fname
2659        Variable val
2660       
2661//      String path = "entry:instrument:beam:monochromator:velocity_selector:wavelength_spread"
2662       
2663        Make/O/D/N=1 wTmpWrite
2664//      Make/O/R/N=1 wTmpWrite
2665        String groupName = "/entry/instrument/beam/monochromator/velocity_selector"     
2666        String varName = "wavelength_spread"
2667        wTmpWrite[0] = val
2668
2669        variable err
2670        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2671        if(err)
2672                Print "HDF write err = ",err
2673        endif
2674        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2675//      err = V_KillNamedDataFolder(fname)
2676//      if(err)
2677//              Print "DataFolder kill err = ",err
2678//      endif
2679        return(err)
2680end
2681
2682// instrument/beam/monochromator/white_beam (data folder)
2683Function V_writeWhiteBeamStatus(fname,str)
2684        String fname,str
2685
2686//      String path = "entry:instrument:beam:monochromator:white_beam:status"
2687
2688        Make/O/T/N=1 tmpTW
2689        String groupName = "/entry/instrument/beam/monochromator/white_beam"    //     
2690        String varName = "status"
2691        tmpTW[0] = str //
2692
2693        variable err
2694        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2695        if(err)
2696                Print "HDF write err = ",err
2697        endif
2698       
2699        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2700//      err = V_KillNamedDataFolder(fname)
2701//      if(err)
2702//              Print "DataFolder kill err = ",err
2703//      endif
2704               
2705        return(err)
2706End
2707
2708Function V_writeWhiteBeamWavelength(fname,val)
2709        String fname
2710        Variable val
2711       
2712//      String path = "entry:instrument:beam:monochromator:white_beam:wavelength"       
2713       
2714        Make/O/D/N=1 wTmpWrite
2715//      Make/O/R/N=1 wTmpWrite
2716        String groupName = "/entry/instrument/beam/monochromator/white_beam"   
2717        String varName = "wavelength"
2718        wTmpWrite[0] = val
2719
2720        variable err
2721        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2722        if(err)
2723                Print "HDF write err = ",err
2724        endif
2725        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2726//      err = V_KillNamedDataFolder(fname)
2727//      if(err)
2728//              Print "DataFolder kill err = ",err
2729//      endif
2730        return(err)
2731end
2732
2733Function V_writeWhiteBeamWavel_spread(fname,val)
2734        String fname
2735        Variable val
2736       
2737//      String path = "entry:instrument:beam:monochromator:white_beam:wavelength_spread"       
2738       
2739        Make/O/D/N=1 wTmpWrite
2740//      Make/O/R/N=1 wTmpWrite
2741        String groupName = "/entry/instrument/beam/monochromator/white_beam"   
2742        String varName = "wavelength_spread"
2743        wTmpWrite[0] = val
2744
2745        variable err
2746        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2747        if(err)
2748                Print "HDF write err = ",err
2749        endif
2750        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2751//      err = V_KillNamedDataFolder(fname)
2752//      if(err)
2753//              Print "DataFolder kill err = ",err
2754//      endif
2755        return(err)
2756end
2757
2758// instrument/beam/superMirror (data folder)
2759// This is the upstream polarizer. There are no other choices for polarizer on VSANS
2760Function V_writePolarizerComposition(fname,str)
2761        String fname,str
2762
2763//      String path = "entry:instrument:beam:superMirror:composition"
2764
2765        Make/O/T/N=1 tmpTW
2766        String groupName = "/entry/instrument/beam/superMirror" //     
2767        String varName = "composition"
2768        tmpTW[0] = str //
2769
2770        variable err
2771        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2772        if(err)
2773                Print "HDF write err = ",err
2774        endif
2775       
2776        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2777//      err = V_KillNamedDataFolder(fname)
2778//      if(err)
2779//              Print "DataFolder kill err = ",err
2780//      endif
2781               
2782        return(err)
2783End
2784
2785Function V_writePolarizerEfficiency(fname,val)
2786        String fname
2787        Variable val
2788       
2789//      String path = "entry:instrument:beam:superMirror:efficiency"   
2790       
2791        Make/O/D/N=1 wTmpWrite
2792//      Make/O/R/N=1 wTmpWrite
2793        String groupName = "/entry/instrument/beam/superMirror"
2794        String varName = "efficiency"
2795        wTmpWrite[0] = val
2796
2797        variable err
2798        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2799        if(err)
2800                Print "HDF write err = ",err
2801        endif
2802        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2803//      err = V_KillNamedDataFolder(fname)
2804//      if(err)
2805//              Print "DataFolder kill err = ",err
2806//      endif
2807        return(err)
2808end
2809
2810Function V_writePolarizerState(fname,str)
2811        String fname,str
2812
2813//      String path = "entry:instrument:beam:superMirror:state"
2814
2815        Make/O/T/N=1 tmpTW
2816        String groupName = "/entry/instrument/beam/superMirror" //     
2817        String varName = "state"
2818        tmpTW[0] = str //
2819
2820        variable err
2821        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2822        if(err)
2823                Print "HDF write err = ",err
2824        endif
2825       
2826        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2827//      err = V_KillNamedDataFolder(fname)
2828//      if(err)
2829//              Print "DataFolder kill err = ",err
2830//      endif
2831               
2832        return(err)
2833End
2834
2835//Function V_writePolarizerType(fname,str)
2836//      String fname,str
2837//
2838////    String path = "entry:instrument:beam:polarizer:type"
2839//
2840//      Make/O/T/N=1 tmpTW
2841//      String groupName = "/entry/instrument/beam/polarizer"   //     
2842//      String varName = "type"
2843//      tmpTW[0] = str //
2844//
2845//      variable err
2846//      err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2847//      if(err)
2848//              Print "HDF write err = ",err
2849//      endif
2850//     
2851//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2852////    err = V_KillNamedDataFolder(fname)
2853////    if(err)
2854////            Print "DataFolder kill err = ",err
2855////    endif
2856//             
2857//      return(err)
2858//End
2859//
2860//// instrument/beam/polarizer_analyzer (data folder)
2861//// integer value
2862//Function V_writePolAnaCell_index(fname,val)
2863//      String fname
2864//      Variable val
2865//
2866////    String path = "entry:instrument:beam:polarizer_analyzer:cell_index"
2867//     
2868//      Make/O/I/N=1 wTmpWrite
2869////    Make/O/R/N=1 wTmpWrite
2870//      String groupName = "/entry/instrument/beam/polarizer_analyzer" 
2871//      String varName = "cell_index"
2872//      wTmpWrite[0] = val
2873//
2874//      variable err
2875//      err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2876//      if(err)
2877//              Print "HDF write err = ",err
2878//      endif
2879//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2880////    err = V_KillNamedDataFolder(fname)
2881////    if(err)
2882////            Print "DataFolder kill err = ",err
2883////    endif
2884//      return(err)
2885//End
2886//
2887//Function V_writePolAnaCell_name(fname,str)
2888//      String fname,str
2889//
2890////    String path = "entry:instrument:beam:polarizer_analyzer:cell_name"
2891//
2892//      Make/O/T/N=1 tmpTW
2893//      String groupName = "/entry/instrument/beam/polarizer_analyzer"  //     
2894//      String varName = "cell_name"
2895//      tmpTW[0] = str //
2896//
2897//      variable err
2898//      err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2899//      if(err)
2900//              Print "HDF write err = ",err
2901//      endif
2902//     
2903//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2904////    err = V_KillNamedDataFolder(fname)
2905////    if(err)
2906////            Print "DataFolder kill err = ",err
2907////    endif
2908//             
2909//      return(err)
2910//End
2911//
2912//Function V_writePolAnaCell_parameters(fname,inW)
2913//      String fname
2914//      Wave inW
2915//
2916////    String path = "entry:instrument:beam:polarizer_analyzer:cell_parameters"
2917//
2918//      Duplicate/O inW wTmpWrite       
2919//// then use redimension as needed to cast the wave to write to the specified type
2920//// see WaveType for the proper codes
2921////    Redimension/T=() wTmpWrite
2922//// -- May also need to check the dimension(s) before writing (don't trust the input)
2923//      String groupName = "/entry/instrument//beam/polarizer_analyzer"
2924//      String varName = "cell_parameters"
2925//
2926//      variable err
2927//      err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2928//      if(err)
2929//              Print "HDF write err = ",err
2930//      endif
2931//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2932////    err = V_KillNamedDataFolder(fname)
2933////    if(err)
2934////            Print "DataFolder kill err = ",err
2935////    endif
2936//      return(err)
2937//End
2938//
2939//Function V_writePolAnaGuideFieldCur_1(fname,val)
2940//      String fname
2941//      Variable val
2942//
2943////    String path = "entry:instrument:beam:polarizer_analyzer:guide_field_current_1"
2944//     
2945//      Make/O/D/N=1 wTmpWrite
2946////    Make/O/R/N=1 wTmpWrite
2947//      String groupName = "/entry/instrument/beam/polarizer_analyzer" 
2948//      String varName = "guide_field_current_1"
2949//      wTmpWrite[0] = val
2950//
2951//      variable err
2952//      err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2953//      if(err)
2954//              Print "HDF write err = ",err
2955//      endif
2956//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2957////    err = V_KillNamedDataFolder(fname)
2958////    if(err)
2959////            Print "DataFolder kill err = ",err
2960////    endif
2961//      return(err)
2962//End
2963//
2964//Function V_writePolAnaGuideFieldCur_2(fname,val)
2965//      String fname
2966//      Variable val
2967//
2968////    String path = "entry:instrument:beam:polarizer_analyzer:guide_field_current_2"
2969//     
2970//      Make/O/D/N=1 wTmpWrite
2971////    Make/O/R/N=1 wTmpWrite
2972//      String groupName = "/entry/instrument/beam/polarizer_analyzer" 
2973//      String varName = "guide_field_current_2"
2974//      wTmpWrite[0] = val
2975//
2976//      variable err
2977//      err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2978//      if(err)
2979//              Print "HDF write err = ",err
2980//      endif
2981//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2982////    err = V_KillNamedDataFolder(fname)
2983////    if(err)
2984////            Print "DataFolder kill err = ",err
2985////    endif
2986//      return(err)
2987//End
2988//
2989//Function V_writePolAnaSolenoid_current(fname,val)
2990//      String fname
2991//      Variable val
2992//
2993////    String path = "entry:instrument:beam:polarizer_analyzer:solenoid_current"
2994//     
2995//      Make/O/D/N=1 wTmpWrite
2996////    Make/O/R/N=1 wTmpWrite
2997//      String groupName = "/entry/instrument/beam/polarizer_analyzer" 
2998//      String varName = "solenoid_current"
2999//      wTmpWrite[0] = val
3000//
3001//      variable err
3002//      err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3003//      if(err)
3004//              Print "HDF write err = ",err
3005//      endif
3006//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3007////    err = V_KillNamedDataFolder(fname)
3008////    if(err)
3009////            Print "DataFolder kill err = ",err
3010////    endif
3011//      return(err)
3012//End
3013//
3014//Function V_writePolAnaStatus(fname,str)
3015//      String fname,str
3016//
3017////    String path = "entry:instrument:beam:polarizer_analyzer:status"
3018//
3019//      Make/O/T/N=1 tmpTW
3020//      String groupName = "/entry/instrument/beam/polarizer_analyzer"  //     
3021//      String varName = "status"
3022//      tmpTW[0] = str //
3023//
3024//      variable err
3025//      err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3026//      if(err)
3027//              Print "HDF write err = ",err
3028//      endif
3029//     
3030//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3031////    err = V_KillNamedDataFolder(fname)
3032////    if(err)
3033////            Print "DataFolder kill err = ",err
3034////    endif
3035//             
3036//      return(err)
3037//End
3038
3039
3040
3041
3042                                       
3043/////// INSTRUMENT/BEAM MONITORS
3044
3045//beam_monitor_low (data folder)
3046// integer value
3047Function V_writeBeamMonLowData(fname,val)
3048        String fname
3049        Variable val
3050
3051//      String path = "entry:instrument:beam_monitor_low:data"
3052       
3053        Make/O/I/N=1 wTmpWrite
3054//      Make/O/R/N=1 wTmpWrite
3055        String groupName = "/entry/instrument/beam_monitor_low"
3056        String varName = "data"
3057        wTmpWrite[0] = val
3058
3059        variable err
3060        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3061        if(err)
3062                Print "HDF write err = ",err
3063        endif
3064        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3065//      err = V_KillNamedDataFolder(fname)
3066//      if(err)
3067//              Print "DataFolder kill err = ",err
3068//      endif
3069        return(err)
3070End
3071
3072Function V_writeBeamMonLowDistance(fname,val)
3073        String fname
3074        Variable val
3075
3076//      String path = "entry:instrument:beam_monitor_low:distance"
3077       
3078        Make/O/D/N=1 wTmpWrite
3079//      Make/O/R/N=1 wTmpWrite
3080        String groupName = "/entry/instrument/beam_monitor_low"
3081        String varName = "distance"
3082        wTmpWrite[0] = val
3083
3084        variable err
3085        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3086        if(err)
3087                Print "HDF write err = ",err
3088        endif
3089        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3090//      err = V_KillNamedDataFolder(fname)
3091//      if(err)
3092//              Print "DataFolder kill err = ",err
3093//      endif
3094        return(err)
3095End
3096
3097Function V_writeBeamMonLowEfficiency(fname,val)
3098        String fname
3099        Variable val
3100
3101//      String path = "entry:instrument:beam_monitor_low:efficiency"
3102       
3103        Make/O/D/N=1 wTmpWrite
3104//      Make/O/R/N=1 wTmpWrite
3105        String groupName = "/entry/instrument/beam_monitor_low"
3106        String varName = "efficiency"
3107        wTmpWrite[0] = val
3108
3109        variable err
3110        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3111        if(err)
3112                Print "HDF write err = ",err
3113        endif
3114        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3115//      err = V_KillNamedDataFolder(fname)
3116//      if(err)
3117//              Print "DataFolder kill err = ",err
3118//      endif
3119        return(err)
3120End
3121
3122Function V_writeBeamMonLowSaved_count(fname,val)
3123        String fname
3124        Variable val
3125
3126//      String path = "entry:instrument:beam_monitor_low:saved_count"
3127       
3128        Make/O/D/N=1 wTmpWrite
3129//      Make/O/R/N=1 wTmpWrite
3130        String groupName = "/entry/instrument/beam_monitor_low"
3131        String varName = "saved_count"
3132        wTmpWrite[0] = val
3133
3134        variable err
3135        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3136        if(err)
3137                Print "HDF write err = ",err
3138        endif
3139        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3140//      err = V_KillNamedDataFolder(fname)
3141//      if(err)
3142//              Print "DataFolder kill err = ",err
3143//      endif
3144        return(err)
3145End
3146
3147Function V_writeBeamMonLowType(fname,str)
3148        String fname,str
3149
3150//      String path = "entry:instrument:beam_monitor_low:type"
3151
3152        Make/O/T/N=1 tmpTW
3153        String groupName = "/entry/instrument/beam_monitor_low" //     
3154        String varName = "type"
3155        tmpTW[0] = str //
3156
3157        variable err
3158        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3159        if(err)
3160                Print "HDF write err = ",err
3161        endif
3162       
3163        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3164//      err = V_KillNamedDataFolder(fname)
3165//      if(err)
3166//              Print "DataFolder kill err = ",err
3167//      endif
3168               
3169        return(err)
3170End
3171
3172//beam_monitor_norm (data folder)
3173// integer value
3174Function V_writeBeamMonNormData(fname,val)
3175        String fname
3176        Variable val
3177
3178//      String path = "entry:instrument:beam_monitor_norm:data"
3179       
3180        Make/O/I/N=1 wTmpWrite
3181//      Make/O/R/N=1 wTmpWrite
3182        String groupName = "/entry/instrument/beam_monitor_norm"       
3183        String varName = "data"
3184        wTmpWrite[0] = val
3185
3186        variable err
3187        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3188        if(err)
3189                Print "HDF write err = ",err
3190        endif
3191        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3192//      err = V_KillNamedDataFolder(fname)
3193//      if(err)
3194//              Print "DataFolder kill err = ",err
3195//      endif
3196        return(err)
3197End
3198
3199// fname is a local WORK folder
3200Function V_putBeamMonNormData(fname,val)
3201        String fname
3202        Variable val
3203
3204        String path = "root:Packages:NIST:VSANS:"+fname+":"
3205        path += "entry:instrument:beam_monitor_norm:data"
3206       
3207        Wave/Z w = $path
3208        if(waveExists(w) == 0)
3209                return(1)
3210        else
3211        w[0] = val
3212                return(0)
3213        endif
3214
3215End
3216
3217
3218Function V_writeBeamMonNormDistance(fname,val)
3219        String fname
3220        Variable val
3221
3222//      String path = "entry:instrument:beam_monitor_norm:distance"
3223       
3224        Make/O/D/N=1 wTmpWrite
3225//      Make/O/R/N=1 wTmpWrite
3226        String groupName = "/entry/instrument/beam_monitor_norm"       
3227        String varName = "distance"
3228        wTmpWrite[0] = val
3229
3230        variable err
3231        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3232        if(err)
3233                Print "HDF write err = ",err
3234        endif
3235        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3236//      err = V_KillNamedDataFolder(fname)
3237//      if(err)
3238//              Print "DataFolder kill err = ",err
3239//      endif
3240        return(err)
3241End
3242
3243Function V_writeBeamMonNormEfficiency(fname,val)
3244        String fname
3245        Variable val
3246
3247//      String path = "entry:instrument:beam_monitor_norm:efficiency"
3248       
3249        Make/O/D/N=1 wTmpWrite
3250//      Make/O/R/N=1 wTmpWrite
3251        String groupName = "/entry/instrument/beam_monitor_norm"       
3252        String varName = "efficiency"
3253        wTmpWrite[0] = val
3254
3255        variable err
3256        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3257        if(err)
3258                Print "HDF write err = ",err
3259        endif
3260        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3261//      err = V_KillNamedDataFolder(fname)
3262//      if(err)
3263//              Print "DataFolder kill err = ",err
3264//      endif
3265        return(err)
3266End
3267
3268
3269Function V_writeBeamMonNormSaved_count(fname,val)
3270        String fname
3271        Variable val
3272
3273//      String path = "entry:instrument:beam_monitor_norm:saved_count"
3274       
3275        Make/O/D/N=1 wTmpWrite
3276//      Make/O/R/N=1 wTmpWrite
3277        String groupName = "/entry/instrument/beam_monitor_norm"       
3278        String varName = "saved_count"
3279        wTmpWrite[0] = val
3280
3281        variable err
3282        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3283        if(err)
3284                Print "HDF write err = ",err
3285        endif
3286        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3287//      err = V_KillNamedDataFolder(fname)
3288//      if(err)
3289//              Print "DataFolder kill err = ",err
3290//      endif
3291        return(err)
3292End
3293
3294// fname is a local WORK folder
3295Function V_putBeamMonNormSaved_count(fname,val)
3296        String fname
3297        Variable val
3298
3299        String path = "root:Packages:NIST:VSANS:"+fname+":"
3300        path += "entry:instrument:beam_monitor_norm:saved_count"
3301       
3302        Wave/Z w = $path
3303        if(waveExists(w) == 0)
3304                return(1)
3305        else
3306        w[0] = val
3307                return(0)
3308        endif
3309
3310End
3311
3312
3313
3314Function V_writeBeamMonNormType(fname,str)
3315        String fname,str
3316
3317//      String path = "entry:instrument:beam_monitor_norm:type"
3318
3319        Make/O/T/N=1 tmpTW
3320        String groupName = "/entry/instrument/beam_monitor_norm"        //     
3321        String varName = "type"
3322        tmpTW[0] = str //
3323
3324        variable err
3325        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3326        if(err)
3327                Print "HDF write err = ",err
3328        endif
3329       
3330        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3331//      err = V_KillNamedDataFolder(fname)
3332//      if(err)
3333//              Print "DataFolder kill err = ",err
3334//      endif
3335               
3336        return(err)
3337End
3338
3339
3340//beam_stop C2 (data folder)
3341Function V_writeBeamStopC2Description(fname,str)
3342        String fname,str
3343
3344//      String path = "entry:instrument:beam_stop:description"
3345
3346        Make/O/T/N=1 tmpTW
3347        String groupName = "/entry/instrument/beam_stop_C2"     //     
3348        String varName = "description"
3349        tmpTW[0] = str //
3350
3351        variable err
3352        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3353        if(err)
3354                Print "HDF write err = ",err
3355        endif
3356       
3357        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3358//      err = V_KillNamedDataFolder(fname)
3359//      if(err)
3360//              Print "DataFolder kill err = ",err
3361//      endif
3362               
3363        return(err)
3364End
3365
3366Function V_writeBeamStopC2Dist_to_det(fname,val)
3367        String fname
3368        Variable val
3369
3370//      String path = "entry:instrument:beam_stop:distance_to_detector"
3371       
3372        Make/O/D/N=1 wTmpWrite
3373//      Make/O/R/N=1 wTmpWrite
3374        String groupName = "/entry/instrument/beam_stop_C2"     
3375        String varName = "distance_to_detector"
3376        wTmpWrite[0] = val
3377
3378        variable err
3379        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3380        if(err)
3381                Print "HDF write err = ",err
3382        endif
3383        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3384//      err = V_KillNamedDataFolder(fname)
3385//      if(err)
3386//              Print "DataFolder kill err = ",err
3387//      endif
3388        return(err)
3389End
3390
3391// is this the index of which size beam stop is in position?
3392// integer value
3393Function V_writeBeamStopC2num_stop(fname,val)
3394        String fname
3395        Variable val
3396
3397//      String path = "entry:instrument:beam_stop:distance_to_detector"
3398       
3399        Make/O/I/N=1 wTmpWrite
3400//      Make/O/R/N=1 wTmpWrite
3401        String groupName = "/entry/instrument/beam_stop_C2"     
3402        String varName = "num_beamstops"
3403        wTmpWrite[0] = val
3404
3405        variable err
3406        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3407        if(err)
3408                Print "HDF write err = ",err
3409        endif
3410        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3411//      err = V_KillNamedDataFolder(fname)
3412//      if(err)
3413//              Print "DataFolder kill err = ",err
3414//      endif
3415        return(err)
3416End
3417
3418Function V_writeBeamStopC2_x_pos(fname,val)
3419        String fname
3420        Variable val
3421
3422//      String path = "entry:instrument:beam_stop:x0"
3423       
3424        Make/O/D/N=1 wTmpWrite
3425//      Make/O/R/N=1 wTmpWrite
3426        String groupName = "/entry/instrument/beam_stop_C2"     
3427        String varName = "x_pos"
3428        wTmpWrite[0] = val
3429
3430        variable err
3431        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3432        if(err)
3433                Print "HDF write err = ",err
3434        endif
3435        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3436//      err = V_KillNamedDataFolder(fname)
3437//      if(err)
3438//              Print "DataFolder kill err = ",err
3439//      endif
3440        return(err)
3441End
3442
3443Function V_writeBeamStopC2_y_pos(fname,val)
3444        String fname
3445        Variable val
3446
3447//      String path = "entry:instrument:beam_stop:y0"
3448       
3449        Make/O/D/N=1 wTmpWrite
3450//      Make/O/R/N=1 wTmpWrite
3451        String groupName = "/entry/instrument/beam_stop_C2"     
3452        String varName = "y_pos"
3453        wTmpWrite[0] = val
3454
3455        variable err
3456        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3457        if(err)
3458                Print "HDF write err = ",err
3459        endif
3460        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3461//      err = V_KillNamedDataFolder(fname)
3462//      if(err)
3463//              Print "DataFolder kill err = ",err
3464//      endif
3465        return(err)
3466End
3467
3468
3469// beam stop C2 (shape)
3470Function V_writeBeamStopC2_height(fname,val)
3471        String fname
3472        Variable val
3473
3474//      String path = "entry:instrument:beam_stop:y0"
3475       
3476        Make/O/D/N=1 wTmpWrite
3477//      Make/O/R/N=1 wTmpWrite
3478        String groupName = "/entry/instrument/beam_stop_C2/shape"       
3479        String varName = "height"
3480        wTmpWrite[0] = val
3481
3482        variable err
3483        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3484        if(err)
3485                Print "HDF write err = ",err
3486        endif
3487        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3488//      err = V_KillNamedDataFolder(fname)
3489//      if(err)
3490//              Print "DataFolder kill err = ",err
3491//      endif
3492        return(err)
3493End
3494
3495Function V_writeBeamStopC2_shape(fname,str)
3496        String fname,str
3497
3498//      String path = "entry:instrument:beam_stop:description"
3499
3500        Make/O/T/N=1 tmpTW
3501        String groupName = "/entry/instrument/beam_stop_C2/shape"       //     
3502        String varName = "shape"
3503        tmpTW[0] = str //
3504
3505        variable err
3506        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3507        if(err)
3508                Print "HDF write err = ",err
3509        endif
3510       
3511        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3512//      err = V_KillNamedDataFolder(fname)
3513//      if(err)
3514//              Print "DataFolder kill err = ",err
3515//      endif
3516               
3517        return(err)
3518End
3519
3520// this is diameter if shape=CIRCLE
3521Function V_writeBeamStopC2_size(fname,val)
3522        String fname
3523        Variable val
3524
3525//      String path = "entry:instrument:beam_stop:y0"
3526       
3527        Make/O/D/N=1 wTmpWrite
3528//      Make/O/R/N=1 wTmpWrite
3529        String groupName = "/entry/instrument/beam_stop_C2/shape"       
3530        String varName = "size"
3531        wTmpWrite[0] = val
3532
3533        variable err
3534        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3535        if(err)
3536                Print "HDF write err = ",err
3537        endif
3538        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3539//      err = V_KillNamedDataFolder(fname)
3540//      if(err)
3541//              Print "DataFolder kill err = ",err
3542//      endif
3543        return(err)
3544End
3545
3546Function V_writeBeamStopC2_width(fname,val)
3547        String fname
3548        Variable val
3549
3550//      String path = "entry:instrument:beam_stop:y0"
3551       
3552        Make/O/D/N=1 wTmpWrite
3553//      Make/O/R/N=1 wTmpWrite
3554        String groupName = "/entry/instrument/beam_stop_C2/shape"       
3555        String varName = "width"
3556        wTmpWrite[0] = val
3557
3558        variable err
3559        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3560        if(err)
3561                Print "HDF write err = ",err
3562        endif
3563        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3564//      err = V_KillNamedDataFolder(fname)
3565//      if(err)
3566//              Print "DataFolder kill err = ",err
3567//      endif
3568        return(err)
3569End
3570
3571// beam stop C3 (data folder)
3572Function V_writeBeamStopC3Description(fname,str)
3573        String fname,str
3574
3575//      String path = "entry:instrument:beam_stop:description"
3576
3577        Make/O/T/N=1 tmpTW
3578        String groupName = "/entry/instrument/beam_stop_C3"     //     
3579        String varName = "description"
3580        tmpTW[0] = str //
3581
3582        variable err
3583        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3584        if(err)
3585                Print "HDF write err = ",err
3586        endif
3587       
3588        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3589//      err = V_KillNamedDataFolder(fname)
3590//      if(err)
3591//              Print "DataFolder kill err = ",err
3592//      endif
3593               
3594        return(err)
3595End
3596
3597Function V_writeBeamStopC3Dist_to_det(fname,val)
3598        String fname
3599        Variable val
3600
3601//      String path = "entry:instrument:beam_stop:distance_to_detector"
3602       
3603        Make/O/D/N=1 wTmpWrite
3604//      Make/O/R/N=1 wTmpWrite
3605        String groupName = "/entry/instrument/beam_stop_C3"     
3606        String varName = "distance_to_detector"
3607        wTmpWrite[0] = val
3608
3609        variable err
3610        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3611        if(err)
3612                Print "HDF write err = ",err
3613        endif
3614        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3615//      err = V_KillNamedDataFolder(fname)
3616//      if(err)
3617//              Print "DataFolder kill err = ",err
3618//      endif
3619        return(err)
3620End
3621
3622// integer value
3623Function V_writeBeamStopC3num_stop(fname,val)
3624        String fname
3625        Variable val
3626
3627//      String path = "entry:instrument:beam_stop:distance_to_detector"
3628       
3629        Make/O/I/N=1 wTmpWrite
3630//      Make/O/R/N=1 wTmpWrite
3631        String groupName = "/entry/instrument/beam_stop_C3"     
3632        String varName = "num_beamstops"
3633        wTmpWrite[0] = val
3634
3635        variable err
3636        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3637        if(err)
3638                Print "HDF write err = ",err
3639        endif
3640        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3641//      err = V_KillNamedDataFolder(fname)
3642//      if(err)
3643//              Print "DataFolder kill err = ",err
3644//      endif
3645        return(err)
3646End
3647
3648Function V_writeBeamStopC3_x_pos(fname,val)
3649        String fname
3650        Variable val
3651
3652//      String path = "entry:instrument:beam_stop:x0"
3653       
3654        Make/O/D/N=1 wTmpWrite
3655//      Make/O/R/N=1 wTmpWrite
3656        String groupName = "/entry/instrument/beam_stop_C3"     
3657        String varName = "x_pos"
3658        wTmpWrite[0] = val
3659
3660        variable err
3661        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3662        if(err)
3663                Print "HDF write err = ",err
3664        endif
3665        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3666//      err = V_KillNamedDataFolder(fname)
3667//      if(err)
3668//              Print "DataFolder kill err = ",err
3669//      endif
3670        return(err)
3671End
3672
3673Function V_writeBeamStopC3_y_pos(fname,val)
3674        String fname
3675        Variable val
3676
3677//      String path = "entry:instrument:beam_stop:y0"
3678       
3679        Make/O/D/N=1 wTmpWrite
3680//      Make/O/R/N=1 wTmpWrite
3681        String groupName = "/entry/instrument/beam_stop_C3"     
3682        String varName = "y_pos"
3683        wTmpWrite[0] = val
3684
3685        variable err
3686        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3687        if(err)
3688                Print "HDF write err = ",err
3689        endif
3690        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3691//      err = V_KillNamedDataFolder(fname)
3692//      if(err)
3693//              Print "DataFolder kill err = ",err
3694//      endif
3695        return(err)
3696End
3697
3698
3699// beam stop C3 (shape)
3700Function V_writeBeamStopC3_height(fname,val)
3701        String fname
3702        Variable val
3703
3704//      String path = "entry:instrument:beam_stop:y0"
3705       
3706        Make/O/D/N=1 wTmpWrite
3707//      Make/O/R/N=1 wTmpWrite
3708        String groupName = "/entry/instrument/beam_stop_C3/shape"       
3709        String varName = "height"
3710        wTmpWrite[0] = val
3711
3712        variable err
3713        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3714        if(err)
3715                Print "HDF write err = ",err
3716        endif
3717        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3718//      err = V_KillNamedDataFolder(fname)
3719//      if(err)
3720//              Print "DataFolder kill err = ",err
3721//      endif
3722        return(err)
3723End
3724
3725Function V_writeBeamStopC3_shape(fname,str)
3726        String fname,str
3727
3728//      String path = "entry:instrument:beam_stop:description"
3729
3730        Make/O/T/N=1 tmpTW
3731        String groupName = "/entry/instrument/beam_stop_C3/shape"       //     
3732        String varName = "shape"
3733        tmpTW[0] = str //
3734
3735        variable err
3736        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3737        if(err)
3738                Print "HDF write err = ",err
3739        endif
3740       
3741        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3742//      err = V_KillNamedDataFolder(fname)
3743//      if(err)
3744//              Print "DataFolder kill err = ",err
3745//      endif
3746               
3747        return(err)
3748End
3749
3750// this is diameter if shape=CIRCLE
3751Function V_writeBeamStopC3_size(fname,val)
3752        String fname
3753        Variable val
3754
3755//      String path = "entry:instrument:beam_stop:y0"
3756       
3757        Make/O/D/N=1 wTmpWrite
3758//      Make/O/R/N=1 wTmpWrite
3759        String groupName = "/entry/instrument/beam_stop_C3/shape"       
3760        String varName = "size"
3761        wTmpWrite[0] = val
3762
3763        variable err
3764        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3765        if(err)
3766                Print "HDF write err = ",err
3767        endif
3768        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3769//      err = V_KillNamedDataFolder(fname)
3770//      if(err)
3771//              Print "DataFolder kill err = ",err
3772//      endif
3773        return(err)
3774End
3775
3776Function V_writeBeamStopC3_width(fname,val)
3777        String fname
3778        Variable val
3779
3780//      String path = "entry:instrument:beam_stop:y0"
3781       
3782        Make/O/D/N=1 wTmpWrite
3783//      Make/O/R/N=1 wTmpWrite
3784        String groupName = "/entry/instrument/beam_stop_C3/shape"       
3785        String varName = "width"
3786        wTmpWrite[0] = val
3787
3788        variable err
3789        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3790        if(err)
3791                Print "HDF write err = ",err
3792        endif
3793        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3794//      err = V_KillNamedDataFolder(fname)
3795//      if(err)
3796//              Print "DataFolder kill err = ",err
3797//      endif
3798        return(err)
3799End
3800
3801
3802
3803//// INSTRUMENT/COLLIMATOR
3804//collimator (data folder) -- this is a TEXT field
3805Function V_writeNumberOfGuides(fname,str)
3806        String fname,str
3807
3808//      String path = "entry:instrument:collimator:number_guides"
3809
3810        Make/O/T/N=1 tmpTW
3811        String groupName = "/entry/instrument/collimator"       
3812        String varName = "number_guides"
3813        tmpTW[0] = str //
3814
3815        variable err
3816        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3817        if(err)
3818                Print "HDF write err = ",err
3819        endif
3820       
3821        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3822//      err = V_KillNamedDataFolder(fname)
3823//      if(err)
3824//              Print "DataFolder kill err = ",err
3825//      endif
3826               
3827        return(err)
3828End
3829
3830
3831//                              geometry (data folder)
3832//                                      shape (data folder)
3833Function V_writeGuideShape(fname,str)
3834        String fname,str
3835
3836//      String path = "entry:instrument:collimator:geometry:shape:shape"
3837
3838        Make/O/T/N=1 tmpTW
3839        String groupName = "/entry/instrument/collimator/geometry/shape"        //     
3840        String varName = "shape"
3841        tmpTW[0] = str //
3842
3843        variable err
3844        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3845        if(err)
3846                Print "HDF write err = ",err
3847        endif
3848       
3849        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3850//      err = V_KillNamedDataFolder(fname)
3851//      if(err)
3852//              Print "DataFolder kill err = ",err
3853//      endif
3854               
3855        return(err)
3856End
3857
3858// TODO -- this may need to be a wave to properly describe the dimensions
3859Function V_writeGuideSize(fname,val)
3860        String fname
3861        Variable val
3862
3863//      String path = "entry:instrument:collimator:geometry:shape:size"
3864       
3865        Make/O/D/N=1 wTmpWrite
3866//      Make/O/R/N=1 wTmpWrite
3867        String groupName = "/entry/instrument/collimator/geometry/shape"       
3868        String varName = "size"
3869        wTmpWrite[0] = val
3870
3871        variable err
3872        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3873        if(err)
3874                Print "HDF write err = ",err
3875        endif
3876        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3877//      err = V_KillNamedDataFolder(fname)
3878//      if(err)
3879//              Print "DataFolder kill err = ",err
3880//      endif
3881        return(err)
3882End
3883
3884//                      converging_pinholes (data folder)
3885Function V_writeConvPinholeStatus(fname,str)
3886        String fname,str
3887
3888//      String path = "entry:instrument:converging_pinholes:status"
3889
3890        Make/O/T/N=1 tmpTW
3891        String groupName = "/entry/instrument/converging_pinholes"      //     
3892        String varName = "status"
3893        tmpTW[0] = str //
3894
3895        variable err
3896        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3897        if(err)
3898                Print "HDF write err = ",err
3899        endif
3900       
3901        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3902//      err = V_KillNamedDataFolder(fname)
3903//      if(err)
3904//              Print "DataFolder kill err = ",err
3905//      endif
3906               
3907        return(err)
3908End
3909
3910//                      converging_slits (not used)
3911
3912
3913
3914
3915
3916
3917////// INSTRUMENT/DETECTORS
3918//                      detector_B (data folder)
3919//
3920// only defined for the "B" detector, and may not be necessary?
3921// TODO -- write to return an ARRAY
3922Function V_writeDet_cal_x(fname,detStr,inW)
3923        String fname,detStr
3924        Wave inW
3925
3926        if(cmpstr(detStr,"B") == 0)
3927//              String path = "entry:instrument:detector_"+detStr+":CALX"
3928               
3929                Duplicate/O inW wTmpWrite       
3930        // then use redimension as needed to cast the wave to write to the specified type
3931        // see WaveType for the proper codes
3932        //      Redimension/T=() wTmpWrite
3933        // -- May also need to check the dimension(s) before writing (don't trust the input)
3934                String groupName = "/entry/instrument/detector_"+detStr
3935                String varName = "cal_x"
3936
3937                variable err
3938                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3939                if(err)
3940                        Print "HDF write err = ",err
3941                endif
3942                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3943//              err = V_KillNamedDataFolder(fname)
3944//              if(err)
3945//                      Print "DataFolder kill err = ",err
3946//              endif
3947                return(err)
3948        else
3949                return(0)
3950        endif
3951End
3952
3953// only defined for the "B" detector, and may not be necessary?
3954// TODO -- write to return an ARRAY
3955Function V_writeDet_cal_y(fname,detStr,inW)
3956        String fname,detStr
3957        Wave inW
3958
3959        if(cmpstr(detStr,"B") == 0)
3960//              String path = "entry:instrument:detector_"+detStr+":CALY"
3961
3962                Duplicate/O inW wTmpWrite       
3963        // then use redimension as needed to cast the wave to write to the specified type
3964        // see WaveType for the proper codes
3965        //      Redimension/T=() wTmpWrite
3966        // -- May also need to check the dimension(s) before writing (don't trust the input)
3967                String groupName = "/entry/instrument/detector_"+detStr
3968                String varName = "cal_y"
3969
3970                variable err
3971                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3972                if(err)
3973                        Print "HDF write err = ",err
3974                endif
3975                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3976//              err = V_KillNamedDataFolder(fname)
3977//              if(err)
3978//                      Print "DataFolder kill err = ",err
3979//              endif
3980                return(err)
3981        else
3982                return(0)
3983        endif
3984End
3985
3986// TODO -- write and X and Y version of this. Pixels are not square
3987// so the FHWM will be different in each direction. May need to return
3988// "dummy" value for "B" detector if pixels there are square
3989Function V_writeDet_pixel_fwhm_x(fname,detStr,val)
3990        String fname,detStr
3991        Variable val
3992
3993//      String path = "entry:instrument:detector_"+detStr+":pixel_fwhm_x"
3994       
3995        Make/O/D/N=1 wTmpWrite
3996//      Make/O/R/N=1 wTmpWrite
3997        String groupName = "/entry/instrument/detector_"+detStr
3998        String varName = "pixel_fwhm_x"
3999        wTmpWrite[0] = val
4000
4001        variable err
4002        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4003        if(err)
4004                Print "HDF write err = ",err
4005        endif
4006        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4007//      err = V_KillNamedDataFolder(fname)
4008//      if(err)
4009//              Print "DataFolder kill err = ",err
4010//      endif
4011        return(err)
4012End
4013
4014
4015// TODO -- write and X and Y version of this. Pixels are not square
4016// so the FHWM will be different in each direction. May need to return
4017// "dummy" value for "B" detector if pixels there are square
4018Function V_writeDet_pixel_fwhm_y(fname,detStr,val)
4019        String fname,detStr
4020        Variable val
4021
4022//      String path = "entry:instrument:detector_"+detStr+":pixel_fwhm_y"
4023       
4024        Make/O/D/N=1 wTmpWrite
4025//      Make/O/R/N=1 wTmpWrite
4026        String groupName = "/entry/instrument/detector_"+detStr
4027        String varName = "pixel_fwhm_y"
4028        wTmpWrite[0] = val
4029
4030        variable err
4031        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4032        if(err)
4033                Print "HDF write err = ",err
4034        endif
4035        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4036//      err = V_KillNamedDataFolder(fname)
4037//      if(err)
4038//              Print "DataFolder kill err = ",err
4039//      endif
4040        return(err)
4041End
4042
4043// integer value
4044Function V_writeDet_pixel_num_x(fname,detStr,val)
4045        String fname,detStr
4046        Variable val
4047
4048//      String path = "entry:instrument:detector_"+detStr+":pixel_nnum_x"
4049       
4050        Make/O/I/N=1 wTmpWrite
4051//      Make/O/R/N=1 wTmpWrite
4052        String groupName = "/entry/instrument/detector_"+detStr
4053        String varName = "pixel_num_x"
4054        wTmpWrite[0] = val
4055
4056        variable err
4057        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4058        if(err)
4059                Print "HDF write err = ",err
4060        endif
4061        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4062//      err = V_KillNamedDataFolder(fname)
4063//      if(err)
4064//              Print "DataFolder kill err = ",err
4065//      endif
4066        return(err)
4067End
4068
4069// integer value
4070Function V_writeDet_pixel_num_y(fname,detStr,val)
4071        String fname,detStr
4072        Variable val
4073
4074//      String path = "entry:instrument:detector_"+detStr+":pixel_num_y"
4075       
4076        Make/O/I/N=1 wTmpWrite
4077//      Make/O/R/N=1 wTmpWrite
4078        String groupName = "/entry/instrument/detector_"+detStr
4079        String varName = "pixel_num_y"
4080        wTmpWrite[0] = val
4081
4082        variable err
4083        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4084        if(err)
4085                Print "HDF write err = ",err
4086        endif
4087        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4088//      err = V_KillNamedDataFolder(fname)
4089//      if(err)
4090//              Print "DataFolder kill err = ",err
4091//      endif
4092        return(err)
4093End
4094
4095//// only defined for the "B" detector, and only to satisfy NXsas
4096//Function V_writeDet_azimuthalAngle(fname,detStr,val)
4097//      String fname,detStr
4098//      Variable val
4099//
4100//      if(cmpstr(detStr,"B") == 0)
4101////            String path = "entry:instrument:detector_"+detStr+":azimuthal_angle"
4102//     
4103//              Make/O/D/N=1 wTmpWrite
4104//      //      Make/O/R/N=1 wTmpWrite
4105//              String groupName = "/entry/instrument/detector_"+detStr
4106//              String varName = "azimuthal_angle"
4107//              wTmpWrite[0] = val
4108//
4109//              variable err
4110//              err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4111//              if(err)
4112//                      Print "HDF write err = ",err
4113//              endif
4114//              // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4115////            err = V_KillNamedDataFolder(fname)
4116////            if(err)
4117////                    Print "DataFolder kill err = ",err
4118////            endif
4119//              return(err)
4120//      else
4121//              return(0)
4122//      endif
4123//End
4124
4125Function V_writeDet_beam_center_x(fname,detStr,val)
4126        String fname,detStr
4127        Variable val
4128
4129//      String path = "entry:instrument:detector_"+detStr+":beam_center_x"
4130       
4131        Make/O/D/N=1 wTmpWrite
4132//      Make/O/R/N=1 wTmpWrite
4133        String groupName = "/entry/instrument/detector_"+detStr
4134        String varName = "beam_center_x"
4135        wTmpWrite[0] = val
4136
4137        variable err
4138        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4139        if(err)
4140                Print "HDF write err = ",err
4141        endif
4142        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4143//      err = V_KillNamedDataFolder(fname)
4144//      if(err)
4145//              Print "DataFolder kill err = ",err
4146//      endif
4147        return(err)
4148End
4149
4150// fname is a local WORK folder
4151Function V_putDet_beam_center_x(fname,detStr,val)
4152        String fname,detStr
4153        Variable val
4154
4155//root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FB:beam_center_x
4156        String path = "root:Packages:NIST:VSANS:"+fname+":"
4157        path += "entry:instrument:detector_"+detStr+":beam_center_x"
4158       
4159        Wave/Z w = $path
4160        if(waveExists(w) == 0)
4161                return(1)
4162        else
4163        w[0] = val
4164                return(0)
4165        endif
4166
4167End
4168
4169Function V_writeDet_beam_center_y(fname,detStr,val)
4170        String fname,detStr
4171        Variable val
4172
4173//      String path = "entry:instrument:detector_"+detStr+":beam_center_y"
4174       
4175        Make/O/D/N=1 wTmpWrite
4176//      Make/O/R/N=1 wTmpWrite
4177        String groupName = "/entry/instrument/detector_"+detStr
4178        String varName = "beam_center_y"
4179        wTmpWrite[0] = val
4180
4181        variable err
4182        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4183        if(err)
4184                Print "HDF write err = ",err
4185        endif
4186        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4187//      err = V_KillNamedDataFolder(fname)
4188//      if(err)
4189//              Print "DataFolder kill err = ",err
4190//      endif
4191        return(err)
4192End
4193
4194
4195// fname is a local WORK folder
4196Function V_putDet_beam_center_y(fname,detStr,val)
4197        String fname,detStr
4198        Variable val
4199
4200//root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FB:beam_center_y
4201        String path = "root:Packages:NIST:VSANS:"+fname+":"
4202        path += "entry:instrument:detector_"+detStr+":beam_center_y"
4203       
4204        Wave/Z w = $path
4205        if(waveExists(w) == 0)
4206                return(1)
4207        else
4208        w[0] = val
4209                return(0)
4210        endif
4211
4212End
4213
4214
4215// TODO -- write this function to return a WAVE with the data
4216// either as a wave reference, or as an input parameter
4217Function V_writeDetectorData(fname,detStr,inW)
4218        String fname,detStr
4219        Wave inW
4220
4221//      String path = "entry:instrument:detector_"+detStr+":data"
4222       
4223        Duplicate/O inW wTmpWrite       
4224// then use redimension as needed to cast the wave to write to the specified type
4225// see WaveType for the proper codes
4226//      Redimension/T=() wTmpWrite
4227// -- May also need to check the dimension(s) before writing (don't trust the input)
4228        String groupName = "/entry/instrument/detector_"+detStr
4229        String varName = "data"
4230
4231        variable err
4232        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4233        if(err)
4234                Print "HDF write err = ",err
4235        endif
4236        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4237//      err = V_KillNamedDataFolder(fname)
4238//      if(err)
4239//              Print "DataFolder kill err = ",err
4240//      endif
4241        return(err)
4242End
4243
4244
4245
4246/////////////////////////
4247
4248
4249// TODO -- write this function to return a WAVE with the data
4250// either as a wave reference, or as an input parameter
4251// ALSO -- the "B" deadtime will be a single value (probably)
4252//  but the tube banks will be 1D arrays of values, one per tube
4253Function V_writeDetector_deadtime(fname,detStr,inW)
4254        String fname,detStr
4255        Wave inW
4256
4257//      String path = "entry:instrument:detector_"+detStr+":dead_time"
4258        if(cmpstr(detStr,"B") == 0)
4259                DoAlert 0,"Bad call to V_writeDetector_deadtime"
4260                return(0)
4261        else
4262
4263                Duplicate/O inW wTmpWrite       
4264        // then use redimension as needed to cast the wave to write to the specified type
4265        // see WaveType for the proper codes
4266        //      Redimension/T=() wTmpWrite
4267        // -- May also need to check the dimension(s) before writing (don't trust the input)
4268                String groupName = "/entry/instrument/detector_"+detStr
4269                String varName = "dead_time"
4270       
4271                variable err
4272                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4273                if(err)
4274                        Print "HDF write err = ",err
4275                endif
4276                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4277        //      err = V_KillNamedDataFolder(fname)
4278        //      if(err)
4279        //              Print "DataFolder kill err = ",err
4280        //      endif
4281                return(err)
4282        endif
4283End
4284
4285// dead time, a single value, only for detB
4286Function V_writeDetector_deadtime_B(fname,detStr,val)
4287        String fname,detStr
4288        variable val
4289
4290//      String path = "entry:instrument:detector_"+detStr+":dead_time"
4291        if(cmpstr(detStr,"B") == 0)
4292       
4293                Make/O/D/N=1 wTmpWrite
4294        //      Make/O/R/N=1 wTmpWrite
4295                String groupName = "/entry/instrument/detector_"+detStr
4296                String varName = "dead_time"
4297                wTmpWrite[0] = val
4298       
4299                variable err
4300                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4301                if(err)
4302                        Print "HDF write err = ",err
4303                endif
4304                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4305        //      err = V_KillNamedDataFolder(fname)
4306        //      if(err)
4307        //              Print "DataFolder kill err = ",err
4308        //      endif
4309       
4310                return(err)     
4311        else
4312                DoAlert 0,"Bad call to V_writeDetector_deadtime_B"
4313                return(0)
4314        endif
4315End
4316
4317Function V_writeDetDescription(fname,detStr,str)
4318        String fname,detStr,str
4319
4320//      String path = "entry:instrument:detector_"+detStr+":description"
4321
4322        Make/O/T/N=1 tmpTW
4323        String groupName = "/entry/instrument/detector_"+detStr //     
4324        String varName = "description"
4325        tmpTW[0] = str //
4326
4327        variable err
4328        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4329        if(err)
4330                Print "HDF write err = ",err
4331        endif
4332       
4333        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4334//      err = V_KillNamedDataFolder(fname)
4335//      if(err)
4336//              Print "DataFolder kill err = ",err
4337//      endif
4338               
4339        return(err)
4340End
4341
4342Function V_writeDet_distance(fname,detStr,val)
4343        String fname,detStr
4344        variable val
4345
4346//      String path = "entry:instrument:detector_"+detStr+":distance"
4347       
4348        Make/O/D/N=1 wTmpWrite
4349//      Make/O/R/N=1 wTmpWrite
4350        String groupName = "/entry/instrument/detector_"+detStr
4351        String varName = "distance"
4352        wTmpWrite[0] = val
4353
4354        variable err
4355        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4356        if(err)
4357                Print "HDF write err = ",err
4358        endif
4359        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4360//      err = V_KillNamedDataFolder(fname)
4361//      if(err)
4362//              Print "DataFolder kill err = ",err
4363//      endif
4364        return(err)
4365End
4366
4367//// only defined for the "B" detector, and only to satisfy NXsas
4368//Function V_writeDet_equatorial_angle(fname,detStr,val)
4369//      String fname,detStr
4370//      variable val
4371//
4372//      if(cmpstr(detStr,"B") == 0)
4373////            String path = "entry:instrument:detector_"+detStr+":equatorial_angle"
4374//     
4375//              Make/O/D/N=1 wTmpWrite
4376//      //      Make/O/R/N=1 wTmpWrite
4377//              String groupName = "/entry/instrument/detector_"+detStr
4378//              String varName = "equatorial_angle"
4379//              wTmpWrite[0] = val
4380//
4381//              variable err
4382//              err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4383//              if(err)
4384//                      Print "HDF write err = ",err
4385//              endif
4386//              // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4387////            err = V_KillNamedDataFolder(fname)
4388////            if(err)
4389////                    Print "DataFolder kill err = ",err
4390////            endif
4391//              return(err)
4392//      else
4393//              return(0)
4394//      endif
4395//End
4396
4397Function V_writeDetEventFileName(fname,detStr,str)
4398        String fname,detStr,str
4399
4400//      String path = "entry:instrument:detector_"+detStr+":event_file_name"
4401
4402        Make/O/T/N=1 tmpTW
4403        String groupName = "/entry/instrument/detector_"+detStr //     
4404        String varName = "event_file_name"
4405        tmpTW[0] = str //
4406
4407        variable err
4408        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4409        if(err)
4410                Print "HDF write err = ",err
4411        endif
4412       
4413        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4414//      err = V_KillNamedDataFolder(fname)
4415//      if(err)
4416//              Print "DataFolder kill err = ",err
4417//      endif
4418               
4419        return(err)
4420End
4421
4422Function V_writeDet_IntegratedCount(fname,detStr,val)
4423        String fname,detStr
4424        Variable val
4425
4426//      String path = "entry:instrument:detector_"+detStr+":integrated_count"
4427       
4428        Make/O/D/N=1 wTmpWrite
4429//      Make/O/R/N=1 wTmpWrite
4430        String groupName = "/entry/instrument/detector_"+detStr
4431        String varName = "integrated_count"
4432        wTmpWrite[0] = val
4433
4434        variable err
4435        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4436        if(err)
4437                Print "HDF write err = ",err
4438        endif
4439        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4440//      err = V_KillNamedDataFolder(fname)
4441//      if(err)
4442//              Print "DataFolder kill err = ",err
4443//      endif
4444        return(err)
4445End
4446
4447// fname is a local WORK folder
4448Function V_putDet_IntegratedCount(fname,detStr,val)
4449        String fname,detStr
4450        Variable val
4451
4452//root:Packages:NIST:VSANS:RAW:entry:instrument:detector_FB:beam_center_x
4453        String path = "root:Packages:NIST:VSANS:"+fname+":"
4454        path += "entry:instrument:detector_"+detStr+":integrated_count"
4455       
4456        Wave/Z w = $path
4457        if(waveExists(w) == 0)
4458                return(1)
4459        else
4460        w[0] = val
4461                return(0)
4462        endif
4463
4464End
4465
4466// this is only written for B and L/R detectors
4467Function V_writeDet_LateralOffset(fname,detStr,val)
4468        String fname,detStr
4469        Variable val
4470
4471//      String path = "entry:instrument:detector_"+detStr+":lateral_offset"
4472
4473        if(cmpstr(detStr,"FT") == 0 || cmpstr(detStr,"FB") == 0)
4474                return(0)
4475        endif
4476        if(cmpstr(detStr,"MT") == 0 || cmpstr(detStr,"MB") == 0)
4477                return(0)
4478        endif   
4479               
4480        Make/O/D/N=1 wTmpWrite
4481//      Make/O/R/N=1 wTmpWrite
4482        String groupName = "/entry/instrument/detector_"+detStr
4483        String varName = "lateral_offset"
4484        wTmpWrite[0] = val
4485
4486        variable err
4487        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4488        if(err)
4489                Print "HDF write err = ",err
4490        endif
4491        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4492//      err = V_KillNamedDataFolder(fname)
4493//      if(err)
4494//              Print "DataFolder kill err = ",err
4495//      endif
4496        return(err)
4497End
4498
4499
4500// this is only written for T/B detectors
4501Function V_writeDet_VerticalOffset(fname,detStr,val)
4502        String fname,detStr
4503        Variable val
4504
4505//      String path = "entry:instrument:detector_"+detStr+":vertical_offset"
4506
4507        if(cmpstr(detStr,"B") == 0)
4508                return(0)
4509        endif
4510        if(cmpstr(detStr,"FR") == 0 || cmpstr(detStr,"FL") == 0)
4511                return(0)
4512        endif
4513        if(cmpstr(detStr,"MR") == 0 || cmpstr(detStr,"ML") == 0)
4514                return(0)
4515        endif   
4516               
4517        Make/O/D/N=1 wTmpWrite
4518//      Make/O/R/N=1 wTmpWrite
4519        String groupName = "/entry/instrument/detector_"+detStr
4520        String varName = "vertical_offset"
4521        wTmpWrite[0] = val
4522
4523        variable err
4524        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4525        if(err)
4526                Print "HDF write err = ",err
4527        endif
4528        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4529//      err = V_KillNamedDataFolder(fname)
4530//      if(err)
4531//              Print "DataFolder kill err = ",err
4532//      endif
4533        return(err)
4534End
4535
4536
4537// TODO - be sure that this is defined correctly
4538// -- it needs to exist in the data file, and only for TB detector panels
4539Function V_writeDet_TBSetback(fname,detStr,val)
4540        String fname,detStr
4541        Variable val
4542
4543//      String path = "entry:instrument:detector_"+detStr+":setback"
4544       
4545        if(cmpstr(detStr,"B") == 0)
4546                return(0)
4547        endif
4548        if(cmpstr(detStr,"FR") == 0 || cmpstr(detStr,"FL") == 0)
4549                return(0)
4550        endif
4551        if(cmpstr(detStr,"MR") == 0 || cmpstr(detStr,"ML") == 0)
4552                return(0)
4553        endif   
4554       
4555        Make/O/D/N=1 wTmpWrite
4556//      Make/O/R/N=1 wTmpWrite
4557        String groupName = "/entry/instrument/detector_"+detStr
4558        String varName = "setback"
4559        wTmpWrite[0] = val
4560
4561        variable err
4562        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4563        if(err)
4564                Print "HDF write err = ",err
4565        endif
4566        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4567//      err = V_KillNamedDataFolder(fname)
4568//      if(err)
4569//              Print "DataFolder kill err = ",err
4570//      endif
4571        return(err)
4572End
4573
4574// gap when panels are "touching"
4575// units are mm
4576// writes panel gap for detector panel specified
4577// does not write anything if "B" is passed (no such field for this detector)
4578//
4579Function V_writeDet_panel_gap(fname,detStr,val)
4580        String fname,detStr
4581        Variable val
4582
4583        if(cmpstr(detStr,"B") == 0)
4584                return(0)
4585        endif
4586       
4587//      String path = "entry:instrument:detector_"+detStr+":panel_gap"
4588
4589        Make/O/D/N=1 wTmpWrite
4590//      Make/O/R/N=1 wTmpWrite
4591        String groupName = "/entry/instrument/detector_"+detStr
4592        String varName = "panel_gap"
4593        wTmpWrite[0] = val
4594
4595        variable err
4596        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4597        if(err)
4598                Print "HDF write err = ",err
4599        endif
4600        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4601//      err = V_KillNamedDataFolder(fname)
4602//      if(err)
4603//              Print "DataFolder kill err = ",err
4604//      endif
4605        return(err)
4606End
4607
4608
4609
4610//// only defined for the "B" detector, and only to satisfy NXsas
4611//Function V_writeDet_polar_angle(fname,detStr,val)
4612//      String fname,detStr
4613//      Variable val
4614//
4615//      if(cmpstr(detStr,"B") == 0)
4616////            String path = "entry:instrument:detector_"+detStr+":polar_angle"
4617//     
4618//              Make/O/D/N=1 wTmpWrite
4619//      //      Make/O/R/N=1 wTmpWrite
4620//              String groupName = "/entry/instrument/detector_"+detStr
4621//              String varName = "polar_angle"
4622//              wTmpWrite[0] = val
4623//
4624//              variable err
4625//              err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4626//              if(err)
4627//                      Print "HDF write err = ",err
4628//              endif
4629//              // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4630////            err = V_KillNamedDataFolder(fname)
4631////            if(err)
4632////                    Print "DataFolder kill err = ",err
4633////            endif
4634//              return(err)
4635//      else
4636//              return(0)
4637//      endif
4638//End
4639
4640//// only defined for the "B" detector, and only to satisfy NXsas
4641//Function V_writeDet_rotational_angle(fname,detStr,val)
4642//      String fname,detStr
4643//      Variable val
4644//
4645//      if(cmpstr(detStr,"B") == 0)
4646////            String path = "entry:instrument:detector_"+detStr+":rotational_angle"
4647//     
4648//              Make/O/D/N=1 wTmpWrite
4649//      //      Make/O/R/N=1 wTmpWrite
4650//              String groupName = "/entry/instrument/detector_"+detStr
4651//              String varName = "rotational_angle"
4652//              wTmpWrite[0] = val
4653//
4654//              variable err
4655//              err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4656//              if(err)
4657//                      Print "HDF write err = ",err
4658//              endif
4659//              // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4660////            err = V_KillNamedDataFolder(fname)
4661////            if(err)
4662////                    Print "DataFolder kill err = ",err
4663////            endif
4664//              return(err)
4665//      else
4666//              return(0)
4667//      endif
4668//End
4669
4670Function V_writeDetSettings(fname,detStr,str)
4671        String fname,detStr,str
4672
4673//      String path = "entry:instrument:detector_"+detStr+":settings"
4674
4675        Make/O/T/N=1 tmpTW
4676        String groupName = "/entry/instrument/detector_"+detStr //     
4677        String varName = "settings"
4678        tmpTW[0] = str //
4679
4680        variable err
4681        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4682        if(err)
4683                Print "HDF write err = ",err
4684        endif
4685       
4686        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4687//      err = V_KillNamedDataFolder(fname)
4688//      if(err)
4689//              Print "DataFolder kill err = ",err
4690//      endif
4691               
4692        return(err)
4693End
4694
4695//// really has no meaning at all
4696//Function V_writeDet_size(fname,detStr,val)
4697//      String fname,detStr
4698//      Variable val
4699//
4700////    String path = "entry:instrument:detector_"+detStr+":size"
4701//     
4702//      Make/O/D/N=1 wTmpWrite
4703////    Make/O/R/N=1 wTmpWrite
4704//      String groupName = "/entry/instrument/detector_"+detStr
4705//      String varName = "size"
4706//      wTmpWrite[0] = val
4707//
4708//      variable err
4709//      err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4710//      if(err)
4711//              Print "HDF write err = ",err
4712//      endif
4713//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4714////    err = V_KillNamedDataFolder(fname)
4715////    if(err)
4716////            Print "DataFolder kill err = ",err
4717////    endif
4718//      return(err)
4719//End
4720
4721//Function V_writeDetType(fname,detStr,str)
4722//      String fname,detStr,str
4723//
4724////    String path = "entry:instrument:detector_"+detStr+":type"
4725//
4726//      Make/O/T/N=1 tmpTW
4727//      String groupName = "/entry/instrument/detector_"+detStr //     
4728//      String varName = "type"
4729//      tmpTW[0] = str //
4730//
4731//      variable err
4732//      err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4733//      if(err)
4734//              Print "HDF write err = ",err
4735//      endif
4736//     
4737//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4738////    err = V_KillNamedDataFolder(fname)
4739////    if(err)
4740////            Print "DataFolder kill err = ",err
4741////    endif
4742//             
4743//      return(err)
4744//End
4745
4746Function V_writeDet_x_pixel_size(fname,detStr,val)
4747        String fname,detStr
4748        Variable val
4749
4750//      String path = "entry:instrument:detector_"+detStr+":x_pixel_size"
4751       
4752        Make/O/D/N=1 wTmpWrite
4753//      Make/O/R/N=1 wTmpWrite
4754        String groupName = "/entry/instrument/detector_"+detStr
4755        String varName = "x_pixel_size"
4756        wTmpWrite[0] = val
4757
4758        variable err
4759        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4760        if(err)
4761                Print "HDF write err = ",err
4762        endif
4763        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4764//      err = V_KillNamedDataFolder(fname)
4765//      if(err)
4766//              Print "DataFolder kill err = ",err
4767//      endif
4768        return(err)
4769End
4770
4771Function V_writeDet_y_pixel_size(fname,detStr,val)
4772        String fname,detStr
4773        Variable val
4774
4775//      String path = "entry:instrument:detector_"+detStr+":y_pixel_size"
4776       
4777        Make/O/D/N=1 wTmpWrite
4778//      Make/O/R/N=1 wTmpWrite
4779        String groupName = "/entry/instrument/detector_"+detStr
4780        String varName = "y_pixel_size"
4781        wTmpWrite[0] = val
4782
4783        variable err
4784        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4785        if(err)
4786                Print "HDF write err = ",err
4787        endif
4788        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4789//      err = V_KillNamedDataFolder(fname)
4790//      if(err)
4791//              Print "DataFolder kill err = ",err
4792//      endif
4793        return(err)
4794End
4795
4796/////////                       detector_FB (data folder) + ALL other PANEL DETECTORS
4797
4798// integer value
4799Function V_writeDet_numberOfTubes(fname,detStr,val)
4800        String fname,detStr
4801        Variable val
4802
4803//      String path = "entry:instrument:detector_"+detStr+":number_of_tubes"
4804        if(cmpstr(detStr,"B") == 0)
4805                return(0)
4806        else
4807       
4808                Make/O/I/N=1 wTmpWrite
4809        //      Make/O/R/N=1 wTmpWrite
4810                String groupName = "/entry/instrument/detector_"+detStr
4811                String varName = "number_of_tubes"
4812                wTmpWrite[0] = val
4813
4814                variable err
4815                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4816                if(err)
4817                        Print "HDF write err = ",err
4818                endif
4819                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4820//              err = V_KillNamedDataFolder(fname)
4821//              if(err)
4822//                      Print "DataFolder kill err = ",err
4823//              endif
4824                return(err)
4825        endif
4826End
4827
4828// deleted from definition
4829//Function V_writeDetPanelSeparation(fname,detStr,val)
4830//      String fname,detStr
4831//      Variable val
4832//
4833////    String path = "entry:instrument:detector_"+detStr+":separation"
4834//      if(cmpstr(detStr,"B") == 0)
4835//              return(0)
4836//      else
4837//     
4838//              Make/O/D/N=1 wTmpWrite
4839//      //      Make/O/R/N=1 wTmpWrite
4840//              String groupName = "/entry/instrument/detector_"+detStr
4841//              String varName = "separation"
4842//              wTmpWrite[0] = val
4843//
4844//              variable err
4845//              err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4846//              if(err)
4847//                      Print "HDF write err = ",err
4848//              endif
4849//              // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4850////            err = V_KillNamedDataFolder(fname)
4851////            if(err)
4852////                    Print "DataFolder kill err = ",err
4853////            endif
4854//              return(err)
4855//      endif
4856//End
4857
4858// TODO -- write this function to return a WAVE with the data
4859// either as a wave reference, or as an input parameter
4860Function V_writeDetTube_spatialCalib(fname,detStr,inW)
4861        String fname,detStr
4862        Wave inW
4863
4864//      String path = "entry:instrument:detector_"+detStr+":spatial_calibration"
4865
4866        if(cmpstr(detStr,"B") == 0)
4867                return(0)
4868        else
4869                Duplicate/O inW wTmpWrite       
4870        // then use redimension as needed to cast the wave to write to the specified type
4871        // see WaveType for the proper codes
4872        //      Redimension/T=() wTmpWrite
4873        // -- May also need to check the dimension(s) before writing (don't trust the input)
4874                String groupName = "/entry/instrument/detector_"+detStr
4875                String varName = "spatial_calibration"
4876
4877                variable err
4878                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4879                if(err)
4880                        Print "HDF write err = ",err
4881                endif
4882                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4883//              err = V_KillNamedDataFolder(fname)
4884//              if(err)
4885//                      Print "DataFolder kill err = ",err
4886//              endif
4887                return(err)
4888        endif
4889End
4890
4891//// TODO -- be clear on how this is defined.
4892//Function V_writeDet_tubeIndex(fname,detStr,val)
4893//      String fname,detStr
4894//      Variable val
4895//
4896////    String path = "entry:instrument:detector_"+detStr+":tube_index"
4897//      if(cmpstr(detStr,"B") == 0)
4898//              return(0)
4899//      else
4900//     
4901//              Make/O/D/N=1 wTmpWrite
4902//      //      Make/O/R/N=1 wTmpWrite
4903//              String groupName = "/entry/instrument/detector_"+detStr
4904//              String varName = "tube_index"
4905//              wTmpWrite[0] = val
4906//
4907//              variable err
4908//              err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4909//              if(err)
4910//                      Print "HDF write err = ",err
4911//              endif
4912//              // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4913////            err = V_KillNamedDataFolder(fname)
4914////            if(err)
4915////                    Print "DataFolder kill err = ",err
4916////            endif
4917//              return(err)
4918//      endif
4919//End
4920
4921Function V_writeDet_tubeOrientation(fname,detStr,str)
4922        String fname,detStr,str
4923
4924//      String path = "entry:instrument:detector_"+detStr+":tube_orientation"
4925
4926        if(cmpstr(detStr,"B") == 0)
4927                return(0)
4928        else
4929                Make/O/T/N=1 tmpTW
4930                String groupName = "/entry/instrument/detector_"+detStr //     
4931                String varName = "tube_orientation"
4932                tmpTW[0] = str //
4933
4934                variable err
4935                err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4936                if(err)
4937                        Print "HDF write err = ",err
4938                endif
4939       
4940                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4941//              err = V_KillNamedDataFolder(fname)
4942//              if(err)
4943//                      Print "DataFolder kill err = ",err
4944//              endif
4945               
4946                return(err)
4947
4948        endif
4949End
4950
4951// TODO -- be clear on how this is defined. Units?
4952Function V_writeDet_tubeWidth(fname,detStr,val)
4953        String fname,detStr
4954        Variable val
4955
4956//      String path = "entry:instrument:detector_"+detStr+":tube_width"
4957        if(cmpstr(detStr,"B") == 0)
4958                return(0)
4959        else
4960       
4961                Make/O/D/N=1 wTmpWrite
4962        //      Make/O/R/N=1 wTmpWrite
4963                String groupName = "/entry/instrument/detector_"+detStr
4964                String varName = "tube_width"
4965                wTmpWrite[0] = val
4966
4967                variable err
4968                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4969                if(err)
4970                        Print "HDF write err = ",err
4971                endif
4972                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4973//              err = V_KillNamedDataFolder(fname)
4974//              if(err)
4975//                      Print "DataFolder kill err = ",err
4976//              endif
4977                return(err)
4978        endif
4979End
4980
4981//////////////////////
4982
4983// INSTRUMENT/LENSES    /APERTURES
4984//  lenses (data folder)
4985
4986Function V_writeLensCurvature(fname,val)
4987        String fname
4988        Variable val
4989
4990//      String path = "entry:instrument:lenses:curvature"
4991       
4992        Make/O/D/N=1 wTmpWrite
4993//      Make/O/R/N=1 wTmpWrite
4994        String groupName = "/entry/instrument/lenses"
4995        String varName = "curvature"
4996        wTmpWrite[0] = val
4997
4998        variable err
4999        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5000        if(err)
5001                Print "HDF write err = ",err
5002        endif
5003        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5004//      err = V_KillNamedDataFolder(fname)
5005//      if(err)
5006//              Print "DataFolder kill err = ",err
5007//      endif
5008        return(err)
5009End
5010
5011Function V_writeLensesFocusType(fname,str)
5012        String fname,str
5013
5014//      String path = "entry:instrument:lenses:focus_type"
5015
5016        Make/O/T/N=1 tmpTW
5017        String groupName = "/entry/instrument/lenses"
5018        String varName = "focus_type"
5019        tmpTW[0] = str //
5020
5021        variable err
5022        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5023        if(err)
5024                Print "HDF write err = ",err
5025        endif
5026       
5027        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5028//      err = V_KillNamedDataFolder(fname)
5029//      if(err)
5030//              Print "DataFolder kill err = ",err
5031//      endif
5032               
5033        return(err)
5034End
5035
5036Function V_writeLensDistance(fname,val)
5037        String fname
5038        Variable val
5039
5040//      String path = "entry:instrument:lenses:lens_distance"
5041       
5042        Make/O/D/N=1 wTmpWrite
5043//      Make/O/R/N=1 wTmpWrite
5044        String groupName = "/entry/instrument/lenses"
5045        String varName = "lens_distance"
5046        wTmpWrite[0] = val
5047
5048        variable err
5049        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5050        if(err)
5051                Print "HDF write err = ",err
5052        endif
5053        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5054//      err = V_KillNamedDataFolder(fname)
5055//      if(err)
5056//              Print "DataFolder kill err = ",err
5057//      endif
5058        return(err)
5059End
5060
5061Function V_writeLensGeometry(fname,str)
5062        String fname,str
5063
5064//      String path = "entry:instrument:lenses:lens_geometry"
5065
5066        Make/O/T/N=1 tmpTW
5067        String groupName = "/entry/instrument/lenses"
5068        String varName = "lens_geometry"
5069        tmpTW[0] = str //
5070
5071        variable err
5072        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5073        if(err)
5074                Print "HDF write err = ",err
5075        endif
5076       
5077        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5078//      err = V_KillNamedDataFolder(fname)
5079//      if(err)
5080//              Print "DataFolder kill err = ",err
5081//      endif
5082               
5083        return(err)
5084End
5085
5086Function V_writeLensMaterial(fname,str)
5087        String fname,str
5088
5089//      String path = "entry:instrument:lenses:lens_material"
5090
5091        Make/O/T/N=1 tmpTW
5092        String groupName = "/entry/instrument/lenses"
5093        String varName = "lens_material"
5094        tmpTW[0] = str //
5095
5096        variable err
5097        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5098        if(err)
5099                Print "HDF write err = ",err
5100        endif
5101       
5102        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5103//      err = V_KillNamedDataFolder(fname)
5104//      if(err)
5105//              Print "DataFolder kill err = ",err
5106//      endif
5107               
5108        return(err)
5109End
5110
5111// integer value
5112Function V_writeNumber_of_Lenses(fname,val)
5113        String fname
5114        Variable val
5115
5116//      String path = "entry:instrument:lenses:number_of_lenses"
5117       
5118        Make/O/I/N=1 wTmpWrite
5119//      Make/O/R/N=1 wTmpWrite
5120        String groupName = "/entry/instrument/lenses"
5121        String varName = "number_of_lenses"
5122        wTmpWrite[0] = val
5123
5124        variable err
5125        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5126        if(err)
5127                Print "HDF write err = ",err
5128        endif
5129        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5130//      err = V_KillNamedDataFolder(fname)
5131//      if(err)
5132//              Print "DataFolder kill err = ",err
5133//      endif
5134        return(err)
5135End
5136
5137// integer value
5138Function V_writeNumber_of_prisms(fname,val)
5139        String fname
5140        Variable val
5141
5142//      String path = "entry:instrument:lenses:number_of_prisms"
5143       
5144        Make/O/I/N=1 wTmpWrite
5145//      Make/O/R/N=1 wTmpWrite
5146        String groupName = "/entry/instrument/lenses"
5147        String varName = "number_of_prisms"
5148        wTmpWrite[0] = val
5149
5150        variable err
5151        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5152        if(err)
5153                Print "HDF write err = ",err
5154        endif
5155        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5156//      err = V_KillNamedDataFolder(fname)
5157//      if(err)
5158//              Print "DataFolder kill err = ",err
5159//      endif
5160        return(err)
5161End
5162
5163Function V_writePrism_distance(fname,val)
5164        String fname
5165        Variable val
5166
5167//      String path = "entry:instrument:lenses:prism_distance"
5168       
5169        Make/O/D/N=1 wTmpWrite
5170//      Make/O/R/N=1 wTmpWrite
5171        String groupName = "/entry/instrument/lenses"
5172        String varName = "prism_distance"
5173        wTmpWrite[0] = val
5174
5175        variable err
5176        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5177        if(err)
5178                Print "HDF write err = ",err
5179        endif
5180        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5181//      err = V_KillNamedDataFolder(fname)
5182//      if(err)
5183//              Print "DataFolder kill err = ",err
5184//      endif
5185        return(err)
5186End
5187
5188Function V_writePrismMaterial(fname,str)
5189        String fname,str
5190
5191//      String path = "entry:instrument:lenses:prism_material"
5192
5193        Make/O/T/N=1 tmpTW
5194        String groupName = "/entry/instrument/lenses"
5195        String varName = "prism_material"
5196        tmpTW[0] = str //
5197
5198        variable err
5199        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5200        if(err)
5201                Print "HDF write err = ",err
5202        endif
5203       
5204        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5205//      err = V_KillNamedDataFolder(fname)
5206//      if(err)
5207//              Print "DataFolder kill err = ",err
5208//      endif
5209               
5210        return(err)
5211End
5212
5213// status of lens/prism = lens | prism | both | out
5214Function V_writeLensPrismStatus(fname,str)
5215        String fname,str
5216
5217//      String path = "entry:instrument:lenses:status"
5218
5219        Make/O/T/N=1 tmpTW
5220        String groupName = "/entry/instrument/lenses"
5221        String varName = "status"
5222        tmpTW[0] = str //
5223
5224        variable err
5225        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5226        if(err)
5227                Print "HDF write err = ",err
5228        endif
5229       
5230        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5231//      err = V_KillNamedDataFolder(fname)
5232//      if(err)
5233//              Print "DataFolder kill err = ",err
5234//      endif
5235               
5236        return(err)
5237End
5238       
5239
5240///////  sample_aperture (1) (data folder)
5241// this is the INTERNAL sample aperture
5242Function V_writeSampleAp_Description(fname,str)
5243        String fname,str
5244
5245//      String path = "entry:instrument:sample_aperture:description"
5246
5247        Make/O/T/N=1 tmpTW
5248        String groupName = "/entry/instrument/sample_aperture"
5249        String varName = "description"
5250        tmpTW[0] = str //
5251
5252        variable err
5253        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5254        if(err)
5255                Print "HDF write err = ",err
5256        endif
5257       
5258        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5259//      err = V_KillNamedDataFolder(fname)
5260//      if(err)
5261//              Print "DataFolder kill err = ",err
5262//      endif
5263               
5264        return(err)
5265End
5266
5267Function V_writeSampleAp_distance(fname,val)
5268        String fname
5269        Variable val
5270
5271//      String path = "entry:instrument:sample_aperture:distance"
5272       
5273        Make/O/D/N=1 wTmpWrite
5274//      Make/O/R/N=1 wTmpWrite
5275        String groupName = "/entry/instrument/sample_aperture"
5276        String varName = "distance"
5277        wTmpWrite[0] = val
5278
5279        variable err
5280        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5281        if(err)
5282                Print "HDF write err = ",err
5283        endif
5284        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5285//      err = V_KillNamedDataFolder(fname)
5286//      if(err)
5287//              Print "DataFolder kill err = ",err
5288//      endif
5289        return(err)
5290End
5291
5292//      sample_apertuer/shape (data folder)
5293Function V_writeSampleAp_height(fname,val)
5294        String fname
5295        Variable val
5296
5297//      String path = "entry:instrument:sample_aperture:distance"
5298       
5299        Make/O/D/N=1 wTmpWrite
5300//      Make/O/R/N=1 wTmpWrite
5301        String groupName = "/entry/instrument/sample_aperture/shape"
5302        String varName = "height"
5303        wTmpWrite[0] = val
5304
5305        variable err
5306        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5307        if(err)
5308                Print "HDF write err = ",err
5309        endif
5310        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5311//      err = V_KillNamedDataFolder(fname)
5312//      if(err)
5313//              Print "DataFolder kill err = ",err
5314//      endif
5315        return(err)
5316End
5317
5318Function V_writeSampleAp_shape(fname,str)
5319        String fname,str
5320
5321//      String path = "entry:instrument:sample_aperture:shape:shape"
5322
5323        Make/O/T/N=1 tmpTW
5324        String groupName = "/entry/instrument/sample_aperture/shape"
5325        String varName = "shape"
5326        tmpTW[0] = str //
5327
5328        variable err
5329        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5330        if(err)
5331                Print "HDF write err = ",err
5332        endif
5333       
5334        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5335//      err = V_KillNamedDataFolder(fname)
5336//      if(err)
5337//              Print "DataFolder kill err = ",err
5338//      endif
5339               
5340        return(err)
5341End
5342
5343Function V_writeSampleAp_size(fname,str)
5344        String fname,str
5345
5346//      String path = "entry:instrument:sample_aperture:shape:shape"
5347
5348        Make/O/T/N=1 tmpTW
5349        String groupName = "/entry/instrument/sample_aperture/shape"
5350        String varName = "size"
5351        tmpTW[0] = str //
5352
5353        variable err
5354        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5355        if(err)
5356                Print "HDF write err = ",err
5357        endif
5358       
5359        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5360//      err = V_KillNamedDataFolder(fname)
5361//      if(err)
5362//              Print "DataFolder kill err = ",err
5363//      endif
5364               
5365        return(err)
5366End
5367
5368Function V_writeSampleAp_width(fname,val)
5369        String fname
5370        Variable val
5371
5372//      String path = "entry:instrument:sample_aperture:distance"
5373       
5374        Make/O/D/N=1 wTmpWrite
5375//      Make/O/R/N=1 wTmpWrite
5376        String groupName = "/entry/instrument/sample_aperture/shape"
5377        String varName = "width"
5378        wTmpWrite[0] = val
5379
5380        variable err
5381        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5382        if(err)
5383                Print "HDF write err = ",err
5384        endif
5385        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5386//      err = V_KillNamedDataFolder(fname)
5387//      if(err)
5388//              Print "DataFolder kill err = ",err
5389//      endif
5390        return(err)
5391End
5392
5393///////  sample_aperture_2 (data folder)
5394// sample aperture (2) is the external aperture, which may or may not be present
5395
5396Function V_writeSampleAp2_Description(fname,str)
5397        String fname,str
5398
5399//      String path = "entry:instrument:sample_aperture_2:description"
5400
5401        Make/O/T/N=1 tmpTW
5402        String groupName = "/entry/instrument/sample_aperture_2"
5403        String varName = "description"
5404        tmpTW[0] = str //
5405
5406        variable err
5407        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5408        if(err)
5409                Print "HDF write err = ",err
5410        endif
5411       
5412        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5413//      err = V_KillNamedDataFolder(fname)
5414//      if(err)
5415//              Print "DataFolder kill err = ",err
5416//      endif
5417               
5418        return(err)
5419End
5420
5421Function V_writeSampleAp2_distance(fname,val)
5422        String fname
5423        Variable val
5424
5425//      String path = "entry:instrument:sample_aperture_2:distance"
5426       
5427        Make/O/D/N=1 wTmpWrite
5428//      Make/O/R/N=1 wTmpWrite
5429        String groupName = "/entry/instrument/sample_aperture_2"
5430        String varName = "distance"
5431        wTmpWrite[0] = val
5432
5433        variable err
5434        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5435        if(err)
5436                Print "HDF write err = ",err
5437        endif
5438        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5439//      err = V_KillNamedDataFolder(fname)
5440//      if(err)
5441//              Print "DataFolder kill err = ",err
5442//      endif
5443        return(err)
5444End
5445
5446
5447//      shape (data folder)
5448Function V_writeSampleAp2_height(fname,val)
5449        String fname
5450        Variable val
5451
5452//      String path = "entry:instrument:sample_aperture:distance"
5453       
5454        Make/O/D/N=1 wTmpWrite
5455//      Make/O/R/N=1 wTmpWrite
5456        String groupName = "/entry/instrument/sample_aperture_2/shape"
5457        String varName = "height"
5458        wTmpWrite[0] = val
5459
5460        variable err
5461        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5462        if(err)
5463                Print "HDF write err = ",err
5464        endif
5465        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5466//      err = V_KillNamedDataFolder(fname)
5467//      if(err)
5468//              Print "DataFolder kill err = ",err
5469//      endif
5470        return(err)
5471End
5472
5473Function V_writeSampleAp2_shape(fname,str)
5474        String fname,str
5475
5476//      String path = "entry:instrument:sample_aperture_2:shape:shape"
5477
5478        Make/O/T/N=1 tmpTW
5479        String groupName = "/entry/instrument/sample_aperture_2/shape"
5480        String varName = "shape"
5481        tmpTW[0] = str //
5482
5483        variable err
5484        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5485        if(err)
5486                Print "HDF write err = ",err
5487        endif
5488       
5489        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5490//      err = V_KillNamedDataFolder(fname)
5491//      if(err)
5492//              Print "DataFolder kill err = ",err
5493//      endif
5494               
5495        return(err)
5496End
5497
5498Function V_writeSampleAp2_size(fname,val)
5499        String fname
5500        Variable val
5501
5502//      String path = "entry:instrument:sample_aperture:distance"
5503       
5504        Make/O/D/N=1 wTmpWrite
5505//      Make/O/R/N=1 wTmpWrite
5506        String groupName = "/entry/instrument/sample_aperture_2/shape"
5507        String varName = "size"
5508        wTmpWrite[0] = val
5509
5510        variable err
5511        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5512        if(err)
5513                Print "HDF write err = ",err
5514        endif
5515        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5516//      err = V_KillNamedDataFolder(fname)
5517//      if(err)
5518//              Print "DataFolder kill err = ",err
5519//      endif
5520        return(err)
5521End
5522
5523Function V_writeSampleAp2_width(fname,val)
5524        String fname
5525        Variable val
5526
5527//      String path = "entry:instrument:sample_aperture:distance"
5528       
5529        Make/O/D/N=1 wTmpWrite
5530//      Make/O/R/N=1 wTmpWrite
5531        String groupName = "/entry/instrument/sample_aperture_2/shape"
5532        String varName = "width"
5533        wTmpWrite[0] = val
5534
5535        variable err
5536        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5537        if(err)
5538                Print "HDF write err = ",err
5539        endif
5540        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5541//      err = V_KillNamedDataFolder(fname)
5542//      if(err)
5543//              Print "DataFolder kill err = ",err
5544//      endif
5545        return(err)
5546End
5547
5548               
5549//////  sample_table (data folder)
5550// location  = "CHAMBER" or HUBER
5551Function V_writeSampleTableLocation(fname,str)
5552        String fname,str
5553
5554//      String path = "entry:instrument:sample_table:location"
5555
5556        Make/O/T/N=1 tmpTW
5557        String groupName = "/entry/instrument/sample_table"
5558        String varName = "location"
5559        tmpTW[0] = str //
5560
5561        variable err
5562        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5563        if(err)
5564                Print "HDF write err = ",err
5565        endif
5566       
5567        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5568//      err = V_KillNamedDataFolder(fname)
5569//      if(err)
5570//              Print "DataFolder kill err = ",err
5571//      endif
5572               
5573        return(err)
5574End
5575
5576// TODO - verify the meaning
5577//      offset_distance (?? for center of sample table vs. sample position)
5578Function V_writeSampleTableOffset(fname,val)
5579        String fname
5580        Variable val
5581
5582//      String path = "entry:instrument:sample_table:offset_distance"
5583       
5584        Make/O/D/N=1 wTmpWrite
5585//      Make/O/R/N=1 wTmpWrite
5586        String groupName = "/entry/instrument/sample_table"
5587        String varName = "offset_distance"
5588        wTmpWrite[0] = val
5589
5590        variable err
5591        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5592        if(err)
5593                Print "HDF write err = ",err
5594        endif
5595        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5596//      err = V_KillNamedDataFolder(fname)
5597//      if(err)
5598//              Print "DataFolder kill err = ",err
5599//      endif
5600        return(err)
5601End     
5602       
5603//  source (data folder)
5604//name "NCNR"
5605Function V_writeSourceName(fname,str)
5606        String fname,str
5607
5608//      String path = "entry:instrument:source:name"
5609
5610        Make/O/T/N=1 tmpTW
5611        String groupName = "/entry/instrument/source"
5612        String varName = "name"
5613        tmpTW[0] = str //
5614
5615        variable err
5616        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5617        if(err)
5618                Print "HDF write err = ",err
5619        endif
5620       
5621        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5622//      err = V_KillNamedDataFolder(fname)
5623//      if(err)
5624//              Print "DataFolder kill err = ",err
5625//      endif
5626               
5627        return(err)
5628End
5629
5630//      power -- nominal only, not connected to any real number
5631Function V_writeReactorPower(fname,val)
5632        String fname
5633        Variable val
5634
5635//      String path = "entry:instrument:source:power"
5636       
5637        Make/O/D/N=1 wTmpWrite
5638//      Make/O/R/N=1 wTmpWrite
5639        String groupName = "/entry/instrument/source"
5640        String varName = "power"
5641        wTmpWrite[0] = val
5642
5643        variable err
5644        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5645        if(err)
5646                Print "HDF write err = ",err
5647        endif
5648        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5649//      err = V_KillNamedDataFolder(fname)
5650//      if(err)
5651//              Print "DataFolder kill err = ",err
5652//      endif
5653        return(err)
5654End     
5655
5656//probe (wave) "neutron"
5657Function V_writeSourceProbe(fname,str)
5658        String fname,str
5659
5660//      String path = "entry:instrument:source:probe"
5661
5662        Make/O/T/N=1 tmpTW
5663        String groupName = "/entry/instrument/source"
5664        String varName = "probe"
5665        tmpTW[0] = str //
5666
5667        variable err
5668        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5669        if(err)
5670                Print "HDF write err = ",err
5671        endif
5672       
5673        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5674//      err = V_KillNamedDataFolder(fname)
5675//      if(err)
5676//              Print "DataFolder kill err = ",err
5677//      endif
5678               
5679        return(err)
5680End
5681
5682//type (wave) "Reactor Neutron Source"
5683Function V_writeSourceType(fname,str)
5684        String fname,str
5685
5686//      String path = "entry:instrument:source:type"
5687
5688        Make/O/T/N=1 tmpTW
5689        String groupName = "/entry/instrument/source"
5690        String varName = "type"
5691        tmpTW[0] = str //
5692
5693        variable err
5694        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5695        if(err)
5696                Print "HDF write err = ",err
5697        endif
5698       
5699        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5700//      err = V_KillNamedDataFolder(fname)
5701//      if(err)
5702//              Print "DataFolder kill err = ",err
5703//      endif
5704               
5705        return(err)
5706End
5707
5708       
5709///////  source_aperture (data folder)
5710
5711Function V_writeSourceAp_Description(fname,str)
5712        String fname,str
5713
5714//      String path = "entry:instrument:source_aperture:description"
5715
5716        Make/O/T/N=1 tmpTW
5717        String groupName = "/entry/instrument/source_aperture"
5718        String varName = "description"
5719        tmpTW[0] = str //
5720
5721        variable err
5722        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5723        if(err)
5724                Print "HDF write err = ",err
5725        endif
5726       
5727        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5728//      err = V_KillNamedDataFolder(fname)
5729//      if(err)
5730//              Print "DataFolder kill err = ",err
5731//      endif
5732               
5733        return(err)
5734End
5735
5736Function V_writeSourceAp_distance(fname,val)
5737        String fname
5738        Variable val
5739
5740//      String path = "entry:instrument:source_aperture:distance"
5741       
5742        Make/O/D/N=1 wTmpWrite
5743//      Make/O/R/N=1 wTmpWrite
5744        String groupName = "/entry/instrument/source_aperture"
5745        String varName = "distance"
5746        wTmpWrite[0] = val
5747
5748        variable err
5749        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5750        if(err)
5751                Print "HDF write err = ",err
5752        endif
5753        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5754//      err = V_KillNamedDataFolder(fname)
5755//      if(err)
5756//              Print "DataFolder kill err = ",err
5757//      endif
5758        return(err)
5759End
5760
5761
5762//      shape (data folder)
5763Function V_writeSourceAp_height(fname,val)
5764        String fname
5765        Variable val
5766
5767//      String path = "entry:instrument:sample_aperture:distance"
5768       
5769        Make/O/D/N=1 wTmpWrite
5770//      Make/O/R/N=1 wTmpWrite
5771        String groupName = "/entry/instrument/source_aperture/shape"
5772        String varName = "height"
5773        wTmpWrite[0] = val
5774
5775        variable err
5776        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5777        if(err)
5778                Print "HDF write err = ",err
5779        endif
5780        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5781//      err = V_KillNamedDataFolder(fname)
5782//      if(err)
5783//              Print "DataFolder kill err = ",err
5784//      endif
5785        return(err)
5786End
5787
5788Function V_writeSourceAp_shape(fname,str)
5789        String fname,str
5790
5791//      String path = "entry:instrument:source_aperture:shape:shape"
5792
5793        Make/O/T/N=1 tmpTW
5794        String groupName = "/entry/instrument/source_aperture/shape"
5795        String varName = "shape"
5796        tmpTW[0] = str //
5797
5798        variable err
5799        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5800        if(err)
5801                Print "HDF write err = ",err
5802        endif
5803       
5804        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5805//      err = V_KillNamedDataFolder(fname)
5806//      if(err)
5807//              Print "DataFolder kill err = ",err
5808//      endif
5809               
5810        return(err)
5811End
5812
5813Function V_writeSourceAp_size(fname,str)
5814        String fname,str
5815
5816//      String path = "entry:instrument:source_aperture:shape:shape"
5817
5818        Make/O/T/N=1 tmpTW
5819        String groupName = "/entry/instrument/source_aperture/shape"
5820        String varName = "size"
5821        tmpTW[0] = str //
5822
5823        variable err
5824        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5825        if(err)
5826                Print "HDF write err = ",err
5827        endif
5828       
5829        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5830//      err = V_KillNamedDataFolder(fname)
5831//      if(err)
5832//              Print "DataFolder kill err = ",err
5833//      endif
5834               
5835        return(err)
5836End
5837
5838Function V_writeSourceAp_width(fname,val)
5839        String fname
5840        Variable val
5841
5842//      String path = "entry:instrument:sample_aperture:distance"
5843       
5844        Make/O/D/N=1 wTmpWrite
5845//      Make/O/R/N=1 wTmpWrite
5846        String groupName = "/entry/instrument/source_aperture/shape"
5847        String varName = "width"
5848        wTmpWrite[0] = val
5849
5850        variable err
5851        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5852        if(err)
5853                Print "HDF write err = ",err
5854        endif
5855        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5856//      err = V_KillNamedDataFolder(fname)
5857//      if(err)
5858//              Print "DataFolder kill err = ",err
5859//      endif
5860        return(err)
5861End
5862
5863
5864//////// SAMPLE
5865//////// SAMPLE
5866//////// SAMPLE
5867
5868//Sample position in changer
5869Function V_writeSamplePosition(fname,str)
5870        String fname,str
5871
5872//      String path = "entry:sample:changer_position"   
5873
5874        Make/O/T/N=1 tmpTW
5875        String groupName = "/entry/sample"
5876        String varName = "changer_position"
5877        tmpTW[0] = str //
5878
5879        variable err
5880        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5881        if(err)
5882                Print "HDF write err = ",err
5883        endif
5884       
5885        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5886//      err = V_KillNamedDataFolder(fname)
5887//      if(err)
5888//              Print "DataFolder kill err = ",err
5889//      endif
5890               
5891        return(err)
5892End
5893
5894
5895// sample label
5896// TODO: value of num is currently not used
5897Function V_writeSampleDescription(fname,str)
5898        String fname,str
5899
5900//      String path = "entry:sample:description"
5901
5902        Make/O/T/N=1 tmpTW
5903        String groupName = "/entry/sample"
5904        String varName = "description"
5905        tmpTW[0] = str //
5906
5907        variable err
5908        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5909        if(err)
5910                Print "HDF write err = ",err
5911        endif
5912       
5913        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5914//      err = V_KillNamedDataFolder(fname)
5915//      if(err)
5916//              Print "DataFolder kill err = ",err
5917//      endif
5918               
5919        return(err)
5920End
5921
5922// fname is a local WORK folder
5923Function V_putSampleDescription(fname,str)
5924        String fname,str
5925
5926        String path = "root:Packages:NIST:VSANS:"+fname+":"
5927        path += "entry:sample:description"
5928       
5929        Wave/Z/T w = $path
5930        if(waveExists(w) == 0)
5931                return(1)
5932        else
5933        w[0] = str
5934                return(0)
5935        endif
5936
5937End
5938
5939
5940
5941// for a z-stage??
5942Function V_writeSample_elevation(fname,val)
5943        String fname
5944        Variable val
5945       
5946//      String path = "entry:sample:elevation" 
5947       
5948        Make/O/D/N=1 wTmpWrite
5949//      Make/O/R/N=1 wTmpWrite
5950        String groupName = "/entry/sample"
5951        String varName = "elevation"
5952        wTmpWrite[0] = val
5953
5954        variable err
5955        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5956        if(err)
5957                Print "HDF write err = ",err
5958        endif
5959        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5960//      err = V_KillNamedDataFolder(fname)
5961//      if(err)
5962//              Print "DataFolder kill err = ",err
5963//      endif
5964        return(err)
5965end
5966
5967//no meaning to this...
5968Function V_writeSample_equatorial_ang(fname,val)
5969        String fname
5970        Variable val
5971       
5972//      String path = "entry:sample:equatorial_angle"   
5973       
5974        Make/O/D/N=1 wTmpWrite
5975//      Make/O/R/N=1 wTmpWrite
5976        String groupName = "/entry/sample"
5977        String varName = "equatorial_angle"
5978        wTmpWrite[0] = val
5979
5980        variable err
5981        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5982        if(err)
5983                Print "HDF write err = ",err
5984        endif
5985        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5986//      err = V_KillNamedDataFolder(fname)
5987//      if(err)
5988//              Print "DataFolder kill err = ",err
5989//      endif
5990        return(err)
5991end
5992
5993
5994//
5995// TODO x- I need to make sure that this is an integer in the JSON definition
5996//              x- currently a text value in the data file - see trac ticket
5997// x- this is also a duplicated field in the reduction block (reduction/group_id is no longer used)
5998//
5999// group ID !!! very important for matching up files
6000// integer value
6001//
6002Function V_writeSample_GroupID(fname,val)
6003        String fname
6004        Variable val
6005       
6006//      String path = "entry:sample:group_id"   
6007       
6008        Make/O/I/N=1 wTmpWrite
6009//      Make/O/R/N=1 wTmpWrite
6010        String groupName = "/entry/sample"
6011        String varName = "group_id"
6012        wTmpWrite[0] = val
6013
6014        variable err
6015        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6016        if(err)
6017                Print "HDF write err = ",err
6018        endif
6019        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6020//      err = V_KillNamedDataFolder(fname)
6021//      if(err)
6022//              Print "DataFolder kill err = ",err
6023//      endif
6024        return(err)
6025end
6026
6027
6028//Sample Rotation Angle
6029Function V_writeSampleRotationAngle(fname,val)
6030        String fname
6031        Variable val
6032       
6033//      String path = "entry:sample:rotation_angle"     
6034       
6035        Make/O/D/N=1 wTmpWrite
6036//      Make/O/R/N=1 wTmpWrite
6037        String groupName = "/entry/sample"
6038        String varName = "rotation_angle"
6039        wTmpWrite[0] = val
6040
6041        variable err
6042        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6043        if(err)
6044                Print "HDF write err = ",err
6045        endif
6046        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6047//      err = V_KillNamedDataFolder(fname)
6048//      if(err)
6049//              Print "DataFolder kill err = ",err
6050//      endif
6051        return(err)
6052end
6053
6054//?? this is huber/chamber??
6055// TODO -- then where is the description of 10CB, etc...
6056Function V_writeSampleHolderDescription(fname,str)
6057        String fname,str
6058
6059//      String path = "entry:sample:sample_holder_description"
6060
6061        Make/O/T/N=1 tmpTW
6062        String groupName = "/entry/sample"
6063        String varName = "sample_holder_description"
6064        tmpTW[0] = str //
6065
6066        variable err
6067        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
6068        if(err)
6069                Print "HDF write err = ",err
6070        endif
6071       
6072        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6073//      err = V_KillNamedDataFolder(fname)
6074//      if(err)
6075//              Print "DataFolder kill err = ",err
6076//      endif
6077               
6078        return(err)
6079End
6080
6081
6082
6083//Sample Temperature
6084Function V_writeSampleTemperature(fname,val)
6085        String fname
6086        Variable val
6087       
6088//      String path = "entry:sample:temperature"       
6089       
6090        Make/O/D/N=1 wTmpWrite
6091//      Make/O/R/N=1 wTmpWrite
6092        String groupName = "/entry/sample"
6093        String varName = "temperature"
6094        wTmpWrite[0] = val
6095
6096        variable err
6097        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6098        if(err)
6099                Print "HDF write err = ",err
6100        endif
6101        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6102//      err = V_KillNamedDataFolder(fname)
6103//      if(err)
6104//              Print "DataFolder kill err = ",err
6105//      endif
6106        return(err)
6107end
6108
6109
6110//Sample Temperature set point
6111Function V_writeSampleTempSetPoint(fname,val)
6112        String fname
6113        Variable val
6114       
6115//      String path = "entry:sample:temperature_setpoint"       
6116       
6117        Make/O/D/N=1 wTmpWrite
6118//      Make/O/R/N=1 wTmpWrite
6119        String groupName = "/entry/sample"
6120        String varName = "temperature_setpoint"
6121        wTmpWrite[0] = val
6122
6123        variable err
6124        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6125        if(err)
6126                Print "HDF write err = ",err
6127        endif
6128        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6129//      err = V_KillNamedDataFolder(fname)
6130//      if(err)
6131//              Print "DataFolder kill err = ",err
6132//      endif
6133        return(err)
6134end
6135
6136
6137//Sample Thickness
6138// TODO -- somehow, this is not set correctly in the acquisition, so NaN results
6139Function V_writeSampleThickness(fname,val)
6140        String fname
6141        Variable val
6142       
6143//      String path = "entry:sample:thickness" 
6144       
6145        Make/O/D/N=1 wTmpWrite
6146//      Make/O/R/N=1 wTmpWrite
6147        String groupName = "/entry/sample"
6148        String varName = "thickness"
6149        wTmpWrite[0] = val
6150
6151        variable err
6152        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6153        if(err)
6154                Print "HDF write err = ",err
6155        endif
6156        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6157//      err = V_KillNamedDataFolder(fname)
6158//      if(err)
6159//              Print "DataFolder kill err = ",err
6160//      endif
6161        return(err)
6162end
6163
6164
6165//Sample Translation
6166Function V_writeSampleTranslation(fname,val)
6167        String fname
6168        Variable val
6169       
6170//      String path = "entry:sample:translation"       
6171       
6172        Make/O/D/N=1 wTmpWrite
6173//      Make/O/R/N=1 wTmpWrite
6174        String groupName = "/entry/sample"
6175        String varName = "translation"
6176        wTmpWrite[0] = val
6177
6178        variable err
6179        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6180        if(err)
6181                Print "HDF write err = ",err
6182        endif
6183        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6184//      err = V_KillNamedDataFolder(fname)
6185//      if(err)
6186//              Print "DataFolder kill err = ",err
6187//      endif
6188        return(err)
6189end
6190
6191// sample transmission
6192Function V_writeSampleTransmission(fname,val)
6193        String fname
6194        Variable val
6195       
6196        String path = "entry:sample:transmission"       
6197       
6198        Make/O/D/N=1 wTmpWrite
6199//      Make/O/R/N=1 wTmpWrite
6200        String groupName = "/entry/sample"
6201        String varName = "transmission"
6202        wTmpWrite[0] = val
6203
6204        variable err
6205        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6206        if(err)
6207                Print "HDF write err = ",err
6208        endif
6209        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6210//      err = V_KillNamedDataFolder(fname)
6211//      if(err)
6212//              Print "DataFolder kill err = ",err
6213//      endif
6214        return(err)
6215end
6216
6217//transmission error (one sigma)
6218Function V_writeSampleTransError(fname,val)
6219        String fname
6220        Variable val
6221       
6222//      String path = "entry:sample:transmission_error"
6223       
6224        Make/O/D/N=1 wTmpWrite
6225//      Make/O/R/N=1 wTmpWrite
6226        String groupName = "/entry/sample"
6227        String varName = "transmission_error"
6228        wTmpWrite[0] = val
6229
6230        variable err
6231        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6232        if(err)
6233                Print "HDF write err = ",err
6234        endif
6235        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6236//      err = V_KillNamedDataFolder(fname)
6237//      if(err)
6238//              Print "DataFolder kill err = ",err
6239//      endif
6240        return(err)
6241end
6242
6243
6244
6245//// SAMPLE / DATA LOGS
6246// write this generic , call with the name of the environment log desired
6247//
6248//
6249// shear_field
6250// pressure
6251// magnetic_field
6252// electric_field
6253//
6254//////// (for example) electric_field (data folder)
6255
6256Function V_writeLog_attachedTo(fname,logStr,str)
6257        String fname,logStr,str
6258
6259//      String path = "entry:sample:"+logstr+":attached_to"
6260
6261        Make/O/T/N=1 tmpTW
6262        String groupName = "/entry/sample/"+logStr
6263        String varName = "attached_to"
6264        tmpTW[0] = str //
6265
6266        variable err
6267        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
6268        if(err)
6269                Print "HDF write err = ",err
6270        endif
6271       
6272        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6273//      err = V_KillNamedDataFolder(fname)
6274//      if(err)
6275//              Print "DataFolder kill err = ",err
6276//      endif
6277               
6278        return(err)
6279End
6280
6281
6282Function V_writeLog_measurement(fname,logStr,str)
6283        String fname,logStr,str
6284
6285        String path = "entry:sample:"+logstr+":measurement"
6286
6287        Make/O/T/N=1 tmpTW
6288        String groupName = "/entry/sample/"+logStr
6289        String varName = "measurement"
6290        tmpTW[0] = str //
6291
6292        variable err
6293        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
6294        if(err)
6295                Print "HDF write err = ",err
6296        endif
6297       
6298        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6299//      err = V_KillNamedDataFolder(fname)
6300//      if(err)
6301//              Print "DataFolder kill err = ",err
6302//      endif
6303               
6304        return(err)
6305End
6306
6307
6308Function V_writeLog_Name(fname,logStr,str)
6309        String fname,logStr,str
6310
6311//      String path = "entry:sample:"+logstr+":name"
6312
6313        Make/O/T/N=1 tmpTW
6314        String groupName = "/entry/sample/"+logStr
6315        String varName = "name"
6316        tmpTW[0] = str //
6317
6318        variable err
6319        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
6320        if(err)
6321                Print "HDF write err = ",err
6322        endif
6323       
6324        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6325//      err = V_KillNamedDataFolder(fname)
6326//      if(err)
6327//              Print "DataFolder kill err = ",err
6328//      endif
6329               
6330        return(err)
6331End
6332
6333
6334//// TODO -- this may require multiple entries, for each sensor _1, _2, etc.
6335//Function V_writeLog_setPoint(fname,logStr,val)
6336//      String fname,logStr
6337//      Variable val
6338//     
6339////    String path = "entry:sample:"+logstr+":setpoint_1"
6340//     
6341//      Make/O/D/N=1 wTmpWrite
6342////    Make/O/R/N=1 wTmpWrite
6343//      String groupName = "/entry/sample/"+logStr
6344//      String varName = "setpoint_1"
6345//      wTmpWrite[0] = val
6346//
6347//      variable err
6348//      err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6349//      if(err)
6350//              Print "HDF write err = ",err
6351//      endif
6352//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6353////    err = V_KillNamedDataFolder(fname)
6354////    if(err)
6355////            Print "DataFolder kill err = ",err
6356////    endif
6357//      return(err)
6358//end
6359//
6360//Function V_writeLog_startTime(fname,logStr,str)
6361//      String fname,logStr,str
6362//
6363////    String path = "entry:sample:"+logstr+":start"
6364//
6365//      Make/O/T/N=1 tmpTW
6366//      String groupName = "/entry/sample/"+logStr
6367//      String varName = "start"
6368//      tmpTW[0] = str //
6369//
6370//      variable err
6371//      err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
6372//      if(err)
6373//              Print "HDF write err = ",err
6374//      endif
6375//     
6376//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6377////    err = V_KillNamedDataFolder(fname)
6378////    if(err)
6379////            Print "DataFolder kill err = ",err
6380////    endif
6381//             
6382//      return(err)
6383//End
6384//
6385//
6386//// TODO -- this may only exist for electric and magnetic field, or be removed
6387//Function V_writeLog_nomValue(fname,logStr,val)
6388//      String fname,logStr
6389//      Variable val
6390//     
6391////    String path = "entry:sample:"+logstr+":value"
6392//     
6393//      Make/O/D/N=1 wTmpWrite
6394////    Make/O/R/N=1 wTmpWrite
6395//      String groupName = "/entry/sample/"+logStr
6396//      String varName = "value"
6397//      wTmpWrite[0] = val
6398//
6399//      variable err
6400//      err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6401//      if(err)
6402//              Print "HDF write err = ",err
6403//      endif
6404//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6405////    err = V_KillNamedDataFolder(fname)
6406////    if(err)
6407////            Print "DataFolder kill err = ",err
6408////    endif
6409//      return(err)
6410//end
6411
6412
6413// for temperature only, logStr must be "temperature_env"
6414Function V_writeTempLog_ControlSensor(fname,logStr,str)
6415        String fname,logStr,str
6416
6417//      String path = "entry:sample:"+logstr+":control_sensor"
6418
6419        Make/O/T/N=1 tmpTW
6420        String groupName = "/entry/sample/"+logStr
6421        String varName = "control_sensor"
6422        tmpTW[0] = str //
6423
6424        variable err
6425        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
6426        if(err)
6427                Print "HDF write err = ",err
6428        endif
6429       
6430        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6431//      err = V_KillNamedDataFolder(fname)
6432//      if(err)
6433//              Print "DataFolder kill err = ",err
6434//      endif
6435               
6436        return(err)
6437End
6438
6439// for temperature only, logStr must be "temperature_env"
6440Function V_writeTempLog_MonitorSensor(fname,logStr,str)
6441        String fname,logStr,str
6442
6443//      String path = "entry:sample:"+logstr+":monitor_sensor"
6444
6445        Make/O/T/N=1 tmpTW
6446        String groupName = "/entry/sample/"+logStr
6447        String varName = "monitor_sensor"
6448        tmpTW[0] = str //
6449
6450        variable err
6451        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
6452        if(err)
6453                Print "HDF write err = ",err
6454        endif
6455       
6456        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6457//      err = V_KillNamedDataFolder(fname)
6458//      if(err)
6459//              Print "DataFolder kill err = ",err
6460//      endif
6461               
6462        return(err)
6463End
6464
6465
6466
6467////////////////////
6468//
6469///////////
6470// NOTE
6471//
6472// for temperature, the "attached_to", "measurement", and "name" fields
6473// are one level down farther than before, and down deeper than for other sensors
6474//
6475//
6476// read the value of V_getTemp_MonitorSensor/ControlSensor to get the name of the sensor level .
6477//
6478
6479Function V_writeTempLog_attachedTo(fname,logStr,str)
6480        String fname,logStr,str
6481
6482//      String path = "entry:sample:temperature_env:"+logstr+":attached_to"
6483
6484        Make/O/T/N=1 tmpTW
6485        String groupName = "/entry/sample/temperature_env/"+logStr
6486        String varName = "attached_to"
6487        tmpTW[0] = str //
6488
6489        variable err
6490        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
6491        if(err)
6492                Print "HDF write err = ",err
6493        endif
6494       
6495        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6496//      err = V_KillNamedDataFolder(fname)
6497//      if(err)
6498//              Print "DataFolder kill err = ",err
6499//      endif
6500               
6501        return(err)
6502End
6503
6504
6505Function V_writeTempLog_highTrip(fname,logStr,val)
6506        String fname,logStr
6507        Variable val
6508       
6509//      String path = "entry:sample:temperature_env:"+logstr+":high_trip_value"
6510       
6511        Make/O/D/N=1 wTmpWrite
6512//      Make/O/R/N=1 wTmpWrite
6513        String groupName = "/entry/sample/temperature_env/"+logStr
6514        String varName = "high_trip_value"
6515        wTmpWrite[0] = val
6516
6517        variable err
6518        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6519        if(err)
6520                Print "HDF write err = ",err
6521        endif
6522        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6523//      err = V_KillNamedDataFolder(fname)
6524//      if(err)
6525//              Print "DataFolder kill err = ",err
6526//      endif
6527        return(err)
6528end
6529
6530Function V_writeTempLog_holdTime(fname,logStr,val)
6531        String fname,logStr
6532        Variable val
6533       
6534//      String path = "entry:sample:temperature_env:"+logstr+":hold_time"
6535       
6536        Make/O/D/N=1 wTmpWrite
6537//      Make/O/R/N=1 wTmpWrite
6538        String groupName = "/entry/sample/temperature_env/"+logStr
6539        String varName = "hold_time"
6540        wTmpWrite[0] = val
6541
6542        variable err
6543        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6544        if(err)
6545                Print "HDF write err = ",err
6546        endif
6547        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6548//      err = V_KillNamedDataFolder(fname)
6549//      if(err)
6550//              Print "DataFolder kill err = ",err
6551//      endif
6552        return(err)
6553end
6554
6555Function V_writeTempLog_lowTrip(fname,logStr,val)
6556        String fname,logStr
6557        Variable val
6558       
6559//      String path = "entry:sample:temperature_env:"+logstr+":low_trip_value"
6560       
6561        Make/O/D/N=1 wTmpWrite
6562//      Make/O/R/N=1 wTmpWrite
6563        String groupName = "/entry/sample/temperature_env/"+logStr
6564        String varName = "low_trip_value"
6565        wTmpWrite[0] = val
6566
6567        variable err
6568        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6569        if(err)
6570                Print "HDF write err = ",err
6571        endif
6572        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6573//      err = V_KillNamedDataFolder(fname)
6574//      if(err)
6575//              Print "DataFolder kill err = ",err
6576//      endif
6577        return(err)
6578end
6579
6580Function V_writeTempLog_measurement(fname,logStr,str)
6581        String fname,logStr,str
6582
6583//      String path = "entry:sample:temperature_env:"+logstr+":measurement"
6584
6585        Make/O/T/N=1 tmpTW
6586        String groupName = "/entry/sample/temperature_env/"+logStr
6587        String varName = "measurement"
6588        tmpTW[0] = str //
6589
6590        variable err
6591        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
6592        if(err)
6593                Print "HDF write err = ",err
6594        endif
6595       
6596        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6597//      err = V_KillNamedDataFolder(fname)
6598//      if(err)
6599//              Print "DataFolder kill err = ",err
6600//      endif
6601               
6602        return(err)
6603End
6604
6605Function V_writeTempLog_model(fname,logStr,str)
6606        String fname,logStr,str
6607
6608//      String path = "entry:sample:temperature_env:"+logstr+":model"
6609
6610        Make/O/T/N=1 tmpTW
6611        String groupName = "/entry/sample/temperature_env/"+logStr
6612        String varName = "model"
6613        tmpTW[0] = str //
6614
6615        variable err
6616        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
6617        if(err)
6618                Print "HDF write err = ",err
6619        endif
6620       
6621        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6622//      err = V_KillNamedDataFolder(fname)
6623//      if(err)
6624//              Print "DataFolder kill err = ",err
6625//      endif
6626               
6627        return(err)
6628End
6629
6630Function V_writeTempLog_name(fname,logStr,str)
6631        String fname,logStr,str
6632
6633//      String path = "entry:sample:temperature_env:"+logstr+":name"
6634
6635        Make/O/T/N=1 tmpTW
6636        String groupName = "/entry/sample/temperature_env/"+logStr
6637        String varName = "name"
6638        tmpTW[0] = str //
6639
6640        variable err
6641        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
6642        if(err)
6643                Print "HDF write err = ",err
6644        endif
6645       
6646        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6647//      err = V_KillNamedDataFolder(fname)
6648//      if(err)
6649//              Print "DataFolder kill err = ",err
6650//      endif
6651               
6652        return(err)
6653End
6654
6655Function V_writeTempLog_runControl(fname,logStr,val)
6656        String fname,logStr
6657        Variable val
6658       
6659//      String path = "entry:sample:temperature_env:"+logstr+":run_control"
6660       
6661        Make/O/D/N=1 wTmpWrite
6662//      Make/O/R/N=1 wTmpWrite
6663        String groupName = "/entry/sample/temperature_env/"+logStr
6664        String varName = "run_control"
6665        wTmpWrite[0] = val
6666
6667        variable err
6668        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6669        if(err)
6670                Print "HDF write err = ",err
6671        endif
6672        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6673//      err = V_KillNamedDataFolder(fname)
6674//      if(err)
6675//              Print "DataFolder kill err = ",err
6676//      endif
6677        return(err)
6678end
6679
6680Function V_writeTempLog_setPoint(fname,logStr,val)
6681        String fname,logStr
6682        Variable val
6683       
6684//      String path = "entry:sample:temperature_env:"+logstr+":setpoint"
6685       
6686        Make/O/D/N=1 wTmpWrite
6687//      Make/O/R/N=1 wTmpWrite
6688        String groupName = "/entry/sample/temperature_env/"+logStr
6689        String varName = "setpoint"
6690        wTmpWrite[0] = val
6691
6692        variable err
6693        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6694        if(err)
6695                Print "HDF write err = ",err
6696        endif
6697        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6698//      err = V_KillNamedDataFolder(fname)
6699//      if(err)
6700//              Print "DataFolder kill err = ",err
6701//      endif
6702        return(err)
6703end
6704
6705Function V_writeTempLog_shortName(fname,logStr,str)
6706        String fname,logStr,str
6707
6708//      String path = "entry:sample:temperature_env:"+logstr+":short_name"
6709
6710        Make/O/T/N=1 tmpTW
6711        String groupName = "/entry/sample/temperature_env/"+logStr
6712        String varName = "short_name"
6713        tmpTW[0] = str //
6714
6715        variable err
6716        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
6717        if(err)
6718                Print "HDF write err = ",err
6719        endif
6720       
6721        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6722//      err = V_KillNamedDataFolder(fname)
6723//      if(err)
6724//              Print "DataFolder kill err = ",err
6725//      endif
6726               
6727        return(err)
6728End
6729
6730Function V_writeTempLog_timeout(fname,logStr,val)
6731        String fname,logStr
6732        Variable val
6733       
6734//      String path = "entry:sample:temperature_env:"+logstr+":timeout"
6735       
6736        Make/O/D/N=1 wTmpWrite
6737//      Make/O/R/N=1 wTmpWrite
6738        String groupName = "/entry/sample/temperature_env/"+logStr
6739        String varName = "timeout"
6740        wTmpWrite[0] = val
6741
6742        variable err
6743        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6744        if(err)
6745                Print "HDF write err = ",err
6746        endif
6747        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6748//      err = V_KillNamedDataFolder(fname)
6749//      if(err)
6750//              Print "DataFolder kill err = ",err
6751//      endif
6752        return(err)
6753end
6754
6755Function V_writeTempLog_tolerance(fname,logStr,val)
6756        String fname,logStr
6757        Variable val
6758       
6759//      String path = "entry:sample:temperature_env:"+logstr+":tolerance"
6760       
6761        Make/O/D/N=1 wTmpWrite
6762//      Make/O/R/N=1 wTmpWrite
6763        String groupName = "/entry/sample/temperature_env/"+logStr
6764        String varName = "tolerance"
6765        wTmpWrite[0] = val
6766
6767        variable err
6768        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6769        if(err)
6770                Print "HDF write err = ",err
6771        endif
6772        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6773//      err = V_KillNamedDataFolder(fname)
6774//      if(err)
6775//              Print "DataFolder kill err = ",err
6776//      endif
6777        return(err)
6778end
6779
6780Function V_writeTempLog_toleranceBand(fname,logStr,val)
6781        String fname,logStr
6782        Variable val
6783       
6784//      String path = "entry:sample:temperature_env:"+logstr+":tolerance_band_time"
6785       
6786        Make/O/D/N=1 wTmpWrite
6787//      Make/O/R/N=1 wTmpWrite
6788        String groupName = "/entry/sample/temperature_env/"+logStr
6789        String varName = "tolerance_band_time"
6790        wTmpWrite[0] = val
6791
6792        variable err
6793        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6794        if(err)
6795                Print "HDF write err = ",err
6796        endif
6797        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6798//      err = V_KillNamedDataFolder(fname)
6799//      if(err)
6800//              Print "DataFolder kill err = ",err
6801//      endif
6802        return(err)
6803end
6804
6805Function V_writeTempLog_Value(fname,logStr,val)
6806        String fname,logStr
6807        Variable val
6808       
6809//      String path = "entry:sample:temperature_env:"+logstr+":value"
6810       
6811        Make/O/D/N=1 wTmpWrite
6812//      Make/O/R/N=1 wTmpWrite
6813        String groupName = "/entry/sample/temperature_env/"+logStr
6814        String varName = "value"
6815        wTmpWrite[0] = val
6816
6817        variable err
6818        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6819        if(err)
6820                Print "HDF write err = ",err
6821        endif
6822        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6823//      err = V_KillNamedDataFolder(fname)
6824//      if(err)
6825//              Print "DataFolder kill err = ",err
6826//      endif
6827        return(err)
6828end
6829
6830
6831
6832
6833
6834//
6835// temperature_env:temp_Internal_1:value_log
6836//
6837////            value_log (data folder)
6838//
6839// TODO:
6840// -- be sure that the calling function properly calls for temperture
6841// logs which are down an extra layer:
6842//      for example, logStr = "temperature_env:temp_Internal_1"
6843//
6844// read the value of V_getTemp_MonitorSensor to get the name of the sensor the next level down.
6845//
6846//
6847/////////////////////////////////////
6848////            value_log (data folder)
6849//
6850// TODO --
6851Function V_writeLog_avgValue(fname,logStr,val)
6852        String fname,logStr
6853        Variable val
6854       
6855//      String path = "entry:sample:"+logstr+":value_log:average_value"
6856       
6857        Make/O/D/N=1 wTmpWrite
6858//      Make/O/R/N=1 wTmpWrite
6859        String groupName = "/entry/sample/"+logStr+"/value_log"
6860        String varName = "average_value"
6861        wTmpWrite[0] = val
6862
6863        variable err
6864        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6865        if(err)
6866                Print "HDF write err = ",err
6867        endif
6868        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6869//      err = V_KillNamedDataFolder(fname)
6870//      if(err)
6871//              Print "DataFolder kill err = ",err
6872//      endif
6873        return(err)
6874end
6875
6876Function V_writeLog_avgValue_err(fname,logStr,val)
6877        String fname,logStr
6878        Variable val
6879       
6880//      String path = "entry:sample:"+logstr+":value_log:average_value_error"
6881       
6882        Make/O/D/N=1 wTmpWrite
6883//      Make/O/R/N=1 wTmpWrite
6884        String groupName = "/entry/sample/"+logStr+"/value_log"
6885        String varName = "average_value_error"
6886        wTmpWrite[0] = val
6887
6888        variable err
6889        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6890        if(err)
6891                Print "HDF write err = ",err
6892        endif
6893        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6894//      err = V_KillNamedDataFolder(fname)
6895//      if(err)
6896//              Print "DataFolder kill err = ",err
6897//      endif
6898        return(err)
6899end
6900
6901Function V_writeLog_maximumValue(fname,logStr,val)
6902        String fname,logStr
6903        Variable val
6904       
6905//      String path = "entry:sample:"+logstr+":value_log:maximum_value"
6906       
6907        Make/O/D/N=1 wTmpWrite
6908//      Make/O/R/N=1 wTmpWrite
6909        String groupName = "/entry/sample/"+logStr+"/value_log"
6910        String varName = "maximum_value"
6911        wTmpWrite[0] = val
6912
6913        variable err
6914        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6915        if(err)
6916                Print "HDF write err = ",err
6917        endif
6918        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6919//      err = V_KillNamedDataFolder(fname)
6920//      if(err)
6921//              Print "DataFolder kill err = ",err
6922//      endif
6923        return(err)
6924end
6925
6926Function V_writeLog_medianValue(fname,logStr,val)
6927        String fname,logStr
6928        Variable val
6929       
6930//      String path = "entry:sample:"+logstr+":value_log:median_value"
6931       
6932        Make/O/D/N=1 wTmpWrite
6933//      Make/O/R/N=1 wTmpWrite
6934        String groupName = "/entry/sample/"+logStr+"/value_log"
6935        String varName = "median_value"
6936        wTmpWrite[0] = val
6937
6938        variable err
6939        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6940        if(err)
6941                Print "HDF write err = ",err
6942        endif
6943        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6944//      err = V_KillNamedDataFolder(fname)
6945//      if(err)
6946//              Print "DataFolder kill err = ",err
6947//      endif
6948        return(err)
6949end
6950
6951Function V_writeLog_minimumValue(fname,logStr,val)
6952        String fname,logStr
6953        Variable val
6954       
6955//      String path = "entry:sample:"+logstr+":value_log:minimum_value"
6956       
6957        Make/O/D/N=1 wTmpWrite
6958//      Make/O/R/N=1 wTmpWrite
6959        String groupName = "/entry/sample/"+logStr+"/value_log"
6960        String varName = "minimum_value"
6961        wTmpWrite[0] = val
6962
6963        variable err
6964        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6965        if(err)
6966                Print "HDF write err = ",err
6967        endif
6968        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
6969//      err = V_KillNamedDataFolder(fname)
6970//      if(err)
6971//              Print "DataFolder kill err = ",err
6972//      endif
6973        return(err)
6974end
6975
6976
6977
6978// TODO -- this needs to be a WAVE reference
6979// be sure this gets written as "time", even though it is read in as "time0"
6980Function V_writeLog_timeWave(fname,logStr,inW)
6981        String fname,logStr
6982        Wave inW
6983       
6984//      String path = "entry:sample:"+logstr+":value_log:time"
6985
6986        Duplicate/O inW wTmpWrite       
6987// then use redimension as needed to cast the wave to write to the specified type
6988// see WaveType for the proper codes
6989//      Redimension/T=() wTmpWrite
6990// -- May also need to check the dimension(s) before writing (don't trust the input)
6991        String groupName = "/entry/sample/"+logStr+"/value_log"
6992        String varName = "time"
6993
6994        variable err
6995        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
6996        if(err)
6997                Print "HDF write err = ",err
6998        endif
6999        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7000//      err = V_KillNamedDataFolder(fname)
7001//      if(err)
7002//              Print "DataFolder kill err = ",err
7003//      endif
7004        return(err)
7005end
7006
7007
7008// TODO -- this needs to be a WAVE reference
7009Function V_writeLog_ValueWave(fname,logStr,inW)
7010        String fname,logStr
7011        Wave inW
7012       
7013//      String path = "entry:sample:"+logstr+":value_log:value"
7014
7015        Duplicate/O inW wTmpWrite       
7016// then use redimension as needed to cast the wave to write to the specified type
7017// see WaveType for the proper codes
7018//      Redimension/T=() wTmpWrite
7019// -- May also need to check the dimension(s) before writing (don't trust the input)
7020        String groupName = "/entry/sample/"+logStr+"/value_log"
7021        String varName = "value"
7022
7023        variable err
7024        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
7025        if(err)
7026                Print "HDF write err = ",err
7027        endif
7028        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7029//      err = V_KillNamedDataFolder(fname)
7030//      if(err)
7031//              Print "DataFolder kill err = ",err
7032//      endif
7033        return(err)
7034end
7035
7036
7037
7038
7039
7040
7041
7042
7043///////// REDUCTION
7044///////// REDUCTION
7045///////// REDUCTION
7046
7047
7048// TODO
7049// -- come up with a scheme to write the entire protocol to the data file?
7050// -- or a scheme to write just the missing bits?
7051
7052
7053// TODO -- needs to be a Text WAVE, and of the proper size and type!!!
7054//  -- this is a test where I write a wave to a field that does not exist...
7055Function V_writeReductionProtocolWave(fname,inTW)
7056        String fname
7057        Wave/T inTW
7058       
7059//      String path = "entry:reduction:absolute_scaling"
7060       
7061        Duplicate/O inTW wTTmpWrite     
7062// then use redimension as needed to cast the wave to write to the specified type
7063// see WaveType for the proper codes
7064//      Redimension/T=() wTmpWrite
7065// -- May also need to check the dimension(s) before writing (don't trust the input)
7066        String groupName = "/entry/reduction"   
7067        String varName = "protocol"
7068
7069        variable err
7070        err = V_WriteWaveToHDF(fname, groupName, varName, wTTmpWrite)
7071        if(err)
7072                Print "HDF write err = ",err
7073        endif
7074        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7075//      err = V_KillNamedDataFolder(fname)
7076//      if(err)
7077//              Print "DataFolder kill err = ",err
7078//      endif
7079        return(err)
7080end
7081
7082
7083// this is a NON NICE entered field
7084//
7085// this is a flag to mark the file as "flipped" so it prevents a 2nd flip
7086// if the flip has been done, the field is written with a value of 1 (= true)
7087//
7088// to "un-mark" the file and allow the flip to be re-done, write -999999
7089Function V_writeLeftRightFlipDone(fname,val)
7090        String fname
7091        Variable val
7092       
7093//      String path = "entry:reduction:left_right_flip"
7094       
7095        Make/O/D/N=1 wTmpWrite
7096//      Make/O/R/N=1 wTmpWrite
7097        String groupName = "/entry/reduction"
7098        String varName = "left_right_flip"
7099        wTmpWrite[0] = val
7100
7101        variable err
7102        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
7103        if(err)
7104                Print "HDF write err = ",err
7105        endif
7106        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7107//      err = V_KillNamedDataFolder(fname)
7108//      if(err)
7109//              Print "DataFolder kill err = ",err
7110//      endif
7111        return(err)
7112end
7113
7114
7115
7116// TODO -- needs to be a WAVE, and of the proper size and type!!!
7117Function V_writeAbsolute_Scaling(fname,inW)
7118        String fname
7119        Wave inW
7120       
7121//      String path = "entry:reduction:absolute_scaling"
7122       
7123        Duplicate/O inW wTmpWrite       
7124// then use redimension as needed to cast the wave to write to the specified type
7125// see WaveType for the proper codes
7126//      Redimension/T=() wTmpWrite
7127// -- May also need to check the dimension(s) before writing (don't trust the input)
7128        String groupName = "/entry/reduction"   
7129        String varName = "absolute_scaling"
7130
7131        variable err
7132        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
7133        if(err)
7134                Print "HDF write err = ",err
7135        endif
7136        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7137//      err = V_KillNamedDataFolder(fname)
7138//      if(err)
7139//              Print "DataFolder kill err = ",err
7140//      endif
7141        return(err)
7142end
7143
7144Function V_writeBackgroundFileName(fname,str)
7145        String fname,str
7146
7147//      String path = "entry:reduction:background_file_name"   
7148
7149        Make/O/T/N=1 tmpTW
7150        String groupName = "/entry/reduction"
7151        String varName = "background_file_name"
7152        tmpTW[0] = str //
7153
7154        variable err
7155        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
7156        if(err)
7157                Print "HDF write err = ",err
7158        endif
7159       
7160        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7161//      err = V_KillNamedDataFolder(fname)
7162//      if(err)
7163//              Print "DataFolder kill err = ",err
7164//      endif
7165               
7166        return(err)
7167End
7168
7169
7170// TODO -- needs to be a WAVE
7171Function V_writeBoxCoordinates(fname,inW)
7172        String fname
7173        Wave inW
7174       
7175//      String path = "entry:reduction:box_coordinates"
7176               
7177        Duplicate/O inW wTmpWrite       
7178// then use redimension as needed to cast the wave to write to the specified type
7179// see WaveType for the proper codes
7180//      Redimension/T=() wTmpWrite
7181// -- May also need to check the dimension(s) before writing (don't trust the input)
7182        String groupName = "/entry/reduction"   
7183        String varName = "box_coordinates"
7184
7185        variable err
7186        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
7187        if(err)
7188                Print "HDF write err = ",err
7189        endif
7190        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7191//      err = V_KillNamedDataFolder(fname)
7192//      if(err)
7193//              Print "DataFolder kill err = ",err
7194//      endif
7195        return(err)
7196end
7197
7198// THIS IS A NON-NICE ENTERED FIELD
7199// -- this is the panel string where the box coordinates refer to (for the open beam and transmission)
7200Function V_writeReduction_BoxPanel(fname,str)
7201        String fname,str
7202
7203//      String path = "entry:reduction:comments"       
7204
7205        Make/O/T/N=1 tmpTW
7206        String groupName = "/entry/reduction"
7207        String varName = "box_panel"
7208        tmpTW[0] = str //
7209
7210        variable err
7211        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
7212        if(err)
7213                Print "HDF write err = ",err
7214        endif
7215       
7216        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7217//      err = V_KillNamedDataFolder(fname)
7218//      if(err)
7219//              Print "DataFolder kill err = ",err
7220//      endif
7221               
7222        return(err)
7223End
7224
7225//box counts
7226Function V_writeBoxCounts(fname,val)
7227        String fname
7228        Variable val
7229       
7230//      String path = "entry:reduction:box_count"       
7231       
7232        Make/O/D/N=1 wTmpWrite
7233//      Make/O/R/N=1 wTmpWrite
7234        String groupName = "/entry/reduction"
7235        String varName = "box_count"
7236        wTmpWrite[0] = val
7237
7238        variable err
7239        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
7240        if(err)
7241                Print "HDF write err = ",err
7242        endif
7243        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7244//      err = V_KillNamedDataFolder(fname)
7245//      if(err)
7246//              Print "DataFolder kill err = ",err
7247//      endif
7248        return(err)
7249end
7250
7251//box counts error
7252Function V_writeBoxCountsError(fname,val)
7253        String fname
7254        Variable val
7255       
7256//      String path = "entry:reduction:box_count_error"
7257       
7258        Make/O/D/N=1 wTmpWrite
7259//      Make/O/R/N=1 wTmpWrite
7260        String groupName = "/entry/reduction"
7261        String varName = "box_count_error"
7262        wTmpWrite[0] = val
7263
7264        variable err
7265        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
7266        if(err)
7267                Print "HDF write err = ",err
7268        endif
7269        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7270//      err = V_KillNamedDataFolder(fname)
7271//      if(err)
7272//              Print "DataFolder kill err = ",err
7273//      endif
7274        return(err)
7275end
7276
7277Function V_writeReductionComments(fname,str)
7278        String fname,str
7279
7280//      String path = "entry:reduction:comments"       
7281
7282        Make/O/T/N=1 tmpTW
7283        String groupName = "/entry/reduction"
7284        String varName = "comments"
7285        tmpTW[0] = str //
7286
7287        variable err
7288        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
7289        if(err)
7290                Print "HDF write err = ",err
7291        endif
7292       
7293        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7294//      err = V_KillNamedDataFolder(fname)
7295//      if(err)
7296//              Print "DataFolder kill err = ",err
7297//      endif
7298               
7299        return(err)
7300End
7301
7302Function V_writeEmptyBeamFileName(fname,str)
7303        String fname,str
7304
7305//      String path = "entry:reduction:empty_beam_file_name"   
7306
7307        Make/O/T/N=1 tmpTW
7308        String groupName = "/entry/reduction"
7309        String varName = "empty_beam_file_name"
7310        tmpTW[0] = str //
7311
7312        variable err
7313        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
7314        if(err)
7315                Print "HDF write err = ",err
7316        endif
7317       
7318        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7319//      err = V_KillNamedDataFolder(fname)
7320//      if(err)
7321//              Print "DataFolder kill err = ",err
7322//      endif
7323               
7324        return(err)
7325End
7326
7327Function V_writeEmptyFileName(fname,str)
7328        String fname,str
7329
7330//      String path = "entry:reduction:empty_beam_file_name"   
7331
7332        Make/O/T/N=1 tmpTW
7333        String groupName = "/entry/reduction"
7334        String varName = "empty_file_name"
7335        tmpTW[0] = str //
7336
7337        variable err
7338        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
7339        if(err)
7340                Print "HDF write err = ",err
7341        endif
7342       
7343        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7344//      err = V_KillNamedDataFolder(fname)
7345//      if(err)
7346//              Print "DataFolder kill err = ",err
7347//      endif
7348               
7349        return(err)
7350End
7351
7352Function V_writeReduction_purpose(fname,str)
7353        String fname,str
7354
7355//      String path = "entry:reduction:file_purpose"   
7356
7357        Make/O/T/N=1 tmpTW
7358        String groupName = "/entry/reduction"
7359        String varName = "file_purpose"
7360        tmpTW[0] = str //
7361
7362        variable err
7363        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
7364        if(err)
7365                Print "HDF write err = ",err
7366        endif
7367       
7368        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7369//      err = V_KillNamedDataFolder(fname)
7370//      if(err)
7371//              Print "DataFolder kill err = ",err
7372//      endif
7373               
7374        return(err)
7375End
7376
7377// DONE x- commented out, not to be used
7378//  x- is this duplicated? - yes - this is duplicated in /entry/sample
7379//  x- so I need to pick a location, or be sure to fix it in both places
7380//Function V_writeReduction_group_ID(fname,val)
7381//      String fname
7382//      Variable val
7383//     
7384////    String path = "entry:reduction:group_id"       
7385//     
7386//      Make/O/D/N=1 wTmpWrite
7387////    Make/O/R/N=1 wTmpWrite
7388//      String groupName = "/entry/reduction"
7389//      String varName = "group_id"
7390//      wTmpWrite[0] = val
7391//
7392//      variable err
7393//      err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
7394//      if(err)
7395//              Print "HDF write err = ",err
7396//      endif
7397//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7398////    err = V_KillNamedDataFolder(fname)
7399////    if(err)
7400////            Print "DataFolder kill err = ",err
7401////    endif
7402//      return(err)
7403//end
7404
7405Function V_writeReductionIntent(fname,str)
7406        String fname,str
7407
7408//      String path = "entry:reduction:intent" 
7409
7410        Make/O/T/N=1 tmpTW
7411        String groupName = "/entry/reduction"
7412        String varName = "intent"
7413        tmpTW[0] = str //
7414
7415        variable err
7416        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
7417        if(err)
7418                Print "HDF write err = ",err
7419        endif
7420       
7421        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7422//      err = V_KillNamedDataFolder(fname)
7423//      if(err)
7424//              Print "DataFolder kill err = ",err
7425//      endif
7426               
7427        return(err)
7428End
7429
7430Function V_writeMaskFileName(fname,str)
7431        String fname,str
7432
7433//      String path = "entry:reduction:empty_beam_file_name"   
7434
7435        Make/O/T/N=1 tmpTW
7436        String groupName = "/entry/reduction"
7437        String varName = "mask_file_name"
7438        tmpTW[0] = str //
7439
7440        variable err
7441        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
7442        if(err)
7443                Print "HDF write err = ",err
7444        endif
7445       
7446        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7447//      err = V_KillNamedDataFolder(fname)
7448//      if(err)
7449//              Print "DataFolder kill err = ",err
7450//      endif
7451               
7452        return(err)
7453End
7454
7455
7456
7457Function V_writeLogFileName(fname,str)
7458        String fname,str
7459
7460//      String path = "entry:reduction:sans_log_file_name"     
7461
7462        Make/O/T/N=1 tmpTW
7463        String groupName = "/entry/reduction"
7464        String varName = "sans_log_file_name"
7465        tmpTW[0] = str //
7466
7467        variable err
7468        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
7469        if(err)
7470                Print "HDF write err = ",err
7471        endif
7472       
7473        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7474//      err = V_KillNamedDataFolder(fname)
7475//      if(err)
7476//              Print "DataFolder kill err = ",err
7477//      endif
7478               
7479        return(err)
7480End
7481
7482
7483Function V_writeSensitivityFileName(fname,str)
7484        String fname,str
7485
7486//      String path = "entry:reduction:sensitivity_file_name"   
7487
7488        Make/O/T/N=1 tmpTW
7489        String groupName = "/entry/reduction"
7490        String varName = "sensitivity_file_name"
7491        tmpTW[0] = str //
7492
7493        variable err
7494        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
7495        if(err)
7496                Print "HDF write err = ",err
7497        endif
7498       
7499        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7500//      err = V_KillNamedDataFolder(fname)
7501//      if(err)
7502//              Print "DataFolder kill err = ",err
7503//      endif
7504               
7505        return(err)
7506End
7507
7508Function V_writeTransmissionFileName(fname,str)
7509        String fname,str
7510
7511//      String path = "entry:reduction:transmission_file_name" 
7512
7513        Make/O/T/N=1 tmpTW
7514        String groupName = "/entry/reduction"
7515        String varName = "transmission_file_name"
7516        tmpTW[0] = str //
7517
7518        variable err
7519        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
7520        if(err)
7521                Print "HDF write err = ",err
7522        endif
7523       
7524        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7525//      err = V_KillNamedDataFolder(fname)
7526//      if(err)
7527//              Print "DataFolder kill err = ",err
7528//      endif
7529               
7530        return(err)
7531End
7532
7533
7534//whole detector transmission
7535Function V_writeSampleTransWholeDetector(fname,val)
7536        String fname
7537        Variable val
7538       
7539//      String path = "entry:reduction:whole_trans"     
7540       
7541        Make/O/D/N=1 wTmpWrite
7542//      Make/O/R/N=1 wTmpWrite
7543        String groupName = "/entry/reduction"
7544        String varName = "whole_trans"
7545        wTmpWrite[0] = val
7546
7547        variable err
7548        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
7549        if(err)
7550                Print "HDF write err = ",err
7551        endif
7552        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7553//      err = V_KillNamedDataFolder(fname)
7554//      if(err)
7555//              Print "DataFolder kill err = ",err
7556//      endif
7557        return(err)
7558end
7559
7560//whole detector transmission error
7561Function V_writeSampleTransWholeDetErr(fname,val)
7562        String fname
7563        Variable val
7564       
7565//      String path = "entry:reduction:whole_trans_error"       
7566       
7567        Make/O/D/N=1 wTmpWrite
7568//      Make/O/R/N=1 wTmpWrite
7569        String groupName = "/entry/reduction"
7570        String varName = "whole_trans_error"
7571        wTmpWrite[0] = val
7572
7573        variable err
7574        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
7575        if(err)
7576                Print "HDF write err = ",err
7577        endif
7578        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7579//      err = V_KillNamedDataFolder(fname)
7580//      if(err)
7581//              Print "DataFolder kill err = ",err
7582//      endif
7583        return(err)
7584end
7585
7586                       
7587///////                 pol_sans (data folder)
7588//
7589//Function V_writePolSANS_cellName(fname,str)
7590//      String fname,str
7591//
7592////    String path = "entry:reduction:pol_sans:cell_name"     
7593//
7594//      Make/O/T/N=1 tmpTW
7595//      String groupName = "/entry/reduction/pol_sans"
7596//      String varName = "cell_name"
7597//      tmpTW[0] = str //
7598//
7599//      variable err
7600//      err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
7601//      if(err)
7602//              Print "HDF write err = ",err
7603//      endif
7604//     
7605//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7606////    err = V_KillNamedDataFolder(fname)
7607////    if(err)
7608////            Print "DataFolder kill err = ",err
7609////    endif
7610//             
7611//      return(err)
7612//End
7613//
7614//
7615//// TODO -- needs to be a WAVE
7616//// is this a text wave?? if it's mixed names + values, then what?
7617//Function V_writePolSANS_cellParams(fname,inW)
7618//      String fname
7619//      Wave inW
7620//     
7621////    String path = "entry:reduction:pol_sans:cell_parameters"
7622//             
7623//      Duplicate/O inW wTmpWrite       
7624//// then use redimension as needed to cast the wave to write to the specified type
7625//// see WaveType for the proper codes
7626////    Redimension/T=() wTmpWrite
7627//// -- May also need to check the dimension(s) before writing (don't trust the input)
7628//      String groupName = "/entry/reduction/pol_sans" 
7629//      String varName = "cell_parameters"
7630//
7631//      variable err
7632//      err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
7633//      if(err)
7634//              Print "HDF write err = ",err
7635//      endif
7636//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7637////    err = V_KillNamedDataFolder(fname)
7638////    if(err)
7639////            Print "DataFolder kill err = ",err
7640////    endif
7641//      return(err)
7642//end
7643//
7644//Function V_writePolSANS_PolSANSPurpose(fname,str)
7645//      String fname,str
7646//
7647////    String path = "entry:reduction:pol_sans:pol_sans_purpose"       
7648//
7649//      Make/O/T/N=1 tmpTW
7650//      String groupName = "/entry/reduction/pol_sans"
7651//      String varName = "pol_sans_purpose"
7652//      tmpTW[0] = str //
7653//
7654//      variable err
7655//      err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
7656//      if(err)
7657//              Print "HDF write err = ",err
7658//      endif
7659//     
7660//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7661////    err = V_KillNamedDataFolder(fname)
7662////    if(err)
7663////            Print "DataFolder kill err = ",err
7664////    endif
7665//             
7666//      return(err)
7667//End
7668
7669                               
7670//////// TOP LEVEL DATA REPRESENTATION
7671//
7672// note that here the data is (supposed to be) a link, not the actual data
7673// Igor HDf implementation cannot follow links properly, as far as I know.
7674// so ignore them here, and focus on the image that may be possible to read
7675//
7676
7677//              data_B (data folder)
7678//                      data (wave) 1           //ignore this, it's a link
7679//                      variables (wave) 320
7680//                      thumbnail (data folder)
7681
7682////data (wave) "binary"
7683//// TODO -- this will need to be completely replaced with a function that can
7684//// read the binary image data. should be possible, but I don't know the details on either end...
7685//Function V_writeDataImage(fname,detStr,str)
7686//      String fname,detStr,str
7687//
7688////    String path = "entry:data_"+detStr+":thumbnail:data"   
7689//
7690//      Make/O/T/N=1 tmpTW
7691//      String groupName = "/entry/data_"+detStr+"/thumbnail"
7692//      String varName = "data"
7693//      tmpTW[0] = str //
7694//
7695//      variable err
7696//      err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
7697//      if(err)
7698//              Print "HDF write err = ",err
7699//      endif
7700//     
7701//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7702////    err = V_KillNamedDataFolder(fname)
7703////    if(err)
7704////            Print "DataFolder kill err = ",err
7705////    endif
7706//             
7707//      return(err)
7708//End
7709//
7710//Function V_writeDataImageDescription(fname,detStr,str)
7711//      String fname,detStr,str
7712//
7713////    String path = "entry:data_"+detStr+":thumbnail:description"     
7714//
7715//      Make/O/T/N=1 tmpTW
7716//      String groupName = "/entry/data_"+detStr+"/thumbnail"
7717//      String varName = "description"
7718//      tmpTW[0] = str //
7719//
7720//      variable err
7721//      err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
7722//      if(err)
7723//              Print "HDF write err = ",err
7724//      endif
7725//     
7726//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7727////    err = V_KillNamedDataFolder(fname)
7728////    if(err)
7729////            Print "DataFolder kill err = ",err
7730////    endif
7731//             
7732//      return(err)
7733//End
7734//                                                             
7735//Function V_writeDataImageType(fname,detStr,str)
7736//      String fname,detStr,str
7737//
7738////    String path = "entry:data_"+detStr+":thumbnail:type"   
7739//
7740//      Make/O/T/N=1 tmpTW
7741//      String groupName = "/entry/data_"+detStr+"/thumbnail"
7742//      String varName = "type"
7743//      tmpTW[0] = str //
7744//
7745//      variable err
7746//      err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
7747//      if(err)
7748//              Print "HDF write err = ",err
7749//      endif
7750//     
7751//      // now be sure to kill the data folder to force a re-read of the data next time this file is read in
7752////    err = V_KillNamedDataFolder(fname)
7753////    if(err)
7754////            Print "DataFolder kill err = ",err
7755////    endif
7756//             
7757//      return(err)
7758//End
7759//
Note: See TracBrowser for help on using the repository browser.