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

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

more additions and corrections to the V_get and V_write functions

creating a folder (not root) for the raw data files to be loaded

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