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

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

more additions to start the work file flow of converting RAW folder to a WORK folder. Raw_to_Work will be the function that sequentially applies the corrections. All corrections can be turned on/off with preferences.

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