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

Last change on this file since 1100 was 1100, checked in by srkline, 5 years ago

Significant restructuring of V_ExecuteProtocol to make the logic of the flow more tractable and adaptable in the future.

Added major change to VSANS event mode reduction panel to allow F and M binned events to be saved to a copy of the correspondng data file. A new data reduction panel for multiple slice reduction is now presented for Event data. This allows reduction of a single slice (all 8 F,M panels, back ignored), or all of the slices.

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