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

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

more changes, filling in functionality of the initial data correction

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