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 | |
---|
73 | Function TESTandWRITE(fileName) |
---|
74 | String fileName |
---|
75 | Struct NISTfile nf |
---|
76 | |
---|
77 | nf.run = "SEP06064.SA3_AJJ_L205" |
---|
78 | nf.title = "A1 9m" |
---|
79 | nf.unitsQ = "/Angstrom" |
---|
80 | nf.unitsI = "/cm" |
---|
81 | nf.unitsIdev = "/cm" |
---|
82 | nf.unitsQdev = "/Angstrom" |
---|
83 | nf.unitsQmean = "/Angstrom" |
---|
84 | nf.unitsshadowfactor = "none" |
---|
85 | |
---|
86 | //synthesise data |
---|
87 | make/d/o/n=100 qq,II,Idev,Qdev,qmean,shadowfactor |
---|
88 | qq=0.003+p*0.002 |
---|
89 | II=100-p |
---|
90 | Idev=sqrt(II) |
---|
91 | Qdev = 0.01*qq |
---|
92 | qmean = qq |
---|
93 | shadowfactor = 1e-6 |
---|
94 | |
---|
95 | Wave nf.q = qq |
---|
96 | Wave nf.I=II |
---|
97 | Wave nf.Idev = Idev |
---|
98 | wave nf.Qdev = Qdev |
---|
99 | wave nf.Qmean = qmean |
---|
100 | wave nf.shadowfactor = shadowfactor |
---|
101 | |
---|
102 | nf.flux_monitor = 1.e8 |
---|
103 | nf.Q_resolution = "estimate" |
---|
104 | nf.sample_thickness = 1 |
---|
105 | nf.sample_transmission = 0.33476 |
---|
106 | nf.unitssample_thickness = "mm" |
---|
107 | |
---|
108 | nf.namesasinstrument = "NG3-SANS" |
---|
109 | nf.radiation = "neutrons" |
---|
110 | nf.beam_shape = "disc" |
---|
111 | nf.wavelength = 6 |
---|
112 | nf.unitswavelength = "Angstrom" |
---|
113 | nf.wavelength_spread = 14.3 |
---|
114 | nf.unitswavelength_spread="percent" |
---|
115 | |
---|
116 | nf.distance_coll = 10.12 |
---|
117 | nf.unitsdistance_coll = "m" |
---|
118 | nf.source_aperture = 50.00 |
---|
119 | nf.unitssource_aperture = "mm" |
---|
120 | nf.typesource_aperture = "radius" |
---|
121 | nf.unitssample_aperture = "mm" |
---|
122 | nf.typesample_aperture = "radius" |
---|
123 | |
---|
124 | |
---|
125 | nf.offset_angle = 0.00 |
---|
126 | nf.unitsoffset_angle = "deg" |
---|
127 | nf.distance_SD = 9 |
---|
128 | nf.unitsdistance_SD="m" |
---|
129 | nf.beam_centreX=68.46 |
---|
130 | nf.beam_centreY=64.30 |
---|
131 | nf.unitsbeam_centreX = "mm" |
---|
132 | nf.unitsbeam_centreY = "mm" |
---|
133 | nf.pixel_sizeX=5 |
---|
134 | nf.pixel_sizeY=5 |
---|
135 | nf.unitspixel_sizeX = "mm" |
---|
136 | nf.unitspixel_sizeY = "mm" |
---|
137 | nf.detectortype = "ORNL" |
---|
138 | |
---|
139 | nf.nameSASprocess="NCNR-IGOR" |
---|
140 | nf.SASprocessdate = "03-SEP-2006 11:42:47" |
---|
141 | nf.average_type = "Circular" |
---|
142 | nf.SAM_file = "SEP06064.SA3_AJJ_L205" |
---|
143 | nf.BKD_file = "SEP06064.SA3_AJJ_L205" |
---|
144 | nf.EMP_file = "SEP06064.SA3_AJJ_L205" |
---|
145 | nf.DIV_file = "SEP06064.SA3_AJJ_L205" |
---|
146 | nf.MASK_file = "SEP06064.SA3_AJJ_L205" |
---|
147 | |
---|
148 | nf.TSTAND = 1.00 |
---|
149 | nf.DSTAND = 1.00 |
---|
150 | nf.unitsDSTAND = "mm" |
---|
151 | nf.IZERO = 230.09 |
---|
152 | nf.XSECT = 1.00 |
---|
153 | nf.unitsXSECT = "mm" |
---|
154 | |
---|
155 | nf.SASnote = "USER:MASK.COM" |
---|
156 | |
---|
157 | writeNIST(fileName,nf) |
---|
158 | End |
---|
159 | |
---|
160 | Function 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 | |
---|
292 | End |
---|