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

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

CHANGES to SANS:
Now allow 4 files to be combined in one step. This required modification of one routine in NIST_XML to allow an extra file name, and significant addition to the NSORT panel to allow an (optional) 4th data file. behaviors are still the same as before with 2, 3, or 4 sets being allowed. The "combine table" also allows up to 4 files to be combined (can be mixed, 2, 3, 4 all allowed).

More addtions to VSANS present as well, not specific changes, but in-progress changes to the beam center handling and ciombining data to 1D.

File size: 138.5 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
168Function 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)
191End
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// file write time (what is this??)
405// TODO - figure out if this is supposed to be an integer or text (ISO)
406Function V_writeFileWriteTime(fname,val)
407        String fname
408        Variable val
409       
410        String path = "entry:file_time"
411       
412        Make/O/D/N=1 wTmpWrite
413//      Make/O/R/N=1 wTmpWrite
414        String groupName = "/entry"     
415        String varName = "file_time"
416        wTmpWrite[0] = val
417
418        variable err
419        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
420        if(err)
421                Print "HDF write err = ",err
422        endif
423        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
424//      err = V_KillNamedDataFolder(fname)
425//      if(err)
426//              Print "DataFolder kill err = ",err
427//      endif
428        return(err)
429End
430               
431//
432Function V_writeHDF_version(fname,str)
433        String fname,str
434       
435//      String path = "entry:hdf_version"       
436
437        Make/O/T/N=1 tmpTW
438        String groupName = "/entry"     //     
439        String varName = "hdf_version"
440        tmpTW[0] = str //
441
442        variable err
443        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
444        if(err)
445                Print "HDF write err = ",err
446        endif
447       
448        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
449//      err = V_KillNamedDataFolder(fname)
450//      if(err)
451//              Print "DataFolder kill err = ",err
452//      endif
453               
454        return(err)
455End
456
457// TODO -- not mine, added somewhere by Nexus writer?
458Function V_writeProgram_name(fname,str)
459        String fname,str
460       
461//      String path = "entry:program_name"     
462
463        Make/O/T/N=1 tmpTW
464        String groupName = "/entry"     //     
465        String varName = "program_name"
466        tmpTW[0] = str //
467
468        variable err
469        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
470        if(err)
471                Print "HDF write err = ",err
472        endif
473       
474        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
475//      err = V_KillNamedDataFolder(fname)
476//      if(err)
477//              Print "DataFolder kill err = ",err
478//      endif
479               
480        return(err)
481End
482
483// TODO -- not mine, added somewhere by Nexus writer?
484// data collection start time
485Function V_writeDataStartTime(fname,str)
486        String fname,str
487       
488//      String path = "entry:start_time"       
489
490        Make/O/T/N=1 tmpTW
491        String groupName = "/entry"     //     
492        String varName = "start_time"
493        tmpTW[0] = str //
494
495        variable err
496        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
497        if(err)
498                Print "HDF write err = ",err
499        endif
500       
501        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
502//      err = V_KillNamedDataFolder(fname)
503//      if(err)
504//              Print "DataFolder kill err = ",err
505//      endif
506               
507        return(err)
508End
509               
510// title of experiment
511Function V_writeTitle(fname,str)
512        String fname,str
513       
514//      String path = "entry:title"     
515
516        Make/O/T/N=1 tmpTW
517        String groupName = "/entry"     //     
518        String varName = "title"
519        tmpTW[0] = str //
520
521        variable err
522        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
523        if(err)
524                Print "HDF write err = ",err
525        endif
526       
527        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
528//      err = V_KillNamedDataFolder(fname)
529//      if(err)
530//              Print "DataFolder kill err = ",err
531//      endif
532               
533        return(err)
534end
535       
536       
537               
538////////// USER
539////////// USER
540////////// USER
541
542// list of user names
543// TODO -- currently not written out to data file??
544Function V_writeUserNames(fname,str)
545        String fname,str
546       
547//      String path = "entry:user:name"
548
549        Make/O/T/N=1 tmpTW
550        String groupName = "/entry/user"        //     
551        String varName = "name"
552        tmpTW[0] = str //
553
554        variable err
555        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
556        if(err)
557                Print "HDF write err = ",err
558        endif
559       
560        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
561//      err = V_KillNamedDataFolder(fname)
562//      if(err)
563//              Print "DataFolder kill err = ",err
564//      endif
565               
566        return(err)
567end
568
569
570//////// CONTROL
571//////// CONTROL
572//////// CONTROL
573
574// TODO -- for the control section, document each of the fields
575//
576Function V_writeCount_end(fname,val)
577        String fname
578        Variable val
579       
580//      String path = "entry:control:count_end"
581       
582        Make/O/D/N=1 wTmpWrite
583//      Make/O/R/N=1 wTmpWrite
584        String groupName = "/entry/control"     
585        String varName = "count_end"
586        wTmpWrite[0] = val
587
588        variable err
589        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
590        if(err)
591                Print "HDF write err = ",err
592        endif
593        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
594//      err = V_KillNamedDataFolder(fname)
595//      if(err)
596//              Print "DataFolder kill err = ",err
597//      endif
598        return(err)
599end
600
601
602Function V_writeCount_start(fname,val)
603        String fname
604        Variable val
605       
606//      String path = "entry:control:count_start"       
607       
608        Make/O/D/N=1 wTmpWrite
609//      Make/O/R/N=1 wTmpWrite
610        String groupName = "/entry/control"     
611        String varName = "count_start"
612        wTmpWrite[0] = val
613
614        variable err
615        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
616        if(err)
617                Print "HDF write err = ",err
618        endif
619        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
620//      err = V_KillNamedDataFolder(fname)
621//      if(err)
622//              Print "DataFolder kill err = ",err
623//      endif
624        return(err)
625end
626
627
628Function V_writeCount_time(fname,val)
629        String fname
630        Variable val
631       
632//      String path = "entry:control:count_time"       
633       
634        Make/O/D/N=1 wTmpWrite
635//      Make/O/R/N=1 wTmpWrite
636        String groupName = "/entry/control"     
637        String varName = "count_time"
638        wTmpWrite[0] = val
639
640        variable err
641        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
642        if(err)
643                Print "HDF write err = ",err
644        endif
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        return(err)
651end
652
653
654Function V_writeCount_time_preset(fname,val)
655        String fname
656        Variable val
657       
658//      String path = "entry:control:count_time_preset"
659       
660        Make/O/D/N=1 wTmpWrite
661//      Make/O/R/N=1 wTmpWrite
662        String groupName = "/entry/control"     
663        String varName = "count_time_preset"
664        wTmpWrite[0] = val
665
666        variable err
667        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
668        if(err)
669                Print "HDF write err = ",err
670        endif
671        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
672//      err = V_KillNamedDataFolder(fname)
673//      if(err)
674//              Print "DataFolder kill err = ",err
675//      endif
676        return(err)
677end
678
679
680Function V_writeDetector_counts(fname,val)
681        String fname
682        Variable val
683       
684//      String path = "entry:control:detector_counts"
685       
686        Make/O/D/N=1 wTmpWrite
687//      Make/O/R/N=1 wTmpWrite
688        String groupName = "/entry/control"     
689        String varName = "detector_counts"
690        wTmpWrite[0] = val
691
692        variable err
693        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
694        if(err)
695                Print "HDF write err = ",err
696        endif
697        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
698//      err = V_KillNamedDataFolder(fname)
699//      if(err)
700//              Print "DataFolder kill err = ",err
701//      endif
702        return(err)
703end
704
705
706Function V_writeDetector_preset(fname,val)
707        String fname
708        Variable val
709       
710//      String path = "entry:control:detector_preset"   
711       
712        Make/O/D/N=1 wTmpWrite
713//      Make/O/R/N=1 wTmpWrite
714        String groupName = "/entry/control"     
715        String varName = "detector_preset"
716        wTmpWrite[0] = val
717
718        variable err
719        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
720        if(err)
721                Print "HDF write err = ",err
722        endif
723        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
724//      err = V_KillNamedDataFolder(fname)
725//      if(err)
726//              Print "DataFolder kill err = ",err
727//      endif
728        return(err)
729end
730
731
732Function V_writeIntegral(fname,val)
733        String fname
734        Variable val
735       
736//      String path = "entry:control:integral"
737       
738        Make/O/D/N=1 wTmpWrite
739//      Make/O/R/N=1 wTmpWrite
740        String groupName = "/entry/control"     
741        String varName = "integral"
742        wTmpWrite[0] = val
743
744        variable err
745        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
746        if(err)
747                Print "HDF write err = ",err
748        endif
749        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
750//      err = V_KillNamedDataFolder(fname)
751//      if(err)
752//              Print "DataFolder kill err = ",err
753//      endif
754        return(err)
755end
756
757// control mode for data acquisition, "timer"
758Function V_writeControlMode(fname,str)
759        String fname,str
760       
761//      String path = "entry:control:mode"     
762
763        Make/O/T/N=1 tmpTW
764        String groupName = "/entry/control"     //     
765        String varName = "mode"
766        tmpTW[0] = str //
767
768        variable err
769        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
770        if(err)
771                Print "HDF write err = ",err
772        endif
773       
774        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
775//      err = V_KillNamedDataFolder(fname)
776//      if(err)
777//              Print "DataFolder kill err = ",err
778//      endif
779               
780        return(err)
781End
782
783//monitor count
784Function V_writeMonitorCount(fname,val)
785        String fname
786        Variable val
787       
788//      String path = "entry:control:monitor_counts"   
789       
790        Make/O/D/N=1 wTmpWrite
791//      Make/O/R/N=1 wTmpWrite
792        String groupName = "/entry/control"     
793        String varName = "monitor_counts"
794        wTmpWrite[0] = val
795
796        variable err
797        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
798        if(err)
799                Print "HDF write err = ",err
800        endif
801        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
802//      err = V_KillNamedDataFolder(fname)
803//      if(err)
804//              Print "DataFolder kill err = ",err
805//      endif
806        return(err)
807end
808
809Function V_writeMonitor_preset(fname,val)
810        String fname
811        Variable val
812       
813//      String path = "entry:control:monitor_preset"
814       
815        Make/O/D/N=1 wTmpWrite
816//      Make/O/R/N=1 wTmpWrite
817        String groupName = "/entry/control"     
818        String varName = "monitor_preset"
819        wTmpWrite[0] = val
820
821        variable err
822        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
823        if(err)
824                Print "HDF write err = ",err
825        endif
826        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
827//      err = V_KillNamedDataFolder(fname)
828//      if(err)
829//              Print "DataFolder kill err = ",err
830//      endif
831        return(err)
832end
833
834Function V_writePreset(fname,val)
835        String fname
836        Variable val
837       
838//      String path = "entry:control:preset"
839       
840        Make/O/D/N=1 wTmpWrite
841//      Make/O/R/N=1 wTmpWrite
842        String groupName = "/entry/control"     
843        String varName = "preset"
844        wTmpWrite[0] = val
845
846        variable err
847        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
848        if(err)
849                Print "HDF write err = ",err
850        endif
851        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
852//      err = V_KillNamedDataFolder(fname)
853//      if(err)
854//              Print "DataFolder kill err = ",err
855//      endif
856        return(err)
857end
858
859
860
861
862
863//////// INSTRUMENT
864//////// INSTRUMENT
865//////// INSTRUMENT
866
867Function V_writeLocalContact(fname,str)
868        String fname,str
869
870//      String path = "entry:instrument:local_contact"
871
872        Make/O/T/N=1 tmpTW
873        String groupName = "/entry/instrument"  //     
874        String varName = "local_contact"
875        tmpTW[0] = str //
876
877        variable err
878        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
879        if(err)
880                Print "HDF write err = ",err
881        endif
882       
883        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
884//      err = V_KillNamedDataFolder(fname)
885//      if(err)
886//              Print "DataFolder kill err = ",err
887//      endif
888               
889        return(err)
890End
891
892Function V_writeInstrumentName(fname,str)
893        String fname,str
894
895//      String path = "entry:instrument:name"
896
897        Make/O/T/N=1 tmpTW
898        String groupName = "/entry/instrument"  //     
899        String varName = "name"
900        tmpTW[0] = str //
901
902        variable err
903        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
904        if(err)
905                Print "HDF write err = ",err
906        endif
907       
908        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
909//      err = V_KillNamedDataFolder(fname)
910//      if(err)
911//              Print "DataFolder kill err = ",err
912//      endif
913               
914        return(err)
915End
916
917Function V_writeInstrumentType(fname,str)
918        String fname,str
919
920//      String path = "entry:instrument:type"
921
922        Make/O/T/N=1 tmpTW
923        String groupName = "/entry/instrument"  //     
924        String varName = "type"
925        tmpTW[0] = str //
926
927        variable err
928        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
929        if(err)
930                Print "HDF write err = ",err
931        endif
932       
933        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
934//      err = V_KillNamedDataFolder(fname)
935//      if(err)
936//              Print "DataFolder kill err = ",err
937//      endif
938               
939        return(err)
940End
941
942////// INSTRUMENT/ATTENUATOR
943// TODO
944// attenuator number -- for VSANS I think I want this to be some "binary" representation
945// of 4 plates in/out - so this may be an integer-> binary, or a text string (4 char)
946Function V_writeAtten_number(fname,val)
947        String fname
948        Variable val
949       
950//      String path = "entry:instrument:attenuator:atten_number"       
951       
952        Make/O/D/N=1 wTmpWrite
953//      Make/O/R/N=1 wTmpWrite
954        String groupName = "/entry/instrument/attenuator"       
955        String varName = "atten_number"
956        wTmpWrite[0] = val
957
958        variable err
959        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
960        if(err)
961                Print "HDF write err = ",err
962        endif
963        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
964//      err = V_KillNamedDataFolder(fname)
965//      if(err)
966//              Print "DataFolder kill err = ",err
967//      endif
968        return(err)
969end
970
971
972// transmission value for the attenuator in the beam
973// use this, but if something wrong, the tables are present
974Function V_writeAttenuator_transmission(fname,val)
975        String fname
976        Variable val
977       
978//      String path = "entry:instrument:attenuator:attenuator_transmission"     
979       
980        Make/O/D/N=1 wTmpWrite
981//      Make/O/R/N=1 wTmpWrite
982        String groupName = "/entry/instrument/attenuator"       
983        String varName = "attenuator_transmission"
984        wTmpWrite[0] = val
985
986        variable err
987        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
988        if(err)
989                Print "HDF write err = ",err
990        endif
991        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
992//      err = V_KillNamedDataFolder(fname)
993//      if(err)
994//              Print "DataFolder kill err = ",err
995//      endif
996        return(err)
997end
998
999// transmission value (error) for the attenuator in the beam
1000// use this, but if something wrong, the tables are present
1001Function V_writeAttenuator_trans_err(fname,val)
1002        String fname
1003        Variable val
1004       
1005//      String path = "entry:instrument:attenuator:attenuator_transmission_error"       
1006       
1007        Make/O/D/N=1 wTmpWrite
1008//      Make/O/R/N=1 wTmpWrite
1009        String groupName = "/entry/instrument/attenuator"       
1010        String varName = "attenuator_transmission_error"
1011        wTmpWrite[0] = val
1012
1013        variable err
1014        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1015        if(err)
1016                Print "HDF write err = ",err
1017        endif
1018        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1019//      err = V_KillNamedDataFolder(fname)
1020//      if(err)
1021//              Print "DataFolder kill err = ",err
1022//      endif
1023        return(err)
1024end
1025
1026
1027// distance from the attenuator to the sample (units??)
1028Function V_writeAttenDistance(fname,val)
1029        String fname
1030        Variable val
1031       
1032//      String path = "entry:instrument:attenuator:distance"   
1033       
1034        Make/O/D/N=1 wTmpWrite
1035//      Make/O/R/N=1 wTmpWrite
1036        String groupName = "/entry/instrument/attenuator"       
1037        String varName = "distance"
1038        wTmpWrite[0] = val
1039
1040        variable err
1041        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1042        if(err)
1043                Print "HDF write err = ",err
1044        endif
1045        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1046//      err = V_KillNamedDataFolder(fname)
1047//      if(err)
1048//              Print "DataFolder kill err = ",err
1049//      endif
1050        return(err)
1051end
1052
1053
1054// attenuator index, to use in the lookup table of transmission values
1055Function V_writeAttenIndex(fname,val)
1056        String fname
1057        Variable val
1058       
1059//      String path = "entry:instrument:attenuator:index"       
1060       
1061        Make/O/D/N=1 wTmpWrite
1062//      Make/O/R/N=1 wTmpWrite
1063        String groupName = "/entry/instrument/attenuator"       
1064        String varName = "index"
1065        wTmpWrite[0] = val
1066
1067        variable err
1068        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1069        if(err)
1070                Print "HDF write err = ",err
1071        endif
1072        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1073//      err = V_KillNamedDataFolder(fname)
1074//      if(err)
1075//              Print "DataFolder kill err = ",err
1076//      endif
1077        return(err)
1078end
1079
1080
1081// table of the attenuation factor
1082Function V_writeAttenIndex_table(fname,inW)
1083        String fname
1084        Wave inW
1085       
1086//      String path = "entry:instrument:attenuator:index_table"
1087       
1088        Duplicate/O inW wTmpWrite       
1089// then use redimension as needed to cast the wave to write to the specified type
1090// see WaveType for the proper codes
1091//      Redimension/T=() wTmpWrite
1092// -- May also need to check the dimension(s) before writing (don't trust the input)
1093        String groupName = "/entry/instrument/attenuator"       
1094        String varName = "index_table"
1095
1096        variable err
1097        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1098        if(err)
1099                Print "HDF write err = ",err
1100        endif
1101        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1102//      err = V_KillNamedDataFolder(fname)
1103//      if(err)
1104//              Print "DataFolder kill err = ",err
1105//      endif
1106        return(err)
1107end
1108
1109
1110// status "in or out"
1111Function V_writeAttenStatus(fname,str)
1112        String fname,str
1113
1114//      String path = "entry:instrument:attenuator:status"
1115
1116        Make/O/T/N=1 tmpTW
1117        String groupName = "/entry/instrument/attenuator"       //     
1118        String varName = "status"
1119        tmpTW[0] = str //
1120
1121        variable err
1122        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1123        if(err)
1124                Print "HDF write err = ",err
1125        endif
1126       
1127        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1128//      err = V_KillNamedDataFolder(fname)
1129//      if(err)
1130//              Print "DataFolder kill err = ",err
1131//      endif
1132               
1133        return(err)
1134End
1135
1136// thickness of the attenuator (PMMA) - units??
1137Function V_writeAttenThickness(fname,val)
1138        String fname
1139        Variable val
1140       
1141//      String path = "entry:instrument:attenuator:thickness"   
1142       
1143        Make/O/D/N=1 wTmpWrite
1144//      Make/O/R/N=1 wTmpWrite
1145        String groupName = "/entry/instrument/attenuator"       
1146        String varName = "thickness"
1147        wTmpWrite[0] = val
1148
1149        variable err
1150        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1151        if(err)
1152                Print "HDF write err = ",err
1153        endif
1154        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1155//      err = V_KillNamedDataFolder(fname)
1156//      if(err)
1157//              Print "DataFolder kill err = ",err
1158//      endif
1159        return(err)
1160end
1161
1162
1163// type of material for the atteunator
1164Function V_writeAttenType(fname,str)
1165        String fname,str
1166
1167//      String path = "entry:instrument:attenuator:type"
1168
1169        Make/O/T/N=1 tmpTW
1170        String groupName = "/entry/instrument/attenuator"       //     
1171        String varName = "type"
1172        tmpTW[0] = str //
1173
1174        variable err
1175        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1176        if(err)
1177                Print "HDF write err = ",err
1178        endif
1179       
1180        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1181//      err = V_KillNamedDataFolder(fname)
1182//      if(err)
1183//              Print "DataFolder kill err = ",err
1184//      endif
1185               
1186        return(err)
1187End
1188
1189
1190////// INSTRUMENT/BEAM
1191// instrument/beam/chopper (data folder)
1192Function V_writeChopperAngular_opening(fname,val)
1193        String fname
1194        Variable val
1195       
1196//      String path = "entry:instrument:beam:chopper:angular_opening"
1197       
1198        Make/O/D/N=1 wTmpWrite
1199//      Make/O/R/N=1 wTmpWrite
1200        String groupName = "/entry/instrument/beam/chopper"     
1201        String varName = "angular_opening"
1202        wTmpWrite[0] = val
1203
1204        variable err
1205        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1206        if(err)
1207                Print "HDF write err = ",err
1208        endif
1209        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1210//      err = V_KillNamedDataFolder(fname)
1211//      if(err)
1212//              Print "DataFolder kill err = ",err
1213//      endif
1214        return(err)
1215end
1216
1217Function V_writeChopDistance_from_sample(fname,val)
1218        String fname
1219        Variable val
1220       
1221//      String path = "entry:instrument:beam:chopper:distance_from_sample"
1222       
1223        Make/O/D/N=1 wTmpWrite
1224//      Make/O/R/N=1 wTmpWrite
1225        String groupName = "/entry/instrument/beam/chopper"     
1226        String varName = "distance_from_sample"
1227        wTmpWrite[0] = val
1228
1229        variable err
1230        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1231        if(err)
1232                Print "HDF write err = ",err
1233        endif
1234        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1235//      err = V_KillNamedDataFolder(fname)
1236//      if(err)
1237//              Print "DataFolder kill err = ",err
1238//      endif
1239        return(err)
1240end
1241
1242Function V_writeChopDistance_from_source(fname,val)
1243        String fname
1244        Variable val
1245       
1246//      String path = "entry:instrument:beam:chopper:distance_from_source"     
1247       
1248        Make/O/D/N=1 wTmpWrite
1249//      Make/O/R/N=1 wTmpWrite
1250        String groupName = "/entry/instrument/beam/chopper"     
1251        String varName = "distance_from_source"
1252        wTmpWrite[0] = val
1253
1254        variable err
1255        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1256        if(err)
1257                Print "HDF write err = ",err
1258        endif
1259        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1260//      err = V_KillNamedDataFolder(fname)
1261//      if(err)
1262//              Print "DataFolder kill err = ",err
1263//      endif
1264        return(err)
1265end
1266
1267Function V_writeChopperDuty_cycle(fname,val)
1268        String fname
1269        Variable val
1270       
1271//      String path = "entry:instrument:beam:chopper:duty_cycle"       
1272       
1273        Make/O/D/N=1 wTmpWrite
1274//      Make/O/R/N=1 wTmpWrite
1275        String groupName = "/entry/instrument/beam/chopper"     
1276        String varName = "duty_cycle"
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_writeChopperRotation_speed(fname,val)
1293        String fname
1294        Variable val
1295       
1296//      String path = "entry:instrument:beam:chopper:rotation_speed"   
1297       
1298        Make/O/D/N=1 wTmpWrite
1299//      Make/O/R/N=1 wTmpWrite
1300        String groupName = "/entry/instrument/beam/chopper"     
1301        String varName = "rotation_speed"
1302        wTmpWrite[0] = val
1303
1304        variable err
1305        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1306        if(err)
1307                Print "HDF write err = ",err
1308        endif
1309        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1310//      err = V_KillNamedDataFolder(fname)
1311//      if(err)
1312//              Print "DataFolder kill err = ",err
1313//      endif
1314        return(err)
1315end
1316
1317Function V_writeChopperSlits(fname,val)
1318        String fname
1319        Variable val
1320       
1321//      String path = "entry:instrument:beam:chopper:slits"     
1322       
1323        Make/O/D/N=1 wTmpWrite
1324//      Make/O/R/N=1 wTmpWrite
1325        String groupName = "/entry/instrument/beam/chopper"     
1326        String varName = "slits"
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
1342Function V_writeChopperstatus(fname,str)
1343        String fname,str
1344
1345//      String path = "entry:instrument:beam:chopper:status"
1346
1347        Make/O/T/N=1 tmpTW
1348        String groupName = "/entry/instrument/beam/chopper"     //     
1349        String varName = "status"
1350        tmpTW[0] = str //
1351
1352        variable err
1353        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1354        if(err)
1355                Print "HDF write err = ",err
1356        endif
1357       
1358        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1359//      err = V_KillNamedDataFolder(fname)
1360//      if(err)
1361//              Print "DataFolder kill err = ",err
1362//      endif
1363               
1364        return(err)
1365End
1366
1367Function V_writeChoppertype(fname,str)
1368        String fname,str
1369
1370//      String path = "entry:instrument:beam:chopper:type"
1371
1372        Make/O/T/N=1 tmpTW
1373        String groupName = "/entry/instrument/beam/chopper"     //     
1374        String varName = "type"
1375        tmpTW[0] = str //
1376
1377        variable err
1378        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1379        if(err)
1380                Print "HDF write err = ",err
1381        endif
1382       
1383        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1384//      err = V_KillNamedDataFolder(fname)
1385//      if(err)
1386//              Print "DataFolder kill err = ",err
1387//      endif
1388               
1389        return(err)
1390End
1391
1392
1393// instrument/beam/flipper (data folder)
1394Function V_writeFlipperDriving_current(fname,val)
1395        String fname
1396        Variable val
1397       
1398//      String path = "entry:instrument:beam:flipper:driving_current"   
1399       
1400        Make/O/D/N=1 wTmpWrite
1401//      Make/O/R/N=1 wTmpWrite
1402        String groupName = "/entry/instrument/beam/flipper"     
1403        String varName = "driving_current"
1404        wTmpWrite[0] = val
1405
1406        variable err
1407        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1408        if(err)
1409                Print "HDF write err = ",err
1410        endif
1411        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1412//      err = V_KillNamedDataFolder(fname)
1413//      if(err)
1414//              Print "DataFolder kill err = ",err
1415//      endif
1416        return(err)
1417end
1418
1419Function V_writeFlipperFrequency(fname,val)
1420        String fname
1421        Variable val
1422       
1423//      String path = "entry:instrument:beam:flipper:frequency"
1424       
1425        Make/O/D/N=1 wTmpWrite
1426//      Make/O/R/N=1 wTmpWrite
1427        String groupName = "/entry/instrument/beam/flipper"     
1428        String varName = "frequency"
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_writeFlipperstatus(fname,str)
1445        String fname,str
1446
1447//      String path = "entry:instrument:beam:flipper:status"
1448
1449        Make/O/T/N=1 tmpTW
1450        String groupName = "/entry/instrument/beam/flipper"     //     
1451        String varName = "status"
1452        tmpTW[0] = str //
1453
1454        variable err
1455        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1456        if(err)
1457                Print "HDF write err = ",err
1458        endif
1459       
1460        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1461//      err = V_KillNamedDataFolder(fname)
1462//      if(err)
1463//              Print "DataFolder kill err = ",err
1464//      endif
1465               
1466        return(err)
1467End
1468
1469Function V_writeFlipperTransmitted_power(fname,val)
1470        String fname
1471        Variable val
1472       
1473//      String path = "entry:instrument:beam:flipper:transmitted_power"
1474
1475        Make/O/D/N=1 wTmpWrite
1476//      Make/O/R/N=1 wTmpWrite
1477        String groupName = "/entry/instrument/beam/flipper"     
1478        String varName = "transmitted_power"
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_writeFlipperWaveform(fname,str)
1495        String fname,str
1496
1497//      String path = "entry:instrument:beam:flipper:waveform"
1498
1499        Make/O/T/N=1 tmpTW
1500        String groupName = "/entry/instrument/beam/flipper"     //     
1501        String varName = "waveform"
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
1519// instrument/beam/monochromator (data folder)
1520Function V_writeMonochromatorType(fname,str)
1521        String fname,str
1522
1523//      String path = "entry:instrument:beam:monochromator:type"
1524
1525        Make/O/T/N=1 tmpTW
1526        String groupName = "/entry/instrument/beam/monochromator"       //     
1527        String varName = "type"
1528        tmpTW[0] = str //
1529
1530        variable err
1531        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1532        if(err)
1533                Print "HDF write err = ",err
1534        endif
1535       
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               
1542        return(err)
1543End
1544
1545Function V_writeWavelength(fname,val)
1546        String fname
1547        Variable val
1548       
1549//      String path = "entry:instrument:beam:monochromator:wavelength" 
1550       
1551        Make/O/D/N=1 wTmpWrite
1552//      Make/O/R/N=1 wTmpWrite
1553        String groupName = "/entry/instrument/beam/monochromator"       
1554        String varName = "wavelength"
1555        wTmpWrite[0] = val
1556
1557        variable err
1558        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1559        if(err)
1560                Print "HDF write err = ",err
1561        endif
1562        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1563//      err = V_KillNamedDataFolder(fname)
1564//      if(err)
1565//              Print "DataFolder kill err = ",err
1566//      endif
1567        return(err)
1568end
1569
1570Function V_writeWavelength_spread(fname,val)
1571        String fname
1572        Variable val
1573       
1574//      String path = "entry:instrument:beam:monochromator:wavelength_spread"   
1575       
1576        Make/O/D/N=1 wTmpWrite
1577//      Make/O/R/N=1 wTmpWrite
1578        String groupName = "/entry/instrument/beam/monochromator"       
1579        String varName = "wavelength_spread"
1580        wTmpWrite[0] = val
1581
1582        variable err
1583        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1584        if(err)
1585                Print "HDF write err = ",err
1586        endif
1587        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1588//      err = V_KillNamedDataFolder(fname)
1589//      if(err)
1590//              Print "DataFolder kill err = ",err
1591//      endif
1592        return(err)
1593end
1594
1595// instrument/beam/monochromator/crystal (data folder)
1596Function V_writeCrystalEnergy(fname,val)
1597        String fname
1598        Variable val
1599       
1600//      String path = "entry:instrument:beam:monochromator:crystal:energy"     
1601       
1602        Make/O/D/N=1 wTmpWrite
1603//      Make/O/R/N=1 wTmpWrite
1604        String groupName = "/entry/instrument/beam/monochromator/crystal"       
1605        String varName = "energy"
1606        wTmpWrite[0] = val
1607
1608        variable err
1609        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1610        if(err)
1611                Print "HDF write err = ",err
1612        endif
1613        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1614//      err = V_KillNamedDataFolder(fname)
1615//      if(err)
1616//              Print "DataFolder kill err = ",err
1617//      endif
1618        return(err)
1619end
1620
1621Function V_writeCrystalHoriz_apert(fname,val)
1622        String fname
1623        Variable val
1624       
1625//      String path = "entry:instrument:beam:monochromator:crystal:horizontal_aperture"
1626       
1627        Make/O/D/N=1 wTmpWrite
1628//      Make/O/R/N=1 wTmpWrite
1629        String groupName = "/entry/instrument/beam/monochromator/crystal"       
1630        String varName = "horizontal_aperture"
1631        wTmpWrite[0] = val
1632
1633        variable err
1634        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1635        if(err)
1636                Print "HDF write err = ",err
1637        endif
1638        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1639//      err = V_KillNamedDataFolder(fname)
1640//      if(err)
1641//              Print "DataFolder kill err = ",err
1642//      endif
1643        return(err)
1644end
1645
1646Function V_writeCrystalHoriz_curvature(fname,val)
1647        String fname
1648        Variable val
1649       
1650//      String path = "entry:instrument:beam:monochromator:crystal:horizontal_curvature"       
1651       
1652        Make/O/D/N=1 wTmpWrite
1653//      Make/O/R/N=1 wTmpWrite
1654        String groupName = "/entry/instrument/beam/monochromator/crystal"       
1655        String varName = "horizontal_curvature"
1656        wTmpWrite[0] = val
1657
1658        variable err
1659        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1660        if(err)
1661                Print "HDF write err = ",err
1662        endif
1663        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1664//      err = V_KillNamedDataFolder(fname)
1665//      if(err)
1666//              Print "DataFolder kill err = ",err
1667//      endif
1668        return(err)
1669end
1670
1671Function V_writeCrystalLattice_parameter(fname,val)
1672        String fname
1673        Variable val
1674       
1675//      String path = "entry:instrument:beam:monochromator:crystal:lattice_parameter"   
1676       
1677        Make/O/D/N=1 wTmpWrite
1678//      Make/O/R/N=1 wTmpWrite
1679        String groupName = "/entry/instrument/beam/monochromator/crystal"       
1680        String varName = "lattice_parameter"
1681        wTmpWrite[0] = val
1682
1683        variable err
1684        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1685        if(err)
1686                Print "HDF write err = ",err
1687        endif
1688        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1689//      err = V_KillNamedDataFolder(fname)
1690//      if(err)
1691//              Print "DataFolder kill err = ",err
1692//      endif
1693        return(err)
1694end
1695
1696Function V_writeCrystalDistance(fname,val)
1697        String fname
1698        Variable val
1699       
1700//      String path = "entry:instrument:beam:monochromator:crystal:distance"   
1701       
1702        Make/O/D/N=1 wTmpWrite
1703//      Make/O/R/N=1 wTmpWrite
1704        String groupName = "/entry/instrument/beam/monochromator/crystal"       
1705        String varName = "distance"
1706        wTmpWrite[0] = val
1707
1708        variable err
1709        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1710        if(err)
1711                Print "HDF write err = ",err
1712        endif
1713        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1714//      err = V_KillNamedDataFolder(fname)
1715//      if(err)
1716//              Print "DataFolder kill err = ",err
1717//      endif
1718        return(err)
1719end
1720
1721Function V_writeCrystalReflection(fname,val)
1722        String fname
1723        Variable val
1724       
1725//      String path = "entry:instrument:beam:monochromator:crystal:reflection" 
1726       
1727        Make/O/D/N=1 wTmpWrite
1728//      Make/O/R/N=1 wTmpWrite
1729        String groupName = "/entry/instrument/beam/monochromator/crystal"       
1730        String varName = "reflection"
1731        wTmpWrite[0] = val
1732
1733        variable err
1734        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1735        if(err)
1736                Print "HDF write err = ",err
1737        endif
1738        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1739//      err = V_KillNamedDataFolder(fname)
1740//      if(err)
1741//              Print "DataFolder kill err = ",err
1742//      endif
1743        return(err)
1744end
1745
1746Function V_writeCrystalRotation(fname,val)
1747        String fname
1748        Variable val
1749       
1750//      String path = "entry:instrument:beam:monochromator:crystal:rotation"   
1751       
1752        Make/O/D/N=1 wTmpWrite
1753//      Make/O/R/N=1 wTmpWrite
1754        String groupName = "/entry/instrument/beam/monochromator/crystal"       
1755        String varName = "rotation"
1756        wTmpWrite[0] = val
1757
1758        variable err
1759        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1760        if(err)
1761                Print "HDF write err = ",err
1762        endif
1763        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1764//      err = V_KillNamedDataFolder(fname)
1765//      if(err)
1766//              Print "DataFolder kill err = ",err
1767//      endif
1768        return(err)
1769end
1770
1771Function V_writeCrystalStatus(fname,str)
1772        String fname,str
1773
1774//      String path = "entry:instrument:beam:monochromator:crystal:status"
1775
1776        Make/O/T/N=1 tmpTW
1777        String groupName = "/entry/instrument/beam/monochromator/crystal"       //     
1778        String varName = "status"
1779        tmpTW[0] = str //
1780
1781        variable err
1782        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1783        if(err)
1784                Print "HDF write err = ",err
1785        endif
1786       
1787        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1788//      err = V_KillNamedDataFolder(fname)
1789//      if(err)
1790//              Print "DataFolder kill err = ",err
1791//      endif
1792               
1793        return(err)
1794End
1795
1796Function V_writeCrystalVertical_aperture(fname,val)
1797        String fname
1798        Variable val
1799       
1800//      String path = "entry:instrument:beam:monochromator:crystal:vertical_aperture"   
1801       
1802        Make/O/D/N=1 wTmpWrite
1803//      Make/O/R/N=1 wTmpWrite
1804        String groupName = "/entry/instrument/beam/monochromator/crystal"       
1805        String varName = "vertical_aperture"
1806        wTmpWrite[0] = val
1807
1808        variable err
1809        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1810        if(err)
1811                Print "HDF write err = ",err
1812        endif
1813        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1814//      err = V_KillNamedDataFolder(fname)
1815//      if(err)
1816//              Print "DataFolder kill err = ",err
1817//      endif
1818        return(err)
1819end
1820
1821Function V_writeCrystalVertical_curv(fname,val)
1822        String fname
1823        Variable val
1824       
1825//      String path = "entry:instrument:beam:monochromator:crystal:vertical_curvature" 
1826       
1827        Make/O/D/N=1 wTmpWrite
1828//      Make/O/R/N=1 wTmpWrite
1829        String groupName = "/entry/instrument/beam/monochromator/crystal"       
1830        String varName = "vertical_curvature"
1831        wTmpWrite[0] = val
1832
1833        variable err
1834        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1835        if(err)
1836                Print "HDF write err = ",err
1837        endif
1838        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1839//      err = V_KillNamedDataFolder(fname)
1840//      if(err)
1841//              Print "DataFolder kill err = ",err
1842//      endif
1843        return(err)
1844end
1845
1846Function V_writeCrystalWavelength(fname,val)
1847        String fname
1848        Variable val
1849       
1850//      String path = "entry:instrument:beam:monochromator:crystal:wavelength" 
1851       
1852        Make/O/D/N=1 wTmpWrite
1853//      Make/O/R/N=1 wTmpWrite
1854        String groupName = "/entry/instrument/beam/monochromator/crystal"       
1855        String varName = "wavelength"
1856        wTmpWrite[0] = val
1857
1858        variable err
1859        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1860        if(err)
1861                Print "HDF write err = ",err
1862        endif
1863        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1864//      err = V_KillNamedDataFolder(fname)
1865//      if(err)
1866//              Print "DataFolder kill err = ",err
1867//      endif
1868        return(err)
1869end
1870
1871Function V_writeCrystalWavelength_spread(fname,val)
1872        String fname
1873        Variable val
1874       
1875//      String path = "entry:instrument:beam:monochromator:crystal:wavelength_spread"   
1876       
1877        Make/O/D/N=1 wTmpWrite
1878//      Make/O/R/N=1 wTmpWrite
1879        String groupName = "/entry/instrument/beam/monochromator/crystal"       
1880        String varName = "wavelength_spread"
1881        wTmpWrite[0] = val
1882
1883        variable err
1884        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1885        if(err)
1886                Print "HDF write err = ",err
1887        endif
1888        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1889//      err = V_KillNamedDataFolder(fname)
1890//      if(err)
1891//              Print "DataFolder kill err = ",err
1892//      endif
1893        return(err)
1894end
1895
1896Function V_writeCrystalWavevector(fname,val)
1897        String fname
1898        Variable val
1899       
1900//      String path = "entry:instrument:beam:monochromator:crystal:wavevector" 
1901       
1902        Make/O/D/N=1 wTmpWrite
1903//      Make/O/R/N=1 wTmpWrite
1904        String groupName = "/entry/instrument/beam/monochromator/crystal"       
1905        String varName = "wavevector"
1906        wTmpWrite[0] = val
1907
1908        variable err
1909        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1910        if(err)
1911                Print "HDF write err = ",err
1912        endif
1913        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1914//      err = V_KillNamedDataFolder(fname)
1915//      if(err)
1916//              Print "DataFolder kill err = ",err
1917//      endif
1918        return(err)
1919end
1920
1921// instrument/beam/monochromator/velocity_selector (data folder)
1922Function V_writeVSDistance(fname,val)
1923        String fname
1924        Variable val
1925       
1926//      String path = "entry:instrument:beam:monochromator:velocity_selector:distance" 
1927       
1928        Make/O/D/N=1 wTmpWrite
1929//      Make/O/R/N=1 wTmpWrite
1930        String groupName = "/entry/instrument/beam/monochromator/velocity_selector"     
1931        String varName = "distance"
1932        wTmpWrite[0] = val
1933
1934        variable err
1935        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1936        if(err)
1937                Print "HDF write err = ",err
1938        endif
1939        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1940//      err = V_KillNamedDataFolder(fname)
1941//      if(err)
1942//              Print "DataFolder kill err = ",err
1943//      endif
1944        return(err)
1945end
1946
1947Function V_writeVSRotation_speed(fname,val)
1948        String fname
1949        Variable val
1950       
1951//      String path = "entry:instrument:beam:monochromator:velocity_selector:rotation_speed"   
1952       
1953        Make/O/D/N=1 wTmpWrite
1954//      Make/O/R/N=1 wTmpWrite
1955        String groupName = "/entry/instrument/beam/monochromator/velocity_selector"     
1956        String varName = "rotation_speed"
1957        wTmpWrite[0] = val
1958
1959        variable err
1960        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
1961        if(err)
1962                Print "HDF write err = ",err
1963        endif
1964        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1965//      err = V_KillNamedDataFolder(fname)
1966//      if(err)
1967//              Print "DataFolder kill err = ",err
1968//      endif
1969        return(err)
1970end
1971
1972Function V_writeVelSelStatus(fname,str)
1973        String fname,str
1974
1975//      String path = "entry:instrument:beam:monochromator:velocity_selector:status"
1976
1977        Make/O/T/N=1 tmpTW
1978        String groupName = "/entry/instrument/beam/monochromator/velocity_selector"     //     
1979        String varName = "status"
1980        tmpTW[0] = str //
1981
1982        variable err
1983        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
1984        if(err)
1985                Print "HDF write err = ",err
1986        endif
1987       
1988        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
1989//      err = V_KillNamedDataFolder(fname)
1990//      if(err)
1991//              Print "DataFolder kill err = ",err
1992//      endif
1993               
1994        return(err)
1995End
1996
1997Function V_writeVSTable(fname,inW)
1998        String fname
1999        Wave inW
2000       
2001//      String path = "entry:instrument:beam:monochromator:velocity_selector:table"     
2002
2003        Duplicate/O inW wTmpWrite       
2004// then use redimension as needed to cast the wave to write to the specified type
2005// see WaveType for the proper codes
2006//      Redimension/T=() wTmpWrite
2007// -- May also need to check the dimension(s) before writing (don't trust the input)
2008        String groupName = "/entry/instrument/beam/monochromator/velocity_selector"     
2009        String varName = "table"
2010
2011        variable err
2012        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2013        if(err)
2014                Print "HDF write err = ",err
2015        endif
2016        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2017//      err = V_KillNamedDataFolder(fname)
2018//      if(err)
2019//              Print "DataFolder kill err = ",err
2020//      endif
2021        return(err)
2022end
2023
2024// TODO -- this is not the correct data type??? what does this mean??
2025Function V_writeVSTable_parameters(fname,val)
2026        String fname
2027        Variable val
2028       
2029        String path = "entry:instrument:beam:monochromator:velocity_selector:table_parameters" 
2030       
2031        Make/O/D/N=1 wTmpWrite
2032//      Make/O/R/N=1 wTmpWrite
2033        String groupName = "/entry/instrument/beam/monochromator/velocity_selector"     
2034        String varName = "table_parameters"
2035        wTmpWrite[0] = val
2036
2037        variable err
2038        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2039        if(err)
2040                Print "HDF write err = ",err
2041        endif
2042        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2043//      err = V_KillNamedDataFolder(fname)
2044//      if(err)
2045//              Print "DataFolder kill err = ",err
2046//      endif
2047        return(err)
2048end
2049
2050Function V_writeVS_tilt(fname,val)
2051        String fname
2052        Variable val
2053       
2054//      String path = "entry:instrument:beam:monochromator:velocity_selector:vs_tilt"   
2055       
2056        Make/O/D/N=1 wTmpWrite
2057//      Make/O/R/N=1 wTmpWrite
2058        String groupName = "/entry/instrument/beam/monochromator/velocity_selector"     
2059        String varName = "vs_tilt"
2060        wTmpWrite[0] = val
2061
2062        variable err
2063        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2064        if(err)
2065                Print "HDF write err = ",err
2066        endif
2067        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2068//      err = V_KillNamedDataFolder(fname)
2069//      if(err)
2070//              Print "DataFolder kill err = ",err
2071//      endif
2072        return(err)
2073end
2074
2075Function V_writeVSWavelength(fname,val)
2076        String fname
2077        Variable val
2078       
2079//      String path = "entry:instrument:beam:monochromator:velocity_selector:wavelength"       
2080       
2081        Make/O/D/N=1 wTmpWrite
2082//      Make/O/R/N=1 wTmpWrite
2083        String groupName = "/entry/instrument/beam/monochromator/velocity_selector"     
2084        String varName = "wavelength"
2085        wTmpWrite[0] = val
2086
2087        variable err
2088        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2089        if(err)
2090                Print "HDF write err = ",err
2091        endif
2092        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2093//      err = V_KillNamedDataFolder(fname)
2094//      if(err)
2095//              Print "DataFolder kill err = ",err
2096//      endif
2097        return(err)
2098end
2099
2100Function V_writeVSWavelength_spread(fname,val)
2101        String fname
2102        Variable val
2103       
2104//      String path = "entry:instrument:beam:monochromator:velocity_selector:wavelength_spread"
2105       
2106        Make/O/D/N=1 wTmpWrite
2107//      Make/O/R/N=1 wTmpWrite
2108        String groupName = "/entry/instrument/beam/monochromator/velocity_selector"     
2109        String varName = "wavelength_spread"
2110        wTmpWrite[0] = val
2111
2112        variable err
2113        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2114        if(err)
2115                Print "HDF write err = ",err
2116        endif
2117        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2118//      err = V_KillNamedDataFolder(fname)
2119//      if(err)
2120//              Print "DataFolder kill err = ",err
2121//      endif
2122        return(err)
2123end
2124
2125// instrument/beam/monochromator/white_beam (data folder)
2126Function V_writeWhiteBeamStatus(fname,str)
2127        String fname,str
2128
2129//      String path = "entry:instrument:beam:monochromator:white_beam:status"
2130
2131        Make/O/T/N=1 tmpTW
2132        String groupName = "/entry/instrument/beam/monochromator/white_beam"    //     
2133        String varName = "status"
2134        tmpTW[0] = str //
2135
2136        variable err
2137        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2138        if(err)
2139                Print "HDF write err = ",err
2140        endif
2141       
2142        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2143//      err = V_KillNamedDataFolder(fname)
2144//      if(err)
2145//              Print "DataFolder kill err = ",err
2146//      endif
2147               
2148        return(err)
2149End
2150
2151Function V_writeWhiteBeamWavelength(fname,val)
2152        String fname
2153        Variable val
2154       
2155//      String path = "entry:instrument:beam:monochromator:white_beam:wavelength"       
2156       
2157        Make/O/D/N=1 wTmpWrite
2158//      Make/O/R/N=1 wTmpWrite
2159        String groupName = "/entry/instrument/beam/monochromator/white_beam"   
2160        String varName = "wavelength"
2161        wTmpWrite[0] = val
2162
2163        variable err
2164        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2165        if(err)
2166                Print "HDF write err = ",err
2167        endif
2168        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2169//      err = V_KillNamedDataFolder(fname)
2170//      if(err)
2171//              Print "DataFolder kill err = ",err
2172//      endif
2173        return(err)
2174end
2175
2176Function V_writeWhiteBeamWavel_spread(fname,val)
2177        String fname
2178        Variable val
2179       
2180//      String path = "entry:instrument:beam:monochromator:white_beam:wavelength_spread"       
2181       
2182        Make/O/D/N=1 wTmpWrite
2183//      Make/O/R/N=1 wTmpWrite
2184        String groupName = "/entry/instrument/beam/monochromator/white_beam"   
2185        String varName = "wavelength_spread"
2186        wTmpWrite[0] = val
2187
2188        variable err
2189        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2190        if(err)
2191                Print "HDF write err = ",err
2192        endif
2193        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2194//      err = V_KillNamedDataFolder(fname)
2195//      if(err)
2196//              Print "DataFolder kill err = ",err
2197//      endif
2198        return(err)
2199end
2200
2201// instrument/beam/polarizer (data folder)
2202Function V_writePolarizerComposition(fname,str)
2203        String fname,str
2204
2205//      String path = "entry:instrument:beam:polarizer:composition"
2206
2207        Make/O/T/N=1 tmpTW
2208        String groupName = "/entry/instrument/beam/polarizer"   //     
2209        String varName = "composition"
2210        tmpTW[0] = str //
2211
2212        variable err
2213        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2214        if(err)
2215                Print "HDF write err = ",err
2216        endif
2217       
2218        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2219//      err = V_KillNamedDataFolder(fname)
2220//      if(err)
2221//              Print "DataFolder kill err = ",err
2222//      endif
2223               
2224        return(err)
2225End
2226
2227Function V_writePolarizerEfficiency(fname,val)
2228        String fname
2229        Variable val
2230       
2231//      String path = "entry:instrument:beam:polarizer:efficiency"     
2232       
2233        Make/O/D/N=1 wTmpWrite
2234//      Make/O/R/N=1 wTmpWrite
2235        String groupName = "/entry/instrument/beam/polarizer"   
2236        String varName = "efficiency"
2237        wTmpWrite[0] = val
2238
2239        variable err
2240        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2241        if(err)
2242                Print "HDF write err = ",err
2243        endif
2244        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2245//      err = V_KillNamedDataFolder(fname)
2246//      if(err)
2247//              Print "DataFolder kill err = ",err
2248//      endif
2249        return(err)
2250end
2251
2252Function V_writePolarizerStatus(fname,str)
2253        String fname,str
2254
2255//      String path = "entry:instrument:beam:polarizer:status"
2256
2257        Make/O/T/N=1 tmpTW
2258        String groupName = "/entry/instrument/beam/polarizer"   //     
2259        String varName = "status"
2260        tmpTW[0] = str //
2261
2262        variable err
2263        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2264        if(err)
2265                Print "HDF write err = ",err
2266        endif
2267       
2268        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2269//      err = V_KillNamedDataFolder(fname)
2270//      if(err)
2271//              Print "DataFolder kill err = ",err
2272//      endif
2273               
2274        return(err)
2275End
2276
2277Function V_writePolarizerType(fname,str)
2278        String fname,str
2279
2280//      String path = "entry:instrument:beam:polarizer:type"
2281
2282        Make/O/T/N=1 tmpTW
2283        String groupName = "/entry/instrument/beam/polarizer"   //     
2284        String varName = "type"
2285        tmpTW[0] = str //
2286
2287        variable err
2288        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2289        if(err)
2290                Print "HDF write err = ",err
2291        endif
2292       
2293        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2294//      err = V_KillNamedDataFolder(fname)
2295//      if(err)
2296//              Print "DataFolder kill err = ",err
2297//      endif
2298               
2299        return(err)
2300End
2301
2302// instrument/beam/polarizer_analyzer (data folder)
2303Function V_writePolAnaCell_index(fname,val)
2304        String fname
2305        Variable val
2306
2307//      String path = "entry:instrument:beam:polarizer_analyzer:cell_index"
2308       
2309        Make/O/D/N=1 wTmpWrite
2310//      Make/O/R/N=1 wTmpWrite
2311        String groupName = "/entry/instrument/beam/polarizer_analyzer" 
2312        String varName = "cell_index"
2313        wTmpWrite[0] = val
2314
2315        variable err
2316        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2317        if(err)
2318                Print "HDF write err = ",err
2319        endif
2320        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2321//      err = V_KillNamedDataFolder(fname)
2322//      if(err)
2323//              Print "DataFolder kill err = ",err
2324//      endif
2325        return(err)
2326End
2327
2328Function V_writePolAnaCell_name(fname,str)
2329        String fname,str
2330
2331//      String path = "entry:instrument:beam:polarizer_analyzer:cell_name"
2332
2333        Make/O/T/N=1 tmpTW
2334        String groupName = "/entry/instrument/beam/polarizer_analyzer"  //     
2335        String varName = "cell_name"
2336        tmpTW[0] = str //
2337
2338        variable err
2339        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2340        if(err)
2341                Print "HDF write err = ",err
2342        endif
2343       
2344        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2345//      err = V_KillNamedDataFolder(fname)
2346//      if(err)
2347//              Print "DataFolder kill err = ",err
2348//      endif
2349               
2350        return(err)
2351End
2352
2353Function V_writePolAnaCell_parameters(fname,inW)
2354        String fname
2355        Wave inW
2356
2357//      String path = "entry:instrument:beam:polarizer_analyzer:cell_parameters"
2358
2359        Duplicate/O inW wTmpWrite       
2360// then use redimension as needed to cast the wave to write to the specified type
2361// see WaveType for the proper codes
2362//      Redimension/T=() wTmpWrite
2363// -- May also need to check the dimension(s) before writing (don't trust the input)
2364        String groupName = "/entry/instrument//beam/polarizer_analyzer"
2365        String varName = "cell_parameters"
2366
2367        variable err
2368        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2369        if(err)
2370                Print "HDF write err = ",err
2371        endif
2372        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2373//      err = V_KillNamedDataFolder(fname)
2374//      if(err)
2375//              Print "DataFolder kill err = ",err
2376//      endif
2377        return(err)
2378End
2379
2380Function V_writePolAnaGuideFieldCur_1(fname,val)
2381        String fname
2382        Variable val
2383
2384//      String path = "entry:instrument:beam:polarizer_analyzer:guide_field_current_1"
2385       
2386        Make/O/D/N=1 wTmpWrite
2387//      Make/O/R/N=1 wTmpWrite
2388        String groupName = "/entry/instrument/beam/polarizer_analyzer" 
2389        String varName = "guide_field_current_1"
2390        wTmpWrite[0] = val
2391
2392        variable err
2393        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2394        if(err)
2395                Print "HDF write err = ",err
2396        endif
2397        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2398//      err = V_KillNamedDataFolder(fname)
2399//      if(err)
2400//              Print "DataFolder kill err = ",err
2401//      endif
2402        return(err)
2403End
2404
2405Function V_writePolAnaGuideFieldCur_2(fname,val)
2406        String fname
2407        Variable val
2408
2409//      String path = "entry:instrument:beam:polarizer_analyzer:guide_field_current_2"
2410       
2411        Make/O/D/N=1 wTmpWrite
2412//      Make/O/R/N=1 wTmpWrite
2413        String groupName = "/entry/instrument/beam/polarizer_analyzer" 
2414        String varName = "guide_field_current_2"
2415        wTmpWrite[0] = val
2416
2417        variable err
2418        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2419        if(err)
2420                Print "HDF write err = ",err
2421        endif
2422        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2423//      err = V_KillNamedDataFolder(fname)
2424//      if(err)
2425//              Print "DataFolder kill err = ",err
2426//      endif
2427        return(err)
2428End
2429
2430Function V_writePolAnaSolenoid_current(fname,val)
2431        String fname
2432        Variable val
2433
2434//      String path = "entry:instrument:beam:polarizer_analyzer:solenoid_current"
2435       
2436        Make/O/D/N=1 wTmpWrite
2437//      Make/O/R/N=1 wTmpWrite
2438        String groupName = "/entry/instrument/beam/polarizer_analyzer" 
2439        String varName = "solenoid_current"
2440        wTmpWrite[0] = val
2441
2442        variable err
2443        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2444        if(err)
2445                Print "HDF write err = ",err
2446        endif
2447        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2448//      err = V_KillNamedDataFolder(fname)
2449//      if(err)
2450//              Print "DataFolder kill err = ",err
2451//      endif
2452        return(err)
2453End
2454
2455Function V_writePolAnaStatus(fname,str)
2456        String fname,str
2457
2458//      String path = "entry:instrument:beam:polarizer_analyzer:status"
2459
2460        Make/O/T/N=1 tmpTW
2461        String groupName = "/entry/instrument/beam/polarizer_analyzer"  //     
2462        String varName = "status"
2463        tmpTW[0] = str //
2464
2465        variable err
2466        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2467        if(err)
2468                Print "HDF write err = ",err
2469        endif
2470       
2471        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2472//      err = V_KillNamedDataFolder(fname)
2473//      if(err)
2474//              Print "DataFolder kill err = ",err
2475//      endif
2476               
2477        return(err)
2478End
2479
2480                                       
2481/////// INSTRUMENT/BEAM MONITORS
2482
2483//beam_monitor_low (data folder)
2484Function V_writeBeamMonLowData(fname,val)
2485        String fname
2486        Variable val
2487
2488//      String path = "entry:instrument:beam_monitor_low:data"
2489       
2490        Make/O/D/N=1 wTmpWrite
2491//      Make/O/R/N=1 wTmpWrite
2492        String groupName = "/entry/instrument/beam_monitor_low"
2493        String varName = "data"
2494        wTmpWrite[0] = val
2495
2496        variable err
2497        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2498        if(err)
2499                Print "HDF write err = ",err
2500        endif
2501        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2502//      err = V_KillNamedDataFolder(fname)
2503//      if(err)
2504//              Print "DataFolder kill err = ",err
2505//      endif
2506        return(err)
2507End
2508
2509Function V_writeBeamMonLowEfficiency(fname,val)
2510        String fname
2511        Variable val
2512
2513//      String path = "entry:instrument:beam_monitor_low:efficiency"
2514       
2515        Make/O/D/N=1 wTmpWrite
2516//      Make/O/R/N=1 wTmpWrite
2517        String groupName = "/entry/instrument/beam_monitor_low"
2518        String varName = "efficiency"
2519        wTmpWrite[0] = val
2520
2521        variable err
2522        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2523        if(err)
2524                Print "HDF write err = ",err
2525        endif
2526        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2527//      err = V_KillNamedDataFolder(fname)
2528//      if(err)
2529//              Print "DataFolder kill err = ",err
2530//      endif
2531        return(err)
2532End
2533
2534Function V_writeBeamMonLowDistance(fname,val)
2535        String fname
2536        Variable val
2537
2538//      String path = "entry:instrument:beam_monitor_low:distance"
2539       
2540        Make/O/D/N=1 wTmpWrite
2541//      Make/O/R/N=1 wTmpWrite
2542        String groupName = "/entry/instrument/beam_monitor_low"
2543        String varName = "distance"
2544        wTmpWrite[0] = val
2545
2546        variable err
2547        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2548        if(err)
2549                Print "HDF write err = ",err
2550        endif
2551        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2552//      err = V_KillNamedDataFolder(fname)
2553//      if(err)
2554//              Print "DataFolder kill err = ",err
2555//      endif
2556        return(err)
2557End
2558
2559Function V_writeBeamMonLowSaved_count(fname,val)
2560        String fname
2561        Variable val
2562
2563//      String path = "entry:instrument:beam_monitor_low:saved_count"
2564       
2565        Make/O/D/N=1 wTmpWrite
2566//      Make/O/R/N=1 wTmpWrite
2567        String groupName = "/entry/instrument/beam_monitor_low"
2568        String varName = "saved_count"
2569        wTmpWrite[0] = val
2570
2571        variable err
2572        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2573        if(err)
2574                Print "HDF write err = ",err
2575        endif
2576        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2577//      err = V_KillNamedDataFolder(fname)
2578//      if(err)
2579//              Print "DataFolder kill err = ",err
2580//      endif
2581        return(err)
2582End
2583
2584Function V_writeBeamMonLowType(fname,str)
2585        String fname,str
2586
2587//      String path = "entry:instrument:beam_monitor_low:type"
2588
2589        Make/O/T/N=1 tmpTW
2590        String groupName = "/entry/instrument/beam_monitor_low" //     
2591        String varName = "type"
2592        tmpTW[0] = str //
2593
2594        variable err
2595        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2596        if(err)
2597                Print "HDF write err = ",err
2598        endif
2599       
2600        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2601//      err = V_KillNamedDataFolder(fname)
2602//      if(err)
2603//              Print "DataFolder kill err = ",err
2604//      endif
2605               
2606        return(err)
2607End
2608
2609//beam_monitor_norm (data folder)
2610Function V_writeBeamMonNormData(fname,val)
2611        String fname
2612        Variable val
2613
2614//      String path = "entry:instrument:beam_monitor_norm:data"
2615       
2616        Make/O/D/N=1 wTmpWrite
2617//      Make/O/R/N=1 wTmpWrite
2618        String groupName = "/entry/instrument/beam_monitor_norm"       
2619        String varName = "data"
2620        wTmpWrite[0] = val
2621
2622        variable err
2623        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2624        if(err)
2625                Print "HDF write err = ",err
2626        endif
2627        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2628//      err = V_KillNamedDataFolder(fname)
2629//      if(err)
2630//              Print "DataFolder kill err = ",err
2631//      endif
2632        return(err)
2633End
2634
2635Function V_writeBeamMonNormEfficiency(fname,val)
2636        String fname
2637        Variable val
2638
2639//      String path = "entry:instrument:beam_monitor_norm:efficiency"
2640       
2641        Make/O/D/N=1 wTmpWrite
2642//      Make/O/R/N=1 wTmpWrite
2643        String groupName = "/entry/instrument/beam_monitor_norm"       
2644        String varName = "efficiency"
2645        wTmpWrite[0] = val
2646
2647        variable err
2648        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2649        if(err)
2650                Print "HDF write err = ",err
2651        endif
2652        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2653//      err = V_KillNamedDataFolder(fname)
2654//      if(err)
2655//              Print "DataFolder kill err = ",err
2656//      endif
2657        return(err)
2658End
2659
2660Function V_writeBeamMonNormDistance(fname,val)
2661        String fname
2662        Variable val
2663
2664//      String path = "entry:instrument:beam_monitor_norm:distance"
2665       
2666        Make/O/D/N=1 wTmpWrite
2667//      Make/O/R/N=1 wTmpWrite
2668        String groupName = "/entry/instrument/beam_monitor_norm"       
2669        String varName = "distance"
2670        wTmpWrite[0] = val
2671
2672        variable err
2673        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2674        if(err)
2675                Print "HDF write err = ",err
2676        endif
2677        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2678//      err = V_KillNamedDataFolder(fname)
2679//      if(err)
2680//              Print "DataFolder kill err = ",err
2681//      endif
2682        return(err)
2683End
2684
2685Function V_writeBeamMonNormSaved_count(fname,val)
2686        String fname
2687        Variable val
2688
2689//      String path = "entry:instrument:beam_monitor_norm:saved_count"
2690       
2691        Make/O/D/N=1 wTmpWrite
2692//      Make/O/R/N=1 wTmpWrite
2693        String groupName = "/entry/instrument/beam_monitor_norm"       
2694        String varName = "saved_count"
2695        wTmpWrite[0] = val
2696
2697        variable err
2698        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2699        if(err)
2700                Print "HDF write err = ",err
2701        endif
2702        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2703//      err = V_KillNamedDataFolder(fname)
2704//      if(err)
2705//              Print "DataFolder kill err = ",err
2706//      endif
2707        return(err)
2708End
2709
2710Function V_writeBeamMonNormType(fname,str)
2711        String fname,str
2712
2713//      String path = "entry:instrument:beam_monitor_norm:type"
2714
2715        Make/O/T/N=1 tmpTW
2716        String groupName = "/entry/instrument/beam_monitor_norm"        //     
2717        String varName = "type"
2718        tmpTW[0] = str //
2719
2720        variable err
2721        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2722        if(err)
2723                Print "HDF write err = ",err
2724        endif
2725       
2726        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2727//      err = V_KillNamedDataFolder(fname)
2728//      if(err)
2729//              Print "DataFolder kill err = ",err
2730//      endif
2731               
2732        return(err)
2733End
2734
2735//beam_stop (data folder)
2736Function V_writeBeamStopDescription(fname,str)
2737        String fname,str
2738
2739//      String path = "entry:instrument:beam_stop:description"
2740
2741        Make/O/T/N=1 tmpTW
2742        String groupName = "/entry/instrument/beam_stop"        //     
2743        String varName = "description"
2744        tmpTW[0] = str //
2745
2746        variable err
2747        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2748        if(err)
2749                Print "HDF write err = ",err
2750        endif
2751       
2752        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2753//      err = V_KillNamedDataFolder(fname)
2754//      if(err)
2755//              Print "DataFolder kill err = ",err
2756//      endif
2757               
2758        return(err)
2759End
2760
2761Function V_writeBeamStopDist_to_det(fname,val)
2762        String fname
2763        Variable val
2764
2765//      String path = "entry:instrument:beam_stop:distance_to_detector"
2766       
2767        Make/O/D/N=1 wTmpWrite
2768//      Make/O/R/N=1 wTmpWrite
2769        String groupName = "/entry/instrument/beam_stop"       
2770        String varName = "distance_to_detector"
2771        wTmpWrite[0] = val
2772
2773        variable err
2774        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2775        if(err)
2776                Print "HDF write err = ",err
2777        endif
2778        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2779//      err = V_KillNamedDataFolder(fname)
2780//      if(err)
2781//              Print "DataFolder kill err = ",err
2782//      endif
2783        return(err)
2784End
2785
2786Function V_writeBeamStop_x_pos(fname,val)
2787        String fname
2788        Variable val
2789
2790//      String path = "entry:instrument:beam_stop:x0"
2791       
2792        Make/O/D/N=1 wTmpWrite
2793//      Make/O/R/N=1 wTmpWrite
2794        String groupName = "/entry/instrument/beam_stop"       
2795        String varName = "x_pos"
2796        wTmpWrite[0] = val
2797
2798        variable err
2799        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2800        if(err)
2801                Print "HDF write err = ",err
2802        endif
2803        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2804//      err = V_KillNamedDataFolder(fname)
2805//      if(err)
2806//              Print "DataFolder kill err = ",err
2807//      endif
2808        return(err)
2809End
2810
2811Function V_writeBeamStop_y_pos(fname,val)
2812        String fname
2813        Variable val
2814
2815//      String path = "entry:instrument:beam_stop:y0"
2816       
2817        Make/O/D/N=1 wTmpWrite
2818//      Make/O/R/N=1 wTmpWrite
2819        String groupName = "/entry/instrument/beam_stop"       
2820        String varName = "y_pos"
2821        wTmpWrite[0] = val
2822
2823        variable err
2824        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2825        if(err)
2826                Print "HDF write err = ",err
2827        endif
2828        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2829//      err = V_KillNamedDataFolder(fname)
2830//      if(err)
2831//              Print "DataFolder kill err = ",err
2832//      endif
2833        return(err)
2834End
2835
2836//// INSTRUMENT/COLLIMATOR
2837//collimator (data folder)
2838Function V_writeNumberOfGuides(fname,val)
2839        String fname
2840        Variable val
2841       
2842//      String path = "entry:instrument:collimator:number_guides"
2843       
2844        Make/O/D/N=1 wTmpWrite
2845//      Make/O/R/N=1 wTmpWrite
2846        String groupName = "/entry/instrument/collimator"       
2847        String varName = "number_guides"
2848        wTmpWrite[0] = val
2849
2850        variable err
2851        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2852        if(err)
2853                Print "HDF write err = ",err
2854        endif
2855        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2856//      err = V_KillNamedDataFolder(fname)
2857//      if(err)
2858//              Print "DataFolder kill err = ",err
2859//      endif
2860        return(err)
2861End
2862
2863//                              geometry (data folder)
2864//                                      shape (data folder)
2865Function V_writeGuideShape(fname,str)
2866        String fname,str
2867
2868//      String path = "entry:instrument:collimator:geometry:shape:shape"
2869
2870        Make/O/T/N=1 tmpTW
2871        String groupName = "/entry/instrument/collimator/geometry/shape"        //     
2872        String varName = "shape"
2873        tmpTW[0] = str //
2874
2875        variable err
2876        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2877        if(err)
2878                Print "HDF write err = ",err
2879        endif
2880       
2881        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2882//      err = V_KillNamedDataFolder(fname)
2883//      if(err)
2884//              Print "DataFolder kill err = ",err
2885//      endif
2886               
2887        return(err)
2888End
2889
2890// TODO -- this may need to be a wave to properly describe the dimensions
2891Function V_writeGuideSize(fname,val)
2892        String fname
2893        Variable val
2894
2895//      String path = "entry:instrument:collimator:geometry:shape:size"
2896       
2897        Make/O/D/N=1 wTmpWrite
2898//      Make/O/R/N=1 wTmpWrite
2899        String groupName = "/entry/instrument/collimator/geometry/shape"       
2900        String varName = "size"
2901        wTmpWrite[0] = val
2902
2903        variable err
2904        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2905        if(err)
2906                Print "HDF write err = ",err
2907        endif
2908        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2909//      err = V_KillNamedDataFolder(fname)
2910//      if(err)
2911//              Print "DataFolder kill err = ",err
2912//      endif
2913        return(err)
2914End
2915
2916//                      converging_pinholes (data folder)
2917Function V_writeConvPinholeStatus(fname,str)
2918        String fname,str
2919
2920//      String path = "entry:instrument:converging_pinholes:status"
2921
2922        Make/O/T/N=1 tmpTW
2923        String groupName = "/entry/instrument/converging_pinholes"      //     
2924        String varName = "status"
2925        tmpTW[0] = str //
2926
2927        variable err
2928        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
2929        if(err)
2930                Print "HDF write err = ",err
2931        endif
2932       
2933        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2934//      err = V_KillNamedDataFolder(fname)
2935//      if(err)
2936//              Print "DataFolder kill err = ",err
2937//      endif
2938               
2939        return(err)
2940End
2941
2942//                      converging_slits (not used)
2943
2944
2945
2946////// INSTRUMENT/DETECTORS
2947//                      detector_B (data folder)
2948//
2949// only defined for the "B" detector, and may not be necessary?
2950// TODO -- write to return an ARRAY
2951Function V_writeDet_cal_x(fname,detStr,inW)
2952        String fname,detStr
2953        Wave inW
2954
2955        if(cmpstr(detStr,"B") == 0)
2956//              String path = "entry:instrument:detector_"+detStr+":CALX"
2957               
2958                Duplicate/O inW wTmpWrite       
2959        // then use redimension as needed to cast the wave to write to the specified type
2960        // see WaveType for the proper codes
2961        //      Redimension/T=() wTmpWrite
2962        // -- May also need to check the dimension(s) before writing (don't trust the input)
2963                String groupName = "/entry/instrument/detector_"+detStr
2964                String varName = "cal_x"
2965
2966                variable err
2967                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
2968                if(err)
2969                        Print "HDF write err = ",err
2970                endif
2971                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
2972//              err = V_KillNamedDataFolder(fname)
2973//              if(err)
2974//                      Print "DataFolder kill err = ",err
2975//              endif
2976                return(err)
2977        else
2978                return(0)
2979        endif
2980End
2981
2982// only defined for the "B" detector, and may not be necessary?
2983// TODO -- write to return an ARRAY
2984Function V_writeDet_cal_y(fname,detStr,inW)
2985        String fname,detStr
2986        Wave inW
2987
2988        if(cmpstr(detStr,"B") == 0)
2989//              String path = "entry:instrument:detector_"+detStr+":CALY"
2990
2991                Duplicate/O inW wTmpWrite       
2992        // then use redimension as needed to cast the wave to write to the specified type
2993        // see WaveType for the proper codes
2994        //      Redimension/T=() wTmpWrite
2995        // -- May also need to check the dimension(s) before writing (don't trust the input)
2996                String groupName = "/entry/instrument/detector_"+detStr
2997                String varName = "cal_y"
2998
2999                variable err
3000                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3001                if(err)
3002                        Print "HDF write err = ",err
3003                endif
3004                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3005//              err = V_KillNamedDataFolder(fname)
3006//              if(err)
3007//                      Print "DataFolder kill err = ",err
3008//              endif
3009                return(err)
3010        else
3011                return(0)
3012        endif
3013End
3014
3015// TODO -- write and X and Y version of this. Pixels are not square
3016// so the FHWM will be different in each direction. May need to return
3017// "dummy" value for "B" detector if pixels there are square
3018Function V_writeDet_pixel_fwhm_x(fname,detStr,val)
3019        String fname,detStr
3020        Variable val
3021
3022//      String path = "entry:instrument:detector_"+detStr+":pixel_fwhm_x"
3023       
3024        Make/O/D/N=1 wTmpWrite
3025//      Make/O/R/N=1 wTmpWrite
3026        String groupName = "/entry/instrument/detector_"+detStr
3027        String varName = "pixel_fwhm_x"
3028        wTmpWrite[0] = val
3029
3030        variable err
3031        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3032        if(err)
3033                Print "HDF write err = ",err
3034        endif
3035        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3036//      err = V_KillNamedDataFolder(fname)
3037//      if(err)
3038//              Print "DataFolder kill err = ",err
3039//      endif
3040        return(err)
3041End
3042
3043
3044// TODO -- write and X and Y version of this. Pixels are not square
3045// so the FHWM will be different in each direction. May need to return
3046// "dummy" value for "B" detector if pixels there are square
3047Function V_writeDet_pixel_fwhm_y(fname,detStr,val)
3048        String fname,detStr
3049        Variable val
3050
3051//      String path = "entry:instrument:detector_"+detStr+":pixel_fwhm_y"
3052       
3053        Make/O/D/N=1 wTmpWrite
3054//      Make/O/R/N=1 wTmpWrite
3055        String groupName = "/entry/instrument/detector_"+detStr
3056        String varName = "pixel_fwhm_y"
3057        wTmpWrite[0] = val
3058
3059        variable err
3060        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3061        if(err)
3062                Print "HDF write err = ",err
3063        endif
3064        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3065//      err = V_KillNamedDataFolder(fname)
3066//      if(err)
3067//              Print "DataFolder kill err = ",err
3068//      endif
3069        return(err)
3070End
3071
3072
3073Function V_writeDet_pixel_num_x(fname,detStr,val)
3074        String fname,detStr
3075        Variable val
3076
3077//      String path = "entry:instrument:detector_"+detStr+":pixel_nnum_x"
3078       
3079        Make/O/D/N=1 wTmpWrite
3080//      Make/O/R/N=1 wTmpWrite
3081        String groupName = "/entry/instrument/detector_"+detStr
3082        String varName = "pixel_num_x"
3083        wTmpWrite[0] = val
3084
3085        variable err
3086        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3087        if(err)
3088                Print "HDF write err = ",err
3089        endif
3090        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3091//      err = V_KillNamedDataFolder(fname)
3092//      if(err)
3093//              Print "DataFolder kill err = ",err
3094//      endif
3095        return(err)
3096End
3097
3098Function V_writeDet_pixel_num_y(fname,detStr,val)
3099        String fname,detStr
3100        Variable val
3101
3102//      String path = "entry:instrument:detector_"+detStr+":pixel_num_y"
3103       
3104        Make/O/D/N=1 wTmpWrite
3105//      Make/O/R/N=1 wTmpWrite
3106        String groupName = "/entry/instrument/detector_"+detStr
3107        String varName = "pixel_num_y"
3108        wTmpWrite[0] = val
3109
3110        variable err
3111        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3112        if(err)
3113                Print "HDF write err = ",err
3114        endif
3115        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3116//      err = V_KillNamedDataFolder(fname)
3117//      if(err)
3118//              Print "DataFolder kill err = ",err
3119//      endif
3120        return(err)
3121End
3122
3123// only defined for the "B" detector, and only to satisfy NXsas
3124Function V_writeDet_azimuthalAngle(fname,detStr,val)
3125        String fname,detStr
3126        Variable val
3127
3128        if(cmpstr(detStr,"B") == 0)
3129//              String path = "entry:instrument:detector_"+detStr+":azimuthal_angle"
3130       
3131                Make/O/D/N=1 wTmpWrite
3132        //      Make/O/R/N=1 wTmpWrite
3133                String groupName = "/entry/instrument/detector_"+detStr
3134                String varName = "azimuthal_angle"
3135                wTmpWrite[0] = val
3136
3137                variable err
3138                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3139                if(err)
3140                        Print "HDF write err = ",err
3141                endif
3142                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3143//              err = V_KillNamedDataFolder(fname)
3144//              if(err)
3145//                      Print "DataFolder kill err = ",err
3146//              endif
3147                return(err)
3148        else
3149                return(0)
3150        endif
3151End
3152
3153Function V_writeDet_beam_center_x(fname,detStr,val)
3154        String fname,detStr
3155        Variable val
3156
3157//      String path = "entry:instrument:detector_"+detStr+":beam_center_x"
3158       
3159        Make/O/D/N=1 wTmpWrite
3160//      Make/O/R/N=1 wTmpWrite
3161        String groupName = "/entry/instrument/detector_"+detStr
3162        String varName = "beam_center_x"
3163        wTmpWrite[0] = val
3164
3165        variable err
3166        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3167        if(err)
3168                Print "HDF write err = ",err
3169        endif
3170        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3171//      err = V_KillNamedDataFolder(fname)
3172//      if(err)
3173//              Print "DataFolder kill err = ",err
3174//      endif
3175        return(err)
3176End
3177
3178// fname is a local WORK folder
3179Function V_putDet_beam_center_x(fname,detStr,val)
3180        String fname,detStr
3181        Variable val
3182
3183//root:Packages:NIST:VSANS:RAW:entry:entry:instrument:detector_FB:beam_center_x
3184        String path = "root:Packages:NIST:VSANS:"+fname+":entry:"
3185        path += "entry:instrument:detector_"+detStr+":beam_center_x"
3186       
3187        Wave/Z w = $path
3188        if(waveExists(w) == 0)
3189                return(1)
3190        else
3191        w[0] = val
3192                return(0)
3193        endif
3194
3195End
3196
3197Function V_writeDet_beam_center_y(fname,detStr,val)
3198        String fname,detStr
3199        Variable val
3200
3201//      String path = "entry:instrument:detector_"+detStr+":beam_center_y"
3202       
3203        Make/O/D/N=1 wTmpWrite
3204//      Make/O/R/N=1 wTmpWrite
3205        String groupName = "/entry/instrument/detector_"+detStr
3206        String varName = "beam_center_y"
3207        wTmpWrite[0] = val
3208
3209        variable err
3210        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3211        if(err)
3212                Print "HDF write err = ",err
3213        endif
3214        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3215//      err = V_KillNamedDataFolder(fname)
3216//      if(err)
3217//              Print "DataFolder kill err = ",err
3218//      endif
3219        return(err)
3220End
3221
3222
3223// fname is a local WORK folder
3224Function V_putDet_beam_center_y(fname,detStr,val)
3225        String fname,detStr
3226        Variable val
3227
3228//root:Packages:NIST:VSANS:RAW:entry:entry:instrument:detector_FB:beam_center_y
3229        String path = "root:Packages:NIST:VSANS:"+fname+":entry:"
3230        path += "entry:instrument:detector_"+detStr+":beam_center_y"
3231       
3232        Wave/Z w = $path
3233        if(waveExists(w) == 0)
3234                return(1)
3235        else
3236        w[0] = val
3237                return(0)
3238        endif
3239
3240End
3241
3242
3243// TODO -- write this function to return a WAVE with the data
3244// either as a wave reference, or as an input parameter
3245Function V_writeDetectorData(fname,detStr,inW)
3246        String fname,detStr
3247        Wave inW
3248
3249//      String path = "entry:instrument:detector_"+detStr+":data"
3250       
3251        Duplicate/O inW wTmpWrite       
3252// then use redimension as needed to cast the wave to write to the specified type
3253// see WaveType for the proper codes
3254//      Redimension/T=() wTmpWrite
3255// -- May also need to check the dimension(s) before writing (don't trust the input)
3256        String groupName = "/entry/instrument/detector_"+detStr
3257        String varName = "data"
3258
3259        variable err
3260        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3261        if(err)
3262                Print "HDF write err = ",err
3263        endif
3264        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3265//      err = V_KillNamedDataFolder(fname)
3266//      if(err)
3267//              Print "DataFolder kill err = ",err
3268//      endif
3269        return(err)
3270End
3271
3272
3273// TODO -- write this function to return a WAVE with the data
3274// either as a wave reference, or as an input parameter
3275// ALSO -- the "B" deadtime will be a single value (probably)
3276//  but the tube banks will be 1D arrays of values, one per tube
3277Function V_writeDetector_deadtime(fname,detStr,inW)
3278        String fname,detStr
3279        Wave inW
3280
3281//      String path = "entry:instrument:detector_"+detStr+":dead_time"
3282       
3283        Duplicate/O inW wTmpWrite       
3284// then use redimension as needed to cast the wave to write to the specified type
3285// see WaveType for the proper codes
3286//      Redimension/T=() wTmpWrite
3287// -- May also need to check the dimension(s) before writing (don't trust the input)
3288        String groupName = "/entry/instrument/detector_"+detStr
3289        String varName = "dead_time"
3290
3291        variable err
3292        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3293        if(err)
3294                Print "HDF write err = ",err
3295        endif
3296        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3297//      err = V_KillNamedDataFolder(fname)
3298//      if(err)
3299//              Print "DataFolder kill err = ",err
3300//      endif
3301        return(err)
3302End
3303
3304
3305Function V_writeDetDescription(fname,detStr,str)
3306        String fname,detStr,str
3307
3308//      String path = "entry:instrument:detector_"+detStr+":description"
3309
3310        Make/O/T/N=1 tmpTW
3311        String groupName = "/entry/instrument/detector_"+detStr //     
3312        String varName = "description"
3313        tmpTW[0] = str //
3314
3315        variable err
3316        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3317        if(err)
3318                Print "HDF write err = ",err
3319        endif
3320       
3321        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3322//      err = V_KillNamedDataFolder(fname)
3323//      if(err)
3324//              Print "DataFolder kill err = ",err
3325//      endif
3326               
3327        return(err)
3328End
3329
3330Function V_writeDet_distance(fname,detStr,val)
3331        String fname,detStr
3332        variable val
3333
3334//      String path = "entry:instrument:detector_"+detStr+":distance"
3335       
3336        Make/O/D/N=1 wTmpWrite
3337//      Make/O/R/N=1 wTmpWrite
3338        String groupName = "/entry/instrument/detector_"+detStr
3339        String varName = "distance"
3340        wTmpWrite[0] = val
3341
3342        variable err
3343        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3344        if(err)
3345                Print "HDF write err = ",err
3346        endif
3347        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3348//      err = V_KillNamedDataFolder(fname)
3349//      if(err)
3350//              Print "DataFolder kill err = ",err
3351//      endif
3352        return(err)
3353End
3354
3355// only defined for the "B" detector, and only to satisfy NXsas
3356Function V_writeDet_equatorial_angle(fname,detStr,val)
3357        String fname,detStr
3358        variable val
3359
3360        if(cmpstr(detStr,"B") == 0)
3361//              String path = "entry:instrument:detector_"+detStr+":equatorial_angle"
3362       
3363                Make/O/D/N=1 wTmpWrite
3364        //      Make/O/R/N=1 wTmpWrite
3365                String groupName = "/entry/instrument/detector_"+detStr
3366                String varName = "equatorial_angle"
3367                wTmpWrite[0] = val
3368
3369                variable err
3370                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3371                if(err)
3372                        Print "HDF write err = ",err
3373                endif
3374                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3375//              err = V_KillNamedDataFolder(fname)
3376//              if(err)
3377//                      Print "DataFolder kill err = ",err
3378//              endif
3379                return(err)
3380        else
3381                return(0)
3382        endif
3383End
3384
3385Function V_writeDetEventFileName(fname,detStr,str)
3386        String fname,detStr,str
3387
3388//      String path = "entry:instrument:detector_"+detStr+":event_file_name"
3389
3390        Make/O/T/N=1 tmpTW
3391        String groupName = "/entry/instrument/detector_"+detStr //     
3392        String varName = "event_file_name"
3393        tmpTW[0] = str //
3394
3395        variable err
3396        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3397        if(err)
3398                Print "HDF write err = ",err
3399        endif
3400       
3401        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3402//      err = V_KillNamedDataFolder(fname)
3403//      if(err)
3404//              Print "DataFolder kill err = ",err
3405//      endif
3406               
3407        return(err)
3408End
3409
3410Function V_writeDet_IntegratedCount(fname,detStr,val)
3411        String fname,detStr
3412        Variable val
3413
3414//      String path = "entry:instrument:detector_"+detStr+":integrated_count"
3415       
3416        Make/O/D/N=1 wTmpWrite
3417//      Make/O/R/N=1 wTmpWrite
3418        String groupName = "/entry/instrument/detector_"+detStr
3419        String varName = "integrated_count"
3420        wTmpWrite[0] = val
3421
3422        variable err
3423        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3424        if(err)
3425                Print "HDF write err = ",err
3426        endif
3427        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3428//      err = V_KillNamedDataFolder(fname)
3429//      if(err)
3430//              Print "DataFolder kill err = ",err
3431//      endif
3432        return(err)
3433End
3434
3435Function V_writeDet_LateralOffset(fname,detStr,val)
3436        String fname,detStr
3437        Variable val
3438
3439//      String path = "entry:instrument:detector_"+detStr+":lateral_offset"
3440       
3441        Make/O/D/N=1 wTmpWrite
3442//      Make/O/R/N=1 wTmpWrite
3443        String groupName = "/entry/instrument/detector_"+detStr
3444        String varName = "lateral_offset"
3445        wTmpWrite[0] = val
3446
3447        variable err
3448        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3449        if(err)
3450                Print "HDF write err = ",err
3451        endif
3452        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3453//      err = V_KillNamedDataFolder(fname)
3454//      if(err)
3455//              Print "DataFolder kill err = ",err
3456//      endif
3457        return(err)
3458End
3459
3460Function V_writeDet_VerticalOffset(fname,detStr,val)
3461        String fname,detStr
3462        Variable val
3463
3464//      String path = "entry:instrument:detector_"+detStr+":vertical_offset"
3465       
3466        Make/O/D/N=1 wTmpWrite
3467//      Make/O/R/N=1 wTmpWrite
3468        String groupName = "/entry/instrument/detector_"+detStr
3469        String varName = "vertical_offset"
3470        wTmpWrite[0] = val
3471
3472        variable err
3473        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3474        if(err)
3475                Print "HDF write err = ",err
3476        endif
3477        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3478//      err = V_KillNamedDataFolder(fname)
3479//      if(err)
3480//              Print "DataFolder kill err = ",err
3481//      endif
3482        return(err)
3483End
3484
3485// only defined for the "B" detector, and only to satisfy NXsas
3486Function V_writeDet_polar_angle(fname,detStr,val)
3487        String fname,detStr
3488        Variable val
3489
3490        if(cmpstr(detStr,"B") == 0)
3491//              String path = "entry:instrument:detector_"+detStr+":polar_angle"
3492       
3493                Make/O/D/N=1 wTmpWrite
3494        //      Make/O/R/N=1 wTmpWrite
3495                String groupName = "/entry/instrument/detector_"+detStr
3496                String varName = "polar_angle"
3497                wTmpWrite[0] = val
3498
3499                variable err
3500                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3501                if(err)
3502                        Print "HDF write err = ",err
3503                endif
3504                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3505//              err = V_KillNamedDataFolder(fname)
3506//              if(err)
3507//                      Print "DataFolder kill err = ",err
3508//              endif
3509                return(err)
3510        else
3511                return(0)
3512        endif
3513End
3514
3515// only defined for the "B" detector, and only to satisfy NXsas
3516Function V_writeDet_rotational_angle(fname,detStr,val)
3517        String fname,detStr
3518        Variable val
3519
3520        if(cmpstr(detStr,"B") == 0)
3521//              String path = "entry:instrument:detector_"+detStr+":rotational_angle"
3522       
3523                Make/O/D/N=1 wTmpWrite
3524        //      Make/O/R/N=1 wTmpWrite
3525                String groupName = "/entry/instrument/detector_"+detStr
3526                String varName = "rotational_angle"
3527                wTmpWrite[0] = val
3528
3529                variable err
3530                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3531                if(err)
3532                        Print "HDF write err = ",err
3533                endif
3534                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3535//              err = V_KillNamedDataFolder(fname)
3536//              if(err)
3537//                      Print "DataFolder kill err = ",err
3538//              endif
3539                return(err)
3540        else
3541                return(0)
3542        endif
3543End
3544
3545Function V_writeDetSettings(fname,detStr,str)
3546        String fname,detStr,str
3547
3548//      String path = "entry:instrument:detector_"+detStr+":settings"
3549
3550        Make/O/T/N=1 tmpTW
3551        String groupName = "/entry/instrument/detector_"+detStr //     
3552        String varName = "settings"
3553        tmpTW[0] = str //
3554
3555        variable err
3556        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3557        if(err)
3558                Print "HDF write err = ",err
3559        endif
3560       
3561        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3562//      err = V_KillNamedDataFolder(fname)
3563//      if(err)
3564//              Print "DataFolder kill err = ",err
3565//      endif
3566               
3567        return(err)
3568End
3569
3570// really has no meaning at all
3571Function V_writeDet_size(fname,detStr,val)
3572        String fname,detStr
3573        Variable val
3574
3575//      String path = "entry:instrument:detector_"+detStr+":size"
3576       
3577        Make/O/D/N=1 wTmpWrite
3578//      Make/O/R/N=1 wTmpWrite
3579        String groupName = "/entry/instrument/detector_"+detStr
3580        String varName = "size"
3581        wTmpWrite[0] = val
3582
3583        variable err
3584        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3585        if(err)
3586                Print "HDF write err = ",err
3587        endif
3588        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3589//      err = V_KillNamedDataFolder(fname)
3590//      if(err)
3591//              Print "DataFolder kill err = ",err
3592//      endif
3593        return(err)
3594End
3595
3596Function V_writeDetType(fname,detStr,str)
3597        String fname,detStr,str
3598
3599//      String path = "entry:instrument:detector_"+detStr+":type"
3600
3601        Make/O/T/N=1 tmpTW
3602        String groupName = "/entry/instrument/detector_"+detStr //     
3603        String varName = "type"
3604        tmpTW[0] = str //
3605
3606        variable err
3607        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3608        if(err)
3609                Print "HDF write err = ",err
3610        endif
3611       
3612        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3613//      err = V_KillNamedDataFolder(fname)
3614//      if(err)
3615//              Print "DataFolder kill err = ",err
3616//      endif
3617               
3618        return(err)
3619End
3620
3621Function V_writeDet_x_pixel_size(fname,detStr,val)
3622        String fname,detStr
3623        Variable val
3624
3625//      String path = "entry:instrument:detector_"+detStr+":x_pixel_size"
3626       
3627        Make/O/D/N=1 wTmpWrite
3628//      Make/O/R/N=1 wTmpWrite
3629        String groupName = "/entry/instrument/detector_"+detStr
3630        String varName = "x_pixel_size"
3631        wTmpWrite[0] = val
3632
3633        variable err
3634        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3635        if(err)
3636                Print "HDF write err = ",err
3637        endif
3638        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3639//      err = V_KillNamedDataFolder(fname)
3640//      if(err)
3641//              Print "DataFolder kill err = ",err
3642//      endif
3643        return(err)
3644End
3645
3646Function V_writeDet_y_pixel_size(fname,detStr,val)
3647        String fname,detStr
3648        Variable val
3649
3650//      String path = "entry:instrument:detector_"+detStr+":y_pixel_size"
3651       
3652        Make/O/D/N=1 wTmpWrite
3653//      Make/O/R/N=1 wTmpWrite
3654        String groupName = "/entry/instrument/detector_"+detStr
3655        String varName = "y_pixel_size"
3656        wTmpWrite[0] = val
3657
3658        variable err
3659        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3660        if(err)
3661                Print "HDF write err = ",err
3662        endif
3663        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3664//      err = V_KillNamedDataFolder(fname)
3665//      if(err)
3666//              Print "DataFolder kill err = ",err
3667//      endif
3668        return(err)
3669End
3670
3671/////////                       detector_FB (data folder) + ALL other PANEL DETECTORS
3672
3673Function V_writeDet_numberOfTubes(fname,detStr,val)
3674        String fname,detStr
3675        Variable val
3676
3677//      String path = "entry:instrument:detector_"+detStr+":number_of_tubes"
3678        if(cmpstr(detStr,"B") == 0)
3679                return(0)
3680        else
3681       
3682                Make/O/D/N=1 wTmpWrite
3683        //      Make/O/R/N=1 wTmpWrite
3684                String groupName = "/entry/instrument/detector_"+detStr
3685                String varName = "number_of_tubes"
3686                wTmpWrite[0] = val
3687
3688                variable err
3689                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3690                if(err)
3691                        Print "HDF write err = ",err
3692                endif
3693                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3694//              err = V_KillNamedDataFolder(fname)
3695//              if(err)
3696//                      Print "DataFolder kill err = ",err
3697//              endif
3698                return(err)
3699        endif
3700End
3701
3702// TODO -- be clear on how this is defined. Separation as defined from what point? Units?
3703Function V_writeDetPanelSeparation(fname,detStr,val)
3704        String fname,detStr
3705        Variable val
3706
3707//      String path = "entry:instrument:detector_"+detStr+":separation"
3708        if(cmpstr(detStr,"B") == 0)
3709                return(0)
3710        else
3711       
3712                Make/O/D/N=1 wTmpWrite
3713        //      Make/O/R/N=1 wTmpWrite
3714                String groupName = "/entry/instrument/detector_"+detStr
3715                String varName = "separation"
3716                wTmpWrite[0] = val
3717
3718                variable err
3719                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3720                if(err)
3721                        Print "HDF write err = ",err
3722                endif
3723                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3724//              err = V_KillNamedDataFolder(fname)
3725//              if(err)
3726//                      Print "DataFolder kill err = ",err
3727//              endif
3728                return(err)
3729        endif
3730End
3731
3732// TODO -- write this function to return a WAVE with the data
3733// either as a wave reference, or as an input parameter
3734Function V_writeDetTube_spatialCalib(fname,detStr,inW)
3735        String fname,detStr
3736        Wave inW
3737
3738//      String path = "entry:instrument:detector_"+detStr+":spatial_calibration"
3739
3740        if(cmpstr(detStr,"B") == 0)
3741                return(0)
3742        else
3743                Duplicate/O inW wTmpWrite       
3744        // then use redimension as needed to cast the wave to write to the specified type
3745        // see WaveType for the proper codes
3746        //      Redimension/T=() wTmpWrite
3747        // -- May also need to check the dimension(s) before writing (don't trust the input)
3748                String groupName = "/entry/instrument/detector_"+detStr
3749                String varName = "spatial_calibration"
3750
3751                variable err
3752                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3753                if(err)
3754                        Print "HDF write err = ",err
3755                endif
3756                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3757//              err = V_KillNamedDataFolder(fname)
3758//              if(err)
3759//                      Print "DataFolder kill err = ",err
3760//              endif
3761                return(err)
3762        endif
3763End
3764
3765// TODO -- be clear on how this is defined.
3766Function V_writeDet_tubeIndex(fname,detStr,val)
3767        String fname,detStr
3768        Variable val
3769
3770//      String path = "entry:instrument:detector_"+detStr+":tube_index"
3771        if(cmpstr(detStr,"B") == 0)
3772                return(0)
3773        else
3774       
3775                Make/O/D/N=1 wTmpWrite
3776        //      Make/O/R/N=1 wTmpWrite
3777                String groupName = "/entry/instrument/detector_"+detStr
3778                String varName = "tube_index"
3779                wTmpWrite[0] = val
3780
3781                variable err
3782                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3783                if(err)
3784                        Print "HDF write err = ",err
3785                endif
3786                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3787//              err = V_KillNamedDataFolder(fname)
3788//              if(err)
3789//                      Print "DataFolder kill err = ",err
3790//              endif
3791                return(err)
3792        endif
3793End
3794
3795Function V_writeDet_tubeOrientation(fname,detStr,str)
3796        String fname,detStr,str
3797
3798//      String path = "entry:instrument:detector_"+detStr+":tube_orientation"
3799
3800        if(cmpstr(detStr,"B") == 0)
3801                return(0)
3802        else
3803                Make/O/T/N=1 tmpTW
3804                String groupName = "/entry/instrument/detector_"+detStr //     
3805                String varName = "tube_orientation"
3806                tmpTW[0] = str //
3807
3808                variable err
3809                err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3810                if(err)
3811                        Print "HDF write err = ",err
3812                endif
3813       
3814                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3815//              err = V_KillNamedDataFolder(fname)
3816//              if(err)
3817//                      Print "DataFolder kill err = ",err
3818//              endif
3819               
3820                return(err)
3821
3822        endif
3823End
3824
3825// TODO -- be clear on how this is defined. Units?
3826Function V_writeDet_tubeWidth(fname,detStr,val)
3827        String fname,detStr
3828        Variable val
3829
3830//      String path = "entry:instrument:detector_"+detStr+":tube_width"
3831        if(cmpstr(detStr,"B") == 0)
3832                return(0)
3833        else
3834       
3835                Make/O/D/N=1 wTmpWrite
3836        //      Make/O/R/N=1 wTmpWrite
3837                String groupName = "/entry/instrument/detector_"+detStr
3838                String varName = "tube_width"
3839                wTmpWrite[0] = val
3840
3841                variable err
3842                err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3843                if(err)
3844                        Print "HDF write err = ",err
3845                endif
3846                // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3847//              err = V_KillNamedDataFolder(fname)
3848//              if(err)
3849//                      Print "DataFolder kill err = ",err
3850//              endif
3851                return(err)
3852        endif
3853End
3854
3855//////////////////////
3856
3857// INSTRUMENT/LENSES    /APERTURES
3858//  lenses (data folder)
3859
3860Function V_writeLensCurvature(fname,val)
3861        String fname
3862        Variable val
3863
3864//      String path = "entry:instrument:lenses:curvature"
3865       
3866        Make/O/D/N=1 wTmpWrite
3867//      Make/O/R/N=1 wTmpWrite
3868        String groupName = "/entry/instrument/lenses"
3869        String varName = "curvature"
3870        wTmpWrite[0] = val
3871
3872        variable err
3873        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3874        if(err)
3875                Print "HDF write err = ",err
3876        endif
3877        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3878//      err = V_KillNamedDataFolder(fname)
3879//      if(err)
3880//              Print "DataFolder kill err = ",err
3881//      endif
3882        return(err)
3883End
3884
3885Function V_writeLensesFocusType(fname,str)
3886        String fname,str
3887
3888//      String path = "entry:instrument:lenses:focus_type"
3889
3890        Make/O/T/N=1 tmpTW
3891        String groupName = "/entry/instrument/lenses"
3892        String varName = "focus_type"
3893        tmpTW[0] = str //
3894
3895        variable err
3896        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3897        if(err)
3898                Print "HDF write err = ",err
3899        endif
3900       
3901        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3902//      err = V_KillNamedDataFolder(fname)
3903//      if(err)
3904//              Print "DataFolder kill err = ",err
3905//      endif
3906               
3907        return(err)
3908End
3909
3910Function V_writeLensDistance(fname,val)
3911        String fname
3912        Variable val
3913
3914//      String path = "entry:instrument:lenses:lens_distance"
3915       
3916        Make/O/D/N=1 wTmpWrite
3917//      Make/O/R/N=1 wTmpWrite
3918        String groupName = "/entry/instrument/lenses"
3919        String varName = "lens_distance"
3920        wTmpWrite[0] = val
3921
3922        variable err
3923        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3924        if(err)
3925                Print "HDF write err = ",err
3926        endif
3927        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3928//      err = V_KillNamedDataFolder(fname)
3929//      if(err)
3930//              Print "DataFolder kill err = ",err
3931//      endif
3932        return(err)
3933End
3934
3935Function V_writeLensGeometry(fname,str)
3936        String fname,str
3937
3938//      String path = "entry:instrument:lenses:lens_geometry"
3939
3940        Make/O/T/N=1 tmpTW
3941        String groupName = "/entry/instrument/lenses"
3942        String varName = "lens_geometry"
3943        tmpTW[0] = str //
3944
3945        variable err
3946        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3947        if(err)
3948                Print "HDF write err = ",err
3949        endif
3950       
3951        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3952//      err = V_KillNamedDataFolder(fname)
3953//      if(err)
3954//              Print "DataFolder kill err = ",err
3955//      endif
3956               
3957        return(err)
3958End
3959
3960Function V_writeLensMaterial(fname,str)
3961        String fname,str
3962
3963//      String path = "entry:instrument:lenses:lens_material"
3964
3965        Make/O/T/N=1 tmpTW
3966        String groupName = "/entry/instrument/lenses"
3967        String varName = "lens_material"
3968        tmpTW[0] = str //
3969
3970        variable err
3971        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
3972        if(err)
3973                Print "HDF write err = ",err
3974        endif
3975       
3976        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
3977//      err = V_KillNamedDataFolder(fname)
3978//      if(err)
3979//              Print "DataFolder kill err = ",err
3980//      endif
3981               
3982        return(err)
3983End
3984
3985Function V_writeNumber_of_Lenses(fname,val)
3986        String fname
3987        Variable val
3988
3989//      String path = "entry:instrument:lenses:number_of_lenses"
3990       
3991        Make/O/D/N=1 wTmpWrite
3992//      Make/O/R/N=1 wTmpWrite
3993        String groupName = "/entry/instrument/lenses"
3994        String varName = "number_of_lenses"
3995        wTmpWrite[0] = val
3996
3997        variable err
3998        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
3999        if(err)
4000                Print "HDF write err = ",err
4001        endif
4002        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4003//      err = V_KillNamedDataFolder(fname)
4004//      if(err)
4005//              Print "DataFolder kill err = ",err
4006//      endif
4007        return(err)
4008End
4009
4010Function V_writeNumber_of_prisms(fname,val)
4011        String fname
4012        Variable val
4013
4014//      String path = "entry:instrument:lenses:number_of_prisms"
4015       
4016        Make/O/D/N=1 wTmpWrite
4017//      Make/O/R/N=1 wTmpWrite
4018        String groupName = "/entry/instrument/lenses"
4019        String varName = "number_of_prisms"
4020        wTmpWrite[0] = val
4021
4022        variable err
4023        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4024        if(err)
4025                Print "HDF write err = ",err
4026        endif
4027        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4028//      err = V_KillNamedDataFolder(fname)
4029//      if(err)
4030//              Print "DataFolder kill err = ",err
4031//      endif
4032        return(err)
4033End
4034
4035Function V_writePrism_distance(fname,val)
4036        String fname
4037        Variable val
4038
4039//      String path = "entry:instrument:lenses:prism_distance"
4040       
4041        Make/O/D/N=1 wTmpWrite
4042//      Make/O/R/N=1 wTmpWrite
4043        String groupName = "/entry/instrument/lenses"
4044        String varName = "prism_distance"
4045        wTmpWrite[0] = val
4046
4047        variable err
4048        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4049        if(err)
4050                Print "HDF write err = ",err
4051        endif
4052        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4053//      err = V_KillNamedDataFolder(fname)
4054//      if(err)
4055//              Print "DataFolder kill err = ",err
4056//      endif
4057        return(err)
4058End
4059
4060Function V_writePrismMaterial(fname,str)
4061        String fname,str
4062
4063//      String path = "entry:instrument:lenses:prism_material"
4064
4065        Make/O/T/N=1 tmpTW
4066        String groupName = "/entry/instrument/lenses"
4067        String varName = "prism_material"
4068        tmpTW[0] = str //
4069
4070        variable err
4071        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4072        if(err)
4073                Print "HDF write err = ",err
4074        endif
4075       
4076        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4077//      err = V_KillNamedDataFolder(fname)
4078//      if(err)
4079//              Print "DataFolder kill err = ",err
4080//      endif
4081               
4082        return(err)
4083End
4084
4085// status of lens/prism = lens | prism | both | out
4086Function V_writeLensPrismStatus(fname,str)
4087        String fname,str
4088
4089//      String path = "entry:instrument:lenses:status"
4090
4091        Make/O/T/N=1 tmpTW
4092        String groupName = "/entry/instrument/lenses"
4093        String varName = "status"
4094        tmpTW[0] = str //
4095
4096        variable err
4097        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4098        if(err)
4099                Print "HDF write err = ",err
4100        endif
4101       
4102        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4103//      err = V_KillNamedDataFolder(fname)
4104//      if(err)
4105//              Print "DataFolder kill err = ",err
4106//      endif
4107               
4108        return(err)
4109End
4110       
4111
4112///////  sample_aperture (data folder)
4113
4114Function V_writeSampleAp_Description(fname,str)
4115        String fname,str
4116
4117//      String path = "entry:instrument:sample_aperture:description"
4118
4119        Make/O/T/N=1 tmpTW
4120        String groupName = "/entry/instrument/sample_aperture"
4121        String varName = "description"
4122        tmpTW[0] = str //
4123
4124        variable err
4125        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4126        if(err)
4127                Print "HDF write err = ",err
4128        endif
4129       
4130        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4131//      err = V_KillNamedDataFolder(fname)
4132//      if(err)
4133//              Print "DataFolder kill err = ",err
4134//      endif
4135               
4136        return(err)
4137End
4138
4139Function V_writeSampleAp_distance(fname,val)
4140        String fname
4141        Variable val
4142
4143//      String path = "entry:instrument:sample_aperture:distance"
4144       
4145        Make/O/D/N=1 wTmpWrite
4146//      Make/O/R/N=1 wTmpWrite
4147        String groupName = "/entry/instrument/sample_aperture"
4148        String varName = "distance"
4149        wTmpWrite[0] = val
4150
4151        variable err
4152        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4153        if(err)
4154                Print "HDF write err = ",err
4155        endif
4156        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4157//      err = V_KillNamedDataFolder(fname)
4158//      if(err)
4159//              Print "DataFolder kill err = ",err
4160//      endif
4161        return(err)
4162End
4163//      shape (data folder)
4164
4165Function V_writeSampleAp_shape(fname,str)
4166        String fname,str
4167
4168//      String path = "entry:instrument:sample_aperture:shape:shape"
4169
4170        Make/O/T/N=1 tmpTW
4171        String groupName = "/entry/instrument/sample_aperture/shape"
4172        String varName = "shape"
4173        tmpTW[0] = str //
4174
4175        variable err
4176        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4177        if(err)
4178                Print "HDF write err = ",err
4179        endif
4180       
4181        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4182//      err = V_KillNamedDataFolder(fname)
4183//      if(err)
4184//              Print "DataFolder kill err = ",err
4185//      endif
4186               
4187        return(err)
4188End
4189
4190// TODO -- this needs to return a WAVE, since the shape may be circle, or rectangle
4191// and will need to return more than a single dimension
4192// TODO -- be careful of the UNITS
4193Function V_writeSampleAp_size(fname,inW)
4194        String fname
4195        Wave inW
4196
4197//      String path = "entry:instrument:sample_aperture:shape:size"
4198
4199        Duplicate/O inW wTmpWrite       
4200// then use redimension as needed to cast the wave to write to the specified type
4201// see WaveType for the proper codes
4202//      Redimension/T=() wTmpWrite
4203// -- May also need to check the dimension(s) before writing (don't trust the input)
4204        String groupName = "/entry/instrument/sample_aperture/shape"   
4205        String varName = "size"
4206
4207        variable err
4208        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4209        if(err)
4210                Print "HDF write err = ",err
4211        endif
4212        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4213//      err = V_KillNamedDataFolder(fname)
4214//      if(err)
4215//              Print "DataFolder kill err = ",err
4216//      endif
4217        return(err)
4218End     
4219
4220
4221///////  sample_aperture_2 (data folder)
4222
4223Function V_writeSampleAp2_Description(fname,str)
4224        String fname,str
4225
4226//      String path = "entry:instrument:sample_aperture_2:description"
4227
4228        Make/O/T/N=1 tmpTW
4229        String groupName = "/entry/instrument/sample_aperture_2"
4230        String varName = "description"
4231        tmpTW[0] = str //
4232
4233        variable err
4234        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4235        if(err)
4236                Print "HDF write err = ",err
4237        endif
4238       
4239        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4240//      err = V_KillNamedDataFolder(fname)
4241//      if(err)
4242//              Print "DataFolder kill err = ",err
4243//      endif
4244               
4245        return(err)
4246End
4247
4248Function V_writeSampleAp2_distance(fname,val)
4249        String fname
4250        Variable val
4251
4252//      String path = "entry:instrument:sample_aperture_2:distance"
4253       
4254        Make/O/D/N=1 wTmpWrite
4255//      Make/O/R/N=1 wTmpWrite
4256        String groupName = "/entry/instrument/sample_aperture_2"
4257        String varName = "distance"
4258        wTmpWrite[0] = val
4259
4260        variable err
4261        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4262        if(err)
4263                Print "HDF write err = ",err
4264        endif
4265        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4266//      err = V_KillNamedDataFolder(fname)
4267//      if(err)
4268//              Print "DataFolder kill err = ",err
4269//      endif
4270        return(err)
4271End
4272//      shape (data folder)
4273
4274Function V_writeSampleAp2_shape(fname,str)
4275        String fname,str
4276
4277//      String path = "entry:instrument:sample_aperture_2:shape:shape"
4278
4279        Make/O/T/N=1 tmpTW
4280        String groupName = "/entry/instrument/sample_aperture_2/shape"
4281        String varName = "shape"
4282        tmpTW[0] = str //
4283
4284        variable err
4285        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4286        if(err)
4287                Print "HDF write err = ",err
4288        endif
4289       
4290        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4291//      err = V_KillNamedDataFolder(fname)
4292//      if(err)
4293//              Print "DataFolder kill err = ",err
4294//      endif
4295               
4296        return(err)
4297End
4298
4299// TODO -- this needs to return a WAVE, since the shape may be circle, or rectangle
4300// and will need to return more than a single dimension
4301// TODO -- be careful of the UNITS
4302Function V_writeSampleAp2_size(fname,inW)
4303        String fname
4304        Wave inW
4305
4306//      String path = "entry:instrument:sample_aperture_2:shape:size"
4307
4308        Duplicate/O inW wTmpWrite       
4309// then use redimension as needed to cast the wave to write to the specified type
4310// see WaveType for the proper codes
4311//      Redimension/T=() wTmpWrite
4312// -- May also need to check the dimension(s) before writing (don't trust the input)
4313        String groupName = "/entry/instrument/sample_aperture_2/shape" 
4314        String varName = "size"
4315
4316        variable err
4317        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4318        if(err)
4319                Print "HDF write err = ",err
4320        endif
4321        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4322//      err = V_KillNamedDataFolder(fname)
4323//      if(err)
4324//              Print "DataFolder kill err = ",err
4325//      endif
4326        return(err)
4327End     
4328
4329               
4330//////  sample_table (data folder)
4331// location  = "CHAMBER" or HUBER
4332Function V_writeSampleTableLocation(fname,str)
4333        String fname,str
4334
4335//      String path = "entry:instrument:sample_table:location"
4336
4337        Make/O/T/N=1 tmpTW
4338        String groupName = "/entry/instrument/sample_table"
4339        String varName = "location"
4340        tmpTW[0] = str //
4341
4342        variable err
4343        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4344        if(err)
4345                Print "HDF write err = ",err
4346        endif
4347       
4348        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4349//      err = V_KillNamedDataFolder(fname)
4350//      if(err)
4351//              Print "DataFolder kill err = ",err
4352//      endif
4353               
4354        return(err)
4355End
4356
4357// TODO - verify the meaning
4358//      offset_distance (?? for center of sample table vs. sample position)
4359Function V_writeSampleTableOffset(fname,val)
4360        String fname
4361        Variable val
4362
4363//      String path = "entry:instrument:sample_table:offset_distance"
4364       
4365        Make/O/D/N=1 wTmpWrite
4366//      Make/O/R/N=1 wTmpWrite
4367        String groupName = "/entry/instrument/sample_table"
4368        String varName = "offset_distance"
4369        wTmpWrite[0] = val
4370
4371        variable err
4372        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4373        if(err)
4374                Print "HDF write err = ",err
4375        endif
4376        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4377//      err = V_KillNamedDataFolder(fname)
4378//      if(err)
4379//              Print "DataFolder kill err = ",err
4380//      endif
4381        return(err)
4382End     
4383       
4384//  source (data folder)
4385//name "NCNR"
4386Function V_writeSourceName(fname,str)
4387        String fname,str
4388
4389//      String path = "entry:instrument:source:name"
4390
4391        Make/O/T/N=1 tmpTW
4392        String groupName = "/entry/instrument/source"
4393        String varName = "name"
4394        tmpTW[0] = str //
4395
4396        variable err
4397        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4398        if(err)
4399                Print "HDF write err = ",err
4400        endif
4401       
4402        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4403//      err = V_KillNamedDataFolder(fname)
4404//      if(err)
4405//              Print "DataFolder kill err = ",err
4406//      endif
4407               
4408        return(err)
4409End
4410
4411//      power -- nominal only, not connected to any real number
4412Function V_writeReactorPower(fname,val)
4413        String fname
4414        Variable val
4415
4416//      String path = "entry:instrument:source:power"
4417       
4418        Make/O/D/N=1 wTmpWrite
4419//      Make/O/R/N=1 wTmpWrite
4420        String groupName = "/entry/instrument/source"
4421        String varName = "power"
4422        wTmpWrite[0] = val
4423
4424        variable err
4425        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4426        if(err)
4427                Print "HDF write err = ",err
4428        endif
4429        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4430//      err = V_KillNamedDataFolder(fname)
4431//      if(err)
4432//              Print "DataFolder kill err = ",err
4433//      endif
4434        return(err)
4435End     
4436
4437//probe (wave) "neutron"
4438Function V_writeSourceProbe(fname,str)
4439        String fname,str
4440
4441//      String path = "entry:instrument:source:probe"
4442
4443        Make/O/T/N=1 tmpTW
4444        String groupName = "/entry/instrument/source"
4445        String varName = "probe"
4446        tmpTW[0] = str //
4447
4448        variable err
4449        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4450        if(err)
4451                Print "HDF write err = ",err
4452        endif
4453       
4454        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4455//      err = V_KillNamedDataFolder(fname)
4456//      if(err)
4457//              Print "DataFolder kill err = ",err
4458//      endif
4459               
4460        return(err)
4461End
4462
4463//type (wave) "Reactor Neutron Source"
4464Function V_writeSourceType(fname,str)
4465        String fname,str
4466
4467//      String path = "entry:instrument:source:type"
4468
4469        Make/O/T/N=1 tmpTW
4470        String groupName = "/entry/instrument/source"
4471        String varName = "type"
4472        tmpTW[0] = str //
4473
4474        variable err
4475        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4476        if(err)
4477                Print "HDF write err = ",err
4478        endif
4479       
4480        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4481//      err = V_KillNamedDataFolder(fname)
4482//      if(err)
4483//              Print "DataFolder kill err = ",err
4484//      endif
4485               
4486        return(err)
4487End
4488
4489       
4490///////  source_aperture (data folder)
4491
4492Function V_writeSourceAp_Description(fname,str)
4493        String fname,str
4494
4495//      String path = "entry:instrument:source_aperture:description"
4496
4497        Make/O/T/N=1 tmpTW
4498        String groupName = "/entry/instrument/source_aperture"
4499        String varName = "description"
4500        tmpTW[0] = str //
4501
4502        variable err
4503        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4504        if(err)
4505                Print "HDF write err = ",err
4506        endif
4507       
4508        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4509//      err = V_KillNamedDataFolder(fname)
4510//      if(err)
4511//              Print "DataFolder kill err = ",err
4512//      endif
4513               
4514        return(err)
4515End
4516
4517Function V_writeSourceAp_distance(fname,val)
4518        String fname
4519        Variable val
4520
4521//      String path = "entry:instrument:source_aperture:distance"
4522       
4523        Make/O/D/N=1 wTmpWrite
4524//      Make/O/R/N=1 wTmpWrite
4525        String groupName = "/entry/instrument/source_aperture"
4526        String varName = "distance"
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)
4540End
4541//      shape (data folder)
4542
4543Function V_writeSourceAp_shape(fname,str)
4544        String fname,str
4545
4546//      String path = "entry:instrument:source_aperture:shape:shape"
4547
4548        Make/O/T/N=1 tmpTW
4549        String groupName = "/entry/instrument/source_aperture/shape"
4550        String varName = "shape"
4551        tmpTW[0] = str //
4552
4553        variable err
4554        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4555        if(err)
4556                Print "HDF write err = ",err
4557        endif
4558       
4559        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4560//      err = V_KillNamedDataFolder(fname)
4561//      if(err)
4562//              Print "DataFolder kill err = ",err
4563//      endif
4564               
4565        return(err)
4566End
4567
4568// TODO -- this needs to return a WAVE, since the shape may be circle, or rectangle
4569// and will need to return more than a single dimension
4570// TODO -- be careful of the UNITS
4571Function V_writeSourceAp_size(fname,inW)
4572        String fname
4573        Wave inW
4574
4575//      String path = "entry:instrument:source_aperture:shape:size"
4576
4577        Duplicate/O inW wTmpWrite       
4578// then use redimension as needed to cast the wave to write to the specified type
4579// see WaveType for the proper codes
4580//      Redimension/T=() wTmpWrite
4581// -- May also need to check the dimension(s) before writing (don't trust the input)
4582        String groupName = "/entry/instrument/source_aperture/shape"   
4583        String varName = "size"
4584
4585        variable err
4586        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4587        if(err)
4588                Print "HDF write err = ",err
4589        endif
4590        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4591//      err = V_KillNamedDataFolder(fname)
4592//      if(err)
4593//              Print "DataFolder kill err = ",err
4594//      endif
4595        return(err)
4596End             
4597
4598
4599
4600
4601//////// SAMPLE
4602//////// SAMPLE
4603//////// SAMPLE
4604
4605//Sample position in changer
4606// TODO -- in the NexusWriter, this ends up as a STRING -- which is wrong. it needs to be FP
4607Function V_writeSamplePosition(fname,val)
4608        String fname
4609        Variable val
4610       
4611//      String path = "entry:sample:changer_position"   
4612       
4613        Make/O/D/N=1 wTmpWrite
4614//      Make/O/R/N=1 wTmpWrite
4615        String groupName = "/entry/sample"
4616        String varName = "changer_position"
4617        wTmpWrite[0] = val
4618
4619        variable err
4620        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4621        if(err)
4622                Print "HDF write err = ",err
4623        endif
4624        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4625//      err = V_KillNamedDataFolder(fname)
4626//      if(err)
4627//              Print "DataFolder kill err = ",err
4628//      endif
4629        return(err)
4630end
4631
4632// sample label
4633// TODO: value of num is currently not used
4634Function V_writeSampleDescription(fname,str)
4635        String fname,str
4636
4637//      String path = "entry:sample:description"
4638
4639        Make/O/T/N=1 tmpTW
4640        String groupName = "/entry/sample"
4641        String varName = "description"
4642        tmpTW[0] = str //
4643
4644        variable err
4645        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4646        if(err)
4647                Print "HDF write err = ",err
4648        endif
4649       
4650        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4651//      err = V_KillNamedDataFolder(fname)
4652//      if(err)
4653//              Print "DataFolder kill err = ",err
4654//      endif
4655               
4656        return(err)
4657End
4658
4659//no meaning to this...
4660Function V_writeSample_equatorial_ang(fname,val)
4661        String fname
4662        Variable val
4663       
4664//      String path = "entry:sample:equatorial_angle"   
4665       
4666        Make/O/D/N=1 wTmpWrite
4667//      Make/O/R/N=1 wTmpWrite
4668        String groupName = "/entry/sample"
4669        String varName = "equatorial_angle"
4670        wTmpWrite[0] = val
4671
4672        variable err
4673        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4674        if(err)
4675                Print "HDF write err = ",err
4676        endif
4677        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4678//      err = V_KillNamedDataFolder(fname)
4679//      if(err)
4680//              Print "DataFolder kill err = ",err
4681//      endif
4682        return(err)
4683end
4684
4685// TODO -- do  I need to make sure that this is an integer?
4686// group ID !!! very important for matching up files
4687Function V_writeSample_GroupID(fname,val)
4688        String fname
4689        Variable val
4690       
4691//      String path = "entry:sample:group_id"   
4692       
4693        Make/O/D/N=1 wTmpWrite
4694//      Make/O/R/N=1 wTmpWrite
4695        String groupName = "/entry/sample"
4696        String varName = "group_id"
4697        wTmpWrite[0] = val
4698
4699        variable err
4700        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4701        if(err)
4702                Print "HDF write err = ",err
4703        endif
4704        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4705//      err = V_KillNamedDataFolder(fname)
4706//      if(err)
4707//              Print "DataFolder kill err = ",err
4708//      endif
4709        return(err)
4710end
4711
4712
4713//Sample Rotation Angle
4714Function V_writeSampleRotationAngle(fname,val)
4715        String fname
4716        Variable val
4717       
4718//      String path = "entry:sample:rotation_angle"     
4719       
4720        Make/O/D/N=1 wTmpWrite
4721//      Make/O/R/N=1 wTmpWrite
4722        String groupName = "/entry/sample"
4723        String varName = "rotation_angle"
4724        wTmpWrite[0] = val
4725
4726        variable err
4727        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4728        if(err)
4729                Print "HDF write err = ",err
4730        endif
4731        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4732//      err = V_KillNamedDataFolder(fname)
4733//      if(err)
4734//              Print "DataFolder kill err = ",err
4735//      endif
4736        return(err)
4737end
4738
4739//?? this is huber/chamber??
4740// TODO -- then where is the description of 10CB, etc...
4741Function V_writeSampleHolderDescription(fname,str)
4742        String fname,str
4743
4744//      String path = "entry:sample:sample_holder_description"
4745
4746        Make/O/T/N=1 tmpTW
4747        String groupName = "/entry/sample"
4748        String varName = "sample_holder_description"
4749        tmpTW[0] = str //
4750
4751        variable err
4752        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4753        if(err)
4754                Print "HDF write err = ",err
4755        endif
4756       
4757        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4758//      err = V_KillNamedDataFolder(fname)
4759//      if(err)
4760//              Print "DataFolder kill err = ",err
4761//      endif
4762               
4763        return(err)
4764End
4765
4766//Sample Thickness
4767// TODO -- somehow, this is not set correctly in the acquisition, so NaN results
4768Function V_writeSampleThickness(fname,val)
4769        String fname
4770        Variable val
4771       
4772//      String path = "entry:sample:thickness" 
4773       
4774        Make/O/D/N=1 wTmpWrite
4775//      Make/O/R/N=1 wTmpWrite
4776        String groupName = "/entry/sample"
4777        String varName = "thickness"
4778        wTmpWrite[0] = val
4779
4780        variable err
4781        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4782        if(err)
4783                Print "HDF write err = ",err
4784        endif
4785        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4786//      err = V_KillNamedDataFolder(fname)
4787//      if(err)
4788//              Print "DataFolder kill err = ",err
4789//      endif
4790        return(err)
4791end
4792
4793// sample transmission
4794Function V_writeSampleTransmission(fname,val)
4795        String fname
4796        Variable val
4797       
4798        String path = "entry:sample:transmission"       
4799//      String path = "QKK0037737:data:Transmission"   
4800       
4801        Make/O/D/N=1 wTmpWrite
4802//      Make/O/R/N=1 wTmpWrite
4803        String groupName = "/entry/sample"
4804        String varName = "transmission"
4805        wTmpWrite[0] = val
4806
4807        variable err
4808        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4809        if(err)
4810                Print "HDF write err = ",err
4811        endif
4812        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4813//      err = V_KillNamedDataFolder(fname)
4814//      if(err)
4815//              Print "DataFolder kill err = ",err
4816//      endif
4817        return(err)
4818end
4819
4820//transmission error (one sigma)
4821Function V_writeSampleTransError(fname,val)
4822        String fname
4823        Variable val
4824       
4825//      String path = "entry:sample:transmission_error"
4826       
4827        Make/O/D/N=1 wTmpWrite
4828//      Make/O/R/N=1 wTmpWrite
4829        String groupName = "/entry/sample"
4830        String varName = "transmission_error"
4831        wTmpWrite[0] = val
4832
4833        variable err
4834        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4835        if(err)
4836                Print "HDF write err = ",err
4837        endif
4838        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4839//      err = V_KillNamedDataFolder(fname)
4840//      if(err)
4841//              Print "DataFolder kill err = ",err
4842//      endif
4843        return(err)
4844end
4845
4846
4847
4848//// SAMPLE / DATA LOGS
4849// write this generic , call with the name of the environment log desired
4850//
4851// temperature_1
4852// temperature_2
4853// shear_field
4854// pressure
4855// magnetic_field
4856// electric_field
4857//
4858//////// (for example) electric_field (data folder)
4859
4860Function V_writeLog_attachedTo(fname,logStr,str)
4861        String fname,logStr,str
4862
4863//      String path = "entry:sample:"+logstr+":attached_to"
4864
4865        Make/O/T/N=1 tmpTW
4866        String groupName = "/entry/sample/"+logStr
4867        String varName = "attached_to"
4868        tmpTW[0] = str //
4869
4870        variable err
4871        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4872        if(err)
4873                Print "HDF write err = ",err
4874        endif
4875       
4876        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4877//      err = V_KillNamedDataFolder(fname)
4878//      if(err)
4879//              Print "DataFolder kill err = ",err
4880//      endif
4881               
4882        return(err)
4883End
4884
4885
4886Function V_writeLog_measurement(fname,logStr,str)
4887        String fname,logStr,str
4888
4889        String path = "entry:sample:"+logstr+":measurement"
4890
4891        Make/O/T/N=1 tmpTW
4892        String groupName = "/entry/sample/"+logStr
4893        String varName = "measurement"
4894        tmpTW[0] = str //
4895
4896        variable err
4897        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4898        if(err)
4899                Print "HDF write err = ",err
4900        endif
4901       
4902        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4903//      err = V_KillNamedDataFolder(fname)
4904//      if(err)
4905//              Print "DataFolder kill err = ",err
4906//      endif
4907               
4908        return(err)
4909End
4910
4911
4912Function V_writeLog_Name(fname,logStr,str)
4913        String fname,logStr,str
4914
4915//      String path = "entry:sample:"+logstr+":name"
4916
4917        Make/O/T/N=1 tmpTW
4918        String groupName = "/entry/sample/"+logStr
4919        String varName = "name"
4920        tmpTW[0] = str //
4921
4922        variable err
4923        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4924        if(err)
4925                Print "HDF write err = ",err
4926        endif
4927       
4928        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4929//      err = V_KillNamedDataFolder(fname)
4930//      if(err)
4931//              Print "DataFolder kill err = ",err
4932//      endif
4933               
4934        return(err)
4935End
4936
4937
4938// TODO --
4939Function V_writeLog_nomValue(fname,logStr,val)
4940        String fname,logStr
4941        Variable val
4942       
4943//      String path = "entry:sample:"+logstr+":value"
4944       
4945        Make/O/D/N=1 wTmpWrite
4946//      Make/O/R/N=1 wTmpWrite
4947        String groupName = "/entry/sample/"+logStr
4948        String varName = "value"
4949        wTmpWrite[0] = val
4950
4951        variable err
4952        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
4953        if(err)
4954                Print "HDF write err = ",err
4955        endif
4956        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4957//      err = V_KillNamedDataFolder(fname)
4958//      if(err)
4959//              Print "DataFolder kill err = ",err
4960//      endif
4961        return(err)
4962end
4963
4964////            value_log (data folder)
4965Function V_writeLog_startTime(fname,logStr,str)
4966        String fname,logStr,str
4967
4968//      String path = "entry:sample:"+logstr+":value_log:start"
4969
4970        Make/O/T/N=1 tmpTW
4971        String groupName = "/entry/sample/"+logStr+"/value_log"
4972        String varName = "start"
4973        tmpTW[0] = str //
4974
4975        variable err
4976        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
4977        if(err)
4978                Print "HDF write err = ",err
4979        endif
4980       
4981        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
4982//      err = V_KillNamedDataFolder(fname)
4983//      if(err)
4984//              Print "DataFolder kill err = ",err
4985//      endif
4986               
4987        return(err)
4988End
4989
4990// TODO --
4991Function V_writeLog_avgValue(fname,logStr,val)
4992        String fname,logStr
4993        Variable val
4994       
4995//      String path = "entry:sample:"+logstr+":value_log:average_value"
4996       
4997        Make/O/D/N=1 wTmpWrite
4998//      Make/O/R/N=1 wTmpWrite
4999        String groupName = "/entry/sample/"+logStr+"/value_log"
5000        String varName = "average_value"
5001        wTmpWrite[0] = val
5002
5003        variable err
5004        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5005        if(err)
5006                Print "HDF write err = ",err
5007        endif
5008        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5009//      err = V_KillNamedDataFolder(fname)
5010//      if(err)
5011//              Print "DataFolder kill err = ",err
5012//      endif
5013        return(err)
5014end
5015
5016// TODO -- this needs to be a WAVE reference
5017Function V_writeLog_time(fname,logStr,inW)
5018        String fname,logStr
5019        Wave inW
5020       
5021//      String path = "entry:sample:"+logstr+":value_log:time"
5022
5023        Duplicate/O inW wTmpWrite       
5024// then use redimension as needed to cast the wave to write to the specified type
5025// see WaveType for the proper codes
5026//      Redimension/T=() wTmpWrite
5027// -- May also need to check the dimension(s) before writing (don't trust the input)
5028        String groupName = "/entry/sample/"+logStr+"/value_log"
5029        String varName = "time"
5030
5031        variable err
5032        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5033        if(err)
5034                Print "HDF write err = ",err
5035        endif
5036        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5037//      err = V_KillNamedDataFolder(fname)
5038//      if(err)
5039//              Print "DataFolder kill err = ",err
5040//      endif
5041        return(err)
5042end
5043
5044
5045// TODO -- this needs to be a WAVE reference
5046Function V_writeLog_Value(fname,logStr,inW)
5047        String fname,logStr
5048        Wave inW
5049       
5050//      String path = "entry:sample:"+logstr+":value_log:value"
5051
5052        Duplicate/O inW wTmpWrite       
5053// then use redimension as needed to cast the wave to write to the specified type
5054// see WaveType for the proper codes
5055//      Redimension/T=() wTmpWrite
5056// -- May also need to check the dimension(s) before writing (don't trust the input)
5057        String groupName = "/entry/sample/"+logStr+"/value_log"
5058        String varName = "value"
5059
5060        variable err
5061        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5062        if(err)
5063                Print "HDF write err = ",err
5064        endif
5065        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5066//      err = V_KillNamedDataFolder(fname)
5067//      if(err)
5068//              Print "DataFolder kill err = ",err
5069//      endif
5070        return(err)
5071end
5072
5073
5074
5075///////// REDUCTION
5076///////// REDUCTION
5077///////// REDUCTION
5078
5079
5080// TODO -- needs to be a WAVE, and of the proper size and type!!!
5081Function V_writeAbsolute_Scaling(fname,inW)
5082        String fname
5083        Wave inW
5084       
5085//      String path = "entry:reduction:absolute_scaling"
5086       
5087        Duplicate/O inW wTmpWrite       
5088// then use redimension as needed to cast the wave to write to the specified type
5089// see WaveType for the proper codes
5090//      Redimension/T=() wTmpWrite
5091// -- May also need to check the dimension(s) before writing (don't trust the input)
5092        String groupName = "/entry/reduction"   
5093        String varName = "absolute_scaling"
5094
5095        variable err
5096        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5097        if(err)
5098                Print "HDF write err = ",err
5099        endif
5100        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5101//      err = V_KillNamedDataFolder(fname)
5102//      if(err)
5103//              Print "DataFolder kill err = ",err
5104//      endif
5105        return(err)
5106end
5107
5108// TODO -- needs to be a WAVE
5109Function V_writeBoxCoordinates(fname,inW)
5110        String fname
5111        Wave inW
5112       
5113//      String path = "entry:reduction:box_coordinates"
5114               
5115        Duplicate/O inW wTmpWrite       
5116// then use redimension as needed to cast the wave to write to the specified type
5117// see WaveType for the proper codes
5118//      Redimension/T=() wTmpWrite
5119// -- May also need to check the dimension(s) before writing (don't trust the input)
5120        String groupName = "/entry/reduction"   
5121        String varName = "box_coordinates"
5122
5123        variable err
5124        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5125        if(err)
5126                Print "HDF write err = ",err
5127        endif
5128        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5129//      err = V_KillNamedDataFolder(fname)
5130//      if(err)
5131//              Print "DataFolder kill err = ",err
5132//      endif
5133        return(err)
5134end
5135
5136//box counts
5137Function V_writeBoxCounts(fname,val)
5138        String fname
5139        Variable val
5140       
5141//      String path = "entry:reduction:box_count"       
5142       
5143        Make/O/D/N=1 wTmpWrite
5144//      Make/O/R/N=1 wTmpWrite
5145        String groupName = "/entry/reduction"
5146        String varName = "box_count"
5147        wTmpWrite[0] = val
5148
5149        variable err
5150        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5151        if(err)
5152                Print "HDF write err = ",err
5153        endif
5154        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5155//      err = V_KillNamedDataFolder(fname)
5156//      if(err)
5157//              Print "DataFolder kill err = ",err
5158//      endif
5159        return(err)
5160end
5161
5162//box counts error
5163Function V_writeBoxCountsError(fname,val)
5164        String fname
5165        Variable val
5166       
5167//      String path = "entry:reduction:box_count_error"
5168       
5169        Make/O/D/N=1 wTmpWrite
5170//      Make/O/R/N=1 wTmpWrite
5171        String groupName = "/entry/reduction"
5172        String varName = "box_count_error"
5173        wTmpWrite[0] = val
5174
5175        variable err
5176        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5177        if(err)
5178                Print "HDF write err = ",err
5179        endif
5180        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5181//      err = V_KillNamedDataFolder(fname)
5182//      if(err)
5183//              Print "DataFolder kill err = ",err
5184//      endif
5185        return(err)
5186end
5187
5188Function V_writeReductionComments(fname,str)
5189        String fname,str
5190
5191//      String path = "entry:reduction:comments"       
5192
5193        Make/O/T/N=1 tmpTW
5194        String groupName = "/entry/reduction"
5195        String varName = "comments"
5196        tmpTW[0] = str //
5197
5198        variable err
5199        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5200        if(err)
5201                Print "HDF write err = ",err
5202        endif
5203       
5204        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5205//      err = V_KillNamedDataFolder(fname)
5206//      if(err)
5207//              Print "DataFolder kill err = ",err
5208//      endif
5209               
5210        return(err)
5211End
5212
5213
5214Function V_writeReductionIntent(fname,str)
5215        String fname,str
5216
5217//      String path = "entry:reduction:intent" 
5218
5219        Make/O/T/N=1 tmpTW
5220        String groupName = "/entry/reduction"
5221        String varName = "intent"
5222        tmpTW[0] = str //
5223
5224        variable err
5225        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5226        if(err)
5227                Print "HDF write err = ",err
5228        endif
5229       
5230        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5231//      err = V_KillNamedDataFolder(fname)
5232//      if(err)
5233//              Print "DataFolder kill err = ",err
5234//      endif
5235               
5236        return(err)
5237End
5238
5239
5240Function V_writeLogFileName(fname,str)
5241        String fname,str
5242
5243//      String path = "entry:reduction:sans_log_file_name"     
5244
5245        Make/O/T/N=1 tmpTW
5246        String groupName = "/entry/reduction"
5247        String varName = "sans_log_file_name"
5248        tmpTW[0] = str //
5249
5250        variable err
5251        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5252        if(err)
5253                Print "HDF write err = ",err
5254        endif
5255       
5256        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5257//      err = V_KillNamedDataFolder(fname)
5258//      if(err)
5259//              Print "DataFolder kill err = ",err
5260//      endif
5261               
5262        return(err)
5263End
5264
5265
5266Function V_writeSensitivityFileName(fname,str)
5267        String fname,str
5268
5269//      String path = "entry:reduction:sensitivity_file_name"   
5270
5271        Make/O/T/N=1 tmpTW
5272        String groupName = "/entry/reduction"
5273        String varName = "sensitivity_file_name"
5274        tmpTW[0] = str //
5275
5276        variable err
5277        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5278        if(err)
5279                Print "HDF write err = ",err
5280        endif
5281       
5282        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5283//      err = V_KillNamedDataFolder(fname)
5284//      if(err)
5285//              Print "DataFolder kill err = ",err
5286//      endif
5287               
5288        return(err)
5289End
5290
5291Function V_writeTransmissionFileName(fname,str)
5292        String fname,str
5293
5294//      String path = "entry:reduction:transmission_file_name" 
5295
5296        Make/O/T/N=1 tmpTW
5297        String groupName = "/entry/reduction"
5298        String varName = "transmission_file_name"
5299        tmpTW[0] = str //
5300
5301        variable err
5302        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5303        if(err)
5304                Print "HDF write err = ",err
5305        endif
5306       
5307        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5308//      err = V_KillNamedDataFolder(fname)
5309//      if(err)
5310//              Print "DataFolder kill err = ",err
5311//      endif
5312               
5313        return(err)
5314End
5315
5316Function V_writeEmptyBeamFileName(fname,str)
5317        String fname,str
5318
5319//      String path = "entry:reduction:empty_beam_file_name"   
5320
5321        Make/O/T/N=1 tmpTW
5322        String groupName = "/entry/reduction"
5323        String varName = "empty_beam_file_name"
5324        tmpTW[0] = str //
5325
5326        variable err
5327        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5328        if(err)
5329                Print "HDF write err = ",err
5330        endif
5331       
5332        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5333//      err = V_KillNamedDataFolder(fname)
5334//      if(err)
5335//              Print "DataFolder kill err = ",err
5336//      endif
5337               
5338        return(err)
5339End
5340
5341
5342//whole detector transmission
5343Function V_writeSampleTransWholeDetector(fname,val)
5344        String fname
5345        Variable val
5346       
5347//      String path = "entry:reduction:whole_trans"     
5348       
5349        Make/O/D/N=1 wTmpWrite
5350//      Make/O/R/N=1 wTmpWrite
5351        String groupName = "/entry/reduction"
5352        String varName = "whole_trans"
5353        wTmpWrite[0] = val
5354
5355        variable err
5356        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5357        if(err)
5358                Print "HDF write err = ",err
5359        endif
5360        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5361//      err = V_KillNamedDataFolder(fname)
5362//      if(err)
5363//              Print "DataFolder kill err = ",err
5364//      endif
5365        return(err)
5366end
5367
5368//whole detector transmission error
5369Function V_writeSampleTransWholeDetErr(fname,val)
5370        String fname
5371        Variable val
5372       
5373//      String path = "entry:reduction:whole_trans_error"       
5374       
5375        Make/O/D/N=1 wTmpWrite
5376//      Make/O/R/N=1 wTmpWrite
5377        String groupName = "/entry/reduction"
5378        String varName = "whole_trans_error"
5379        wTmpWrite[0] = val
5380
5381        variable err
5382        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5383        if(err)
5384                Print "HDF write err = ",err
5385        endif
5386        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5387//      err = V_KillNamedDataFolder(fname)
5388//      if(err)
5389//              Print "DataFolder kill err = ",err
5390//      endif
5391        return(err)
5392end
5393
5394                       
5395/////                   pol_sans (data folder)
5396
5397Function V_writePolSANS_cellName(fname,str)
5398        String fname,str
5399
5400//      String path = "entry:reduction:pol_sans:cell_name"     
5401
5402        Make/O/T/N=1 tmpTW
5403        String groupName = "/entry/reduction/pol_sans"
5404        String varName = "cell_name"
5405        tmpTW[0] = str //
5406
5407        variable err
5408        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5409        if(err)
5410                Print "HDF write err = ",err
5411        endif
5412       
5413        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5414//      err = V_KillNamedDataFolder(fname)
5415//      if(err)
5416//              Print "DataFolder kill err = ",err
5417//      endif
5418               
5419        return(err)
5420End
5421
5422
5423// TODO -- needs to be a WAVE
5424// is this a text wave?? if it's mixed names + values, then what?
5425Function V_writePolSANS_cellParams(fname,inW)
5426        String fname
5427        Wave inW
5428       
5429//      String path = "entry:reduction:pol_sans:cell_parameters"
5430               
5431        Duplicate/O inW wTmpWrite       
5432// then use redimension as needed to cast the wave to write to the specified type
5433// see WaveType for the proper codes
5434//      Redimension/T=() wTmpWrite
5435// -- May also need to check the dimension(s) before writing (don't trust the input)
5436        String groupName = "/entry/reduction/pol_sans" 
5437        String varName = "cell_parameters"
5438
5439        variable err
5440        err = V_WriteWaveToHDF(fname, groupName, varName, wTmpWrite)
5441        if(err)
5442                Print "HDF write err = ",err
5443        endif
5444        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5445//      err = V_KillNamedDataFolder(fname)
5446//      if(err)
5447//              Print "DataFolder kill err = ",err
5448//      endif
5449        return(err)
5450end
5451
5452Function V_writePolSANS_PolSANSPurpose(fname,str)
5453        String fname,str
5454
5455//      String path = "entry:reduction:pol_sans:pol_sans_purpose"       
5456
5457        Make/O/T/N=1 tmpTW
5458        String groupName = "/entry/reduction/pol_sans"
5459        String varName = "pol_sans_purpose"
5460        tmpTW[0] = str //
5461
5462        variable err
5463        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5464        if(err)
5465                Print "HDF write err = ",err
5466        endif
5467       
5468        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5469//      err = V_KillNamedDataFolder(fname)
5470//      if(err)
5471//              Print "DataFolder kill err = ",err
5472//      endif
5473               
5474        return(err)
5475End
5476
5477                               
5478//////// TOP LEVEL DATA REPRESENTATION
5479//
5480// note that here the data is (supposed to be) a link, not the actual data
5481// Igor HDf implementation cannot follow links properly, as far as I know.
5482// so ignore them here, and focus on the image that may be possible to read
5483//
5484
5485//              data_B (data folder)
5486//                      data (wave) 1           //ignore this, it's a link
5487//                      variables (wave) 320
5488//                      thumbnail (data folder)
5489
5490//data (wave) "binary"
5491// TODO -- this will need to be completely replaced with a function that can
5492// read the binary image data. should be possible, but I don't know the details on either end...
5493Function V_writeDataImage(fname,detStr,str)
5494        String fname,detStr,str
5495
5496//      String path = "entry:data_"+detStr+":thumbnail:data"   
5497
5498        Make/O/T/N=1 tmpTW
5499        String groupName = "/entry/data_"+detStr+"/thumbnail"
5500        String varName = "data"
5501        tmpTW[0] = str //
5502
5503        variable err
5504        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5505        if(err)
5506                Print "HDF write err = ",err
5507        endif
5508       
5509        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5510//      err = V_KillNamedDataFolder(fname)
5511//      if(err)
5512//              Print "DataFolder kill err = ",err
5513//      endif
5514               
5515        return(err)
5516End
5517
5518Function V_writeDataImageDescription(fname,detStr,str)
5519        String fname,detStr,str
5520
5521//      String path = "entry:data_"+detStr+":thumbnail:description"     
5522
5523        Make/O/T/N=1 tmpTW
5524        String groupName = "/entry/data_"+detStr+"/thumbnail"
5525        String varName = "description"
5526        tmpTW[0] = str //
5527
5528        variable err
5529        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5530        if(err)
5531                Print "HDF write err = ",err
5532        endif
5533       
5534        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5535//      err = V_KillNamedDataFolder(fname)
5536//      if(err)
5537//              Print "DataFolder kill err = ",err
5538//      endif
5539               
5540        return(err)
5541End
5542                                                               
5543Function V_writeDataImageType(fname,detStr,str)
5544        String fname,detStr,str
5545
5546//      String path = "entry:data_"+detStr+":thumbnail:type"   
5547
5548        Make/O/T/N=1 tmpTW
5549        String groupName = "/entry/data_"+detStr+"/thumbnail"
5550        String varName = "type"
5551        tmpTW[0] = str //
5552
5553        variable err
5554        err = V_WriteTextWaveToHDF(fname, groupName, varName, tmpTW)
5555        if(err)
5556                Print "HDF write err = ",err
5557        endif
5558       
5559        // now be sure to kill the data folder to force a re-read of the data next time this file is read in
5560//      err = V_KillNamedDataFolder(fname)
5561//      if(err)
5562//              Print "DataFolder kill err = ",err
5563//      endif
5564               
5565        return(err)
5566End
5567
Note: See TracBrowser for help on using the repository browser.