source: 1dwg/trunk/IgorPro/NISTsasxml.ipf @ 7

Last change on this file since 7 was 7, checked in by prjemian, 13 years ago

use trunk,tags,branches

File size: 12.1 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2        Structure NISTfile
3        string filename
4        string Run
5        string title
6
7        //<SASdata>
8        Wave Q,I,Idev,Qdev,Qmean,Shadowfactor
9        string unitsQ,unitsI,unitsIdev,unitsQdev,unitsQmean,unitsShadowfactor
10
11        Variable flux_monitor
12        string Q_resolution
13
14        //<SASsample>
15        variable sample_thickness
16        string unitssample_thickness
17        variable sample_transmission
18
19        //SASinstrument
20        string nameSASinstrument
21        // SASinstrument/SASsource
22        string radiation
23        string beam_shape
24        variable wavelength
25        string unitswavelength
26        variable wavelength_spread
27        string unitswavelength_spread
28 
29        //<SAScollimation>
30        variable distance_coll
31        string unitsdistance_coll
32        variable source_aperture
33        string unitssource_aperture
34        string typesource_aperture
35        variable sample_aperture
36        string unitssample_aperture
37        string typesample_aperture
38
39        //SASdetector         <SASdetector>
40        variable offset_angle
41        string unitsoffset_angle
42        variable  distance_SD
43        string unitsdistance_SD
44        variable beam_centreX
45        string unitsbeam_centreX
46        variable beam_centreY
47        string unitsbeam_centreY
48        variable pixel_sizeX
49        string unitspixel_sizeX
50        variable pixel_sizeY
51        string unitspixel_sizeY
52        string detectortype
53
54        // <SASprocess name="NCNR-IGOR">
55        string nameSASprocess
56        string SASprocessdate
57        string average_type
58        string SAM_file
59        string BKD_file
60        string EMP_file
61        string DIV_file
62        string MASK_file
63        string ABS_parameters
64        variable TSTAND
65        variable DSTAND
66        string unitsDSTAND
67        variable IZERO
68        variable XSECT
69        string unitsXSECT
70        string SASnote
71        Endstructure
72       
73Function TESTandWRITE(fileName)
74String fileName
75Struct NISTfile nf
76
77nf.run = "SEP06064.SA3_AJJ_L205"
78nf.title = "A1 9m"
79nf.unitsQ = "/Angstrom"
80nf.unitsI = "/cm"
81nf.unitsIdev = "/cm"
82nf.unitsQdev = "/Angstrom"
83nf.unitsQmean = "/Angstrom"
84nf.unitsshadowfactor = "none"
85
86//synthesise data
87make/d/o/n=100 qq,II,Idev,Qdev,qmean,shadowfactor
88qq=0.003+p*0.002
89II=100-p
90Idev=sqrt(II)
91Qdev = 0.01*qq
92qmean = qq
93shadowfactor = 1e-6
94
95Wave nf.q = qq
96Wave nf.I=II
97Wave nf.Idev = Idev
98wave nf.Qdev = Qdev
99wave nf.Qmean = qmean
100wave nf.shadowfactor = shadowfactor
101
102nf.flux_monitor = 1.e8
103nf.Q_resolution = "estimate"
104nf.sample_thickness = 1
105nf.sample_transmission = 0.33476
106nf.unitssample_thickness = "mm"
107
108nf.namesasinstrument = "NG3-SANS"
109nf.radiation = "neutrons"
110nf.beam_shape = "disc"
111nf.wavelength = 6
112nf.unitswavelength = "Angstrom"
113nf.wavelength_spread = 14.3
114nf.unitswavelength_spread="percent"
115
116nf.distance_coll = 10.12
117nf.unitsdistance_coll = "m"
118nf.source_aperture = 50.00
119nf.unitssource_aperture = "mm"
120nf.typesource_aperture = "radius"
121nf.unitssample_aperture = "mm"
122nf.typesample_aperture = "radius"
123
124
125nf.offset_angle = 0.00
126nf.unitsoffset_angle = "deg"
127nf.distance_SD = 9
128nf.unitsdistance_SD="m"
129nf.beam_centreX=68.46
130nf.beam_centreY=64.30
131nf.unitsbeam_centreX = "mm"
132nf.unitsbeam_centreY = "mm"
133nf.pixel_sizeX=5
134nf.pixel_sizeY=5
135nf.unitspixel_sizeX = "mm"
136nf.unitspixel_sizeY = "mm"
137nf.detectortype = "ORNL"
138
139nf.nameSASprocess="NCNR-IGOR"
140nf.SASprocessdate = "03-SEP-2006 11:42:47"
141nf.average_type = "Circular"
142nf.SAM_file = "SEP06064.SA3_AJJ_L205"
143nf.BKD_file = "SEP06064.SA3_AJJ_L205"
144nf.EMP_file = "SEP06064.SA3_AJJ_L205"
145nf.DIV_file = "SEP06064.SA3_AJJ_L205"
146nf.MASK_file = "SEP06064.SA3_AJJ_L205"
147
148nf.TSTAND = 1.00
149nf.DSTAND = 1.00
150nf.unitsDSTAND = "mm"
151nf.IZERO = 230.09
152nf.XSECT = 1.00
153nf.unitsXSECT = "mm"
154
155nf.SASnote = "USER:MASK.COM"
156
157writeNIST(fileName,nf)
158End
159
160Function writeNIST(fileName, NISTfileStruct)
161        //the fileName for the XML file
162        //TODO check that the filename is ok for the OS.
163        String fileName
164        Struct NISTfile &NISTfileStruct
165        //where we are going to store the filereference
166        variable fileID
167
168        //create the sasXML file with SASroot
169        //no namespace, no prefix
170        fileID = xmlcreatefile(fileName,"SASroot","","")
171
172        //create a version attribute for the root element
173        xmlsetAttr(fileID,"/SASroot","","xml_output_version","12.07a")
174
175        //create the SASentry node
176        xmladdnode(fileID,"/SASroot","","SASentry","",1)
177       
178        //create the Run node
179        xmladdnode(fileID,"/SASroot/SASentry","","Run",NISTfileStruct.Run,1)
180       
181        //create the Title node
182        xmladdnode(fileID,"/SASroot/SASentry","","Title",NISTfileStruct.Title,1)
183       
184        //create the SASdata node
185        xmladdnode(fileID,"/SASroot/SASentry","","SASdata","",1)
186       
187        //now for the hard part, write the data
188        variable ii
189        for(ii=0 ; ii<numpnts(NISTfileStruct.Q) ; ii+=1)
190                xmladdnode(fileID,"/SASroot/SASentry/SASdata","","Idata","",1)
191                xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Q",num2str(NISTfileStruct.Q[ii]),1)
192                xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Q","","units",NISTfileStruct.unitsQ)
193
194                xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","I",num2str(NISTfileStruct.I[ii]),1)
195                xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/I","","units",NISTfileStruct.unitsI)
196
197                xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Idev",num2str(NISTfileStruct.Idev[ii]),1)
198                xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Idev","","units",NISTfileStruct.unitsIdev)
199
200                xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Qdev",num2str(NISTfileStruct.Qdev[ii]),1)
201                xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Qdev","","units",NISTfileStruct.unitsQdev)
202
203                xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","Qmean",num2str(NISTfileStruct.Qmean[ii]),1)
204                xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/Qmean","","units",NISTfileStruct.unitsQmean)
205
206                xmladdnode(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]","","shadowfactor",num2str(NISTfileStruct.shadowfactor[ii]),1)
207                xmlsetAttr(fileID,"/SASroot/SASentry/SASdata/Idata["+num2istr(ii+1)+"]/shadowfactor","","units",NISTfileStruct.unitsshadowfactor)
208        endfor
209       
210        //create the flux_monitor node
211        xmladdnode(fileID,"/SASroot/SASentry","","flux_monitor",num2str(NISTfileStruct.flux_monitor),1)
212        //Q_resolution node
213        xmladdnode(fileID,"/SASroot/SASentry","","Q_resolution",NISTfileStruct.Q_resolution,1)
214       
215        //SASsample node
216        xmladdnode(fileID,"/SASroot/SASentry","","SASsample","",1)
217       
218        //sample_thickness
219        xmladdnode(fileID,"/SASroot/SASentry/SASsample","","sample_thickness",num2str(NISTfileStruct.sample_thickness),1)
220        xmlsetAttr(fileID,"/SASroot/SASentry/SASsample/sample_thickness","","units",NISTfileStruct.unitssample_thickness)
221
222        //sample_transmission
223        xmladdnode(fileID,"/SASroot/SASentry/SASsample","","sample_transmission",num2str(NISTfileStruct.sample_transmission),1)
224       
225        //SASinstrumtent
226        xmladdnode(fileID,"/SASroot/SASentry","","SASinstrument","",1)
227        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","name",NISTfileStruct.nameSASinstrument,1)
228       
229        //SASsource
230        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","SASsource","",1)
231        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASsource","","radiation",NISTfileStruct.radiation,1)
232        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASsource","","beam_shape",NISTfileStruct.beam_shape,1)
233        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASsource","","wavelength",num2str(NISTfileStruct.wavelength),1)
234        xmlsetAttr(fileID,"/SASroot/SASentry/SASinstrument/SASsource/wavelength","","units",NISTfileStruct.unitswavelength)
235        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASsource","","wavelength_spread",num2str(NISTfileStruct.wavelength_spread),1)
236        xmlsetAttr(fileID,"/SASroot/SASentry/SASinstrument/SASsource/wavelength_spread","","units",NISTfileStruct.unitswavelength_spread)
237
238        //SAScollimation
239        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","SAScollimation","",1)
240        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SAScollimation","","distance_coll",num2str(NISTfileStruct.distance_coll),1)
241        xmlsetAttr(fileID,"/SASroot/SASentry/SASinstrument/SAScollimation/distance_coll","","units",NISTfileStruct.unitsdistance_coll)
242        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SAScollimation","","source_aperture",num2str(NISTfileStruct.source_aperture),1)
243        xmlsetAttr(fileID,"/SASroot/SASentry/SASinstrument/SAScollimation/source_aperture","","units",NISTfileStruct.unitssource_aperture)
244        xmlsetAttr(fileID,"/SASroot/SASentry/SASinstrument/SAScollimation/source_aperture","","type",NISTfileStruct.typesource_aperture)
245        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SAScollimation","","sample_aperture",num2str(NISTfileStruct.sample_aperture),1)
246        xmlsetAttr(fileID,"/SASroot/SASentry/SASinstrument/SAScollimation/sample_aperture","","units",NISTfileStruct.unitssample_aperture)
247        xmlsetAttr(fileID,"/SASroot/SASentry/SASinstrument/SAScollimation/sample_aperture","","type",NISTfileStruct.typesample_aperture)
248
249        //SASdetector
250        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument","","SASdetector","",1)
251        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASdetector","","offset_angle",num2str(NISTfileStruct.offset_angle),1)
252        xmlsetAttr(fileID,"/SASroot/SASentry/SASinstrument/SASdetector/offset_angle","","units",NISTfileStruct.unitsoffset_angle)
253        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASdetector","","distance_SD",num2str(NISTfileStruct.distance_SD),1)
254        xmlsetAttr(fileID,"/SASroot/SASentry/SASinstrument/SASdetector/distance_SD","","units",NISTfileStruct.unitsdistance_SD)
255        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASdetector","","beam_centreX",num2str(NISTfileStruct.beam_centreX),1)
256        xmlsetAttr(fileID,"/SASroot/SASentry/SASinstrument/SASdetector/beam_centreX","","units",NISTfileStruct.unitsbeam_centreX)
257        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASdetector","","beam_centreY",num2str(NISTfileStruct.beam_centreY),1)
258        xmlsetAttr(fileID,"/SASroot/SASentry/SASinstrument/SASdetector/beam_centreY","","units",NISTfileStruct.unitsbeam_centreY)
259        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASdetector","","pixel_sizeX",num2str(NISTfileStruct.pixel_sizeX),1)
260        xmlsetAttr(fileID,"/SASroot/SASentry/SASinstrument/SASdetector/pixel_sizeX","","units",NISTfileStruct.unitspixel_sizeX)
261        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASdetector","","pixel_sizeY",num2str(NISTfileStruct.pixel_sizeY),1)
262        xmlsetAttr(fileID,"/SASroot/SASentry/SASinstrument/SASdetector/pixel_sizeY","","units",NISTfileStruct.unitspixel_sizeY)
263        xmladdnode(fileID,"/SASroot/SASentry/SASinstrument/SASdetector","","detectortype",NISTfileStruct.detectortype,1)
264
265        //SASprocess
266        xmladdnode(fileID,"/SASroot/SASentry","","SASprocess","",1)
267        xmlsetAttr(fileID,"/SASroot/SASentry/SASprocess","","name",NISTfileStruct.nameSASprocess)
268        xmladdnode(fileID,"/SASroot/SASentry/SASprocess","","date",NISTfileStruct.SASprocessdate,1)
269        xmladdnode(fileID,"/SASroot/SASentry/SASprocess","","average_type",NISTfileStruct.average_type,1)
270        xmladdnode(fileID,"/SASroot/SASentry/SASprocess","","SAM_file",NISTfileStruct.SAM_file,1)
271        xmladdnode(fileID,"/SASroot/SASentry/SASprocess","","BKD_file",NISTfileStruct.BKD_file,1)
272        xmladdnode(fileID,"/SASroot/SASentry/SASprocess","","EMP_file",NISTfileStruct.EMP_file,1)
273        xmladdnode(fileID,"/SASroot/SASentry/SASprocess","","DIV_file",NISTfileStruct.DIV_file,1)
274        xmladdnode(fileID,"/SASroot/SASentry/SASprocess","","MASK_file",NISTfileStruct.MASK_file,1)
275
276        //ABS_parameters
277        xmladdnode(fileID,"/SASroot/SASentry/SASprocess","","ABS_parameters","",1)
278        xmladdnode(fileID,"/SASroot/SASentry/SASprocess/ABS_parameters","","TSTAND",num2str(NISTfileStruct.TSTAND),1)
279        xmladdnode(fileID,"/SASroot/SASentry/SASprocess/ABS_parameters","","DSTAND",num2str(NISTfileStruct.DSTAND),1)
280        xmlsetAttr(fileID,"/SASroot/SASentry/SASprocess/ABS_parameters/DSTAND","","units",NISTfileStruct.unitsDSTAND)
281        xmladdnode(fileID,"/SASroot/SASentry/SASprocess/ABS_parameters","","IZERO",num2str(NISTfileStruct.IZERO),1)
282        xmladdnode(fileID,"/SASroot/SASentry/SASprocess/ABS_parameters","","XSECT",num2str(NISTfileStruct.XSECT),1)
283        xmlsetAttr(fileID,"/SASroot/SASentry/SASprocess/ABS_parameters/XSECT","","units",NISTfileStruct.unitsXSECT)
284       
285        //SASnote
286        xmladdnode(fileID,"/SASroot/SASentry/SASprocess","","SASnote",NISTfileStruct.SASnote,1)
287
288        //save and close the file
289        xmlsavefile(fileID)
290        xmlclosefile(fileID,0)
291
292End
Note: See TracBrowser for help on using the repository browser.